是否可以有条件地向 NSIS 安装程序添加文件/文件夹和安装选项?我的想法是,如果文件夹Foo存在于给定位置,则应将其添加到安装程序中,并且安装Foo的选项也应添加到安装程序中。但是如果文件夹Foo不存在,NSIS 脚本应该只创建安装程序,但保留Foo和从中选择Foo的选项。
问问题
2236 次
3 回答
0
You can try to include a file with /NONFATAL. If it exists, it will be included by the compiler. In runtime, you can check if installer was able to extract it.
File /NONFATAL "file.zip"
${If} ${FileExists} "$OUTDIR\file.zip"
...
${EndIf}
于 2013-03-01T13:41:38.163 回答
0
替换文件的示例,该文件取决于正在运行的服务并且在目标位置是否存在
IfFileExists "$SYSDIR\my_file.dll" exist notexist
exist:
ExecWait 'net stop desired_service'
SetOutPath $SYSDIR
SetOverwrite on
File "/oname=$SYSDIR\my_file.dll" "Path to my file\my_file.dll"
ExecWait 'net start desired_service'
notexist:
.....what you want to do if doesn't exists
于 2020-06-26T12:08:21.327 回答
0
在 NSIS 2File /NONFATAL /R "c:\foo"
中,你可以在没有外部工具的情况下做到最好,当没有文件时,你需要一些技巧来隐藏该部分:
!include LogicLib.nsh
Page Components
Page InstFiles
Section "Main"
SetOutPath $InstDir
# File "C:\myfiles\myapp.exe"
SectionEnd
Section "Install Foo" SID_FOO
SetOutPath $InstDir
File /NONFATAL /r "C:\myfiles\foo\*.*"
SectionEnd
Function .onInit
SectionGetSize ${SID_FOO} $0
StrCmp $0 0 "" +3
SectionSetFlags ${SID_FOO} 0 ; Force all flags off including the checkmark
SectionSetText ${SID_FOO} "" ; Hide the section because its size is 0
FunctionEnd
如果这是不可接受的,您可以使用!system
并从 cmd.exe 获得一些帮助来检查是否存在某些东西:
!tempfile INCEXIST
!system 'if exist "C:\myfiles\foo\*.*" echo !define HAVE_FOO > "${INCEXIST}"'
!include "${INCEXIST}"
!delfile "${INCEXIST}"
!ifdef HAVE_FOO
Section "Install Foo"
SetOutPath $InstDir
File /r "C:\myfiles\foo\*.*"
SectionEnd
!endif
在 NSIS 3!if
中支持 /FileExists 开关:
!if /FileExists "C:\myfiles\foo\*.*"
Section "Install Foo"
SetOutPath $InstDir
File /r "C:\myfiles\foo\*.*"
SectionEnd
!endif
于 2016-03-29T19:41:53.043 回答