• entries
1212
1738
• views
1145138

NSIS is a good thing

88 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 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.

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.

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

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...

Create an account

Register a new account