使用 NSIS 安装软件时,如何通过从目标文件夹获取路径来检查驱动器中的 space

How to check the space in the drive by taking the path from the Destination Folder When installing the software using NSIS

如何在安装软件时通过从目标文件夹中获取路径来检查驱动器中的space。

我可以使用以下代码片段检查特定驱动器的 space(例如,"C")。

但我想动态地从目标文件夹中获取驱动器或路径,并检查驱动器的 space 是否有足够的 space 。

!define sysGetDiskFreeSpaceEx 'kernel32::GetDiskFreeSpaceExA(t, *l, *l, *l) i'    
function CheckSpaceFunc
      IntCmp  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  / 1024
      Pop 
      ; check space
      System::Int64Op  > [=11=]
      Pop 
    functionend


    Section "TestApp"

      SectionIn RO


      StrCpy [=11=] 40000 ; kb u need
      StrCpy  'c:' ; check drive c: for space
      Call CheckSpaceFunc
      IntCmp  1 okay
      MessageBox MB_OK "Error: Not enough disk space"
      okay:

    SectionEnd

谁能帮帮我

内置目录页面(Page Directory!insertmacro MUI_PAGE_DIRECTORY)将为您执行免费 space 检查并处理所有细节。

直接执行 StrCpy $InstDir 3 获取驱动器号并自行执行检查可能很诱人,但这可能会给您错误的结果,因为 NTFS supports mounting other volumes as a folder.

GetDiskFreeSpaceEx 确实支持目录路径,但我相信路径必须存在,所以如果你想在 $InstDir 创建之前使用 $InstDir,那么你必须切断子文件夹,直到 GetDiskFreeSpaceEx 成功(或者路径左侧只有一个无效的驱动器号)。

您的 !define 也应该从 GetDiskFreeSpaceExA 更改为 GetDiskFreeSpaceEx,因为它使用 t 字符串类型。这将使它与 Unicode 兼容。