Archive: $INSTDIR with a variable


$INSTDIR with a variable
Alrighty, let's see if I can explain this properly. In my script I set variables for commonly used words like the directory where I have the files installed to. So first I do this..

# Macro
!macro setVars ;sets variables for the start page and the folder which contains the shortcut icon.
StrCpy $1 "MyProgram" ;Sets the name for the install dir.

!macroend

Then, further down the script I have my install directory setup like this..

# Installer attributes
OutFile "E:\Temp\Releasing\MyFile.exe"
InstallDir "$DOCUMENTS\$1"

Below that, I have

Function .onInit
!insertmacro setVars
FunctionEnd

With the .onInit loading with the Welcome page.

In theory, the installer should default to My Documents\MyProgram, but it doesn't. When you first get to the directory page all you see in the text field is the path to My Documents. If you browse to a new folder or drive, the "MyProgram" bit is added to the end, but if you just hit next without browsing, everything is dumped into the My Documents folder. I can rectify this by changing the variable in the InstallDir path to say "$DOCUMENTS\MyProgram" but the program name is different between programs and I like just using one script for all of them, and I just edit the variables for the different programs.

Do I need to add some different variables? Maybe change the placement of the Function? Start the .onInit function somewhere else? If you have any clue, please let me know.

I've attached my .nsi file to this post, it's a frankenstein script and I know it's messy but it does what it's ( mostly ) supposed to do.

Thanks to all in advance.


And it seems I can't even attach a file, it's no wonder I can't seem to script an installer...


The value from InstallDir is processed before .onInit is called. You should manually copy a new value to $INSTDIR in .onInit.

Function .onInit
StrCpy $INSTDIR $DOCUMENTS\MyProgram
FunctionEnd

That explains it, thanQ very much.