Archive: Coding 101: How to tell NSIS what files to include in build?


Coding 101: How to tell NSIS what files to include in build?
Just picking up the installer for help with another project. I have looked at sample code, but still do not quite understand how NSIS "knows" what files to include in the install setup. Aside from using the HM NIS Edit wizard, I am still fuzzy on what part of the script describes what files to include.

Would someone be able to link a simple zip that includes the script and say 3 files to be installed into 1 directory? That way i can see how the files are called and stored when the script is compiled.

If there is a better way to describe it, I would not be adverse to seeing it, as well.

Thanks

Gato Muerto


Including a file to the installer:

For including a file to the installer, you can use the command File. The path you supply with this command is the one saying where is the file on your computer. Like for example:

File "Test.exe"
(Include the file "Test.exe" from the folder the script is located and extract it on $OUTDIR (= $INSTDIR in this case) when the user runs it)

Specifying where you want to extract a file:

You can specify where do you want to extract the file by using the command "SetOutDir" before using the file command. Example:

SetOutDir "C:\MyDir"
File "Test.exe"
(Include the file "Test.exe" from the folder the script is located and extract it on $OUTDIR ("C:\MyDir" in this case) when the user runs it)

As you could see above, that first example I showed you is the same exact thing as using:

SetOutDir "$INSTDIR"
File "Test.exe"
(Include the file "Test.exe" from the folder the script is located and extract it on $OUTDIR (= $INSTDIR in this case) when the user runs it)

Including a whole tree of a folder:

There are 2 ways to include every single file inside a folder:

1) Extracting the folder as it is:
File /r "C:\MyDir"
When you extract, it will look like this:

$OUTDIR\MyDir
$OUTDIR\MyDir\Test.exe

2) Extracting all the files contained on a folder to $OUTDIR:
File "C:\MyDir\*.*"
When you extract, it will look like this:

$OUTDIR\Test.exe

Including a whole tree of a folder:

There are 2 ways to include every single file inside a folder:

1) Extracting the folder as it is:
File /r "C:\MyDir"
When you extract, it will look like this:

$OUTDIR\MyDir
$OUTDIR\MyDir\Test.exe
So, when using the file command in this way, it is both telling the script to include these files in the installer, as well as the files to be extracted later? What system do you use if you want to include files into the installer, but yet do not want to have all the files extracted unless specified?
Secondly, does this method above decribed allow for recursive directory storage?

I'm currently using the wizard's setup for calling my files, but I really want to know the how/why it works so I can be a bit cleaner with the code. Long lists of "File XXX" just doesn't look clean enough. Blah

If you write a macro that you can give lots of arguments to then you could end up with something like

!InsertMacro addfiles file01 file02 file03

But it is just a script, not the Sistine Chapel so you could just stick with lots of File commands :)


You can skip the extraction of certain files by jumping over the File commands, e.g.

IfFileExists "$INSTDIR\file.exe" NoExtract
File "/oname=$INSTDIR\file.exe" "file.exe"
NoExtract:

You can also use other flow-control Commands like MessageBox, IntCmp, StrCmp etc

-Stu

Thanks for the help. It still seems a little unwieldy, but I suppose the information has to be included somehow. I prefer clean, organized code, since I tend to get disorganized and confused enough as it is. :D


Comments are your friend, and so is LogicLib.nsh (see Include\LogicLib.nsh).

-Stu