• Advertisement
  • entries
    1212
  • comments
    1738
  • views
    1143710

NSIS is a good thing

Sign in to follow this  

82 views

On my to-do list for Duck Tiles is "make the DT installer". I had just figured on using the old (and I do mean old) tried-n-true "Baby InstallShield that comes with VC++ 6", but I thought it might be time to look at something new. There's Microsoft's built-in MSI installer, but I also want to target Windows 98 and it'd be a bit of a stretch to require the user to install an MSI runtime that's larger than the actual game install.

My needs are simple. I need to copy one EXE file with no other runtime DLL's (because I rule). I need to install a shortcut to the start menu and (optionally) to the desktop. Upon uninstall, I need to remove those files along with some stuff in the registry that the game creates to track progress.

In other words, I need about the simplest install possible.

The baby-InstallShield solution is certainly tried and true. I shipped tens of thousands of games with it and can't recall any install-related problems, so that's a front-runner. Only problem is that it doesn't compile installs to a single EXE, which is the norm nowadays. I've got a later InstallShield Express that was free in PCPlus magazine, but if I install that I'll have to get a serial number from the site, which will guarantee a salesbot calling me to upgrade to a later version.

So I checked out free solutions. I had a buncha old bookmarks, but everything on my list was either gone, in "maintenance mode", or went commercial.

NSIS wasn't a very good solution when I last looked at it several years ago. It was really more of a glorified self-exploding ZIP than a full install program. It's grown up quite a lot since then. It's still quite simple, but is also very extensible.

The thing I like best about it, though, is its scripting. Rather than having some kind of "project file" containing links to all of the files to pack into an EXE, the program just scans your installer script and packs in all of the files that you specify in your code.

That means that my entire installer/uninstaller is built from this little bit of easy-to-follow code.

Name "Duck Tiles"
SetCompressor LZMA

; The icon for the installer and uninstaller
Icon "dt_install.ico"
UninstallIcon "dt_install.ico"

; The file to write
OutFile "setup.exe"

; The default installation directory
InstallDir "$PROGRAMFILES\Duck Tiles"

; Store the install path so further installs will just overwrite the existing install
InstallDirRegKey HKLM "Software\The Code Zone" "Install_Dir"

; Pages
Page components
Page directory
Page instfiles

UninstPage uninstConfirm
UninstPage instfiles

; Program installation section
Section "Duck Tiles Game"
SectionIn RO
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
File "ducktiles.exe"
; Write the installation path into the registry
WriteRegStr HKLM "SOFTWARE\The Code Zone\Duck Tiles" "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Duck Tiles" "DisplayName" "Duck Tiles"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Duck Tiles" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Duck Tiles" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Duck Tiles" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd

; Start menu shortcuts section
Section "Start Menu Shortcuts"
SectionIn RO
CreateDirectory "$SMPROGRAMS\Duck Tiles"
CreateShortCut "$SMPROGRAMS\Duck Tiles\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortCut "$SMPROGRAMS\Duck Tiles\Duck Tiles.lnk" "$INSTDIR\ducktiles.exe" "" "$INSTDIR\ducktiles.exe" 0
SectionEnd

; Desktop menu shortcuts section
Section "Desktop Shortcut"
CreateShortCut "$DESKTOP\Duck Tiles.lnk" "$INSTDIR\ducktiles.exe" "" "$INSTDIR\ducktiles.exe" 0
SectionEnd

; Uninstaller
Section "Uninstall"
; Remove registry keys that the game created
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Duck Tiles"
DeleteRegKey HKLM "SOFTWARE\The Code Zone\Duck Tiles"
DeleteRegKey /ifempty HKLM "SOFTWARE\The Code Zone"
; Remove files and uninstaller
Delete $INSTDIR\ducktiles.exe
Delete $INSTDIR\uninstall.exe
; Remove shortcuts, if any
Delete "$SMPROGRAMS\Duck Tiles\*.*"
Delete "$DESKTOP\Duck Tiles.lnk"
; Remove directories used
RMDir "$SMPROGRAMS\Duck Tiles"
RMDir "$INSTDIR"
SectionEnd



One thing I also recommend if you get NSIS is the free HM NIS Edit. It's a little editor that can compile your install script and display error messages. NSIS is a command-line kind of thing, but this thing eliminates your need to see it.

Took me all of about two hours to put together the install program for Duck Tiles.

I'm now a convert.
Sign in to follow this  


3 Comments


Recommended Comments

I was considering using NSIS for my current project. I've seen alot of things that use it so I figured it might be good.

Share this comment


Link to comment
I'm quite enjoying the installer project wizard that comes with Visual Studio .NET . If you find any other solution, let me know.

Share this comment


Link to comment
I hate the Visual Studio installer projects with a passion but it does have the good quality of being updated with your builds. I've used NSIS (1.x) in the past and have been quite happy with it.

Maybe with a utility project I could get the best of both worlds with NSIS. The new one looks alot nicer than the old one...

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement