brainz
14th June 2001 10:42 UTC
A quick question ....
I'm trying to use variables as a part of the name of files that are to be installed
So let us change example1.nsi as follows:
; The name of the installer
Name "Example1"
; The file to write
OutFile "example1.exe"
; The default installation directory
InstallDir $PROGRAMFILES\Example1
; The text to prompt the user to enter a directory
DirText "This will install the very simple example1 on your computer. Choose a directory"
; The stuff to install
Section "ThisNameIsIgnoredSoWhyBother?"
; Set output path to the installation directory.
SetOutPath $INSTDIR
;Set $1 to be the location of the files to install
StrCpy $1 c:\WINNT
; Put file there
File $1\notepad.exe
SectionEnd ; end the section
; eof
When I do the compile step, I get the following :
File: "$1\notepad.exe" -> no files found.
Usage: File (/r filespec [...]|/oname=outfile one_file_only)
Am I missing something, or is my syntax wrong, or are variables not allowed in the File statement ?
Any help gratefully accepted ...
TIA
tim
Edgewize
14th June 2001 11:57 UTC
The argument to the File command is the local path to the file when you are building the installer, not the path that will be used when the user runs it. You could try using the /ONAME="blah" flag for File (see the HTML documentation for NSIS) but it may not work across directories. What you really want is to use the SetOutPath command:
SetOutPath $1
File "c:\windows\notepad.exe"
brainz
14th June 2001 14:31 UTC
Not sure that you understand why I want to use a variable. I understand totally that the argument to File is the local path when the installer is collecting the files to build the install ...
Suppose I have a long list of files that get installed (>10), and for each new build in the development environment, we put them in a new directory, identified by a new build number, so current release compiled code ends up in
c:\files\devt\app\v1.2\release
and then for my next release it ends up in
c:\files\devt\app\v1.3\release
Suppose I keep the nsi script in c:\files\devt\app, then I will have to modify >10 lines which say
v1.2\release\filename1
v1.2\release\filename2
v1.2\release\filename3
v1.2\release\filename4 ...
Whereas if I could use a variable, in the code I could use
StrCpy $1 v1.3\release
and
File $1\filename1
File $1\filename2
File $1\filename3
File $1\filename4 ...
I am trying to reduce the chance of a developer getting a release wrong by ensuring that the script has to be changed in the minimum number of places. I guess a better solution is to put the .nsi file in
c:\files\devt\app\v1.2\release
and then use
File filename1
File filename2
File filename3
File filename4 ...
which is what I will probably do ... but from a code control perspective I'd like to be able to do the above ...
(Note I'm clear that none of this affects where the file ultimately gets installed by the installer that is built !!)
Also from the documentation, it suggests that you might be able to do this, under Variables it says
"The following are variables that are usable in Instructions"
and under "Instructions - General purpose, basic instructions" we find File.
To me this suggest that you might be able to do it.
Perhaps this is a bug, perhaps not ... depends on your view...
Don't take any of this the wrong way Edge, I think NSIS is a great piece of software, and the comments I make are just things I notice that I think are worth comment ...
Keep up the great work ...
thanks
tim
Edgewize
14th June 2001 18:07 UTC
Doh, I understand. The *local* directory name is a variable. I get it now :D
Try the !cd change-local-directory-during-the-compile command. I don't think that variables are expanded while compiling, only while the installer is running, but you could use
!cd "c:\files\devt\app\v1.2\release"
before the File commands, and it should work just fine.