[英]How to check the space in the drive by taking the path from the Destination Folder When installing the software using NSIS
How to check the space in the drive by taking the path from the Destination Folder When installing the software. 安装软件时,如何通过从目标文件夹获取路径来检查驱动器中的空间。
I am able to check the space of the specific drive (for eg, "C") using the below code snippet. 我可以使用下面的代码片段检查特定驱动器的空间(例如“ C”)。
But I want to take the drive or path from the Destination folder dynamically and check the space of the drive whether there is enough space or not. 但是我想从目标文件夹中动态获取驱动器或路径,并检查驱动器的空间是否有足够的空间。
!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
Could anyone please help me 谁能帮我
The built-in directory page ( Page Directory
or !insertmacro MUI_PAGE_DIRECTORY
) will perform the free space check for you and takes care of all the details. 内置目录页面(
Page Directory
或!insertmacro MUI_PAGE_DIRECTORY
)将为您执行可用空间检查并处理所有详细信息。
It might be tempting to just do StrCpy $1 $InstDir 3
to get the drive letter and perform the check yourself but this can give you the wrong result because NTFS supports mounting other volumes as a folder . 仅仅通过
StrCpy $1 $InstDir 3
来获取驱动器号并自己执行检查可能很诱人,但这会给您错误的结果,因为NTFS支持将其他卷作为文件夹挂载 。
GetDiskFreeSpaceEx
does support directory paths but I believe the path has to exist so if you want to use $InstDir before $InstDir has been created then you must chop off subfolders until GetDiskFreeSpaceEx
succeeds (or you only have a invalid drive letter left of the path). GetDiskFreeSpaceEx
确实支持目录路径,但我认为该路径必须存在,因此,如果您想在$ InstDir创建之前使用$ InstDir,则必须斩断子文件夹,直到GetDiskFreeSpaceEx
成功(否则路径的剩余驱动器号无效) 。
Your !define
should also be changed from GetDiskFreeSpaceExA
to GetDiskFreeSpaceEx
because it uses the t
string type. 你
!define
也应该从改变GetDiskFreeSpaceExA
到GetDiskFreeSpaceEx
因为它使用了t
字符串类型。 This will make it Unicode compatible. 这将使其与Unicode兼容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.