5

I am making an NSIS script which checks if a previous version of the application is installed. If so, it asks whether or not the configuration file should be imported from this previous version. So I have a global variable config file which I am trying to set at runtime depending on whether the user chooses "yes" or "no". The problem I am having is when compiling it complains with File: "${XMLConfigDir}*.xml" -> no files found. because XMLConfigDir has not been set yet. So is there anyway to set a variable at runtime?

Harry
  • 1,362
  • 12
  • 19

2 Answers2

11

There is difference between declaring variables (Var command) and symbols (defined with !define command):

Var /GLOBAL myVar ; This is variable -> use it as $myVar

!define mySymbol; This is symbol -> use it as ${mySymbol} 

Try this:

!define XMLConfigDir "C:\some_path_to_XML\subdir\"

Section "Main Section" 
        File "${XMLConfigDir}*.xml"
SectionEnd

Symbols can be also set using /D command line switch during installer runtime.

Slappy
  • 5,250
  • 1
  • 23
  • 29
  • /D switch can be also used during compilation as: makensis.exe /DmySymbol="C:\some_path_to_XML\subdir\" script_to_compile.nsi – Slappy Aug 15 '12 at 18:02
  • 1
    Cheers for the info but I don't understand how it answers my question of not being able to use the File command with a variable which is unknown at compile time but determined at runtime. – Harry Aug 16 '12 at 09:48
2

The solution to my problem was to use the CopyFiles built in function rather than the SetOutPath followed by File.

Harry
  • 1,362
  • 12
  • 19