How to make a Professional Quality Installer
I’ve noticed that many mods either use the Click Team Installer, with that nasty advertisement, or a zipfile with a hideous installation readme of seemingly infinite length. Installation is the user’s first experience with your mod, and you sure don’t want to mess up in the first five minutes!
Here are the things I expect from a professional quality installer:
· A small download size.
· A nice clean looking interface, with nice promo art which will give ma an idea of what to expect from the product.
· The ability to read the installation instructions in my native language. (Which is English for me… but not for all TW players – you get the point )
· The ability to choose any installation directory.
· The ability to download only the components of the mod I want. (Maybe I don’t want to download the 500MB campaign on some obscure nation I don’t know anything about – I’m sure it’s great, but the main campaign will suit me just fine.)
· The ability to download some popular mini-mods as well.
· Web installs are always nice, when they can be provided.
· Icons and shortcuts.
· No ugly advertisements at the end! You can add all of this to your installer without having to pay a penny for commercial software. Here’s how:
First, go to http://nsis.sourceforge.net/Download and download the latest release of the Nullsoft Scriptable Installer. (2.4.1 at the time of the writing of this article) NSIS is a free program with no strings attached. It is not a limited demo or packaged with spyware/adware, so don’t worry about downloading it. Take a look at all of the fancy features in NSIS’s installer. NSIS’s installer is made with… NSIS! NSIS is aimed at programmers: it compiles code written in the NSIS scripting languages into Windows Installers. This tends to scare away a lot of people. You could program your NSIS installers directly, but it’s a lot of repetitive work to do so, and you’d have to learn NSIS’s scripting language. Instead, we’ll download a program which can generate the code for us.
http://hmne.sourceforge.net/index.php#Download Download HM NIS Edit. Once again, this program is completely free with no strings attached.
Open up HM NIS Edit, and choose the New Script from Wizard… option:
You should see a pop up that looks like this:The next pane should look like this:Enter your information (or leave it blank, if you prefer) and hit the Next button.
Now you’ll see this:
If you have an icon you would like to use for your installation program, resize it to 32x32 pixels and convert it to the .ico format with an image editing program, such as Photoshop, or the GIMP. Then enter your icon in the Setup icon field.
The Setup file field is the path to which the output installation program will be saved. Change it to whatever you want, but don’t leave it the default, or you will never figure out where your installer was saved. (Especially on Vista, where it may end up being saved to the Virtual Store.)
Setup lang is the collection of languages which you will allow your users to select when installing. It’s best not to select them all and have your user sort through all of them. Choose the languages your users are most likely to speak. If you are making a mod about Hungary for example, you might want to add Hungarian as a language here. If you are making a general mod which is likely to be used by a large number of people, choose the most widely spoken few languages: English, French, Spanish, and German, should cover about 90% of the people who will use your mod.
Leave the GUI option set to Modern for now. The other two options you should have, Default and Tiny, are pretty ugly, IMO. Later on, you can download more themes from nsis.sourgeforge.net, or even make your own themes.
Compress is the compression method which your installer will use to archive the install data. LZMA is a newer compression method. It’s a nice compromise between speed and size. I’d recommend that you choose LZMA, but your choice compression method won’t have an enormous impact on the performance of your installer.
Okay, that was a lot. Now hit the Next button.
This is what you will see:Application default directory Is the default folder to which the installer will install your mod. Set it to $PROGRAMFILES\SEGA\Medieval II Total War\ as I did. Most of your users will probably have their M2TW installed here. But not all of them, so by no means should you uncheck the Allow user to change the application directory checkbox.
Hopefully you had the forethought to release your mod under a license. If you didn’t, it is probably a good idea to get one. I would recommend releasing your mod under an open source license (since you will be releasing your source in the download anyway). If you want to go open source, try using the MIT, Apache Server, BSD, or GPL licenses. Once you have your license, save it into a plain text file (.txt), or rich text file (.rtf) and select the file under the License file option.
The next option doesn’t make much of a difference: it just specifies how your user should agree to the license.
Here comes the fun part:
This is where you specify the files to be included in the installation. Installation files in Nullsoft are divided into sections. Think of a section as something which could be an individual download. Remember how I said you could let the user choose what they want to download earlier? This is how. First off, check the Allow user to select the components to install box. Next, delete the example files shown in the box to the right. Click on each entry, and then click the delete button above. MainSection is mandatory in every NSIS installation. This is the part of the installation that users must download for the installation to work. In M2TW speak, this equates to the imperial/default campaign.
To set the files for the MainSection, Press the Add directory tree button over the list box on the right. This dialog will pop up:
In the Select Directory field, enter your mod folder. (Before doing so, remove any features you want to keep optional – cut out the files and paste them onto your desktop).
Leave Destination directory to $INSTDIR, or things will be seriously messed up. I don’t think anyone wants your mod in their System32 folder…
Set If file exists to Always overwrite. This will make your installer catch and report errors rather than try to continue if a file fails to install.
Hit the OK button.
Now you should be back to the wizard. Under Description, enter “MyModName Main Campaign”, or something similar.
If you don’t want any optional features in your installer, you are done – skip to the next step. Otherwise, let’s continue:
If you wanted to have optional features, hopefully you cut out the features that were optional and pasted the files onto your desktop. If you didn’t, go back now and do it! And you’ll have to reenter your mod’s directory tree into the MainSection. Now, take the files you put on your desktop, and split them up into the various features, such as campaign 1, campaign 2, extra battle maps, and so on. Put all of these files back into proper M2TW directory trees. You should have one mod folder on your desktop for each feature. In the wizard, create a new section and give it a name. Set the files for the section to the corresponding mod folder on your desktop. Add a description for the section. Rinse and repeat.
The next step is self explanatory. Here are my recommended settings:Up top, you should have the name of your mod. I'd recommend that you check all three of the checkboxes below that. The most important part of this page is the setup. Normally, we would have specified an executable as part of our MainSection, and the wizard would have automatically generated shortcuts for us. Our main executable is medieval2.exe for a M2TW mod, and kingdoms.exe for a Kingdoms mod. Hoever, it is illegal to redistribute these files, so we cannot include them as part of our main section. You'll have to add the shortcuts in manually. Since you don't have an executable to link to, you should make a batch (.bat) file and link to that. Fill in the two entries as I did above.
Next pane:Obviously, if you are using kingdoms, $INSTDIR\medieval2.exe should be $INSTDIR\kingdoms.exe. If you are using a .bat file, set Program to the bat file instead. Otherwise, set Params to @ and your config file. If you have a readme (once again, you should) set Readme to $INSTDIR\myreadmefile.txt. (The readme file should have also been included in your MainSection. If it wasn’t, go back and fix it…)
Don’t forget your uninstaller! (And don’t leave it out on purpose…) It is best to simply leave the first two fields alone. You may want to specify an icon for your uninstaller. (Probably the same one as you used for your installer.)Check the first two boxes and hit Finish. You will be prompted to save the script output. Enter whatever name you like.
You should see something like this now:This is the code that was generated by HM NIS Edit. We’ve only scratched the surface of NSIS, and there is a lot more which can be done by scripting the code manually (actually, you can do pretty much anything.) If there is a demand for a tutorial on more advanced installer techniques, I may write a follow up to this tutorial. But I digress. This tutorial is about the basics. I promised no coding, so what now? Why not hit the compile button?
Now just open up Windows Explorer and go to the folder where you saved your .exe. There’s your installer!