您的位置:首页 > 其它

NSIS检查磁盘空间不足

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

!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


备忘
The End
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐