Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSIS script condition compilation based upon existence of a file

Tags:

nsis

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?

like image 753
Ray Hayes Avatar asked Mar 01 '23 13:03

Ray Hayes


1 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 you are compiling on windows

like image 106
Anders Avatar answered May 09 '23 06:05

Anders