1 ;-----------------------------------------------------------------------
2 ; NSIS Installation Script ;
4 ; khuckins@catalystdevworks.com ;
5 ; This will be a guide to working with NSIS to create an installer. ;
6 ; It is a heavily commented practice installer, basically. ;
8 ; Comments are designated by # and ; ;
9 ; # tends to be at the beginning of a line, while ; is ;
10 ; primarilly used as end-of-line comments. However it's ;
11 ; common to use just ; for comments as well. ;
13 ;------------------------------------------------------------------------
19 !include "MUI2.nsh" ;This enables the use of ModernUI, and must go at the top
21 !include "defines.nsh" ;Definitions for our variables
22 !include "LogicLib.nsh" ;Sparsly documented library, but necessary for any real logic
23 !include "nsDialogs.nsh" ;Need this to create custom pages
25 !include ReplaceInFile.nsh
26 ;---------------------------------------------------------------
27 ; Installer's filename
28 Outfile "${APPNAME} Installer.exe"
29 RequestExecutionLevel admin
36 ;==================================
38 !insertmacro MUI_PAGE_WELCOME
39 !define MUI_PAGE_CUSTOMFUNCTION_PRE VersionChecker
40 !insertmacro MUI_PAGE_LICENSE "license.rtf" ;Loads licence.rtf to show license content
41 !insertmacro MUI_PAGE_DIRECTORY
42 !insertmacro MUI_PAGE_INSTFILES
43 !insertmacro MUI_PAGE_FINISH
45 !insertmacro MUI_LANGUAGE "English"
46 ;-------------------------------------
47 ; Code to verify if a user is an admin
48 !macro VerifyUserIsAdmin
49 UserInfo::GetAccountType
51 ${If} $0 != "admin" ;Require admin rights
52 messageBox mb_iconstop "Administrator rights required!"
53 setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
58 ;---------------------------------------------------------------------
60 ; 2. Read our current version and check if it's newer, older, or the same
61 ; LogicLib gives S>, S<, and S== for comparing strings.
66 SetRegView 64 ;So we can read the Registry of 64 bit devices
68 ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
69 ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R0" "JavaHome"
71 MessageBox MB_OK "Java not detected. Setup will now exit."
74 ${If} $R0 S< ${JRE_MIN_VERSION}
75 MessageBox MB_OK "You must update Java. Setup will now exit."
78 ReadRegStr $R2 HKCU "Software\${COMPANYNAME}\${APPNAME}" "Version"
80 Goto INSTALL ;As you were, citizen.
81 ${ElseIf} $R2 S== ${FULLVERSION} ;Same version is installed
82 MessageBox MB_OKCANCEL|MB_ICONSTOP "You already have this version of ${APPNAME} installed. You must uninstall the currently installed version to continue." IDOK UNINSTALL IDCANCEL QUIT
83 ${ElseIf} $R2 S> ${FULLVERSION} ;Older version is installed
84 MessageBox MB_OKCANCEL|MB_ICONSTOP "You are tring to install an older version of ${APPNAME} than the one you currently have installed. You must uninstall the currently installed verion to continue." IDOK UNINSTALL IDCANCEL QUIT
85 ${ElseIf} $R2 S< ${FULLVERSION} ;Newer version is installed
86 MessageBox MB_OKCANCEL|MB_ICONSTOP "You have a previous version of ${APPNAME} installed. You must uninstall the currently installed version to continue." IDOK UNINSTALL IDCANCEL QUIT
89 ExecWait '"$INSTDIR\Uninstall ${APPNAME}.exe"_?=$INSTDIR'
98 setShellVarContext all
99 !insertmacro VerifyUserIsAdmin
103 function VersionChecker
104 !insertmacro VersionCheck
107 ;--------------------------
108 ; Where our install files go
109 InstallDir "$PROGRAMFILES\${APPNAME}" ;This is where our variables come in.
110 ;----------------------------------------------
113 ; Install directory files - keep these in the same directory
114 ; as the script before compiling.
115 SetOutPath $INSTDIR\ ;Sets output path to our InstallDir
117 File /r ..\..\extension
119 File ..\..\hatch.properties
120 File ..\..\logging.properties
122 ; Set path variable in org.ils_evergreen.hatch.json to $INSTDIR\hatch.bat
123 ${StrRep} '$0' '$INSTDIR' '\' '\\'
124 !insertmacro _ReplaceInFile "$INSTDIR\extension\host\org.evergreen_ils.hatch.json" "/path/to/hatch.sh" "$0\\hatch.bat"
127 writeUninstaller "$INSTDIR\Uninstall ${APPNAME}.exe"
129 ; Registry info for Add/Remove Programs
130 WriteRegStr HKCU "Software\${COMPANYNAME}\${APPNAME}" "Install Path" $INSTDIR
131 WriteRegStr HKCU "Software\${COMPANYNAME}\${APPNAME}" "Version" "${FULLVERSION}"
132 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${COMPANYNAME} - ${APPNAME} - ${DESCRIPTION}"
133 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "$\"$INSTDIR\Uninstall ${APPNAME}.exe$\""
134 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\Uninstall ${APPNAME}.exe$\" /S"
135 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "InstallLocation" "$\"$INSTDIR$\""
136 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ ${APPNAME}" "DisplayIcon" "$\"$INSTDIR\logo.ico$\""
137 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "Publisher" "$\"${COMPANYNAME}$\""
138 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "HelpLink" "$\"${HELPURL}$\""
139 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "URLUpdateInfo" "$\"${UPDATEURL}$\""
140 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "URLInfoAbout" "$\"${ABOUTURL}$\""
141 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayVersion" "$\"${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}$\""
142 WriteRegStr HKCU "Software\Google\Chrome\NativeMessagingHosts\org.evergreen_ils.hatch" "" "$INSTDIR\extension\host\org.evergreen_ils.hatch.json"
143 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "VersionMajor" ${VERSIONMAJOR}
144 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "VersionMinor" ${VERSIONMINOR}
145 # There is no option for modifying or repairing the install
146 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "NoModify" 1
147 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "NoRepair" 1
148 # Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size
149 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
151 ;Uncommend when extension is on web store
153 ;WriteRegStr HKLM "Software\Wow6432Node\Google\Chrome\Extensions\${EXTENSIONID}" "update_url" "${EXTENSION_UPDATEURL}"
155 ;WriteRegStr HKLM "Software\Google\Chrome\Extensions\${EXTENSIONID}" "update_url" "${EXTENSION_UPDATEURL}"
159 #############################
163 SetShellVarContext all
166 MessageBox MB_OKCANCEL "Permanently remove ${APPNAME}?" IDOK next
169 !insertmacro VerifyUserIsAdmin
173 # Remove the actual files
175 rmDir /r $INSTDIR\extension
176 rmDir /r $INSTDIR\lib
177 # Delete uninstaller last
178 delete "$INSTDIR\Uninstall ${APPNAME}.exe"
180 # Remove installation directory
183 # Remove uninstaller info from registry
184 DeleteRegKey HKCU "Software\${COMPANYNAME}\${APPNAME}"
185 DeleteRegKey HKCU "Software\${COMPANYNAME}"
186 DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
187 DeleteRegKey HKCU "Software\Google\Chrome\NativeMessagingHosts\org.evergreen_ils.hatch"
188 DeleteRegKey HKLM "Software\Google\Chrome\Extensions\${EXTENSIONID}"
190 DeleteRegKey HKLM "Software\Wow6432Node\Google\Chrome\Extensions\${EXTENSIONID}"