1 / 76

Sega 500

Sega 500. More Advanced NSIS. Jeff “Ezeikeil” Giles jgiles@artschool.com http://gamestudies.cdis.org/~jgiles. More on NSIS. As I eluded to last day, the NSIS is an insanely powerful.

cyma
Télécharger la présentation

Sega 500

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sega 500 More Advanced NSIS Jeff “Ezeikeil” Giles jgiles@artschool.com http://gamestudies.cdis.org/~jgiles

  2. More on NSIS • As I eluded to last day, the NSIS is an insanely powerful. • To demonstrate that, we’re going to run with it some more and create some new NSI scripts that edit the registry, create uninstallers and edit ini files.

  3. Adding Registry Entries • Thus, getting down to it, editing the Registry is the first step to creating an uninstaller. • In effect, we store some data in it which we can later access to find out what files we put where.

  4. Adding Registry Entries • So first, a quick look at what the registry looks like. • You can access yours by typing regedit at the command prompt.

  5. Adding Registry Entries Stored values Registry keys

  6. Adding Registry Entries • The NSIS gives us acronyms for accessing these: HKCR or HKEY_CLASSES_ROOT HKLM or HKEY_LOCAL_MACHINE HKCU or HKEY_CURRENT_USER HKU or HKEY_USERS HKCC or HKEY_CURRENT_CONFIG HKDD or HKEY_DYN_DATA HKPD or HKEY_PERFORMANCE_DATA

  7. Adding Registry Entries • Having a quick look we see that we can store all sorts of information in here. • My UT 2003 reg entry:

  8. Adding Registry Entries • Now, you can edit this by hand if you like by right clicking the REF_SZ value, but this IS playing with fire... You will likely break stuff. • The registry is how windows know what, and where things are!

  9. Adding Registry Entries • So what tools does NSIS give us then? • Well, if you refer to the docs, there’s a list of like a dozen items. We don’t need all of this functionality so we’ll just look at what we are going to use here.

  10. Adding Registry Entries • InstallDirRegKey is the first item we need. • This attribute tells the installer to check a string in the registry, and use it for the install dir if that string is valid.

  11. Adding Registry Entries • If this attribute is present, it will override the InstallDir attribute if the registry key is valid, otherwise it will fall back to the InstallDir default.

  12. Adding Registry Entries • Usage: InstallDirRegKey HKLM SOFTWARE\EZE_INSTALL "Install_Dir" Registry path Which key to install under Value name

  13. Adding Registry Entries • What this gives us… A variable to store our path in A new registry directory under local machine

  14. Adding Registry Entries • HKLM: is HKEY_LOCAL_MACHINE key and we’ll be using this the most. • However, there’s no reason why you couldn’t store some of your data elsewhere.

  15. Adding Registry Entries • SOFTWARE\EZE_INSTALL is literally the path in the registry (under HKLM) where to store our data • And the Install_Dir is the variable we create to hold out install path. It’s currently uninitalized.

  16. Editing Registry Entries • Next we’ll need to set our value with WriteRegStr • Simply writes a string into the registry. • Notice the path and parameter is the same as above. WriteRegStr HKLM SOFTWARE\EZE_INSTALL "Install_Dir" "$INSTDIR"

  17. Editing Registry Entries • In this case, we store the path to our install directory. WriteRegStr HKLM SOFTWARE\EZE_INSTALL "Install_Dir" "$INSTDIR"

  18. Editing Registry Entries • So the next step towards building an uninstaller is to let the windows uninstaller know about it.

  19. Editing Registry Entries • We achieve this by adding uninstall information into the windows uninstall registry. SoftwareMicrosoftWindowsCurrentVersionUninstall

  20. Editing Registry Entries • We simply use the same WriteRegStr command and specify a different path WriteRegStr HKLM "Software\Microsoft\Windows\ CurrentVersion\Uninstall\Goober" "DisplayName" " EZE Installer (REMOVE ME)"

  21. Editing Registry Entries • However in this case, we need to define our uninstall string also. WriteRegStr HKLM "Software\Microsoft\Windows\ CurrentVersion\Uninstall\Goober" "UninstallString" '"$INSTDIR\uninstall.exe"'

  22. Creating the Uninstaller • The actual creation of the uninstaller surprisingly simple…a one liner. • Where uninstall.exe is the desired name of the output uninstall program. WriteUninstaller "uninstall.exe"

  23. Creating the Uninstaller • Well, yeah, this will create the program for us, but it’s won’t do anything because we’ve not told it about where to get it’s uninstall information.

  24. Creating the Uninstaller • Well, funnily enough, NSIS has commands for this too: • DeleteRegKey: • Deletes a registry key. If “/ifempty” is specified, the registry key will only be deleted if it has no subkeys (otherwise, the whole registry tree will be removed).

  25. Creating the Uninstaller • So, in this case, we’ll need to specify DeleteRegKey command for both our dir and the windows uninstall dir.

  26. Creating the Uninstaller • Notice the paths are the same as when we used the WriteRegStr. Windows uninstall dir DeleteRegKey HKLM "Software\Microsoft\Windows\ CurrentVersion\Uninstall\Goober" DeleteRegKey HKLM SOFTWARE\EZE_INSTALL Our Install registry entry

  27. Creating the Uninstaller • And this will do just what it promises and remove the entries in the registry. • But what about the files? An uninstaller is no good if we don’t get ride of those!

  28. Creating the Uninstaller • To simply delete a file is nothing more than: Delete $INSTDIR\Goober\Notepad.exe • Delete command: • Delete file (which can be a file or wildcard, but should be specified with a full path) from the target system.

  29. Creating the Uninstaller • Hrmmm…”Wild card”? • Sure we can delete files one by one…But that’s lame. If we go back to the old DOS prompt days, we would use * operators to indicate “all”

  30. Creating the Uninstaller • So if we go with the *.* we tell it the delete all files with any postfix • Will purge everything in this folder. • This also works for copying. Delete $INSTDIR\Goober\*.*

  31. Creating the Uninstaller • So then we just need to get ride of the uninstaller program and the directory. Kill off the uninstaller Delete $INSTDIR\uninstall.exe RMDir "$INSTDIR\Goober Remove the folder

  32. Creating the Uninstaller • RMDir command: • Remove the specified directory (which should be a full path). • Without /r, the directory will only be removed if it is completely empty. • If /r is specified, the directory will be removed recursively, so all directories and files in the specified directory will be removed.

  33. Creating the Uninstaller • So lets whip one up, and from there we’ll look at Editing ini files with NSIS • But this time, lets use something other than notepad to get started…

  34. Slate Blue • I discovered this great scripting tool called Slate Blue which is super handy for setting up your nsi scripts. • There are 2 versions both available from http://www.morphedmedia.com/ …both are free.

  35. Slate Blue • Version 1.0 is a really handy GUI for creating simple nsi scripts that can save you from the mundane tasks of setup…like name and color and what not.

  36. Slate Blue • Then there’s version 1.07 which is a really nice scripting program which allows you to create and edit nsi scripts. • However, the last time I looked, it was a bit unstable.

  37. Slate Blue • Not to mention that it has a full list of NSIS commands in the left window. • The right side is where you do your scripting…very handy.

  38. Editing INI files • So on with INI files

  39. Editing INI files • Once again, the actual editing of an existing ini file is surprisingly easy and NSIS have given us a nice tool to do it. • WriteINIStr • Writes entry_name=value into [section_name] of ini_filename. The error flag is set if the string could not be written to the ini file.

  40. Editing INI files • In other words, this will seek a section head in a file and add an entry. • Eg, if I wanted to add an entry to section [public] in test.ini I could use

  41. Editing INI files Section name [public] File name and full path WriteINIStr $INSTDIR\Goober\test.ini public "num1" "Something 1" Variable name Value to be set

  42. Editing INI files • Note: You can also use the WriteINIStr to create an ini file that is of the name in the path.

  43. Editing INI files • OK, this is good and all, but there has to be some way to not have to enter ALL the ini edit commands into the installer… • ’cause all that typing would suck.

  44. Editing INI files • Rest easy, there is. • We can read from existing ini files using the ReadIniStr.

  45. Editing INI files Section name [public] to read from File name and full path ReadIniStr $1 "C:\...Folder\READtest.ini" Mo "num" Variable name to read Register in which to store the data

  46. Editing INI files • Ok great, we can read from one file to another…one line at a time…still lots of typing involved in this. • But NSIS as you recall has piles of functionality with it. We can do string operations and even branching!

  47. Editing INI files • So here’s what I have in mind. We’ll read data from an existing ini and store it in a variable. • We’ll then copy this data from the variable into the target ini file. • Loop until we reach the end of the read file.

  48. Editing INI files • The data will be appended to the end of the test.ini file. • The only requirement in this case is that the variables in the read file must be named similar to num1, num2, num3…numX.

  49. Editing INI files • Functionally, this is a really simple loop with a counter.

  50. Editing INI files • Some functionality that we’ll need: • StrCpy • Sets the user variable $x with str. Note that str can contain other variables, or the user variable being set (concatenating strings this way is possible, etc).

More Related