]> git.street.me.uk Git - andy/viking.git/blame - win32/installer/viking-installer.nsi
[WINDOWS] Enable optional install of GPSBabel 1.5.1
[andy/viking.git] / win32 / installer / viking-installer.nsi
CommitLineData
773eb66a
MA
1; Installer script for win32 Viking
2; Based on Win32 Pidgin installer by Herman Bloggs <hermanator12002@yahoo.com>
3; and Daniel Atallah <daniel_atallah@yahoo.com>
4; Heavily modified for Viking by Mathieu Albinet <mathieu_a@users.sourceforge.net>
5
6;--------------------------------
7;Global Variables
8Var name
9
10;--------------------------------
11;Configuration
e70384e0 12;Needs to be 4 numbers: W.X.Y.Z
b1f2d51f 13!define VIKING_VERSION "1.5.0.0"
773eb66a
MA
14
15;The name var is set in .onInit
16Name $name
17
18OutFile "viking-${VIKING_VERSION}.exe"
19
20SetCompressor /SOLID lzma
21ShowInstDetails show
22ShowUninstDetails show
23SetDateSave on
24
25; $name and $INSTDIR are set in .onInit function..
26
27!include "MUI.nsh"
28!include "Sections.nsh"
29!include "WinVer.nsh"
30!include "LogicLib.nsh"
93950f79
MA
31;; http://nsis.sourceforge.net/File_Association
32!include "FileAssociation.nsh"
773eb66a
MA
33
34!include "FileFunc.nsh"
35!insertmacro GetParameters
36!insertmacro GetOptions
37!insertmacro GetParent
38
39!include "WordFunc.nsh"
40
41;--------------------------------
42;Defines
43
44!define VIKING_NSIS_INCLUDE_PATH "."
45
46; Remove these and the stuff that uses them at some point
47!define VIKING_REG_KEY "SOFTWARE\viking"
48!define VIKING_UNINSTALL_KEY "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\viking"
49
50!define HKLM_APP_PATHS_KEY "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\viking.exe"
51!define VIKING_UNINST_EXE "viking-uninst.exe"
52
773eb66a
MA
53;--------------------------------
54;Version resource
55VIProductVersion "${VIKING_VERSION}"
56VIAddVersionKey "ProductName" "Viking"
57VIAddVersionKey "FileVersion" "${VIKING_VERSION}"
58VIAddVersionKey "ProductVersion" "${VIKING_VERSION}"
59VIAddVersionKey "LegalCopyright" ""
60VIAddVersionKey "FileDescription" "Viking Installer"
61
62;--------------------------------
63;Modern UI Configuration
64
65 !define MUI_ICON ".\pixmaps\viking_icon.ico"
66 !define MUI_UNICON ".\pixmaps\viking_icon.ico"
67; !define MUI_WELCOMEFINISHPAGE_BITMAP ".\pixmaps\viking-intro.bmp"
68; !define MUI_HEADERIMAGE
69; !define MUI_HEADERIMAGE_BITMAP ".\pixmaps\viking-header.bmp"
70
71 ; Alter License section
72 !define MUI_LICENSEPAGE_BUTTON $(VIKING_LICENSE_BUTTON)
73 !define MUI_LICENSEPAGE_TEXT_BOTTOM $(VIKING_LICENSE_BOTTOM_TEXT)
74
75 !define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
76 !define MUI_LANGDLL_REGISTRY_KEY ${VIKING_REG_KEY}
77 !define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
78
79 !define MUI_COMPONENTSPAGE_SMALLDESC
80 !define MUI_ABORTWARNING
81
82 ;Finish Page config
83 !define MUI_FINISHPAGE_NOAUTOCLOSE
84 !define MUI_FINISHPAGE_RUN "$INSTDIR\viking.exe"
85 !define MUI_FINISHPAGE_RUN_NOTCHECKED
86 !define MUI_FINISHPAGE_LINK $(VIKING_FINISH_VISIT_WEB_SITE)
87 !define MUI_FINISHPAGE_LINK_LOCATION "http://viking.sourceforge.net"
88
89;--------------------------------
90;Pages
91
92 !insertmacro MUI_PAGE_WELCOME
93 !insertmacro MUI_PAGE_LICENSE ".\bin\COPYING_GPL.txt"
94 !insertmacro MUI_PAGE_COMPONENTS
95
96 ; Viking install dir page
97 !insertmacro MUI_PAGE_DIRECTORY
98
99 !insertmacro MUI_PAGE_INSTFILES
100 !insertmacro MUI_PAGE_FINISH
101
102 !insertmacro MUI_UNPAGE_WELCOME
103 !insertmacro MUI_UNPAGE_CONFIRM
104 !insertmacro MUI_UNPAGE_INSTFILES
105 !insertmacro MUI_UNPAGE_FINISH
106
107;--------------------------------
108;Languages
109
110 ;; English goes first because its the default. The rest are
111 ;; in alphabetical order (at least the strings actually displayed
112 ;; will be).
113
114 !insertmacro MUI_LANGUAGE "English"
115 !insertmacro MUI_LANGUAGE "French"
25d341c5 116 !insertmacro MUI_LANGUAGE "Spanish"
773eb66a
MA
117
118;--------------------------------
119;Translations
120
121 !define VIKING_DEFAULT_LANGFILE "${VIKING_NSIS_INCLUDE_PATH}\translations\english.nsh"
122
123 !include "${VIKING_NSIS_INCLUDE_PATH}\langmacros.nsh"
124
125 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "ENGLISH" "${VIKING_NSIS_INCLUDE_PATH}\translations\english.nsh"
126 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "FRENCH" "${VIKING_NSIS_INCLUDE_PATH}\translations\french.nsh"
c34f39b7 127 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "SPANISH" "${VIKING_NSIS_INCLUDE_PATH}\translations\spanish.nsh"
773eb66a
MA
128
129;--------------------------------
130;Reserve Files
131 ; Only need this if using bzip2 compression
132
133 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
134 !insertmacro MUI_RESERVEFILE_LANGDLL
135 ReserveFile "${NSISDIR}\Plugins\UserInfo.dll"
136
137
138;;;;;;;;;;;;;;;;;;;;;;;;;;;;
139;; Start Install Sections ;;
140;;;;;;;;;;;;;;;;;;;;;;;;;;;;
141
142;--------------------------------
143;Uninstall any old version of Viking
144
145Section -SecUninstallOldViking
146 ; Check install rights..
147 Call CheckUserInstallRights
148 Pop $R0
149
150 ;First try to uninstall Viking
151 StrCpy $R4 ${VIKING_REG_KEY}
152 StrCpy $R5 ${VIKING_UNINSTALL_KEY}
153 StrCpy $R6 ${VIKING_UNINST_EXE}
154 StrCpy $R7 "Viking"
155
156 ;Determine user install rights
157 StrCmp $R0 "HKLM" compare_hklm
158 StrCmp $R0 "HKCU" compare_hkcu done
159
160 compare_hkcu:
161 ReadRegStr $R1 HKCU $R4 ""
162 ReadRegStr $R2 HKCU $R4 "Version"
163 ReadRegStr $R3 HKCU "$R5" "UninstallString"
164 Goto try_uninstall
165
166 compare_hklm:
167 ReadRegStr $R1 HKLM $R4 ""
168 ReadRegStr $R2 HKLM $R4 "Version"
169 ReadRegStr $R3 HKLM "$R5" "UninstallString"
170
171 ; If a previous version exists, remove it
172 try_uninstall:
173 StrCmp $R1 "" done
174 StrCmp $R2 "" uninstall_problem
175 ; Check if we have uninstall string..
176 IfFileExists $R3 0 uninstall_problem
177 ; Have uninstall string, go ahead and uninstall.
178 SetOverwrite on
179 ; Need to copy uninstaller outside of the install dir
180 ClearErrors
181 CopyFiles /SILENT $R3 "$TEMP\$R6"
182 SetOverwrite off
183 IfErrors uninstall_problem
184 ; Ready to uninstall..
185 ClearErrors
186 ExecWait '"$TEMP\$R6" /S _?=$R1'
187 IfErrors exec_error
188 Delete "$TEMP\$R6"
189 Goto done
190
191 exec_error:
192 Delete "$TEMP\$R6"
193 Goto uninstall_problem
194
195 uninstall_problem:
196 ; We can't uninstall. Either the user must manually uninstall or we ignore and reinstall over it.
197 MessageBox MB_OKCANCEL $(VIKING_PROMPT_CONTINUE_WITHOUT_UNINSTALL) /SD IDOK IDOK done
198 Quit
199 done:
200SectionEnd
201
202;--------------------------------
203;Viking Install Section
204
205Section $(VIKING_SECTION_TITLE) SecViking
206 SectionIn 1 RO
207
208 ; Check install rights..
209 Call CheckUserInstallRights
210 Pop $R0
211 StrCmp $R0 "NONE" viking_none
212 StrCmp $R0 "HKLM" viking_hklm viking_hkcu
213
214 ;Install rights for Local Machine
215 viking_hklm:
216 WriteRegStr HKLM "${HKLM_APP_PATHS_KEY}" "" "$INSTDIR\viking.exe"
217 WriteRegStr HKLM "${HKLM_APP_PATHS_KEY}" "Path" "$R1\bin"
218 WriteRegStr HKLM ${VIKING_REG_KEY} "" "$INSTDIR"
219 WriteRegStr HKLM ${VIKING_REG_KEY} "Version" "${VIKING_VERSION}"
220 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "DisplayName" "Viking"
221 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "DisplayVersion" "${VIKING_VERSION}"
222 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "HelpLink" "http://sourceforge.net/apps/mediawiki/viking/"
223 WriteRegDWORD HKLM "${VIKING_UNINSTALL_KEY}" "NoModify" 1
224 WriteRegDWORD HKLM "${VIKING_UNINSTALL_KEY}" "NoRepair" 1
225 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "UninstallString" "$INSTDIR\${VIKING_UNINST_EXE}"
226 ; Sets scope of the desktop and Start Menu entries for all users.
227 SetShellVarContext "all"
228 Goto viking_install_files
229
230 ;Install rights for Current User only
231 viking_hkcu:
232 WriteRegStr HKCU ${VIKING_REG_KEY} "" "$INSTDIR"
233 WriteRegStr HKCU ${VIKING_REG_KEY} "Version" "${VIKING_VERSION}"
234 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "DisplayName" "Viking"
235 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "DisplayVersion" "${VIKING_VERSION}"
236 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "HelpLink" "http://sourceforge.net/apps/mediawiki/viking/"
237 WriteRegDWORD HKCU "${VIKING_UNINSTALL_KEY}" "NoModify" 1
238 WriteRegDWORD HKCU "${VIKING_UNINSTALL_KEY}" "NoRepair" 1
239 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "UninstallString" "$INSTDIR\${VIKING_UNINST_EXE}"
240 Goto viking_install_files
241
242 ;No install rights!
243 viking_none:
244
245 viking_install_files:
246 SetOutPath "$INSTDIR"
247 SetOverwrite on
248
249 File /r .\bin\*.*
250
251 ; If we don't have install rights we're done
252 StrCmp $R0 "NONE" done
253 SetOverwrite off
254
255 ; write out uninstaller
256 SetOverwrite on
257 WriteUninstaller "$INSTDIR\${VIKING_UNINST_EXE}"
258 SetOverwrite off
259
260 done:
261SectionEnd ; end of default Viking section
262
263;--------------------------------
264;Shortcuts
265
266SectionGroup /e $(VIKING_SHORTCUTS_SECTION_TITLE) SecShortcuts
267 ;Desktop shortcuts
268 Section /o $(VIKING_DESKTOP_SHORTCUT_SECTION_TITLE) SecDesktopShortcut
269 SetOverwrite on
270 CreateShortCut "$DESKTOP\Viking.lnk" "$INSTDIR\viking.exe"
271 SetOverwrite off
272 SectionEnd
273 ;Start menu shortcuts
274 Section $(VIKING_STARTMENU_SHORTCUT_SECTION_TITLE) SecStartMenuShortcut
275 SetOverwrite on
276 CreateDirectory "$SMPROGRAMS\Viking"
277 CreateShortCut "$SMPROGRAMS\Viking\Viking.lnk" "$INSTDIR\viking.exe"
278 CreateShortCut "$SMPROGRAMS\Viking\User Manual.lnk" "$INSTDIR\viking.pdf"
279 CreateShortCut "$SMPROGRAMS\Viking\Uninstall.lnk" "$INSTDIR\viking-uninst.exe"
280 SetOverwrite off
281 SectionEnd
282SectionGroupEnd
283
93950f79
MA
284;--------------------------------
285;File association
773eb66a 286
93950f79
MA
287Section $(VIKING_FILE_ASSOCIATION_SECTION_TITLE) SecFileAssociation
288 ${registerExtension} "$INSTDIR\viking.exe" ".vik" "Viking File"
289SectionEnd
773eb66a 290
f570ee2b
RN
291;--------------------------------
292; GPSBabel Install Section
293;
294Section $(VIKING_GPSBABEL_SECTION_TITLE) SecGPSBabel
295 File "bin\Optional\GPSBabel-1.5.1-Setup.exe"
296 ExecWait '"$INSTDIR\GPSBabel-1.5.1-Setup.exe" /SILENT'
297 Delete "$INSTDIR\GPSBabel-1.5.1-Setup.exe"
298SectionEnd
773eb66a
MA
299
300;--------------------------------
301;Uninstaller Section
302
303
304Section Uninstall
305 Call un.CheckUserInstallRights
306 Pop $R0
307 StrCmp $R0 "NONE" no_rights
308 StrCmp $R0 "HKCU" try_hkcu try_hklm
309
310 try_hkcu:
311 ReadRegStr $R0 HKCU ${VIKING_REG_KEY} ""
312 StrCmp $R0 $INSTDIR 0 cant_uninstall
313 ; HKCU install path matches our INSTDIR so uninstall
314 DeleteRegKey HKCU ${VIKING_REG_KEY}
315 DeleteRegKey HKCU "${VIKING_UNINSTALL_KEY}"
316 Goto cont_uninstall
317
318 try_hklm:
319 ReadRegStr $R0 HKLM ${VIKING_REG_KEY} ""
320 StrCmp $R0 $INSTDIR 0 try_hkcu
321 ; HKLM install path matches our INSTDIR so uninstall
322 DeleteRegKey HKLM ${VIKING_REG_KEY}
323 DeleteRegKey HKLM "${VIKING_UNINSTALL_KEY}"
324 DeleteRegKey HKLM "${HKLM_APP_PATHS_KEY}"
325 ; Sets start menu and desktop scope to all users..
326 SetShellVarContext "all"
327
328 cont_uninstall:
329
59a4fc6d
RN
330 ;Simply wipe the Viking install dir
331 RMDir /r "$INSTDIR"
773eb66a
MA
332
333 ; Shortcuts..
334 Delete "$DESKTOP\Viking.lnk"
335
93950f79
MA
336 ; File association
337 ${unregisterExtension} ".vik" "Viking File"
338
773eb66a
MA
339 Goto done
340
341 cant_uninstall:
342 MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_1) /SD IDOK
343 Quit
344
345 no_rights:
346 MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_2) /SD IDOK
347 Quit
348
349 done:
350SectionEnd ; end of uninstall section
351
352;--------------------------------
353;Descriptions
354!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
355
356 !insertmacro MUI_DESCRIPTION_TEXT ${SecViking} \
357 $(VIKING_SECTION_DESCRIPTION)
358 !insertmacro MUI_DESCRIPTION_TEXT ${SecShortcuts} \
359 $(VIKING_SHORTCUTS_SECTION_DESCRIPTION)
360 !insertmacro MUI_DESCRIPTION_TEXT ${SecDesktopShortcut} \
361 $(VIKING_DESKTOP_SHORTCUT_DESC)
362 !insertmacro MUI_DESCRIPTION_TEXT ${SecStartMenuShortcut} \
363 $(VIKING_STARTMENU_SHORTCUT_DESC)
93950f79
MA
364 !insertmacro MUI_DESCRIPTION_TEXT ${SecFileAssociation} \
365 $(VIKING_FILE_ASSOCIATION_DESC)
f570ee2b
RN
366 !insertmacro MUI_DESCRIPTION_TEXT ${SecGPSBabel} \
367 $(VIKING_INSTALL_GPSBABEL_DESC)
773eb66a
MA
368
369!insertmacro MUI_FUNCTION_DESCRIPTION_END
370
371;--------------------------------
372;Functions
373
374;Macro to determine user install rights
375;Will be used to determine where to install the program, shortcuts, ...
376!macro CheckUserInstallRightsMacro UN
377Function ${UN}CheckUserInstallRights
378 Push $0
379 Push $1
380 ClearErrors
381 UserInfo::GetName
382 IfErrors Win9x
383 Pop $0
384 UserInfo::GetAccountType
385 Pop $1
386
387 StrCmp $1 "Admin" 0 +3
388 StrCpy $1 "HKLM"
389 Goto done
390 StrCmp $1 "Power" 0 +3
391 StrCpy $1 "HKLM"
392 Goto done
393 StrCmp $1 "User" 0 +3
394 StrCpy $1 "HKCU"
395 Goto done
396 StrCmp $1 "Guest" 0 +3
397 StrCpy $1 "NONE"
398 Goto done
399 ; Unknown error
400 StrCpy $1 "NONE"
401 Goto done
402
403 Win9x:
404 StrCpy $1 "HKLM"
405
406 done:
407 Exch $1
408 Exch
409 Pop $0
410FunctionEnd
411!macroend
412!insertmacro CheckUserInstallRightsMacro ""
413!insertmacro CheckUserInstallRightsMacro "un."
414
415;Macro to determine if Viking is running before installation/unistallation
416!macro RunCheckMacro UN
417Function ${UN}RunCheck
418 FindProcDLL::FindProc "viking.exe"
419 IntCmp $R0 1 0 notRunning
420 MessageBox MB_OK|MB_ICONEXCLAMATION $(VIKING_IS_RUNNING) /SD IDOK
421 Abort
422 notRunning:
423FunctionEnd
424!macroend
425
426!insertmacro RunCheckMacro ""
427!insertmacro RunCheckMacro "un."
428
429;Installer extra configuration at execution time: language, path, ...
430Function .onInit
431 ;Check if viking installer is already running
432 Push $R0
433 Push $R1
434 Push $R2
435
436 ;Check if viking is running
437 Call RunCheck
438 StrCpy $name "Viking ${VIKING_VERSION}"
439
440 ClearErrors
441 ;Make sure that there was a previous installation
442 ReadRegStr $R0 HKCU "${VIKING_REG_KEY}" "Installer Language"
443
444 ;Preselect the "shortcuts" checkboxes according to the previous installation
445 !insertmacro SelectSection ${SecDesktopShortcut}
446 !insertmacro selectSection ${SecStartMenuShortcut}
447
448 ;Read command line parameters
449
450 ;Read language command line parameters
451 ${GetParameters} $R0
452 ClearErrors
453 ${GetOptions} "$R0" "/L=" $R1
454 IfErrors +3
455 StrCpy $LANGUAGE $R1
456 Goto skip_lang
457
458 ; Select Language
459 ; Display Language selection dialog
460 !insertmacro MUI_LANGDLL_DISPLAY
461 skip_lang:
462
463 ;Read desktop shortcut command line options
464 ClearErrors
465 ${GetOptions} "$R0" "/DS=" $R1
466 IfErrors +8
467 SectionGetFlags ${SecDesktopShortcut} $R2
468 StrCmp "1" $R1 0 +2
469 IntOp $R2 $R2 | ${SF_SELECTED}
470 StrCmp "0" $R1 0 +3
471 IntOp $R1 ${SF_SELECTED} ~
472 IntOp $R2 $R2 & $R1
473 SectionSetFlags ${SecDesktopShortcut} $R2
474
475 ;Read start menu shortcuts command line options
476 ClearErrors
477 ${GetOptions} "$R0" "/SMS=" $R1
478 IfErrors +8
479 SectionGetFlags ${SecStartMenuShortcut} $R2
480 StrCmp "1" $R1 0 +2
481 IntOp $R2 $R2 | ${SF_SELECTED}
482 StrCmp "0" $R1 0 +3
483 IntOp $R1 ${SF_SELECTED} ~
484 IntOp $R2 $R2 & $R1
485 SectionSetFlags ${SecStartMenuShortcut} $R2
486
487 ; If install path was set on the command, use it.
488 StrCmp $INSTDIR "" 0 instdir_done
489
490 ; If viking is currently installed, we should default to where it is currently installed
491 ClearErrors
492 ReadRegStr $INSTDIR HKCU "${VIKING_REG_KEY}" ""
493 IfErrors +2
494 StrCmp $INSTDIR "" 0 instdir_done
495 ClearErrors
496 ReadRegStr $INSTDIR HKLM "${VIKING_REG_KEY}" ""
497 IfErrors +2
498 StrCmp $INSTDIR "" 0 instdir_done
499
500 Call CheckUserInstallRights
501 Pop $R0
502
503 StrCmp $R0 "HKLM" 0 user_dir
504 StrCpy $INSTDIR "$PROGRAMFILES\Viking"
505 Goto instdir_done
506 user_dir:
507 Push $SMPROGRAMS
508 ${GetParent} $SMPROGRAMS $R2
509 ${GetParent} $R2 $R2
510 StrCpy $INSTDIR "$R2\Viking"
511
512 instdir_done:
513;LogSet on
514 Pop $R2
515 Pop $R1
516 Pop $R0
517FunctionEnd
518
519Function un.onInit
520 ;Check if viking is running
521 Call un.RunCheck
522 StrCpy $name "Viking ${VIKING_VERSION}"
523
524 ; Get stored language preference
525 !insertmacro MUI_UNGETLANGUAGE
526
527FunctionEnd