Since I recently went through this I thought I’d try to help out the next person out there, below are steps how you can turn your compiled code into an installer.
Step 1: download and install NSIS
http://nsis.sourceforge.net/Main_Page
NSIS is a great FOSS (free open source software) for creating installers.
Step 2: download and install HM NIS Edit
http://hmne.sourceforge.net/
This is a FOSS NSIS editor. Which includes a wizard which makes the whole process much easier for a beginner.
Step 3:
Open up HM NSIS, and click File, then click New Script from Wizard. The wizard will let you fill in the usual application name, who made it, web site address etc. Everything is basically self explanatory or leave as it is (default options).
Default options are ok here.
When you get to the “Application directory and license” window, the thing to consider here is that Windows 7 and Windows XP have different security settings, by default HM NSIS Edit has the install directory to be “Program Files” then whatever your program is called. In Windows 7 (and probably Vista) installing to the programs directory could cause you some security headaches as without altering some permissions Windows 7 won’t let the software user write to this directory. So for example if you have a save game file or configuration file that your program needs to write, this will give you a headache. So in my case I just made the default directory to be C:MyProgramName instead and put in a note for Windows 7 and Vista users not to install to the Program Files directory. Ideally you would code your game to save to the user profile to bypass this, but for now this was my quick solution.
Suggestion: change the install directory to avoid security issues
Next up is the “Application Files” window, here click on the “Add directory tree button” and select your “Release” folder (assuming you are using Microsoft Visual Studio) or whichever folder where all your game files are (make sure all your paths and config files that point to paths match this hierarchy). This will tell NSIS to pack these files into your installer and to copy them into the directory that the user specified in the previous steps.
If your application has no further requirements you are basically done, you could click next and then compile the file (by clicking the appropriate button on the HM NSIS editor). However if like me you do have some other requirements you can use this window to assist in getting those installed as well. In my case I need to ensure that the user has proper DirectX files. So first I downloaded the DirectX redistributable file (google: microsoft DirectXend-user runtimes) then download the standalone installer (you could also take the web installer [if you are sure your user will be connected to the internet], however there is some debate whether this violates the end user license agreement). Once you download the redistributable, extract it to some easy to find directory. Now in HM NSIS Edit (still in the Application Files screen) click “New Group” name this group “Dependencies” or “Requirements” (we create a new group so that HM NSIS Edit doesn’t get confused as to what your application executable is [if you add it to the main group, it may think that Directx setup file is your main app], plus to keep things clean and organized) or whatever, and add the folder with the DirectX files to your application as well. HINT: to cut down on the download size you can eliminate the x64 files (which are for 64 bit applications) if your app is 32bit (see this link: http://msdn.microsoft.com/en-us/library/ee416805(v=vs.85).aspx). You can now finish up in HM NSIS Edit wizard by clicking next and filling out the other self explanatory options.
Add your release folder and all required media via these steps.
You can also add DirectX setup files via similar steps.
Ok now we are in the editor itself and not in any wizard, go to the new group (they are called “Sections” now, so find “Section “Requirements” SEC02″ (as it appears in my expample) then scroll down and insert the line below before “Section End”) you created and after the files are copied add this line
ExecWait “$INSTDIRdxsetup.exe /silent
This will tell NSIS to call the DirectX setup in silent mode, it will ensure that all the files in this particular redistributable (there are different versions that get released over time) get updated into your operating system. Now that we have updated these files we don’t need the redistributable files anymore, so lets delete them rather than keeping them on the user’s hard drive. To do this scroll down to the “Uninstall” section of the NSIS script and cut the Delete file parts of DirectX, and paste them right after the dxsetup.exe /silent.
Bonus hint: because this takes a while you can tell your users that it does so as to not have them wondering if the application crashed, here is how you can do this: insert this line before the “dxsetup.exe” command -> DetailPrint “Updating DirectX this may take a few moments…”
There we’ve just updated DirectX and made sure that our user doesn’t have to be bothered with these steps. Now if like me you are using Visual Studio the user may (depends on operating system) also need the Microsoft Visual Studio 2008 runtimes (vcredist_x86.exe for 32 bit apps and vcredist_x64.exe for 64bit apps). NOTE: there are different runtimes for the different versions of Visual Studio (eg: 2005, 2008 etc) so be sure to get the right one you need. Once you download this file put it somewhere safe. Now we’ll tell NSIS to pack this file into the installer and to run it right after the DirectX setup.
In my case adding this line does the trick:
ExecWait ‘C:SDEVDownloadsvcredist_x86.exe /q:a /c:”VCREDI~1.EXE /q:a /c:”"msiexec /i vcredist.msi /qn”" “‘
If you notice the location of my vcredist_x86.exe file is C:SDEVDownloads etc, so yours will vary, but this is enough for NSIS to pack the file and then run it in silent mode (see this blog for more info: http://blogs.msdn.com/b/astebner/archive/2007/02/07/update-regarding-silent-install-of-the-vc-8-0-runtime-vcredist-packages.aspx).
Since we aren’t copying this file to the user’s folder there’s no need for further cleanup. Go ahead and compile the file and then test it on some other PC than your own, now you can see what your user will see when they try to install your app, hopefuly it works great and they’ll have a trouble free installation.
BONUS OGRE HINTS:
Because Ogre applications tend to use a “Media” directory (where all your graphics, sound, gui etc, resources tend to be) and a resources.cfg files and because you have both a debug and release directory, here is what I did. I took my Media directory and moved it underneath the Release folder. Now I took the resources.cfg file in the Release folder and pointed it towards this new location.
So for example usually the resources.cfg files look like this:
FileSystem=../../media
FileSystem=../../media/fonts
FileSystem=../../media/materials/programs
FileSystem=../../media/materials/scripts
FileSystem=../../media/materials/textures
etc… etc…
Change them to:
FileSystem=media
FileSystem=media/materials/programs
FileSystem=media/materials/scripts
FileSystem=media/materials/textures
etc… etc… in the release folder (since the Media directory is now in the Release folder)
and
FileSystem=../Release/media
FileSystem=../Release/media/materials/programs
FileSystem=../Release/media/materials/scripts
FileSystem=../Release/media/materials/textures
etc… etc… in the Debug folder (pointing them at the Release folder Media folder which we moved).