-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpsi.nsi
518 lines (423 loc) · 15.9 KB
/
psi.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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
;*******************************************************************************
; psi.nsi - NSIS installer script for Psi
;
; Copyright (c) 2004-2005 Mircea Bardac (IceRAM)
; E-mail: dev@mircea.bardac.net
; XMPP: iceram@jabber.org
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 2
; of the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this file; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;
; See ReadME.txt for more information on the script.
;*******************************************************************************
; Installer Script Version
!define INSTALLER_VERSION "2.0"
; Psi Installer Configuration File
!include "../config.nsh"
; Application name
!define APPNAME "Psi"
!define APPFULLVERSION "${APPVERSION}${APPEXTRAVERSION}"
!define APPNAMEANDVERSION "${APPNAME} ${APPFULLVERSION}"
!define LCAPPNAME "psi" ; lowercase APPNAME
; Version information for the installer executable
VIAddVersionKey ProductName "${APPNAME}"
VIAddVersionKey ProductVersion "${APPFULLVERSION}"
VIAddVersionKey Comments "${APPNAMEANDVERSION} installer - build ${INSTALLER_BUILD} / script ver. ${INSTALLER_VERSION} (c) ${INSTALLER_COPYRIGHT_YEAR} The Psi Team"
VIAddVersionKey CompanyName ""
VIAddVersionKey LegalCopyright ""
VIAddVersionKey FileDescription "${APPNAMEANDVERSION} Installer (build ${INSTALLER_BUILD}) - Win32 Installer v${INSTALLER_VERSION}"
VIAddVersionKey FileVersion "${INSTALLER_VERSION}b${INSTALLER_BUILD}"
VIAddVersionKey InternalName "${APPNAMEANDVERSION} Installer (build ${INSTALLER_BUILD}) - Win32 Installer v${INSTALLER_VERSION}"
VIAddVersionKey LegalTrademarks ""
!ifdef BUILD_WITH_LANGPACKS
VIAddVersionKey OriginalFilename "${LCAPPNAME}-${APPFULLVERSION}-win-setup.exe"
VIAddVersionKey PrivateBuild "Language Packs Included: yes"
!else
VIAddVersionKey OriginalFilename "${LCAPPNAME}-${APPFULLVERSION}-win-setup-base.exe"
VIAddVersionKey PrivateBuild "Language Packs Included: none"
!endif
VIAddVersionKey SpecialBuild "Build number: ${INSTALLER_BUILD}"
VIProductVersion "${APPVERSION}.0.${INSTALLER_BUILD}"
SetCompressor lzma
Var DONE_INIT
Var RUN_BY_ADMIN
Var INST_CONTEXT
Var LSTR_SHORTCUTS
Var LSTR_CURRENTUSER
Var LSTR_ALLUSERS
Var LSTR_QUICKLAUNCH
Var LSTR_DESKTOP_S
Var LSTR_STARTMENU_GROUP
Var LSTR_ASK_EXIT_PSI
Var LSTR_UNINST_RUNNING
Var LSTR_INST_RUNNING
Var LSTR_WARN_ADMIN_1
Var LSTR_WARN_ADMIN_2
Var LSTR_PSIBASE
Var LSTR_LANGUAGES
Var LSTR_AUTOSTART
Var LSTR_A_INSTALLED
Var LSTR_ERR_UNINST
!include "Sections.nsh"
!include "installer-functions.nsh"
!define XPSTYLE on
BrandingText "- ${APPNAMEANDVERSION} installer - build ${INSTALLER_BUILD} / script ver. ${INSTALLER_VERSION} (c) ${INSTALLER_COPYRIGHT_YEAR} The Psi Team "
!define HOME_URL "http://psi-im.org/"
; Main Install settings
!define APP_BUILD "${INSTALLER_HOME}${FILE_SEPARATOR}build${FILE_SEPARATOR}"
!define INSTALLER_SRC "${INSTALLER_HOME}${FILE_SEPARATOR}src${FILE_SEPARATOR}"
!define APP_SOURCE "${APP_BUILD}psi_app${FILE_SEPARATOR}"
Name "${APPNAMEANDVERSION}"
InstallDir "$PROGRAMFILES\${APPNAME}"
!ifdef BUILD_WITH_LANGPACKS
OutFile "${APP_BUILD}${LCAPPNAME}-${APPFULLVERSION}-win-setup.exe"
!else
OutFile "${APP_BUILD}${LCAPPNAME}-${APPFULLVERSION}-win-setup-base.exe"
!endif
InstallDirRegKey HKLM "Software\Affinix\${APPNAME}" ""
; Modern interface settings
!include "MUI.nsh"
;--------------------------------
;Page settings
!define MUI_ICON "${INSTALLER_SRC}install.ico"
!define MUI_UNICON "${INSTALLER_SRC}uninstall.ico"
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "${INSTALLER_SRC}psi-header-l.bmp"
!define MUI_HEADERIMAGE_BITMAP_RTL "${INSTALLER_SRC}psi-header-r.bmp"
!define MUI_HEADERIMAGE_UNBITMAP "${INSTALLER_SRC}psi-header-l.bmp"
!define MUI_HEADERIMAGE_UNBITMAP_RTL "${INSTALLER_SRC}psi-header-r.bmp"
!define MUI_ABORTWARNING
!define MUI_COMPONENTSPAGE_NODESC
!define MUI_FINISHPAGE_RUN "$INSTDIR\Psi.exe"
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\Readme.txt"
!define MUI_FINISHPAGE_LINK "Click here to visit the Psi Homepage"
!define MUI_FINISHPAGE_LINK_LOCATION "http://psi-im.org"
!define MUI_WELCOMEFINISHPAGE_BITMAP "${INSTALLER_SRC}psi-l.bmp"
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "${INSTALLER_SRC}psi-l.bmp"
;!define MUI_LICENSEPAGE_CHECKBOX
;--------------------------------
;Language Selection Dialog Settings
;Remember the installer language
!define MUI_LANGDLL_REGISTRY_ROOT "HKLM"
!define MUI_LANGDLL_REGISTRY_KEY "Software\Affinix\${APPNAME}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
PAGE custom InitRoutines
!define MUI_PAGE_CUSTOMFUNCTION_SHOW CompNames
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "${APP_SOURCE}COPYING"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
UNINSTPAGE custom un.InitRoutines
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
; Languages
!include "installer-languages.nsh"
;--------------------------------
;Reserve Files
!insertmacro MUI_RESERVEFILE_LANGDLL
;--------------------------------
; macro for creating urls
!Macro "CreateURL" "URLFile" "URLSite"
WriteINIStr "$INSTDIR\${URLFile}.url" "InternetShortcut" "URL" "${URLSite}"
!macroend
;--------------------------------
;*********************************
; Sections of the installer
Section "" SectionBase
; Set Section properties
SetOverwrite on
SectionIn RO
; Set Section Files and Shortcuts
!include "${APP_BUILD}psi_files_install.nsh"
SetOutPath "$INSTDIR\"
!insertmacro "CreateURL" "Psi - Home page" "http://psi-im.org"
!insertmacro "CreateURL" "Psi - Forum" "http://psi-im.org/forum"
!insertmacro "CreateURL" "Psi - Documentation" "http://psi-im.org/wiki"
SectionEnd
; ********************************
!ifdef BUILD_WITH_LANGPACKS
SectionGroup "_" SectionLang
!include "${APP_BUILD}psi_lang_install.nsh"
; See ReadME.txt for more information
SectionGroupEnd
!endif
Section "" SectionSM
StrCmp $RUN_BY_ADMIN "true" sm_admin
sm_normal:
SetShellVarContext current
Goto sm_done
sm_admin:
SetShellVarContext all
sm_done:
CreateDirectory "$SMPROGRAMS\${APPNAME}"
SetOutPath "$INSTDIR\"
CreateShortCut "$SMPROGRAMS\${APPNAME}\Psi - Forum.lnk" "$INSTDIR\Psi - Forum.url"
CreateShortCut "$SMPROGRAMS\${APPNAME}\Psi - Documentation.lnk" "$INSTDIR\Psi - Documentation.url"
CreateShortCut "$SMPROGRAMS\${APPNAME}\Psi - Home page.lnk" "$INSTDIR\Psi - Home page.url"
CreateShortCut "$SMPROGRAMS\${APPNAME}\Psi.lnk" "$INSTDIR\Psi.exe"
CreateShortCut "$SMPROGRAMS\${APPNAME}\Uninstall.lnk" "$INSTDIR\uninstall.exe"
CreateShortCut "$SMPROGRAMS\${APPNAME}\ReadME.lnk" "$INSTDIR\Readme.txt"
SetShellVarContext current
SectionEnd
; ********************************
SectionGroup "_" SectionShortcuts
Section "" SectionSD
SetShellVarContext current
SetOutPath "$INSTDIR\"
CreateShortCut "$DESKTOP\Psi.lnk" "$INSTDIR\Psi.exe"
SectionEnd
Section /o "" SectionQuickLaunch
SetShellVarContext current
SetOutPath "$INSTDIR\"
CreateShortCut "$QUICKLAUNCH\Psi.lnk" "$INSTDIR\Psi.exe"
SectionEnd
SectionGroupEnd
Section "" SectionAutomaticStartup
SetShellVarContext current
SetOutPath "$INSTDIR\"
CreateShortCut "$SMSTARTUP\Psi.lnk" "$INSTDIR\Psi.exe"
; WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "Psi" "$INSTDIR\Psi.exe"
; ^ doesn't work - Psi is not started with the correct working dir
SectionEnd
Section -FinishSection
StrCmp $RUN_BY_ADMIN "true" lastsettings_is_admin
WriteRegStr HKCU "Software\Affinix\${APPNAME}" "" "$INSTDIR"
WriteRegStr HKCU "Software\Affinix\${APPNAME}" "Version" "${APPFULLVERSION}"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${APPNAME} (remove only)"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "$INSTDIR\uninstall.exe"
Goto lastsettings_done
lastsettings_is_admin:
WriteRegStr HKLM "Software\Affinix\${APPNAME}" "" "$INSTDIR"
WriteRegStr HKLM "Software\Affinix\${APPNAME}" "Version" "${APPFULLVERSION}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${APPNAME} (remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "$INSTDIR\uninstall.exe"
lastsettings_done:
WriteUninstaller "$INSTDIR\uninstall.exe"
SectionEnd
Function CompNames
SectionSetText ${SectionBase} "$LSTR_PSIBASE"
!ifdef BUILD_WITH_LANGPACKS
SectionSetText ${SectionLang} "$LSTR_LANGUAGES"
!endif
SectionSetText ${SectionSM} "$LSTR_STARTMENU_GROUP ($INST_CONTEXT)"
SectionSetText ${SectionShortcuts} "$LSTR_SHORTCUTS ($LSTR_CURRENTUSER)"
SectionSetText ${SectionSD} "$LSTR_DESKTOP_S"
SectionSetText ${SectionQuickLaunch} "$LSTR_QUICKLAUNCH"
SectionSetText ${SectionAutomaticStartup} "$LSTR_AUTOSTART ($LSTR_CURRENTUSER)"
FunctionEnd
; ***************************************
; installer initialization
Function InitRoutines
StrCmp $DONE_INIT "1" done_init
StrCpy $DONE_INIT "1"
; MessageBox MB_OK "Installing in $LANGUAGE"
!insertmacro INIT_LANG_STRINGS
; allow only one instance of the installer
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "psi${APPFULLVERSION}-installer") i .r1 ?e'
Pop $R0
StrCmp $R0 0 +3
MessageBox MB_OK "$LSTR_INST_RUNNING"
Quit
; ****************
; close active Psi sessions
Call ClosePsiInstances
; ****************
; check for an existing installation of Psi
Call UninstallPreviousPsi
; ****************
Call IsUserAdmin
Pop $R0
StrCpy $RUN_BY_ADMIN $R0 ; saving information
StrCmp $R0 "true" is_admin
; not an admin
MessageBox MB_OK|MB_ICONINFORMATION "$LSTR_WARN_ADMIN_1$\n$\n$LSTR_WARN_ADMIN_2"
StrCpy $INST_CONTEXT $LSTR_CURRENTUSER
goto done_init
is_admin:
StrCpy $INST_CONTEXT $LSTR_ALLUSERS
done_init:
FunctionEnd
Function .onInit
; permit the user to choose the installer language
; the setting will be used to automatically select a language pack if availaible
!insertmacro MUI_LANGDLL_DISPLAY
; ****************
; expand Shorcuts Section
SectionGetFlags ${SectionShortcuts} $0
IntOp $0 $0 | ${SF_EXPAND}
SectionSetFlags ${SectionShortcuts} $0
; ****************
!ifdef BUILD_WITH_LANGPACKS
; automatically choose language pack to install
!include "${APP_BUILD}psi_lang_setup.nsh"
; See ReadME.txt for more information
; ****************
!endif
StrCpy $DONE_INIT "0"
; init strings now
FunctionEnd
; ******************************************************
; Uninstall functions
; function that checks if the user running the UNinstaller is an Administrator
Function un.IsUserAdmin
Push $R0
Push $R1
Push $R2
ClearErrors
UserInfo::GetName
IfErrors Win9x
Pop $R1
UserInfo::GetAccountType
Pop $R2
StrCmp $R2 "Admin" 0 Continue
StrCpy $R0 "true"
Goto Done
Continue:
StrCmp $R2 "" Win9x
StrCpy $R0 "false"
Goto Done
Win9x:
StrCpy $R0 "true"
Done:
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
; ********************************
; Close Psi Instances
; Waits for all running instances of Psi to close
Function un.ClosePsiInstances
Push $0 ;saving stack
newcheck:
FindWindow $0 "QWidget" "Psi" 0
IntCmp $0 0 done
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "$LSTR_ASK_EXIT_PSI" IDRETRY newcheck
; cancel
Quit
done:
Pop $0 ; restoring stack
FunctionEnd
Function un.InitRoutines
; MessageBox MB_OK "Uninstalling"
StrCmp $DONE_INIT "1" done_un_init
StrCpy $DONE_INIT "1"
!insertmacro INIT_LANG_STRINGS
; allow only one instance of the uninstaller
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "psi${APPFULLVERSION}-uninstaller") i .r1 ?e'
Pop $R0
StrCmp $R0 0 +3
MessageBox MB_OK "$LSTR_UNINST_RUNNING"
Abort
;ask the user to close all psi instances on uninstall
Call un.ClosePsiInstances
done_un_init:
FunctionEnd
Function un.onInit
; ****************
;uninstall saved language setting
!insertmacro MUI_UNGETLANGUAGE
StrCpy $DONE_INIT "0"
FunctionEnd
;Uninstall section
Section Uninstall
;Remove from registry...
Call un.IsUserAdmin
Pop $R0
StrCmp $R0 "true" uninstall_is_admin
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
DeleteRegKey HKCU "Software\Affinix\${APPNAME}"
Goto uninstall_done
uninstall_is_admin:
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
DeleteRegKey HKLM "Software\Affinix\${APPNAME}"
uninstall_done:
; Delete self
Delete "$INSTDIR\uninstall.exe"
; Delete links
Delete "$INSTDIR\Psi - Forum.url";
Delete "$INSTDIR\Psi - Home page.url";
Delete "$INSTDIR\Psi - Documentation.url";
; Delete Shortcuts
SetShellVarContext current
Delete "$DESKTOP\Psi.lnk"
Delete "$SMPROGRAMS\${APPNAME}\Psi.lnk"
Delete "$SMPROGRAMS\${APPNAME}\Uninstall.lnk"
Delete "$SMPROGRAMS\${APPNAME}\ReadME.lnk"
Delete "$QUICKLAUNCH\Psi.lnk"
Delete "$SMPROGRAMS\${APPNAME}\Psi - Forum.lnk"
Delete "$SMPROGRAMS\${APPNAME}\Psi - Home page.lnk"
Delete "$SMPROGRAMS\${APPNAME}\Psi - Documentation.lnk"
RMDir "$SMPROGRAMS\${APPNAME}"
SetShellVarContext all
Delete "$DESKTOP\Psi.lnk"
Delete "$SMPROGRAMS\${APPNAME}\Psi.lnk"
Delete "$SMPROGRAMS\${APPNAME}\Uninstall.lnk"
Delete "$SMPROGRAMS\${APPNAME}\ReadME.lnk"
Delete "$QUICKLAUNCH\Psi.lnk"
Delete "$SMPROGRAMS\${APPNAME}\Psi - Forum.lnk"
Delete "$SMPROGRAMS\${APPNAME}\Psi - Home page.lnk"
Delete "$SMPROGRAMS\${APPNAME}\Psi - Documentation.lnk"
RMDir "$SMPROGRAMS\${APPNAME}"
; DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "Psi"
; ^ Registry shortcut doesn't work
SetShellVarContext current
Delete "$SMSTARTUP\Psi.lnk"
!ifdef BUILD_WITH_LANGPACKS
; Delete Language files
!include "${APP_BUILD}psi_lang_uninstall.nsh"
; See ReadME.txt for more information
!endif
; Clean up Psi (base)
!include "${APP_BUILD}psi_files_uninstall.nsh"
SectionEnd
Function UninstallPreviousPsi
Call IsUserAdmin
Pop $R0
StrCpy $RUN_BY_ADMIN $R0 ; saving information
StrCmp $R0 "true" unppsi_is_admin
ReadRegStr $R0 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString"
ReadRegStr $R1 HKCU "Software\Affinix\${APPNAME}" ""
goto unppsi_done
unppsi_is_admin:
ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString"
ReadRegStr $R1 HKLM "Software\Affinix\${APPNAME}" ""
unppsi_done:
; $R0 holds the path to the uninstaller
; $R1 holds the install dir
StrCmp $R0 "" auto_uninstall_done
MessageBox MB_YESNO|MB_ICONEXCLAMATION "$LSTR_A_INSTALLED" \
IDYES auto_uninstall_yes \
IDNO auto_uninstall_done
;Run the uninstaller
auto_uninstall_yes:
ClearErrors
ExecWait '$R0 /S _?=$INSTDIR'
;Uninstall silently
;Do not copy the uninstaller to a temp file
IfErrors no_remove_uninstaller
Goto auto_uninstall_done
no_remove_uninstaller:
MessageBox MB_YESNO|MB_ICONQUESTION "$LSTR_ERR_UNINST" \
IDYES auto_uninstall_done \
IDNO auto_uninstall_exit
auto_uninstall_exit:
Quit
auto_uninstall_done:
FunctionEnd
; eof