2012-08-16 142 views
1

我对NSIS安装程序脚本完全陌生,我想将安装目录设置为计算机上最大的磁盘。任何人都可以指导我如何去做。查找最大Drive,NSIS安装程序

+0

通常使得使用$ PROGRAMFILES \ YourApp作为默认更有意义...... – Anders 2012-08-16 17:42:11

+0

你应该还记得卷可以安装在NTFS的文件夹中,因此只需检查驱动器号就可能找不到最大的卷... – Anders 2012-08-16 17:45:25

回答

2
!include LogicLib.nsh 
System::Call 'kernel32::GetLogicalDrives()i.r0' 
StrCpy $1 $windir 3 ; Fallback if things go wrong 
StrCpy $2 0 
StrCpy $4 65 ; 'A' 
loop: 
    IntOp $3 $0 & 1 
    ${If} $3 <> 0 
     IntFmt $3 "%c:\" $4 
     System::Call 'kernel32::GetDiskFreeSpaceEx(tr3,*l.r5,*l,*l)i' 
     ${If} $5 L> $2 
      StrCpy $2 $5 
      StrCpy $1 $3 
     ${EndIf} 
    ${EndIf} 
    IntOp $4 $4 + 1 
    IntOp $0 $0 >> 1 
    StrCmp $0 0 "" loop 
StrCpy $InstDir "$1" ;You should probably append something to the path here, you cannot install to the root of a drive by default 

放入.onInit或目录页面预回调...

+0

此代码检查可用空间,因为安装程序以这种方式更有意义,它将避免只读卷... – Anders 2012-08-16 17:46:44

+0

伟大的作品!我完成了安装部分。安装可执行文件后,我需要提示用户插入另一张DVD来安装实用程序。你能指导我怎么做 – sam 2012-08-17 18:41:52

+0

如果它与这个问题无关,那么你应该问一个新的问题(并接受这个答案,如果它是正确的) – Anders 2012-08-17 18:51:40