Old 4th March 2002, 15:45   #1
paraclete
Junior Member
 
Join Date: Jan 2002
Posts: 24
HowTo: User variables for Name, DirText, File

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

;StrCpy $5 $1 ; <--- This doesn't work
Name $1 ; <-- This doesn't work
OutFile $2.exe ; <--- This doesn't work
InstallDir $PROGRAMFILES\$1
InstallDirRegKey HKLM SOFTWARE\LaSofStuf\$1 "Install_Dir"
DirText "Welcome to the installation/setup program for $1 ver $3"

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"
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
paraclete is offline   Reply With Quote
Old 4th March 2002, 19:23   #2
superrock
Member
 
superrock's Avatar
 
Join Date: Jan 2002
Location: Graz, Austria
Posts: 50
Variables only valid in Sections

Hi,

Sorry, variables are only valid in Sections. Unfortunately this is the standard behavior of this tool.

See documentation(makensis.htm): "Installer attributes"

With the exception of InstallDir, none of these attributes allow use of Variables other than $\r and $\n in their strings.

You must use a preprocessor function for it ( e.g. ${variable} ).

Greetings,
Andreas

superrock is offline   Reply With Quote
Old 4th March 2002, 19:49   #3
paraclete
Junior Member
 
Join Date: Jan 2002
Posts: 24
Thanks for the very prompt reply.

I'm still thinking the 'File' command inside the install section should have worked. Am I doing something wrong there? Should I define a user variable $R1?

I didn't see anything about preprocessing variables. I'll take a relook.

These icons are cool.
paraclete is offline   Reply With Quote
Old 4th March 2002, 22:23   #4
superrock
Member
 
superrock's Avatar
 
Join Date: Jan 2002
Location: Graz, Austria
Posts: 50
File & variables

Hi Paraclete

I really don't know why FIle is not working with variables. The documentations does not disallow to do what you want.

For preprocessing an example for you. For further details refer "Compiler defines/conditional compilation"

;Superrock example
!define VER_MAIN 3
!define VER_MAJOR 0
!define VER_MINOR 91
!define VERSION ${VER_MAIN}.${VER_MAJOR}.${VER_MINOR}
!define APPLNAME TestVars
!define INSTSOURCE V:\

Name ${APPLNAME}
OutFile ${APPLNAME}.exe
InstallDir $PROGRAMFILES\${APPLNAME}
InstallDirRegKey HKLM SOFTWARE\LaSofStuf\${APPLNAME} "Install_Dir"
DirText "Welcome to the installation/setup program for ${APPLNAME} V${VERSION}"

; The stuff to install
Section "${PACKAGE} Program files"

SetOutPath $INSTDIR

File "${INSTSOURCE}\${APPLNAME}.exe"

Strcpy $1 ${APPLNAME}
WriteRegStr HKCU SOFTWARE\MySw\$1\Params "Install_Dir" "$INSTDIR"
WriteRegStr HKCU SOFTWARE\MySw\$1\Params "TestVar1" "$1"
.
.

SectionEnd


Greetings,
Andreas
superrock is offline   Reply With Quote
Old 4th March 2002, 22:41   #5
paraclete
Junior Member
 
Join Date: Jan 2002
Posts: 24
Thanks Andreas!!

I'll post a bug report on 'File'. With just a glance, it looks like maybe I can do something equivalent with !define.

Paraclete
paraclete is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump