Archive: Possible Nsis bug with 'File' and user variables


Possible Nsis bug with 'File' and user variables
I've got several very common installation files. I'd like to use variables so I can !include and call.

I'm having trouble getting user variables to work the way I would think they would/should work. They don't seem to be usable outside a section, so they are unavailable for "Name", "OutFile", "InstallDir", etc. I tried .onInit, which partially works.

Within a Section, they seem to be partially available.
File $1 or File "$1" doesn't seem to work.

WriteRegStr HKCU SOFTWARE\MySw\$1\Params "Install_Dir" "$INSTDIR"
WriteRegStr HKCU SOFTWARE\MySw\$1\Params "TestVar1" "$1"
both work as I would expect.

Am I doing something wrong? Is there another way to accomplish this same functionality? I would like to have MyInstall.nsi as parameterized as possible, perhaps even to the point of using command line arguments. That seems partially possible.

Is there a way to set variables before 'Name', 'OutFile' ?

Below is a TestVars.nsi

Function .onInit
StrCpy $1 "TestVars"
StrCpy $2 "$1Setup.exe"
StrCpy $3 "3.0.91"
StrCpy $4 "V:\$1.exe"
FunctionEnd

Name MyApp
OutFile MyAppSetup.exe
InstallDir $PROGRAMFILES\MyApp
InstallDirRegKey HKLM SOFTWARE\MySw\MyApp "Install_Dir"
DirText "Welcome to the setup program for MyApp ver 3.0.91"

Section "ThisNameIsIgnored"
SetOutPath $INSTDIR
; Put files there
; File $4 <-- This doesn't work

WriteRegStr HKCU SOFTWARE\MySw\$1\Params "Install_Dir" "$INSTDIR"
WriteRegStr HKCU SOFTWARE\MySw\$1\Params "TestVar1" "$1" ; <-- Works
WriteRegStr HKCU SOFTWARE\MySw\$1\Params "TestVar2" "$2"
WriteRegStr HKCU SOFTWARE\MySw\$1\Params "TestVar3" "$3"
WriteRegStr HKCU SOFTWARE\MySw\$1\Params "TestVar4" "$4"

SectionEnd ; end the section

Regards,
Paraclete


What you really want are symbols:

http://www.nullsoft.com/free/nsis/ma...htm#bangdefine

So, you might do:

!define AppName "TestVars"
!define ExeName "${AppName}Setup.exe"
!define Version "3.0.91"
!define LocalPath "V:\${AppName}.exe"

Then, later:

File ${LocalPath}

The problem with using variables is the File command needs to compress and store the file at compile time, but variables aren't defined until runtime.

-H