-
Notifications
You must be signed in to change notification settings - Fork 2
/
gridmonger.nsi
285 lines (213 loc) · 9.46 KB
/
gridmonger.nsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
!include x64.nsh
!include MUI2.nsh
!include LogicLib.nsh
!include WinCore.nsh
!include Integration.nsh
!define NAME "Gridmonger"
!searchparse /file CURRENT_VERSION '' VERSION
!system 'nim versionAndGitHash > versionFile'
!searchparse /file versionFile '' VERSION_AND_HASH
!define /date CURRENT_YEAR "%Y"
!define APP_EXE "gridmonger.exe"
!define UNINSTALL_EXE "uninstall.exe"
!define OUT_PATH "dist/windows"
!define ASSOC_EXT ".gmm"
!define ASSOC_PROGID "${NAME}"
!define ASSOC_VERB "Open with ${NAME}"
!define REGPATH_UNINSTSUBKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}"
!ifdef ARCH32
!define ARCH "32"
!else
!define ARCH "64"
!endif
Unicode True
RequestExecutionLevel admin
Function .onInit
${If} ${RunningX64}
!ifdef ARCH32
MessageBox MB_YESNO "This will install the 32-bit version of Gridmonger.$\r$\n$\r$\nYou are running 64-bit Windows, therefore installing the 64-bit version is recommended.$\r$\n$\r$\nDo you still wish to continue?" IDYES go
Abort
go:
!endif
SetRegView 64
${EndIf}
FunctionEnd
Name "${NAME}"
Caption "${NAME} v${VERSION} Setup - ${ARCH}-bit"
OutFile "${OUT_PATH}/gridmonger-v${VERSION_AND_HASH}-win${ARCH}-setup.exe"
!ifdef ARCH32
InstallDir "$PROGRAMFILES32\${NAME}"
!else
InstallDir "$PROGRAMFILES64\${NAME}"
!endif
VIAddVersionKey "ProductName" "${NAME}"
VIAddVersionKey "ProductVersion" "${VERSION}"
VIAddVersionKey "LegalCopyright" "(c) John Novak 2020-${CURRENT_YEAR}"
VIAddVersionKey "FileDescription" "${NAME} installer"
VIAddVersionKey "FileVersion" "${VERSION}"
VIProductVersion ${VERSION}.0
VIFileVersion ${VERSION}.0
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
!define MUI_UNABORTWARNING
!define MUI_ICON extras\appicons\windows\gridmonger.ico
!define MUI_UNICON extras\appicons\windows\gridmonger.ico
!define MUI_WELCOMEFINISHPAGE_BITMAP extras\installer-images\welcome-finish.bmp
!define MUI_UNWELCOMEFINISHPAGE_BITMAP extras\installer-images\welcome-finish.bmp
;--------------------------------
;Pages
; Installer
!define MUI_WELCOMEPAGE_TITLE "Welcome to Gridmonger setup"
!define welcome1 "This wizard will guide you through the installation of Gridmonger.$\r$\n$\r$\n"
!define welcome2 "Please close all running instances of Gridmonger before proceeding.$\r$\n$\r$\n"
!define welcome3 "Click Next to continue."
!define MUI_WELCOMEPAGE_TEXT "${welcome1}${welcome2}${welcome3}"
!insertmacro MUI_PAGE_WELCOME
!define MUI_COMPONENTSPAGE_NODESC
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
; Uninstaller
!define MUI_WELCOMEPAGE_TITLE "Welcome to Gridmonger uninstall"
!define unwelcome1 "This wizard will guide you through the uninstallation of Gridmonger.$\r$\n$\r$\n"
!define unwelcome2 "No data will be removed from your Gridmonger user folder (user themes, configuration, etc.)$\r$\n$\r$\n"
!define unwelcome3 "Please close all running instances of the program before proceeding.$\r$\n$\r$\n"
!define unwelcome4 "Click Next to continue."
!define MUI_WELCOMEPAGE_TEXT "${unwelcome1}${unwelcome2}${unwelcome3}${unwelcome4}"
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
!macro RemoveInstalledFiles un
Function ${un}RemoveInstalledFiles
RMDir /r $INSTDIR\Data
RMDir /r "$INSTDIR\Example Maps"
RMDir /r $INSTDIR\Manual
RMDir /r $INSTDIR\Themes
Delete $INSTDIR\*.dll
Delete $INSTDIR\cacert.pem
Delete $INSTDIR\${APP_EXE}
Delete $INSTDIR\${UNINSTALL_EXE}
FunctionEnd
!macroend
!insertmacro RemoveInstalledFiles ""
!insertmacro RemoveInstalledFiles "un."
!macro RemoveShortcuts un
Function ${un}RemoveShortcuts
Delete "$SMPROGRAMS\${NAME}.lnk"
Delete "$DESKTOP\${NAME}.lnk"
FunctionEnd
!macroend
!insertmacro RemoveShortcuts ""
!insertmacro RemoveShortcuts "un."
!macro RemoveShellIntegration un
Function ${un}RemoveShellIntegration
# Unregister file type
ClearErrors
DeleteRegKey ShCtx "Software\Classes\${ASSOC_PROGID}\shell\${ASSOC_VERB}"
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_PROGID}\shell"
${IfNot} ${Errors}
DeleteRegKey ShCtx "Software\Classes\${ASSOC_PROGID}\DefaultIcon"
${EndIf}
ReadRegStr $0 ShCtx "Software\Classes\${ASSOC_EXT}" ""
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_PROGID}"
${IfNot} ${Errors}
${AndIf} $0 == "${ASSOC_PROGID}"
DeleteRegValue ShCtx "Software\Classes\${ASSOC_EXT}" ""
DeleteRegKey /IfEmpty ShCtx "Software\Classes\${ASSOC_EXT}"
${EndIf}
# Unregister "Default Programs"
!ifdef REGISTER_DEFAULTPROGRAMS
DeleteRegValue ShCtx "Software\RegisteredApplications" "${NAME}"
DeleteRegKey ShCtx "Software\Classes\Applications\${APP_EXE}\Capabilities"
DeleteRegKey /IfEmpty ShCtx "Software\Classes\Applications\${APP_EXE}"
!endif
# Attempt to clean up junk left behind by the Windows shell
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Search\JumplistData" "$INSTDIR\${APP_EXE}"
DeleteRegValue HKCU "Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" "$INSTDIR\${APP_EXE}.FriendlyAppName"
DeleteRegValue HKCU "Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" "$INSTDIR\${APP_EXE}.ApplicationCompany"
DeleteRegValue HKCU "Software\Microsoft\Windows\ShellNoRoam\MUICache" "$INSTDIR\${APP_EXE}" ; WinXP
DeleteRegValue HKCU "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store" "$INSTDIR\${APP_EXE}"
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" "${ASSOC_PROGID}_${ASSOC_EXT}"
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" "Applications\${APP_EXE}_${ASSOC_EXT}"
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}\OpenWithProgids" "${ASSOC_PROGID}"
DeleteRegKey /IfEmpty HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}\OpenWithProgids"
DeleteRegKey /IfEmpty HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}\OpenWithList"
DeleteRegKey /IfEmpty HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${ASSOC_EXT}"
${NotifyShell_AssocChanged}
FunctionEnd
!macroend
!insertmacro RemoveShellIntegration ""
!insertmacro RemoveShellIntegration "un."
;=============================================================================
; Sections
;=============================================================================
Section "Gridmonger (required)" Gridmonger
SectionIn RO
SetOutPath $INSTDIR
Call RemoveInstalledFiles
Call RemoveShortcuts
Call RemoveShellIntegration
File /r Data
File /r Manual
File /r Themes
File extras\windows-deps\*
File ${APP_EXE}
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\${NAME} "InstallDir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM ${REGPATH_UNINSTSUBKEY} "DisplayName" "${NAME}"
WriteRegStr HKLM ${REGPATH_UNINSTSUBKEY} "DisplayIcon" "$INSTDIR\${APP_EXE},0"
WriteRegStr HKLM ${REGPATH_UNINSTSUBKEY} "InstallLocation" $INSTDIR
WriteRegStr HKLM ${REGPATH_UNINSTSUBKEY} "UninstallString" '"$INSTDIR\${UNINSTALL_EXE}"'
WriteRegDWORD HKLM ${REGPATH_UNINSTSUBKEY} "NoModify" 1
WriteRegDWORD HKLM ${REGPATH_UNINSTSUBKEY} "NoRepair" 1
WriteUninstaller "$INSTDIR\${UNINSTALL_EXE}"
SectionEnd
;-----------------------------------------------------------------------------
;
Section "Desktop icon" Shortcuts_Desktop
CreateShortcut "$DESKTOP\${NAME}.lnk" "$INSTDIR\${APP_EXE}"
SectionEnd
Section "Start Menu icon" Shortcuts_StartMenu
CreateShortcut "$SMPROGRAMS\${NAME}.lnk" "$INSTDIR\${APP_EXE}"
SectionEnd
;-----------------------------------------------------------------------------
Section "Associate with GMM (Gridmonger Map) files" Shell_FileAssoc
# Register file type
WriteRegStr ShCtx "Software\Classes\${ASSOC_PROGID}\DefaultIcon" "" "$INSTDIR\${APP_EXE},0"
WriteRegStr ShCtx "Software\Classes\${ASSOC_PROGID}\shell\${ASSOC_VERB}\command" "" '"$INSTDIR\${APP_EXE}" "%1"'
WriteRegStr ShCtx "Software\Classes\${ASSOC_EXT}" "" "${ASSOC_PROGID}"
# Register "Default Programs"
WriteRegStr ShCtx "Software\Classes\Applications\${APP_EXE}\Capabilities" "ApplicationDescription" "${NAME}"
WriteRegStr ShCtx "Software\Classes\Applications\${APP_EXE}\Capabilities\FileAssociations" "${ASSOC_EXT}" "${ASSOC_PROGID}"
WriteRegStr ShCtx "Software\RegisteredApplications" "${NAME}" "Software\Classes\Applications\${APP_EXE}\Capabilities"
${NotifyShell_AssocChanged}
SectionEnd
;-----------------------------------------------------------------------------
SectionGroup /e "Optional features" Optional
Section "Example maps" Optional_ExampleMaps
SetOutPath $INSTDIR
File /r "Example Maps"
SectionEnd
SectionGroupEnd
;=============================================================================
; Uninstaller
;=============================================================================
Section "Uninstall"
; Remove registry keys
DeleteRegKey HKLM ${REGPATH_UNINSTSUBKEY}
DeleteRegKey HKLM SOFTWARE\${NAME}
Call un.RemoveInstalledFiles
Call un.RemoveShortcuts
Call un.RemoveShellIntegration
; Remove directories
RMDir /r "$INSTDIR"
RMDir "$INSTDIR\.."
SectionEnd