Games Explorer Manager Install

From NSIS Wiki

Author: sag47 (talk, contrib)


Download

Games Explorer Manager Install src.zip (98 KB) An installer for the GEM (You must compile it with NSIS).
Zip.gif Games Explorer Manager (871 KB) Here is a link to the GEM without the installer. Which was created by Extensible Software

About

About GEM

The Games Explorer Manager (GEM) is a nice little tool that allows the user to edit the Games Explorer and add their own games or programs (that are already installed) even though Windows Vista didn't already detect them and put it in the list. This is if a user has a game that is so old, not well known that Vista doesn't add it to the games list automatically, or that the developers of the game didn't set up the installer to register with the Vista Games Explorer then this would be a great alternative for someone looking for a quick an easy fix that is simple.

About GEM Installer

This is an installer for the Games Explorer Manager (GEM). This installer is fully compatible with Windows Vista. This installer uses many techniques, concepts, and examples that have been developed over time by the NSIS developers and community. There is a section that will go over the features and functionality of the installer.

Who Created It?

GEM

The Games Explorer Manager (GEM) was developed by a company called Extensible Software. The actual copyright to GEM is held by Andy Chentsov.

GEM Installer

The installer for GEM was created by Sam Gleske (User:sag47).

Instructions

Compiling GEM Installer

  1. Install NSIS using the latest NSIS distrobution.
  2. Then download the GEM Installer source (see Download section of this document)
  3. Extract the source to your desktop ({Desktop})
  4. Now download the Games Explorer Manager (see Download section of this document)
  5. Extract the Games Explorer Manager to your desktop
  6. Copy {Desktop}\GameExplorerManager.exe to {Desktop}\Games Explorer Manager Install src\program
  7. Right click on GameExplorerManager.nsi and click on "Compile NSIS Script"

Reading and understanding the source

Read Documentation
Your first bet is to read through the NSIS documentation and get a feel for how NSIS scripting generally works. I know its a pain to look at for the first time but the more you write scripts and try to may it do things then the easier it gets to look at. Most of your problems can be solved there.

Temporary alternative to reading NSIS help documentation
Go through this entire document/webpage. If you see any command used that you don't understand then copy that command and look it up in the help documentation. By doing this you will develop a strong base for the commands and structure of NSIS. It is much more entertaining to figure out what things mean than it is to simply read the documentation.

Searching for a solution
If you've read through the help documentation then do a wiki search. Now the NSIS wiki search engine isn't that great so I recommend using Google to search the wiki in a format like "My Question site:nsis.sourceforge.net" without the quotes.

For example if you search for "remove shortcuts vista" in the NSIS search then you get nothing. But if you use Google, "remove shortcuts vista site:nsis.sourceforge.net", then you get your answer right away.

Turn to the forum
If after all that you still didn't find out what you want to know or a solution to your problem then search the Community forum. If after searching there you don't find anything then create a username and make a post in the forum and you should see an answer within 24-36 hours.

Concepts used by Installer

Terminology Defined

Header: When I say I'm putting code in the header I mean I am putting it somewhere in the installer script that is not inside of a Function, Macro, or Section.

Sources: At the end of each section of this guide you may see the following types of sources.

  • Internet Source
  • NSIS Documentation Source
  • NSIS Example Source
  • NSIS Forum Source
  • NSIS Wiki Source
  • Other Source
  • Tool Alert

NSIS Documentation and Example sources are located on your computer in the installed directory of NSIS (by default is C:\Program Files\NSIS). All other sources will include a link. A Tool Alert is simply letting the reader (thats you) know about a little trick I did when I was programing and if you click on it then it will redirect you to a list of download links to the tools I used when programming this installer.

  • Tool Alert: I used HM NIS Edit to automatically generate my installer. Then I edited the script that was generated.

Best Compression

Through thorough research and development I've devised a small set of settings that produce the highest possible compression by NSIS.

; Best Compression
SetCompress Auto
SetCompressor /SOLID lzma
SetCompressorDictSize 32
SetDatablockOptimize On

Header

Everything listed in this section shows what is placed in the header. See Terminology for what a header is.

Helper Defines

Defines help to organize the programming as well as speed up changes and production of an installer. The advantages to using helper defines is when you change the text of one define then it changes the text everywhere that define is called.

; helper defines
!define PRODUCT_NAME "Games Explorer Manager"
!define INSTALLER_NAME "setup.exe"
!define PRODUCT_VERSION "1.0.0.6" ; Version must adhere to X.X.X.X standard
!define PRODUCT_PUBLISHER "Extensible Software"
!define PRODUCT_WEB_SITE "http://www.extensiblesoft.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\GameExplorerManager.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
; Refreshing Windows Defines
!define SHCNE_ASSOCCHANGED 0x8000000
!define SHCNF_IDLIST 0
; More Plugins
!addplugindir "res"

Installer File Version

This is where the file version and file info are defined for the installer. I used the header defines to fill most of it out. This is the reason why the version must adhere to the X.X.X.X standard. Note that this must be placed after the language is defined in the script (English in this case).

; File info
VIProductVersion "${PRODUCT_VERSION}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "${PRODUCT_NAME} ${PRODUCT_VERSION}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "${PRODUCT_PUBLISHER}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "${PRODUCT_COPYRIGHT}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "${PRODUCT_NAME} Installer"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${PRODUCT_VERSION}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "OriginalFilename" "${INSTALLER_NAME}"
  • NSIS Example Source: {NSISDIR}\Examples\VersionInfo.nsi

General Installer Info

This is where I customized a lot of my installers attributes and also how it is presented to the user. If you notice, a lot of helper defines are being used (called). So when you change the define all of these values are changed as well.

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "${INSTALLER_NAME}"
InstallDir "$PROGRAMFILES\Games Explorer Manager"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
BrandingText /TRIMRIGHT "Games Explorer Manager Beta 6"
ShowInstDetails show
ShowUnInstDetails show
RequestExecutionLevel admin

.onInit Function

Only allow one installer instance at a time.

This is a nice concept that I got from the NSIS wiki. I modified it a little to fit my needs and then like all users should I updated the wiki to include my modified example so others can benefit.

  BringToFront
; Check if already running
; If so don't open another but bring to front
  System::Call "kernel32::CreateMutexA(i 0, i 0, t '$(^Name)') i .r0 ?e"
  Pop $0
  StrCmp $0 0 launch
   StrLen $0 "$(^Name)"
   IntOp $0 $0 + 1
  loop:
    FindWindow $1 '#32770' '' 0 $1
    IntCmp $1 0 +4
    System::Call "user32::GetWindowText(i r1, t .r2, i r0) i."
    StrCmp $2 "$(^Name)" 0 loop
    System::Call "user32::ShowWindow(i r1,i 9) i."         ; If minimized then maximize
    System::Call "user32::SetForegroundWindow(i r1) i."    ; Brint to front
    Abort
  launch:

Check if already installed.

This is something I custom wrote myself by using common sense and a well rounded knowledge of the Windows Registry. I also used the MessageBox plug-in because it allows a lot of leeway with prompting the user. Now what is going on in the code below is the installer reads the Windows Registry for the location of the Uninstaller for GEM. Then if the Uninstaller exists then the program is installed (if not then it must not be installed so continue with the setup). If install is detected then a custom message box is displayed (using the MessageBox plug-in) and then the user decides whether to cancel the setup or to launch the Uninstaller of the currently installed program.

; Check to see if already installed
  ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Games Explorer Manager" "UninstallString"
  IfFileExists $R0 +1 NotInstalled
  messagebox::show MB_DEFBUTTON4|MB_TOPMOST "Games Explorer Manager" \
	"0,103" \
	"GEM is apparently already installed." \
	"Launch Uninstall" "Cancel"
	Pop $R1
  StrCmp $R1 2 Quit +1
  Exec $R0
Quit:
  Quit
 
NotInstalled:

.onInstSuccess and un.onUninstSuccess Functions

In both of these functions (.onInstSuccess and un.onUninstSuccess) I call the System plugin. What this particular call does is refresh every window the user has (similar to logging out and back in to Windows). The advantage of doing this is if you install icons and create file associations then the user sees the change immediately. I chose to only call it after the successful installation or uninstallation of GEM. If you notice I am calling Helper Defines with ${SHCNE_ASSOCCHANGED} and ${SHCNF_IDLIST}. This method also works in Windows Vista!

; Refresh the System
  System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
  • NSIS Example Source: {NSISDIR}\Examples\makensis.nsi

Modern UI Modification

Icons and Graphics

I wanted to change the default icon and graphic scheme in the Modern UI. Well I had to edit the header of my installer.

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "res\inst.ico"
!define MUI_UNICON "res\inst.ico"
 
; Interface Configuration
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_RIGHT
!define MUI_HEADERIMAGE_BITMAP "res\ge_top.bmp"
!define MUI_WELCOMEFINISHPAGE_BITMAP "res\ge_left.bmp"
  • NSIS Documentation Source: {NSISDIR}\Docs\Modern UI

Custom Page

This section is showing you how I created a custom page in the Modern User Interface.

First I inserted my custom page in where I wanted it to appear in my install process and commented out the pages I don't want the user to see.

; Welcome page
;!insertmacro MUI_PAGE_WELCOME
; License page
!insertmacro MUI_PAGE_LICENSE "program\license.rtf"
Page custom ScreenShotCustom "" ": Screenshot"
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!define MUI_FINISHPAGE_RUN "$INSTDIR\GameExplorerManager.exe"
!insertmacro MUI_PAGE_FINISH
 
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
 
; Language files
!insertmacro MUI_LANGUAGE "English"

Then I modify my .onInit Function to initiate the plugins dir. Extract my custom page, screenshot.ini, and finally write any values into my custom page.

Function .onInit
  InitPluginsDir
  File /oname=$PLUGINSDIR\ScreenThumb.bmp "res\ScreenThumb.bmp"
  ; MUI_INSTALL_OPTIONS_EXTRACT puts the file in $PLUGINSDIR
  !insertmacro MUI_INSTALLOPTIONS_EXTRACT "screenshot.ini"
FunctionEnd

Then in the header I wanted to reserve the custom page screenshot.ini.

ReserveFile "screenshot.ini"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

Then I wrote the page's custom function that allowed me to call the page to appear (ScreenShotCustom).

Function ScreenShotCustom
  WriteIniStr "$PLUGINSDIR\screenshot.ini" "Field 1" "Text" "$PLUGINSDIR\ScreenThumb.bmp"
  !insertmacro MUI_HEADER_TEXT "Game Explorer Manager Beta 6" "Here is a screenshot."
  !insertmacro MUI_INSTALLOPTIONS_DISPLAY "screenshot.ini"
FunctionEnd
  • NSIS Documentation Source: {NSISDIR}\Docs\InstallOptions, {NSISDIR}\Docs\Modern UI
  • NSIS Example Source: {NSISDIR}\Examples\Modern UI\InstallOptions.nsi
  • Tool Alert: I used HM NIS Edit to generate my custom page.

Uninstall Section

In the uninstaller I'm using a neat little trick to delete all files within a folder. *.* means anyfile.anyextension. So when I say Delete "$INSTDIR\*.*" then I mean delete all files in the install dir no matter what the name is.

Section Uninstall
  Delete "$INSTDIR\*.*"
 
  Delete "$DESKTOP\Games Explorer Manager.lnk"
  Delete "$SMPROGRAMS\Games Explorer Manager\*.*"
 
  RMDir /r "$SMPROGRAMS\Games Explorer Manager"
  RMDir /r "$INSTDIR"
 
  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
  SetAutoClose true
SectionEnd

un.onInit Function

Before running the uninstaller I make sure to check that GEM is not running because this means it won't be able to be deleted.

Function un.onInit
  FindWindow $0 "TMainForm" "Game Explorer Manager"
  StrCmp $0 0 Remove
    MessageBox MB_ICONSTOP|MB_OK "It appears that the Game Explorer Manager is currently open.$\n\
                                  Close it and restart uninstaller."
    Quit
Remove:
FunctionEnd

Vista Compatibility

XPStyle on

XP Style must first be turned on in order to ensure the compatibility with RequestExecutionLevel. I can't remember where I read this but when I find it I will post the source. Plus I like my installers to look smooth and not like Windows 2000.

RequestExecutionLevel admin

I want my installer to be run at the admin level in Windows Vista. This way the shortcuts are removed correctly when the program is uninstalled.

Development

TODO:

  • Nothing at the moment

Tools Used

  • NSIS 2.29 as original base (Download latest version)
  • NSIS documentation, faq, forum, and wiki
  • HM NIS Edit as an IDE, The wizard was used to generate the original script. Then the script was modified.
  • I recommend NSIS Plus! which downloads the latest version of NSIS, HM NIS Edit, associates nsi and nsh files with HM NIS Edit, and installs useful plugins for both. (Hint: After installed press Ctrl+G when editing a script in HM NIS Edit)
  • UI SPY to get the window name and class for checking if app is running.

See Also

GEM
Allow only one installer instance
Check whether your application is running during uninstallation
Game explorer
Games plug-in
MessageBox plug-in
Shortcuts removal fails on Windows Vista
UAC plug-in

Personal tools
donate
ads