🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

NSIS is a good thing

Published April 04, 2005
Advertisement
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 uninstallerIcon "dt_install.ico"UninstallIcon "dt_install.ico"; The file to writeOutFile "setup.exe"; The default installation directoryInstallDir "$PROGRAMFILES\Duck Tiles"; Store the install path so further installs will just overwrite the existing installInstallDirRegKey HKLM "Software\The Code Zone" "Install_Dir"; PagesPage componentsPage directoryPage instfilesUninstPage uninstConfirmUninstPage instfiles; Program installation sectionSection "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 sectionSection "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" 0SectionEnd; Desktop menu shortcuts sectionSection "Desktop Shortcut"  CreateShortCut "$DESKTOP\Duck Tiles.lnk" "$INSTDIR\ducktiles.exe" "" "$INSTDIR\ducktiles.exe" 0SectionEnd; UninstallerSection "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.
Previous Entry Gift card fun
0 likes 3 comments

Comments

Stompy9999
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.
April 04, 2005 09:06 AM
Rob Loach
I'm quite enjoying the installer project wizard that comes with Visual Studio .NET . If you find any other solution, let me know.
April 04, 2005 09:38 AM
MauMan
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...
April 04, 2005 10:59 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement