[英]How to check the space in the drive by taking the path from the Destination Folder When installing the software using NSIS
安裝軟件時,如何通過從目標文件夾獲取路徑來檢查驅動器中的空間。
我可以使用下面的代碼片段檢查特定驅動器的空間(例如“ C”)。
但是我想從目標文件夾中動態獲取驅動器或路徑,並檢查驅動器的空間是否有足夠的空間。
!define sysGetDiskFreeSpaceEx 'kernel32::GetDiskFreeSpaceExA(t, *l, *l, *l) i'
function CheckSpaceFunc
IntCmp $2 0 ignorequota
; obey quota
System::Call '${sysGetDiskFreeSpaceEx}(r1,.r2,,.)'
goto converttokb
; ignore quota
ignorequota:
System::Call '${sysGetDiskFreeSpaceEx}(r1,.,,.r2)'
converttokb:
; convert the large integer byte values into managable kb
System::Int64Op $2 / 1024
Pop $2
; check space
System::Int64Op $2 > $0
Pop $2
functionend
Section "TestApp"
SectionIn RO
StrCpy $0 40000 ; kb u need
StrCpy $1 'c:' ; check drive c: for space
Call CheckSpaceFunc
IntCmp $2 1 okay
MessageBox MB_OK "Error: Not enough disk space"
okay:
SectionEnd
誰能幫我
內置目錄頁面( Page Directory
或!insertmacro MUI_PAGE_DIRECTORY
)將為您執行可用空間檢查並處理所有詳細信息。
僅僅通過StrCpy $1 $InstDir 3
來獲取驅動器號並自己執行檢查可能很誘人,但這會給您錯誤的結果,因為NTFS支持將其他卷作為文件夾掛載 。
GetDiskFreeSpaceEx
確實支持目錄路徑,但我認為該路徑必須存在,因此,如果您想在$ InstDir創建之前使用$ InstDir,則必須斬斷子文件夾,直到GetDiskFreeSpaceEx
成功(否則路徑的剩余驅動器號無效) 。
你!define
也應該從改變GetDiskFreeSpaceExA
到GetDiskFreeSpaceEx
因為它使用了t
字符串類型。 這將使其與Unicode兼容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.