NSIS script compilation of conditions based on file existence

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

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

Is there a way to make “IfExist” type logic to compile?

+4
source share
2 answers
!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 that you are compiling on windows

+6
source

I have no answer to your general question about file detection during compilation, but I have a solution to how it sounds, how you are trying to execute.

My installers use something like this:

In the CustomBranding.nsh file:

 !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 this the type of “alternative branding” you are asking about?

+2
source

All Articles