Setting a variable at run time
Asked Answered
M

2

7

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?

Marte answered 15/8, 2012 at 12:33 Comment(0)
M
3

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

Marte answered 17/8, 2012 at 12:25 Comment(0)
A
13

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.

Amblygonite answered 15/8, 2012 at 16:51 Comment(2)
/D switch can be also used during compilation as: makensis.exe /DmySymbol="C:\some_path_to_XML\subdir\" script_to_compile.nsiAmblygonite
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.Marte
M
3

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

Marte answered 17/8, 2012 at 12:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.