NSIS检查磁盘空间不足

NSIS检查磁盘空间不足,转载自:http://stackoverflow.com/questions/989172/how-can-i-check-free-space-during-a-nullsoft-silent-install

<textarea cols="50" rows="15" name="code" class="cpp:nogutter:nocontrols">!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 </textarea>  

备忘
The End 

你可能感兴趣的:(NSIS检查磁盘空间不足)