Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I wrote a function called <code>CheckFreeSpace</code> in NSIS to do this. Unfortunately it has the following limitations:</p> <ul> <li>To compute the size of all the sections in your installation, you have to modify <code>CheckFreeSpace</code> to add each section, by knowing each variable that each section id was written into. I can't find a way of iterating over all sections that will be installed using NSIS.</li> <li>Installation drive must be computed because <code>${DriveSpace}</code> requires a drive letter, not a path to an arbitrary directory. The drive letter string is computed with <code>StrCpy $instdrive $INSTDIR 3</code>. If the <code>$INSTDIR</code> variable is a relative path or does not begin with a string such as <code>C:\</code>, this will fail.</li> <li>If the installation cannot continue it produces a <code>MessageBox</code>. You can suppress the <code>MessageBox</code> by adding <code>/SD IDOK</code> at the end of the statement, but then the user is not informed of the installation failure: I can't find a way to emit to <code>stdout</code> from NSIS. Perhaps the return code from the installer is enough?</li> <li>If the disk free space is really low (like 10kb), the installer won't run at all; it doesn't have space to unpack its temporary DLL's into the <code>\tmp</code> directory.</li> </ul> <p>Also, in my implementation below, <code>CheckFreeSpace</code> has a hardcoded value for the space free after installation. Obviously that can be parameterized.</p> <p>Here it is within a sample installer:</p> <pre><code>!include FileFunc.nsh !insertmacro DriveSpace Name "CheckFreeSpace" OutFile "C:\CheckFreeSpace.exe" InstallDir C:\tmp\checkfreespace Page instfiles Section "install_section" install_section_id Call CheckFreeSpace CreateDirectory $INSTDIR SetOutPath $INSTDIR File "C:\installme.bat" WriteUninstaller "$INSTDIR\Uninstall.exe" DetailPrint "Installation Successful." SectionEnd Section "Uninstall" RMDIR /r "$INSTDIR" SectionEnd Function CheckFreeSpace var /GLOBAL installsize var /GLOBAL adjustedinstallsize var /GLOBAL freespace var /GLOBAL instdrive ; Verify that we have sufficient space for the install ; SectionGetSize returns the size of each section in kilobyte. SectionGetSize ${install_section_id} $installsize ; Adjust the required install size by 10mb, as a minimum amount ; of free space left after installation. IntOp $adjustedinstallsize $installsize + 10240 ; Compute the drive that is the installation target; the ; ${DriveSpace} macro will not accept a path, it must be a drive. StrCpy $instdrive $INSTDIR 3 ; Compute drive space free in kilobyte ${DriveSpace} $instdrive "/D=F /S=K" $freespace DetailPrint "Determined installer needs $adjustedinstallsize kb ($installsize kb) while $freespace kb is free" IntCmp $adjustedinstallsize $freespace spaceok spaceok MessageBox MB_OK|MB_ICONSTOP "Insufficient space for installation. Please free space for installation directory $INSTDIR and try again." DetailPrint "Insufficient space for installation. Installer needs $adjustedinstallsize kb, but freespace is only $freespace kb." Abort "Insufficient space for installation." spaceok: DetailPrint "Installation target space is sufficient" FunctionEnd </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload