tags:

views:

431

answers:

2

I have an NSIS based installer that I need to be able generate slightly different versions of under different conditions.

The conditions are easy to establish at compile time, if a particular file exists on the disk then the alternative branding can be used. I know I could use a command-line option to the makensis.exe to provide this behaviour, but it would be better if the compiler could take care of this for me.

Is there a way of making a compile time "IfExist" type logic?

+2  A: 

I don't have the answer to your generic question of compile-time file detection, but I do have a solution to what it sounds like you're trying to accomplish.

My installers use something like this:

In the file CustomBranding.nsh:

!define CUSTOM_BRANDING
!define APPNAME "Brand X"
!define LOGO "C:\Brand_X_Logo.png"

In the main installer script:

!include /NONFATAL "CustomBranding.nsh"
!ifndef CUSTOM_BRANDING
    !define APPNAME "Generic"
    !define LOGO "C:\Generic_Logo.png"
!endif

Is that the kind of "alternative branding" you're asking about?

Kyle Gagnet
Well, the branding in my case is to the product rather than the installer, although I can see how to take your mechanism and use it. I shall try your solution and look at Ander's solution when I get back in the office tomorrow.
Ray Hayes
+3  A: 
!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

Note: the !system command used here assumes you are compiling on windows

Anders
The limitation of using Windows is acceptable for me. I shall take your code for a spin tomorrow, along with Kyle's. Thanks.
Ray Hayes