4

我有一个基于 NSIS 的安装程序,我需要能够在不同条件下生成稍微不同的版本。

这些条件在编译时很容易建立,如果磁盘上存在特定文件,则可以使用替代品牌。我知道我可以使用 makesis.exe 的命令行选项来提供这种行为,但如果编译器可以为我处理这个问题会更好。

有没有办法制作编译时“IfExist”类型的逻辑?

4

2 回答 2

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 上编译

于 2009-07-09T18:43:34.463 回答
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

你问的是那种“另类品牌”吗?

于 2009-07-09T13:38:56.217 回答