我有一个基于NSIS的安装程序,我需要能够在不同的条件下生成略有不同的版本。
在编译时很容易建立条件,如果磁盘上存在特定文件,则可以使用替代品牌。我知道我可以使用makensis.exe的命令行选项来提供这种行为,但如果编译器可以为我处理这个问题会更好。
有没有办法让编译时“IfExist”输入逻辑?
答案 0 :(得分:6)
!macro CompileTimeIfFileExist path define
!tempfile tmpinc
!system 'IF EXIST "${path}" echo !define ${define} > "${tmpinc}"'
!include "${tmpinc}"
!delfile "${tmpinc}"
!undef tmpinc
!macroend
Section
!insertmacro CompileTimeIfFileExist "$%windir%\explorer.exe" itsThere
!ifdef itsThere
MessageBox mb_Topmost yes
!else
MessageBox mb_Topmost no
!endif
SectionEnd
注意:此处使用的!system命令假设您正在编译Windows
答案 1 :(得分:2)
我对编译时文件检测的一般性问题没有答案,但我确实找到了你想要完成的解决方案。
我的安装程序使用类似的东西:
在CustomBranding.nsh文件中:
!define CUSTOM_BRANDING
!define APPNAME "Brand X"
!define LOGO "C:\Brand_X_Logo.png"
在主安装程序脚本中:
!include /NONFATAL "CustomBranding.nsh"
!ifndef CUSTOM_BRANDING
!define APPNAME "Generic"
!define LOGO "C:\Generic_Logo.png"
!endif
这是你要问的那种“另类品牌”吗?