Skip to content
⌘ NSIS Forum Archive

Required Working Space Warning

18 posts

NSISNUB#

Required Working Space Warning

I looked around quite a bit but couldn't really find what I was looking for, I am also pretty new at NSIS.

In the directory page I have noticed that it will not allow you to install to a drive that does not have enough space the next button will not be enabled. This is good.

However what I am looking to do is warn the user that they might not have enough space after an install to work with the piece of software.

ie. 3.4 GB install on a 4GB drive, I would like to show a popup or warning that says something along the lines of "The free space on chosen location may not be enough to use the software correctly"

I was thinking of something along the lines of doing this:


!define MUI_PAGE_CUSTOMFUNCTION_LEAVE "checkSpaceInstDir"
!insertmacro MUI_PAGE_DIRECTORY

Function checkSpaceInstDir
//Calculating the free drive space here if it is less than a certain threshold ie. 2GB
//Popup a message, with the option of continuing or to Cancel the install
FunctionEnd


Am I way out in left field or will something like this work?


cheers,
MSG#
This will work, but I wouldn't cancel the install. I'd just call abort so the user stays in the directory page to select a different drive.
NSISNUB#
OK sounds good, I am not sure how to compute the remaining drive space though how do I know what directory was selected from the directory page, I am assuming I could use ${DriveSpace} somehow after that????
Animaether#
by default, the selected directory will be copied into the $INSTDIR variable. So you can just get get drive letter from that (See the ${GetRoot} function from the File Functions Header), then pass that on to ${DriveSpace}
MSG#
Keep in mind that you have to use the IntOp64 function of the system plugin, as drive spaces are almost always >4GB.
NSISNUB#
Ok I have computed the drive space from the chosen $INSTDIR, but it's giving me the total drive space from the chosen $INSTDIR, where does the software size value come from in this directory page? If I can get that then I can just subtract it from the $INSTDIR number I am getting and I will have found my solution.

Can I simply just use this for the continue?

MessageBox MB_YESNO "You only have $R1 GB Free of Disk Space do you want to continue?"

Noob question but how do I implement the Abort? so it simply goes back to the directory page?
jpderuiter#
Sorry, but this was discussed a week ago already
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.
NSISNUB#
Yes I read that but I think my problem is a little different. Here is the code snippet.

!define MUI_PAGE_CUSTOMFUNCTION_LEAVE "checkSpaceInstDir"
!insertmacro MUI_PAGE_DIRECTORY

Function checkSpaceInstDir
${GetRoot} $INSTDIR $R0
${DriveSpace} $R0 "/D=F /S=G" $R1
SectionGetSize ${INSTALLER_SPACE} $R2
#$R3 = $R1-$R2 do something like this.
MessageBox MB_YESNO "Free disk space after Install will be $R3 do you want to continue with the Install?"
FunctionEnd

My question is what would the "INSTALLER_SPACE" variable be? the Directory Page knows that size because it doesn't enable the next button until the $INSTDIR is greater than it.
MSG#
Getting the required space is EXACTLY what is discussed in the thread linked by jp. Your problem is not different.
Afrow UK#
The first parameter for SectionGetSize is the zero-based index of the section to get the size of. Rather than specify the index yourself, you can specify a constant of which the Section instruction can define itself (see the docs on Section).

Stu
NSISNUB#
I took the function from the referenced thread, My space required is coming up with 0????

StrCpy $spaceNeeded 0
StrCpy $counter 0
${Do}
${If} ${SectionIsSelected} $counter
SectionGetSize $counter $0
IntOp $spaceNeeded $spaceNeeded + $0
IntOp $counter $counter + 1
${EndIf}
${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"



Is there a way to simply parse what the Directory Page shows? or is there a reason I am getting 0, BTW the Directory Page shows my Space Req being 7.9GB
Afrow UK#
Try putting ClearErrors at the top. Also the IntOp $counter $counter + 1 should be moved to after the ${EndIf} otherwise as soon as it hits an unselected section it will loop infinitely.

Stu
Animaether#
Originally Posted by Afrow UK View Post
Also the IntOp $counter $counter + 1 should be moved to after the ${EndIf} otherwise as soon as it hits an unselected section it will loop infinitely.
Whoops - that was an error in the other thread's post (mine); added an addendum there as well.
NSISNUB#
One more question, why doesn't this work?

${If} $result < X
MessageBox MB_YESNO|MB_ICONQUESTION "The amount of free space after install will be: $result GB$\r$\n \
It is less than what is recommended.$\r$\n \
Do you still want to install to this location?" \
IDNO Abort
${Endif}


It doesn't compile, If yes I want to continue to the next page of the installer, and no I want to abort so it stays at the current page which should work, what is missing?

thanks,
Afrow UK#
If you read the manual on MessageBox it needs labels to jump to, not instructions.

Edit: And you can also do this:
${If} ${Cmd} `MessageBox MB_YESNO|MB_ICONQUESTION 'Call Abort?' IDYES`
Abort
${EndIf}
Stu