Reuse same logic on several files to choose which files to install.
Hello. I'm new to NSIS, but have been searching Wiki, FAQ, manual, forum, and Google for hours and can't make progress. If you can point me in the right direction, thanks.
I have a handful of files. I want them all stuck into the installer, in case they are needed. For each file, I want the installer to check if the destination exists. If it exists, then I want to make a backup by renaming with a .bak extension. If the backup exists, I don't want to touch the backup. I do not want to clobber any files. If there is a backup, and no original (for whatever odd reason), then I'll just install the file, but not touch the .bak.
I have worked out the logic to achieve this. I was trying to stick this logic into a Function or a Macro, so that I could reuse it. This would mean passing the file name as a parameter. I keep getting an error from the File command, because it apparently does not like variables. I have fiddled with the /oname switch, but File still requires a static name at the end.
Wiki Examples 3.2.1 and 3.2.2 clearly show File being passed as a variable inside both a Macro and a Function, which is the first relevant document I read. It appears these examples are incorrect. Or else it fails to demonstrate how to achieve this.
This is the only Section in my .nsi file. The little bit of logic is what I was trying to avoid typing over and over manually, as it is ugly and hard to follow. If there's another way to achieve the same result, I'd be interested to consider that as well. Other syntax, techniques or modules.
Section "-noop"
SetOutPath $INSTDIR
# Logic to Check for Installed and Backups, Rename or Copy
# but never overwrite
IfFileExists "INSTALL.txt" 0 +3
IfFileExists "INSTALL.txt.bak" +3 0 # I B -> !R !C
Rename "INSTALL.txt" "INSTALL.txt.bak" # I !B -> R C
File "INSTALL.txt" # !I B -> !R C - same
# !I !B -> !R C - same
SectionEnd