2009-07-09 75 views
4

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

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

有没有办法编译时间“IfExist”类型逻辑?

回答

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 

!注意:这里使用的系统命令假定你是在Windows编译

+0

使用Windows的限制对我来说是可以接受的。我会拿你的代码明天和Kyle一起旋转。谢谢。 – 2009-07-09 18:53:24

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 

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

+0

嗯,在我的情况下,品牌是产品,而不是安装程序,但我可以看到如何把你的机制,用它。当我明天回到办公室时,我会尝试你的解决方案,看看Ander的解决方案。 – 2009-07-09 18:52:00