-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|171|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Article Home -> Presentation and Organisation


 
Afr0
Created : 03 April 2012
Edited : 03 April 2012
System : Windows
Language : Forth

Scripting installers with NSIS

Learning the NSIS-script language

If you need an installer for your game, you probably need it to be customisable so that it can do the things you want. Don't worry - NSIS to the rescue!

The scripting language used by NSIS is quite simple, and though the syntax isn't the best, it is easy to understand and learn.

Let's look at some code...



First of all, you should include "LogicLib.nsh". It contains if, elseif and endif macros (I know, the language doesn't come with these!!)
The Name command specifies the name of your installer as it appears when the user starts it.
The OutFile command specifies the name of the created executable.
RequestExecutionLevel is used for Vista and Win7 to request an execution level under UAC.
I'm actually not sure what the Page command does, but I believe it adds a predefined dialog to the installer.
You can use the Var command to create variables. These are not type-specific.

In order to implement functions, you can use the Function command. Functions can also override globally available functions. For instance, .onInit is executed as the installer starts up.



As you can see, reading the registry is a piece of cake! The ReadRegStr command takes three parameters;

  • A string to read into
  • The registry folder to read
  • The key to read!

  • $INSTDIR is a global string that can be used to keep track of the installation directory.
    There's also $PROGRAMFILES, $PROGRAMFILES32 and $PROGRAMFILES64 to keep track of where "Program Files" is on the current computer.

    You can split an installation into sections using the Section command;



    Here you can see that there's another global variable called $TEMP that keeps track of where a Windows' temp directory is.
    The File command is perhaps the most important command in the language. When the compiler encounters it, it takes the specified file and compresses it into the final executable. However, upon script execution, this command extracts that very same file to wherever SetOutPath was pointed to.
    ExecWait pauses the installation and executes the specified executable - this is mostly useful for executing installers for libraries that your game/program depends upon.

    Below is an example of a section that creates a bunch of different folders and extracts a bunch of different files into them;


     

    Comments