Archive: Are "space required" and "space available" in variables somewhere?


Are "space required" and "space available" in variables somewhere?
These pop up when I specify output directory, but are they available in variables?

I want to make a message box that says "this is going to take up xGB of hard drive space, are you sure you want to continue?"

(And I want to express it in terms of GB not Kb.)


I'm not sure if they happen to get stored in variables - I don't think so, though.

If you're already on the directory page, then you could just steal them out of the labels and parse them from there.

Alternatively, and more flexible, you can use SectionGetSize to get the size of a section - just add all of the sections that the user selected up to get the total kilobyte count - just divide by 1000000 or 1048576 to get GB or GiB), and ${DriveSpace} from the File Functions header (See the help file) to get the available space on a drive.

Edit: SectionGetSize returns kilobyte, not byte -_-


something like this...


!include "LogicLib.nsh"
!include "FileFunc.nsh"

...

Var counter
Var spaceNeeded
Var spaceAvailable

Function someFunction
StrCpy $spaceNeeded 0
StrCpy $counter 0
${Do}
${If} ${SectionIsSelected} $counter
SectionGetSize $counter $0
IntOp $spaceNeeded $spaceNeeded + $0
${EndIf}
IntOp $counter $counter + 1
${LoopUntil} ${Errors}
System::Int64Op $spaceNeeded / 1048576 ; GiB
Pop $spaceNeeded
${GetRoot} "$INSTDIR" $0
${DriveSpace} "$0\" "/D=F /S=G" $spaceAvailable ; G = GiB
MessageBox MB_OK "Install dir: $INSTDIR$\r$\nSpace required: $spaceNeeded$\r$\nSpace available: $spaceAvailable"
FunctionEnd

Thanks! It works for the Space Available very well.

But, if the total installation is less than 1GB it outputs 0.

Is there anyway of it outputting 0.4GB for example


${DriveSpace} is described in the manual:
http://nsis.sourceforge.net/Docs/AppendixE.html#E.1.4

If you change the /S=G part of the command to /S=K then the result will be shown in kilobytes instead of Gigabytes. If you really want to display 0.4 GB then you'll need to do some more work.


Just correcting an error in my earlier post (Can no longer edit) pointed out in another thread.. whoops.

The counter increase should be inside the loop, not inside the section selected conditional handling.


${Do}
${If} ${SectionIsSelected} $counter
SectionGetSize $counter $0
IntOp $spaceNeeded $spaceNeeded + $0
${EndIf}
IntOp $counter $counter + 1
${LoopUntil} ${Errors}