20.4 NSIS-Windows Installer

20.4 NSIS-Windows Installer

Any complete and developed game needs to be distributed to an audience. Some gamers might have to enter a store and purchase the game, and others may be able to download the game from the Internet and play immediately. Regardless, the game needs to install itself onto the computer. Most applications do this through an installer, which is responsible for not only successfully configuring a product to run, but also for providing options to uninstall if the user decides to remove the software.

Some developers create their own installation programs, while others pay for a commercial product to do this for them, but there is also the option of using a free, open-source SDK to develop installation software. One of the SDKs available to do this is NSIS.

NSIS (Nullsoft Scriptable Install System), created by Nullsoft, offers a comprehensive suite of tools for building install applications. NSIS can be downloaded from http://www.nsis.sourceforge.net/. The following sections explore how NSIS works.

NSIS includes a comprehensive list of features described in the following list:

  • Generates self-contained executable installers

  • Supports zlib, bzip2, and LZMA data compression

  • Contains uninstall support

  • Offers both Classic and Modern wizard interfaces

  • Includes multiple install configurations (usually Minimal, Typical, Full, and Custom)

  • Uses CRC32 checksum to self-verify installer

  • Able to display license agreement in text or RTF format

  • Able to detect destination directory from the registry

  • Allows installers as large as 2 GB

  • Includes optional silent mode for automated installations

  • Completely free for any use

  • Installers have their own VMs that let you write code to support file/directory copying, renaming, deletion, searching, and more


For a complete list of features, please visit the NSIS website.

20.4.1 Scripted Installs

To build installation programs NSIS uses a scripting language, whose details are included in the SDK documentation. A scripting language is much like any ordinary programming language, such as C++, but is often easier to use and is dedicated to controlling one specific application. In this case, the NSIS scripting language is intended to be used for creating installation programs.

The language can be written in any text editor, from Notepad to Code::Blocks, and the files should be saved with an .nsi extension. Using the scripting language it's possible to define all the different wizard pages a user needs to navigate in order to install the application. It's possible to include a license page, an install components page, a directory selection page, and so on.

Once the script is complete and defines the pages, all the files needed to be installed, and any other properties, then the script can be compiled by the NSIS compiler. Like a C++ compiler, the NSIS compiler assembles the scripted code into an executable form so the installer can be run and used like any normal application. In short, you do not need to distribute your script files to the users. Only the completed, compiled install application needs to be distributed.

20.4.2 Writing a Script

Using the NSIS scripting language a wide variety of installation programs can be written, and the language offers great versatility in defining how an installation is presented to a user. Let's examine a sample script to see how an installation can be built.

In NSIS the semicolon character (;) precedes a comment in the same way a double slash (//) precedes a comment in C++. And as in C++, all NSIS comments are there for the benefit of the programmer and are ignored by the compiler.

      ; this is an NSIS comment 

Most NSIS scripts begin by defining the name of the installation. This is achieved by defining a variable called Name. For example, a game called "Super Shooter" might have an NSIS install name of "Super Shooter Install." The name is something to be decided upon by the programmer and is usually something suitable to the product.

      Name "Super Shooter Install" 

All NSIS scripts should define an output variable. This a file name such as "test.exe," which tells the compiler what file name to assign the compiled installation program.

      OutFile "super_shooter_install.exe" 

Next, an install application often defines an InstallDir variable. This variable decides the default installation folder to which the product is to be installed. If the folder selection dialog is presented to the user during the install, then the user will be able to change this path by selecting a different folder.

      InstallDir $PROGRAMFILES\Super_Shooter 

image from book
Figure 20.3

After a series of variables have been defined, the pages of the install can be set. Pages refer to the different screens a user will need to navigate when running the installation wizard. These can be the license screen, the folder selection screen, the components install screen, and so on. The following example defines two pages:

      Page directory      Page instfiles 

One of the final parts in a basic script file is the section block. A script file can have many sections, and each section defines a group of files to install. In more complex installations the user might be able to pick and choose between specific groups of files, such as Minimum, Standard, and Maximum installations. For this simple install, however, only one group is defined, and this group tells the compiler which files to install.

      Section ""      SetOutPath $INSTDIR      File test.nsi      SectionEnd 

The entire sample script file would look as follows:

      ; example1.nsi      ;      ; This script is perhaps one of the simplest NSIS you can make. All of the      ; optional settings are left to their default settings. The installer simply      ; prompts the user asking him or her where to install, and drops a copy of      ; example1.nsi there.      ;--------------------------------      ; The name of the installer      Name "Example1"      ; The file to write      OutFile "example1.exe"      ; The default installation directory      InstallDir $PROGRAMFILES\Example1      ;--------------------------------      ; Pages      Page directory      Page instfiles      ;--------------------------------      ; The stuff to install      Section "" ; No components page, name is not important       ; Set output path to the installation directory.       SetOutPath $INSTDIR       ; Put file there       File example1.nsi      SectionEnd ; end the section 

20.4.3 Compiling a Script

Compiling an NSIS script is a simple process. Click with the right mouse button on the specified script file to compile. The standard shortcut menu appears with the option "Compile NSIS Script." Select this to begin the compilation process.

20.4.5 Running an Installer

Once compiled, an installer can be run much like any other application. In Figure 20.4, the installer is being taken for a test run and a number of files are about to be installed.

image from book
Figure 20.4

Introduction to Game Programming with C++
Introduction to Game Programming with C++ (Wordware Game Developers Library)
ISBN: 1598220322
EAN: 2147483647
Year: 2007
Pages: 225
Authors: Alan Thorn

Similar book on Amazon
Beginning C++ Through Game Programming
Beginning C++ Through Game Programming
Beginning Game Programming
Beginning Game Programming
The Ultimate Guide to Video Game Writing and Design
The Ultimate Guide to Video Game Writing and Design

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net