-
Notifications
You must be signed in to change notification settings - Fork 19
/
installer.nsi
412 lines (331 loc) · 12.9 KB
/
installer.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#
# RS TV Show Tracker
# NSIS installer script
#
# Required plugins to build:
# - http://nsis.sourceforge.net/KillProcDLL_plug-in
# To stop the currently running instance in case of update.
# - http://nsis.sourceforge.net/AccessControl_plug-in
# To give full access to the user on the install path. This is an
# experimental and not-always-working hack that is soon to be deprecated.
# - http://nsis.sourceforge.net/Aero_plug-in
# To apply the Aero glass effect on the installer.
# - http://nsis.sourceforge.net/UAC_plug-in
# To elevate the installer as needed, then drop rights when finished.
#
# A copy of these plugins is provided in the Dependencies\NSIS folder.
#
# Inner workings of the script:
# - The TARGET_DIR variable (can be specified with /DTARGET_DIR= on the compiler)
# specifies which build to use from the bin\ directory. "Release" if not present,
# however build_nightly.cmd uses the "Nightly" temporary directory.
# - The VERSION variable can be specified, or it will be read from the "version.nsh"
# file, which is generated by Visual Studio via SignatureGen.tt during a compile.
#
!define APP_NAME "RS TV Show Tracker"
!define COMP_NAME "RoliSoft"
!define WEB_SITE "http://lab.rolisoft.net"
!define COPYRIGHT "© 2013 RoliSoft"
!define DESCRIPTION "RS TV Show Tracker"
!ifndef INSTALLER_NAME
!define INSTALLER_NAME "tvshowtracker_v2_setup.exe"
!endif
!ifndef TARGET_DIR
!define TARGET_DIR "Release"
!endif
!ifndef VERSION
!include "version.nsh"
!endif
!define MAIN_APP_EXE "RSTVShowTracker.exe"
!define INSTALL_TYPE "SetShellVarContext current"
!define REG_ROOT "HKCU"
!define REG_APP_PATH "Software\Microsoft\Windows\CurrentVersion\App Paths\${MAIN_APP_EXE}"
!define UNINSTALL_PATH "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}"
!define LICENSE_TXT "LICENSE.rtf"
!define MUI_ICON "${NSISDIR}\contrib\graphics\icons\orange-install.ico"
!define MUI_UNICON "${NSISDIR}\contrib\graphics\icons\orange-uninstall.ico"
!define MUI_HEADERIMAGE on
!define MUI_HEADERIMAGE_RIGHT on
!define MUI_HEADERIMAGE_BITMAP "Images\nsis-header.bmp"
!define MUI_HEADERIMAGE_UNBITMAP "${NSISDIR}\contrib\graphics\header\orange-uninstall.bmp"
!define MUI_WELCOMEFINISHPAGE_BITMAP "Images\nsis-wizard.bmp"
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "${NSISDIR}\contrib\graphics\wizard\orange-uninstall.bmp"
!define MUI_CUSTOMFUNCTION_GUIINIT GuiInitAero
!define MUI_CUSTOMFUNCTION_UNGUIINIT un.GuiInitAero
!define REG_START_MENU "Start Menu Folder"
var SM_Folder
!include "FileFunc.nsh"
!include "LogicLib.nsh"
!include "x64.nsh"
#!addplugindir "Dependencies\NSIS"
######################################################################
VIProductVersion "${VERSION}"
VIAddVersionKey "ProductName" "${APP_NAME}"
VIAddVersionKey "ProductVersion" "${VERSION}"
VIAddVersionKey "CompanyName" "${COMP_NAME}"
VIAddVersionKey "LegalCopyright" "${COPYRIGHT}"
VIAddVersionKey "FileDescription" "${DESCRIPTION}"
VIAddVersionKey "FileVersion" "${VERSION}"
######################################################################
SetCompressor /FINAL /SOLID LZMA
Name "${APP_NAME}"
Caption "${APP_NAME}"
OutFile "${INSTALLER_NAME}"
BrandingText "${APP_NAME}"
XPStyle on
InstallDirRegKey "${REG_ROOT}" "${REG_APP_PATH}" ""
InstallDir "$PROGRAMFILES\${COMP_NAME}\${APP_NAME}"
RequestExecutionLevel user
######################################################################
!include "UAC.nsh"
!macro Init thing
uac_retry:
!insertmacro UAC_RunElevated
${Switch} $0
${Case} 0
${IfThen} $1 = 1 ${|} Quit ${|}
${IfThen} $3 <> 0 ${|} ${Break} ${|}
${If} $1 = 3
MessageBox mb_YesNo|mb_IconExclamation|mb_TopMost|mb_SetForeground "This ${thing} requires administrator privileges. Retry the elevation?" /SD IDNO IDYES uac_retry IDNO 0
${EndIf}
${Case} 1223
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "This ${thing} requires administrator privileges."
Quit
${Case} 1062
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Unable to elevate installer because the logon service is not running."
Quit
${Default}
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Unable to elevate installer due to unexpected error $0."
Quit
${EndSwitch}
!macroend
######################################################################
Function .onInit
!insertmacro Init "installer"
ClearErrors
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
${If} $R0 < 6
${OrIf} ${Errors}
MessageBox MB_OK|MB_ICONSTOP "This software doesn't support systems older than Windows 7."
Quit
${EndIf}
${If} ${Silent}
KillProcDLL::KillProc "${MAIN_APP_EXE}"
${EndIf}
ClearErrors
ReadRegStr $R0 HKCU "${REG_APP_PATH}" ""
${IfNot} ${Errors}
# leave as-is, already installed by installer
${ElseIf} ${RunningX64}
${If} ${FileExists} "$INSTDIR\*.*"
# leave as-is, already installed by portable
${Else}
SetRegView 64
StrCpy $INSTDIR "$PROGRAMFILES64\${COMP_NAME}\${APP_NAME}"
${EndIf}
${EndIf}
FunctionEnd
Function .onInstSuccess
ClearErrors
${GetParameters} $R0
${GetOptions} $R0 "/AR" $R1
${IfNot} ${Errors}
ExecShell "open" '"$INSTDIR\${MAIN_APP_EXE}"'
${Else}
ClearErrors
${GetParameters} $R0
${GetOptions} $R0 "/SR" $R1
${IfNot} ${Errors}
ExecShell "open" '"$INSTDIR\${MAIN_APP_EXE}"' "-hide"
${Endif}
${EndIf}
FunctionEnd
Function GuiInitAero
Aero::Apply
FunctionEnd
Function un.GuiInitAero
Aero::Apply
FunctionEnd
Function un.onInit
!insertmacro Init "uninstaller"
FunctionEnd
######################################################################
!include "MUI2.nsh"
!define MUI_ABORTWARNING
!define MUI_UNABORTWARNING
!define MUI_PAGE_CUSTOMFUNCTION_SHOW WelcomeChangeFonts
!insertmacro MUI_PAGE_WELCOME
!ifdef LICENSE_TXT
!define MUI_PAGE_CUSTOMFUNCTION_PRE HeaderChangeFonts
!insertmacro MUI_PAGE_LICENSE "${LICENSE_TXT}"
!endif
!define MUI_PAGE_CUSTOMFUNCTION_PRE HeaderChangeFonts
!insertmacro MUI_PAGE_DIRECTORY
!ifdef REG_START_MENU
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "${APP_NAME}"
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "${REG_ROOT}"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "${UNINSTALL_PATH}"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${REG_START_MENU}"
!define MUI_PAGE_CUSTOMFUNCTION_PRE HeaderChangeFonts
!insertmacro MUI_PAGE_STARTMENU Application $SM_Folder
!endif
!define MUI_PAGE_CUSTOMFUNCTION_PRE HeaderChangeFonts
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_TEXT "Start ${APP_NAME}"
!define MUI_FINISHPAGE_RUN_FUNCTION FinishLaunchApplication
!define MUI_FINISHPAGE_SHOWREADME
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Create Desktop Shortcut"
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION FinishCreateDesktopShortcut
!define MUI_PAGE_CUSTOMFUNCTION_SHOW FinishChangeFonts
!insertmacro MUI_PAGE_FINISH
!define MUI_PAGE_CUSTOMFUNCTION_SHOW un.HeaderChangeFonts
!insertmacro MUI_UNPAGE_CONFIRM
!define MUI_PAGE_CUSTOMFUNCTION_SHOW un.HeaderChangeFonts
!insertmacro MUI_UNPAGE_INSTFILES
!define MUI_PAGE_CUSTOMFUNCTION_SHOW un.FinishChangeFonts
!insertmacro MUI_UNPAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
######################################################################
Function WelcomeChangeFonts
CreateFont $0 "Segoe UI" "13" "700"
SendMessage $mui.WelcomePage.Title ${WM_SETFONT} $0 0
FunctionEnd
Function FinishChangeFonts
CreateFont $0 "Segoe UI" "13" "700"
SendMessage $mui.FinishPage.Title ${WM_SETFONT} $0 0
FunctionEnd
Function HeaderChangeFonts
CreateFont $0 "Segoe UI" "10" "700"
SendMessage $mui.Header.Text ${WM_SETFONT} $0 0
#CreateFont $0 "Segoe UI" "9" "500"
#SendMessage $mui.Header.SubText ${WM_SETFONT} $0 0
FunctionEnd
Function un.FinishChangeFonts
CreateFont $0 "Segoe UI" "13" "700"
SendMessage $mui.FinishPage.Title ${WM_SETFONT} $0 0
FunctionEnd
Function un.HeaderChangeFonts
CreateFont $0 "Segoe UI" "10" "700"
SendMessage $mui.Header.Text ${WM_SETFONT} $0 0
#CreateFont $0 "Segoe UI" "9" "500"
#SendMessage $mui.Header.SubText ${WM_SETFONT} $0 0
FunctionEnd
Function FinishCreateDesktopShortcut
CreateShortcut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}"
FunctionEnd
Function FinishLaunchApplication
!insertmacro UAC_AsUser_ExecShell "" "$INSTDIR\${MAIN_APP_EXE}" "" "" ""
#ExecShell "open" '"$INSTDIR\${MAIN_APP_EXE}"'
FunctionEnd
######################################################################
Section -MainProgram
${INSTALL_TYPE}
SetOverwrite ifnewer
SetOutPath "$INSTDIR\libs"
File "Dependencies\*.dll"
File "Dependencies\*.License.txt"
SetOutPath "$INSTDIR"
File "bin\${TARGET_DIR}\RSTVShowTracker.License.txt"
File "bin\${TARGET_DIR}\RSTVShowTracker.exe"
File "bin\${TARGET_DIR}\RSTVShowTracker.exe.config"
File "bin\${TARGET_DIR}\RSTVShowTracker.pdb"
# remove old leftover files
Delete "Dependencies\WPFToolkit.Extended.dll"
Delete "BouncyCastle.Crypto.dll"
Delete "CookComputing.XmlRpcV2.dll"
Delete "Hammock.ClientProfile.dll"
Delete "HtmlAgilityPack.dll"
Delete "Ionic.Zip.Reduced.dll"
Delete "IronPython.dll"
Delete "Microsoft.Dynamic.dll"
Delete "Microsoft.Scripting.dll"
Delete "Microsoft.Windows.Shell.dll"
Delete "Microsoft.WindowsAPICodePack.dll"
Delete "Microsoft.WindowsAPICodePack.Shell.dll"
Delete "Newtonsoft.Json.dll"
Delete "nunit.framework.dll"
Delete "protobuf-net.dll"
Delete "SharpCompress.dll"
Delete "StarksoftBiko.dll"
Delete "Starksoft.Net.Proxy.dll"
Delete "System.Data.SQLite.dll"
Delete "TaskDialog.dll"
Delete "Transitionals.dll"
Delete "Twitterizer2.dll"
Delete "VistaControls.dll"
Delete "WPFToolkit.Extended.dll"
# try to fix permission issues
AccessControl::EnableFileInheritance "$INSTDIR"
AccessControl::GrantOnFile "$INSTDIR" "(BU)" "FullAccess"
AccessControl::GrantOnFile "$INSTDIR" "(S-1-5-32-545)" "FullAccess"
nsExec::ExecToLog '"$SYSDIR\takeown.exe" /r /d y /f *'
nsExec::ExecToLog '"$SYSDIR\icacls.exe" . /t /inheritance:e /grant Users:(OI)(CI)F'
SectionEnd
######################################################################
Section -Prerequisites
SetOutPath "$INSTDIR"
; Check .Net Framework 4.5
ClearErrors
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Release"
${If} $0 < 378389
${OrIf} ${Errors}
Banner::show /NOUNLOAD /set 76 ".Net Framework 4.5" "Downloading web installer..."
NSISdl::download_quiet http://download.microsoft.com/download/B/A/4/BA4A7E71-2906-4B2D-A0E1-80CF16844F5F/dotNetFx45_Full_setup.exe "$INSTDIR\dotNetFx45_Full_setup.exe"
Banner::destroy
Banner::show /NOUNLOAD /set 76 ".Net Framework 4.5" "Waiting for installation to finish..."
ExecWait "$INSTDIR\dotNetFx45_Full_setup.exe /passive /norestart"
Delete "$INSTDIR\dotNetFx45_Full_setup.exe"
Banner::destroy
${EndIf}
SectionEnd
######################################################################
Section -Icons_Reg
SetOutPath "$INSTDIR"
WriteUninstaller "$INSTDIR\uninstall.exe"
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
CreateDirectory "$SMPROGRAMS\${APP_NAME}"
CreateShortCut "$SMPROGRAMS\${APP_NAME}\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}"
CreateShortCut "$SMPROGRAMS\${APP_NAME}\Uninstall.lnk" "$INSTDIR\uninstall.exe"
!ifdef WEB_SITE
WriteIniStr "$INSTDIR\${APP_NAME} website.url" "InternetShortcut" "URL" "${WEB_SITE}"
WriteIniStr "$INSTDIR\${APP_NAME} website.url" "InternetShortcut" "IconFile" "%SystemRoot%\system32\SHELL32.dll"
WriteIniStr "$INSTDIR\${APP_NAME} website.url" "InternetShortcut" "IconIndex" "277"
CreateShortCut "$SMPROGRAMS\${APP_NAME}\Website.lnk" "$INSTDIR\${APP_NAME} website.url" "" "%SystemRoot%\system32\SHELL32.dll" "277"
!endif
!insertmacro MUI_STARTMENU_WRITE_END
WriteRegStr ${REG_ROOT} "${REG_APP_PATH}" "" "$INSTDIR\${MAIN_APP_EXE}"
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayName" "${APP_NAME}"
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "UninstallString" "$INSTDIR\uninstall.exe"
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayIcon" "$INSTDIR\${MAIN_APP_EXE}"
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayVersion" "${VERSION}"
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "Publisher" "${COMP_NAME}"
!ifdef WEB_SITE
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "URLInfoAbout" "${WEB_SITE}"
!endif
SectionEnd
######################################################################
Section Uninstall
${INSTALL_TYPE}
Delete "$INSTDIR\libs\*.dll"
Delete "$INSTDIR\libs\*.License.txt"
Delete "$INSTDIR\RSTVShowTracker.License.txt"
Delete "$INSTDIR\RSTVShowTracker.exe"
Delete "$INSTDIR\RSTVShowTracker.exe.config"
Delete "$INSTDIR\RSTVShowTracker.pdb"
Delete "$INSTDIR\uninstall.exe"
!ifdef WEB_SITE
Delete "$INSTDIR\${APP_NAME} website.url"
!endif
RmDir "$INSTDIR"
Delete "$SMPROGRAMS\${APP_NAME}\${APP_NAME}.lnk"
Delete "$SMPROGRAMS\${APP_NAME}\Uninstall.lnk"
!ifdef WEB_SITE
Delete "$SMPROGRAMS\${APP_NAME}\Website.lnk"
!endif
Delete "$DESKTOP\${APP_NAME}.lnk"
RMDir /r "$SMPROGRAMS\${APP_NAME}"
DeleteRegKey ${REG_ROOT} "${REG_APP_PATH}"
DeleteRegKey ${REG_ROOT} "${UNINSTALL_PATH}"
SectionEnd