Good stuff - nice to have a tutorial for new users.
However, the NSIS-script in the tutorial is somewhat too complicated, and some of the stuff is not really needed to make a usable .exe. I've got a working .nsi-script half as large as Ghrey's. I can even trim down the basic script with the necessary functions to 12 lines, as opposed to Ghrey's 71. I'll post that at the bottom of this tutorial. But we don't have to go that far - some of the functions I left out are rather nifty. So, I'll go through the script section by section:
# [Installer Attributes]
# The bits in quotes are what your mod's name is. This'll be displayed at the top of the setup window.
Name "The Indira NPC for BG1 Tutu"
# The outfile is what your .exe will be named. I put v(blank).exe at the end, so I can manually enter the version number, rather than changing it in the script file all the time.
OutFile "IndiraNPC_v.exe"
Caption ""
BrandingText ""
Here, we can drop the two last lines completely. With having [Caption ""] and [BradingText ""], the NSIS-installer will be using the default settings, so this is not necessary.
# [Additional Installer Settings ]
ShowInstDetails show
AutoCloseWindow false
SilentInstall normal
CRCCheck on
SetCompress auto
SetDatablockOptimize on
SetOverwrite on
The only thing that is not-default here is the first line; [ShowInstDetails show], which means that the details of the installing-process will be shown. If you want the user to see this, let that line remain, and delete the others, as they are unnecessary.
# [Background Gradient]
# The background gradient is... uh, yeah, the background gradient. Search online for some sort of html colour code. I forget how to do it, but my installers use a dark to light green shading. Not that FFFFFF is not it. I just don't want people stealing my colour. I'm pretty sure FFFFFF is either pure white or pure black.
BGGradient FFFFFF FFFFFF FFFFFF
This isn't really necessary either, but provides a nice touch. As Ghrey hinted, this will set the background (i.e. cover the whole screen) with some sort of colour. To explain what Ghrey forgot, the
first row of colour-code is the TOP colour, the
second row of colour-code is the BOTTOM colour. So, if you have two different colours here, the first colour on top will gradient down to the second colour at the bottom. The
third row of colour-code is the colour of the TEXT viewed (by default in the upper left corner). The text is the same as the [Name] from the beginning of the script, i.e. The Indira NPC for BG1 Tutu for this tutorial.
If you don't add this line, there will be no background, and only the little grey box containing all the necessary info will be show. It's just a matter of preference.
# [Files]
Section "default"
SetOutPath $INSTDIR
# This stuff is the files and folders that will be compressed in your .exe. The /r switch means it'll copy the entire folder and its subfolders. NOTE: When you finally run the .nsi through MakeNSISw, be sure you don't have a backup folder with files in it. Either move them temporarily, or uninstall your mod via WeiDU before running the .nsi.
File "C:\games\bgtutu\Setup-IndiNPC.tp2"
File "C:\games\bgtutu\Setup-IndiNPC.exe"
File "C:\games\bgtutu\Setup-IndiNPC.bat"
File /r "C:\games\bgtutu\IndiNPC"
SectionEnd
This section is rather important. Leave it as it is.
# [Directory Selection]
# Not sure what this does, honestly. I think it's superceded by the entry below.
InstallDir "$PROGRAMFILES\BG1Tutu\"
As Ghrey suggests, this is superceded by the next section. Cut.
# [Finding the BGII install path]
# This will scan your registry for the BG2Main.exe entry, and thus find the path to BG2. I'm sure BioWare has the registry keys for the other games online somewhere. IWD and BG1 and whatnot.
InstallDirRegKey HKLM \
"Software\Microsoft\Windows\CurrentVersion\App Paths\BG2Main.Exe" \
"Path"
I've used [InstallDirRegKey HKLM "SOFTWARE\Microsoft\DirectPlay\Applications\Baldur's Gate2" "Path"] instead of searching for BG2Main.exe. They do the exact same thing, they both find the BGII-dir, only mine's a bit shorter.
# DirShow show
# This is a message that will be displayed at the "choose your destination" screen. It'll warn the end user that the path provided might be wrong. This is probably only an issue for users who've done multiple installs (i.e. one for Tutu, one for BG2 itself). Assuming they're literate enough to do a multiple install, they're also literate enough to know what the two paths are. One would hope, anyways. As the saying goes, when you make assumptions, you make an "ass" out of "u" and... um, "mumptions".
DirText "Your Baldur's Gate Tutu path has been detected. If it's different from what's shown, you'll have to enter the path manually."
Not much to say here, either. If you leave this out, the installer won't ask for a directory, but install to the default install-directory immediatly. So, please - do - not - remove - this.
;called when the installer is nearly finished initializing
Function .onInit
;message box
# This'll display whatever you write here when the user first clicks the .exe.
MessageBox MB_YESNO "This will install The Indira NPC for BG1 Tutu. Continue?" IDYES NoAbort
Abort
NoAbort:
FunctionEnd
One of those nifty functions I talked about earlier. Keep it. Not vital, however.
;called when the user hits the 'cancel' button
Function .onUserAbort
# Change the "Abort install?" to whatever you please. Pretty self-explanatory.
MessageBox MB_YESNO "Abort install?" IDYES NoCancelAbort
Abort
NoCancelAbort:
FunctionEnd
Also an useful function, however less nifty than the previous. Definently not necessary, though.
;called when the install was successful
Function .onInstSuccess
# Here's a critical bit. Remember that .bat file we made earlier? This is the file that will get run once installation is complete. It should automatically call setup-mod.exe, and if setup-mod.exe needs to update itself, the .bat will instruct the end user to hit the enter key twice. If you don't want to bother with the .bat step, you can put setup-mod.exe in this field, as well.
Exec "$INSTDIR\Setup-IndiNPC.bat"
FunctionEnd
Critical bit? Yes. Has to be done this way? No.
This is how I do it; instead of putting this in a new function, I put the [Exec "$INSTDIR\Setup-IndiNPC.bat"] in the Section we previously had called "Default". Remember that one, with all the files? Yes, there. The difference is little, but noticeble: With Ghrey's .onInstSuccess-function, the installer will execute the .bat when the user presses "Close" on the installer. With my method, the installer will execute it right after it has copied all the files over to the game-directory. It's really just a matter of preferences. My way is simpler, shorter and makes it feel as if the WeiDU-installation is a part of the general installation, i.e. the IndiraNPC_v.exe-installation. So, I've chosed to do it my way.
While we're on it, there's three another optional functions I'd like to recommend, that Ghrey hasn't brought up. First, we have:
LicenseText "Readme:"
LicenseData readme.txt
I've usually put this after the OutFile-entry.
This opens up a nice little 'Licence'-box, where the text from readme.txt is displayed, and the user must press an 'I agree'-button before they can proceed. Great for showing shorter readme's or other instructions.
Then, we have:
ComponentText "This will install the following features on your computer."
This, I usually put after the Licence-stuff.
Now, what does this do? Well, it creates a checklist with all the different [Sections] we have in the script. This is very useful for larger scripts with different optional sections. To put it short, the user can check and uncheck the different contents of the installer, and choose what to install. The name displayed will be what Ghreyfain has named "default", in other words the word or sentenced specified after the [Section] in the script.
Then, we have:
MessageBox MB_OK "Woooo!!! Install successful!!! Enjoy!!!"
Put this after the [Exec "$INSTDIR\Setup-IndiNPC.bat"] if you have this line in a section (as I described above), or in an .onInstSuccess-function.
This will show a nice little messagebox with an "Okay"-button saying "Woooo!!! Install successful!!! Enjoy!!!" when the install is complete.
Naturally, there's a lot of more available functions and features and other fun and usefull stuff. But this is the basics.
So, to move on to the 12-lined script I promised earlier. This is a basic script covering all the necessary stuff for the installer. All other things are optional and not really needed, this is enough to get a working installer.
Name "SConrad's supermod with a NSIS-installer!"
OutFile "Foo.exe"
DirText "Choose your game directory:"
InstallDirRegKey HKLM "SOFTWARE\Microsoft\DirectPlay\Applications\Baldur's Gate2" "Path"
Section "default"
SetOutPath $INSTDIR
File /r "Foo"
File "Setup-Foo.exe"
File "Setup-Foo.tp2"
File "Setup-Foo.bat"
ExecWait "$INSTDIR\SETUP-Foo.bat"
SectionEnd
Note that in order to get this script to be functional by NSIS, you must put the .nsi-script in the same folder as where you have all the files, and then run the script with the MakeNSISW from that location.
Now, what will this little thing do?
Well, when the user clicks the Foo.exe, they will be asked to specify their game-directory, with the one from the registry as default. When they click 'Install', the installer will copy over all files to the game-directory and then automatically execute the .bat-file. The WeiDU-installation will follow, and when that is done, all that is left is the NSIS-installer, which will say 'Completed' and the user can close it. Install is finished!
Do you really, desperatly, need anything more than that?