Games Explorer Manager Install: Difference between revisions
No edit summary |
|||
(67 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{PageAuthor|sag47}} | |||
= Download = | = Download = | ||
<attach> | <attach>Games Explorer Manager Install src.zip</attach> An installer for the GEM (You must compile it with NSIS).<BR> | ||
[[File:Zip.gif]] [http://www.extensiblesoft.com/gamex/GameExplorerManager10beta6.zip Games Explorer Manager] (871 KB) Here is a link to the GEM without the installer. | [[File:Zip.gif]] [http://www.extensiblesoft.com/gamex/GameExplorerManager10beta6.zip Games Explorer Manager] (871 KB) Here is a link to the GEM without the installer. Which was created by [http://www.extensiblesoft.com/gamex/ Extensible Software] | ||
= About = | = About = | ||
== About GEM == | == 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. | The Games Explorer Manager ([http://www.extensiblesoft.com/gamex/ 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 == | == About GEM Installer == | ||
Line 15: | Line 16: | ||
=== GEM Installer === | === GEM Installer === | ||
The installer for GEM was created | The installer for GEM was created by [http://www.pages.drexel.edu/~sag47/ Sam Gleske] ([[User:sag47]]). | ||
= Instructions = | |||
== Compiling GEM Installer == | |||
# Install NSIS using the latest NSIS distrobution. | |||
# Then download the GEM Installer source (see [[#Download|Download]] section of this document) | |||
# Extract the source to your desktop (''{Desktop}'') | |||
# Now download the Games Explorer Manager (see [[#Download|Download]] section of this document) | |||
# Extract the Games Explorer Manager to your desktop | |||
# Copy ''{Desktop}\GameExplorerManager.exe'' to ''{Desktop}\Games Explorer Manager Install src\program'' | |||
# Right click on ''GameExplorerManager.nsi'' and click on "Compile NSIS Script" | |||
== Reading and understanding the source == | |||
'''Read Documentation'''<BR> | |||
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'''<BR> | |||
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'''<BR> | |||
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 [http://www.google.com 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 [http://www.google.com Google], "remove shortcuts vista site:nsis.sourceforge.net", then you get your answer right away. | |||
'''Turn to the forum'''<BR> | |||
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 = | = 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 | |||
* [[#Tools Used|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 [[#Tools Used|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. | |||
* [[#Tools Used|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. | |||
<highlight-nsis>; Best Compression | |||
SetCompress Auto | |||
SetCompressor /SOLID lzma | |||
SetCompressorDictSize 32 | |||
SetDatablockOptimize On</highlight-nsis> | |||
== Header == | |||
Everything listed in this section shows what is placed in the header. See [[#Terminology Defined|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. | |||
<highlight-nsis>; 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"</highlight-nsis> | |||
=== 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). | |||
<highlight-nsis>; 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}"</highlight-nsis> | |||
* 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. | |||
<highlight-nsis>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</highlight-nsis> | |||
== .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. | |||
<highlight-nsis> 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:</highlight-nsis> | |||
* NSIS Wiki Source: [[Allow only one installer instance]] | |||
=== 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. | |||
<highlight-nsis>; 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:</highlight-nsis> | |||
* NSIS Wiki Source: [[MessageBox plug-in]] | |||
== .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|Helper Defines]] with ''${SHCNE_ASSOCCHANGED}'' and ''${SHCNF_IDLIST}''. This method also works in Windows Vista! | |||
<highlight-nsis>; Refresh the System | |||
System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'</highlight-nsis> | |||
* 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. | |||
<highlight-nsis>; 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"</highlight-nsis> | |||
* 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. | |||
<highlight-nsis>; 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"</highlight-nsis> | |||
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. | |||
<highlight-nsis>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</highlight-nsis> | |||
Then in the header I wanted to reserve the custom page ''screenshot.ini''. | |||
<highlight-nsis>ReserveFile "screenshot.ini" | |||
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS</highlight-nsis> | |||
Then I wrote the page's custom function that allowed me to call the page to appear (''ScreenShotCustom''). | |||
<highlight-nsis>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</highlight-nsis> | |||
* NSIS Documentation Source: ''{NSISDIR}\Docs\InstallOptions'', ''{NSISDIR}\Docs\Modern UI'' | |||
* NSIS Example Source: ''{NSISDIR}\Examples\Modern UI\InstallOptions.nsi'' | |||
* [http://nsis.sourceforge.net/Games_Explorer_Manager_Install#Tools_Used 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. | |||
<highlight-nsis>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</highlight-nsis> | |||
== 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. | |||
<highlight-nsis>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</highlight-nsis> | |||
* NSIS Wiki Source: [[Check whether your application is running during uninstallation]] | |||
* [[#Tools Used|Tool Alert]]: I used UI Spy to get the Window Class and Window Title. | |||
== Vista Compatibility == | |||
<highlight-nsis>XPStyle on</highlight-nsis> | |||
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. | |||
<highlight-nsis>RequestExecutionLevel admin</highlight-nsis> | |||
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. | |||
* NSIS Wiki Source: [[Shortcuts removal fails on Windows Vista]], [[UAC plug-in]] | |||
= Development = | |||
=== TODO: === | |||
* Nothing at the moment | |||
=== Tools Used === | |||
* NSIS 2.29 as original base ([[Download]] latest version) | |||
* NSIS documentation, faq, forum, and wiki | |||
* [http://hmne.sf.net/ HM NIS Edit] as an IDE, The wizard was used to generate the original script. Then the script was modified. | |||
* I recommend [http://www.pages.drexel.edu/~sag47/uharc/NSIS-Installer.zip 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) | |||
* [http://www.download.com/UI-SPY/3000-2094_4-10520066.html UI SPY] to get the window name and class for checking if app is running. | |||
== See Also == | |||
[http://www.extensiblesoft.com/gamex/ GEM]<BR> | |||
[[Allow only one installer instance]]<BR> | |||
[[Check whether your application is running during uninstallation]]<BR> | |||
[[Game explorer]]<BR> | |||
[[Games plug-in]]<BR> | |||
[[MessageBox plug-in]]<BR> | |||
[[Shortcuts removal fails on Windows Vista]]<BR> | |||
[[UAC plug-in]]<BR> | |||
[[Category:Real World Installers]] |
Latest revision as of 03:55, 11 March 2011
Author: sag47 (talk, contrib) |
Download
Games Explorer Manager Install src.zip (98 KB) An installer for the GEM (You must compile it with NSIS).
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
- Install NSIS using the latest NSIS distrobution.
- Then download the GEM Installer source (see Download section of this document)
- Extract the source to your desktop ({Desktop})
- Now download the Games Explorer Manager (see Download section of this document)
- Extract the Games Explorer Manager to your desktop
- Copy {Desktop}\GameExplorerManager.exe to {Desktop}\Games Explorer Manager Install src\program
- 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:
- NSIS Wiki Source: Allow only one installer instance
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:
- NSIS Wiki Source: MessageBox plug-in
.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
- NSIS Wiki Source: Check whether your application is running during uninstallation
- Tool Alert: I used UI Spy to get the Window Class and Window Title.
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.
- NSIS Wiki Source: Shortcuts removal fails on Windows Vista, UAC plug-in
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