Archive: Required Working Space Warning


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,


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.


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????


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}


Keep in mind that you have to use the IntOp64 function of the system plugin, as drive spaces are almost always >4GB.


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?


SectionGetSize. Abort goes back to a page when called in the page's leave function.

Stu


SectionGetSize of what though?


Sorry, but this was discussed a week ago already
http://forums.winamp.com/showthread.php?t=321448


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.


Getting the required space is EXACTLY what is discussed in the thread linked by jp. Your problem is not different.


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


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


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


Thanks, that worked.


Originally posted by Afrow UK
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.

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,


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