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>
6 ;--------------------------------
10 ;--------------------------------
12 ;Needs to be 4 numbers: W.X.Y.Z
13 !define VIKING_VERSION "1.6.1.0"
15 ;The name var is set in .onInit
18 ;Allow overiding location of binary components for the install
20 !define BINARIES ".\bin"
23 OutFile "viking-${VIKING_VERSION}.exe"
25 ;NB Using /SOLID method on a mingw32 setup seems to generate an exe that fails the CRC check
26 ;So now don't set the compressor here - it can be set by the calling command/script if necessary.
27 ;SetCompressor /SOLID bzip2
29 ShowUninstDetails show
32 ; $name and $INSTDIR are set in .onInit function..
35 !include "Sections.nsh"
37 !include "LogicLib.nsh"
39 ;; http://nsis.sourceforge.net/File_Association
40 !include "FileAssociation.nsh"
42 !include "FileFunc.nsh"
43 !insertmacro GetParameters
44 !insertmacro GetOptions
45 !insertmacro GetParent
47 !include "WordFunc.nsh"
49 ;--------------------------------
52 !define VIKING_NSIS_INCLUDE_PATH "."
54 ; Remove these and the stuff that uses them at some point
55 !define VIKING_REG_KEY "SOFTWARE\viking"
56 !define VIKING_UNINSTALL_KEY "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\viking"
58 !define HKLM_APP_PATHS_KEY "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\viking.exe"
59 !define VIKING_UNINST_EXE "viking-uninst.exe"
61 ;--------------------------------
63 VIProductVersion "${VIKING_VERSION}"
64 VIAddVersionKey "ProductName" "Viking"
65 VIAddVersionKey "FileVersion" "${VIKING_VERSION}"
66 VIAddVersionKey "ProductVersion" "${VIKING_VERSION}"
67 VIAddVersionKey "LegalCopyright" ""
68 VIAddVersionKey "FileDescription" "Viking Installer"
70 ;--------------------------------
71 ;Modern UI Configuration
73 !define MUI_ICON ".\pixmaps\viking_icon.ico"
74 !define MUI_UNICON ".\pixmaps\viking_icon.ico"
75 ; !define MUI_WELCOMEFINISHPAGE_BITMAP ".\pixmaps\viking-intro.bmp"
76 ; !define MUI_HEADERIMAGE
77 ; !define MUI_HEADERIMAGE_BITMAP ".\pixmaps\viking-header.bmp"
79 ; Alter License section
80 !define MUI_LICENSEPAGE_BUTTON $(VIKING_LICENSE_BUTTON)
81 !define MUI_LICENSEPAGE_TEXT_BOTTOM $(VIKING_LICENSE_BOTTOM_TEXT)
83 !define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
84 !define MUI_LANGDLL_REGISTRY_KEY ${VIKING_REG_KEY}
85 !define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
87 !define MUI_COMPONENTSPAGE_SMALLDESC
88 !define MUI_ABORTWARNING
91 !define MUI_FINISHPAGE_NOAUTOCLOSE
92 !define MUI_FINISHPAGE_RUN "$INSTDIR\viking.exe"
93 !define MUI_FINISHPAGE_RUN_NOTCHECKED
94 !define MUI_FINISHPAGE_LINK $(VIKING_FINISH_VISIT_WEB_SITE)
95 !define MUI_FINISHPAGE_LINK_LOCATION "http://viking.sourceforge.net"
97 ;--------------------------------
100 !insertmacro MUI_PAGE_WELCOME
101 !insertmacro MUI_PAGE_LICENSE "${BINARIES}\COPYING_GPL.txt"
102 !insertmacro MUI_PAGE_COMPONENTS
104 ; Viking install dir page
105 !insertmacro MUI_PAGE_DIRECTORY
107 !insertmacro MUI_PAGE_INSTFILES
108 !insertmacro MUI_PAGE_FINISH
110 !insertmacro MUI_UNPAGE_WELCOME
111 !insertmacro MUI_UNPAGE_CONFIRM
112 !insertmacro MUI_UNPAGE_INSTFILES
113 !insertmacro MUI_UNPAGE_FINISH
115 ;--------------------------------
118 ;; English goes first because its the default. The rest are
119 ;; in alphabetical order (at least the strings actually displayed
122 !insertmacro MUI_LANGUAGE "English"
123 !insertmacro MUI_LANGUAGE "French"
124 !insertmacro MUI_LANGUAGE "Spanish"
126 ;--------------------------------
129 !define VIKING_DEFAULT_LANGFILE "${VIKING_NSIS_INCLUDE_PATH}\translations\english.nsh"
131 !include "${VIKING_NSIS_INCLUDE_PATH}\langmacros.nsh"
133 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "ENGLISH" "${VIKING_NSIS_INCLUDE_PATH}\translations\english.nsh"
134 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "FRENCH" "${VIKING_NSIS_INCLUDE_PATH}\translations\french.nsh"
135 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "SPANISH" "${VIKING_NSIS_INCLUDE_PATH}\translations\spanish.nsh"
137 ;--------------------------------
139 ; Only need this if using bzip2 compression
141 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
142 !insertmacro MUI_RESERVEFILE_LANGDLL
143 ReserveFile "${NSISDIR}\Plugins\UserInfo.dll"
146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
147 ;; Start Install Sections ;;
148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
150 LicenseData "${BINARIES}\COPYING_GPL.txt"
151 LicenseForceSelection checkbox
153 ;--------------------------------
154 ;Uninstall any old version of Viking
156 Section -SecUninstallOldViking
157 ; Check install rights..
158 Call CheckUserInstallRights
161 ;First try to uninstall Viking
162 StrCpy $R4 ${VIKING_REG_KEY}
163 StrCpy $R5 ${VIKING_UNINSTALL_KEY}
164 StrCpy $R6 ${VIKING_UNINST_EXE}
167 ;Determine user install rights
168 StrCmp $R0 "HKLM" compare_hklm
169 StrCmp $R0 "HKCU" compare_hkcu done
172 ReadRegStr $R1 HKCU $R4 ""
173 ReadRegStr $R2 HKCU $R4 "Version"
174 ReadRegStr $R3 HKCU "$R5" "UninstallString"
178 ReadRegStr $R1 HKLM $R4 ""
179 ReadRegStr $R2 HKLM $R4 "Version"
180 ReadRegStr $R3 HKLM "$R5" "UninstallString"
182 ; If a previous version exists, remove it
185 StrCmp $R2 "" uninstall_problem
186 ; Check if we have uninstall string..
187 IfFileExists $R3 0 uninstall_problem
188 ; Have uninstall string, go ahead and uninstall.
190 ; Need to copy uninstaller outside of the install dir
192 CopyFiles /SILENT $R3 "$TEMP\$R6"
194 IfErrors uninstall_problem
195 ; Ready to uninstall..
197 ExecWait '"$TEMP\$R6" /S _?=$R1'
204 Goto uninstall_problem
207 ; We can't uninstall. Either the user must manually uninstall or we ignore and reinstall over it.
208 MessageBox MB_OKCANCEL $(VIKING_PROMPT_CONTINUE_WITHOUT_UNINSTALL) /SD IDOK IDOK done
214 ;--------------------------------
215 ;Viking Install Section
217 Section $(VIKING_SECTION_TITLE) SecViking
220 ; Check install rights..
221 Call CheckUserInstallRights
223 StrCmp $R0 "NONE" viking_none
224 StrCmp $R0 "HKLM" viking_hklm viking_hkcu
226 ;Install rights for Local Machine
228 WriteRegStr HKLM "${HKLM_APP_PATHS_KEY}" "" "$INSTDIR\viking.exe"
229 WriteRegStr HKLM "${HKLM_APP_PATHS_KEY}" "Path" "$R1\bin"
230 ; Sets scope of the desktop and Start Menu entries for all users.
231 SetShellVarContext "all"
232 Goto viking_install_files
234 ;Install rights for Current User only
236 Goto viking_install_files
241 viking_install_files:
242 SetOutPath "$INSTDIR"
246 WriteRegStr SHCTX ${VIKING_REG_KEY} "" "$INSTDIR"
247 WriteRegStr SHCTX ${VIKING_REG_KEY} "Version" "${VIKING_VERSION}"
249 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "DisplayName" "Viking (x86)"
251 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "DisplayName" "Viking (x64)"
253 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "DisplayVersion" "${VIKING_VERSION}"
254 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "DisplayIcon" "$INSTDIR\viking_icon.ico"
255 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "HelpLink" "http://sourceforge.net/p/viking/wikiallura"
256 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "URLInfoAbout" "http://sourceforge.net/projects/viking/"
257 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "Publisher" "The Viking developer community"
258 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "Comments" "$(VIKING_UNINSTALL_COMMENTS)"
259 WriteRegDWORD SHCTX "${VIKING_UNINSTALL_KEY}" "NoModify" 1
260 WriteRegDWORD SHCTX "${VIKING_UNINSTALL_KEY}" "NoRepair" 1
261 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "UninstallString" "$INSTDIR\${VIKING_UNINST_EXE}"
263 ; Copy only specific items as now some components (e.g. GPSBabel) are optional.
264 ; This is mostly to get a more accurate install size value (especially as saved into the registry)
265 File ${BINARIES}\viking*
266 File ${BINARIES}\g*.exe
267 File ${BINARIES}\*.dll
268 File ${BINARIES}\*.txt
269 File ${BINARIES}\magic.mgc
270 File /r ${BINARIES}\data
271 File /r ${BINARIES}\locale
273 ; Estimate install size based on files in $INSTDIR
274 ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
275 IntFmt $0 "0x%08X" $0
276 WriteRegDWORD SHCTX "${VIKING_UNINSTALL_KEY}" "EstimatedSize" "$0"
278 ; If we don't have install rights we're done
279 StrCmp $R0 "NONE" done
282 ; write out uninstaller
284 WriteUninstaller "$INSTDIR\${VIKING_UNINST_EXE}"
287 ; Always associate Viking file type
288 ${registerExtension} "$INSTDIR\viking.exe" ".vik" "Viking File"
290 SectionEnd ; end of default Viking section
292 ;--------------------------------
295 SectionGroup /e $(VIKING_SHORTCUTS_SECTION_TITLE) SecShortcuts
297 Section /o $(VIKING_DESKTOP_SHORTCUT_SECTION_TITLE) SecDesktopShortcut
299 CreateShortCut "$DESKTOP\Viking.lnk" "$INSTDIR\viking.exe"
302 ;Start menu shortcuts
303 Section $(VIKING_STARTMENU_SHORTCUT_SECTION_TITLE) SecStartMenuShortcut
305 CreateDirectory "$SMPROGRAMS\Viking"
306 CreateShortCut "$SMPROGRAMS\Viking\Viking.lnk" "$INSTDIR\viking.exe"
307 CreateShortCut "$SMPROGRAMS\Viking\User Manual.lnk" "$INSTDIR\viking.pdf"
308 CreateShortCut "$SMPROGRAMS\Viking\Uninstall.lnk" "$INSTDIR\viking-uninst.exe"
313 ;--------------------------------
316 Section $(VIKING_FILE_ASSOCIATION_SECTION_TITLE) SecFileAssociation
317 ${registerExtension} "$INSTDIR\viking.exe" ".gpx" "GPX File"
320 ;--------------------------------
321 ; GPSBabel Install Section
323 Section $(VIKING_GPSBABEL_SECTION_TITLE) SecGPSBabel
324 File "${BINARIES}\Optional\GPSBabel-1.5.2-Setup.exe"
325 ExecWait '"$INSTDIR\GPSBabel-1.5.2-Setup.exe" /SILENT'
326 Delete "$INSTDIR\GPSBabel-1.5.2-Setup.exe"
329 ;--------------------------------
334 Call un.CheckUserInstallRights
336 StrCmp $R0 "NONE" no_rights
337 StrCmp $R0 "HKCU" try_hkcu try_hklm
340 ReadRegStr $R0 HKCU ${VIKING_REG_KEY} ""
341 StrCmp $R0 $INSTDIR 0 cant_uninstall
342 ; HKCU install path matches our INSTDIR so uninstall
343 DeleteRegKey HKCU ${VIKING_REG_KEY}
344 DeleteRegKey HKCU "${VIKING_UNINSTALL_KEY}"
348 ReadRegStr $R0 HKLM ${VIKING_REG_KEY} ""
349 StrCmp $R0 $INSTDIR 0 try_hkcu
350 ; HKLM install path matches our INSTDIR so uninstall
351 DeleteRegKey HKLM ${VIKING_REG_KEY}
352 DeleteRegKey HKLM "${VIKING_UNINSTALL_KEY}"
353 DeleteRegKey HKLM "${HKLM_APP_PATHS_KEY}"
354 ; Sets start menu and desktop scope to all users..
355 SetShellVarContext "all"
359 ; http://nsis.sourceforge.net/Docs/Chapter4.html
362 ; Warning: is not safe. Can delete entire Program Files directory!
364 ; TODO try this method instead:
365 ; http://nsis.sourceforge.net/Uninstall_only_installed_files
367 ; Specific remove files
368 ; Thus alsos leaves any files the user has saved (particularly .vik or .gpx) into the Viking directory
369 Delete "$INSTDIR\viking-cache.py"
370 Delete "$INSTDIR\viking.pdf"
371 Delete "$INSTDIR\viking_icon.ico"
372 Delete "$INSTDIR\*.exe"
373 Delete "$INSTDIR\*.dll"
374 Delete "$INSTDIR\*.txt"
375 Delete "$INSTDIR\magic.mgc"
376 Delete "$INSTDIR\data\*txt"
377 Delete "$INSTDIR\data\*xml"
378 RMDir "$INSTDIR\data"
379 RMDir /r "$INSTDIR\locale"
383 Delete "$DESKTOP\Viking.lnk"
386 ${unregisterExtension} ".vik" "Viking File"
387 ${unregisterExtension} ".gpx" "GPX File"
392 MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_1) /SD IDOK
396 MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_2) /SD IDOK
400 SectionEnd ; end of uninstall section
402 ;--------------------------------
404 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
406 !insertmacro MUI_DESCRIPTION_TEXT ${SecViking} \
407 $(VIKING_SECTION_DESCRIPTION)
408 !insertmacro MUI_DESCRIPTION_TEXT ${SecShortcuts} \
409 $(VIKING_SHORTCUTS_SECTION_DESCRIPTION)
410 !insertmacro MUI_DESCRIPTION_TEXT ${SecDesktopShortcut} \
411 $(VIKING_DESKTOP_SHORTCUT_DESC)
412 !insertmacro MUI_DESCRIPTION_TEXT ${SecStartMenuShortcut} \
413 $(VIKING_STARTMENU_SHORTCUT_DESC)
414 !insertmacro MUI_DESCRIPTION_TEXT ${SecFileAssociation} \
415 $(VIKING_FILE_ASSOCIATION_DESC)
416 !insertmacro MUI_DESCRIPTION_TEXT ${SecGPSBabel} \
417 $(VIKING_INSTALL_GPSBABEL_DESC)
419 !insertmacro MUI_FUNCTION_DESCRIPTION_END
421 ;--------------------------------
424 ;Macro to determine user install rights
425 ;Will be used to determine where to install the program, shortcuts, ...
426 !macro CheckUserInstallRightsMacro UN
427 Function ${UN}CheckUserInstallRights
434 UserInfo::GetAccountType
437 StrCmp $1 "Admin" 0 +3
440 StrCmp $1 "Power" 0 +3
443 StrCmp $1 "User" 0 +3
446 StrCmp $1 "Guest" 0 +3
462 !insertmacro CheckUserInstallRightsMacro ""
463 !insertmacro CheckUserInstallRightsMacro "un."
465 ;Macro to determine if Viking is running before installation/unistallation
466 !macro RunCheckMacro UN
467 Function ${UN}RunCheck
468 FindProcDLL::FindProc "viking.exe"
469 IntCmp $R0 1 0 notRunning
470 MessageBox MB_OK|MB_ICONEXCLAMATION $(VIKING_IS_RUNNING) /SD IDOK
476 ;!insertmacro RunCheckMacro ""
477 ;!insertmacro RunCheckMacro "un."
479 ;Installer extra configuration at execution time: language, path, ...
481 ;Check if viking installer is already running
486 ;Check if viking is running
488 StrCpy $name "Viking ${VIKING_VERSION}"
491 ;Make sure that there was a previous installation
492 ReadRegStr $R0 HKCU "${VIKING_REG_KEY}" "Installer Language"
494 ;Preselect the "shortcuts" checkboxes according to the previous installation
495 !insertmacro SelectSection ${SecDesktopShortcut}
496 !insertmacro selectSection ${SecStartMenuShortcut}
498 ;Read command line parameters
500 ;Read language command line parameters
503 ${GetOptions} "$R0" "/L=" $R1
509 ; Display Language selection dialog
510 !insertmacro MUI_LANGDLL_DISPLAY
513 ;Read desktop shortcut command line options
515 ${GetOptions} "$R0" "/DS=" $R1
517 SectionGetFlags ${SecDesktopShortcut} $R2
519 IntOp $R2 $R2 | ${SF_SELECTED}
521 IntOp $R1 ${SF_SELECTED} ~
523 SectionSetFlags ${SecDesktopShortcut} $R2
525 ;Read start menu shortcuts command line options
527 ${GetOptions} "$R0" "/SMS=" $R1
529 SectionGetFlags ${SecStartMenuShortcut} $R2
531 IntOp $R2 $R2 | ${SF_SELECTED}
533 IntOp $R1 ${SF_SELECTED} ~
535 SectionSetFlags ${SecStartMenuShortcut} $R2
537 ; If install path was set on the command, use it.
538 StrCmp $INSTDIR "" 0 instdir_done
540 ; If viking is currently installed, we should default to where it is currently installed
542 ReadRegStr $INSTDIR HKCU "${VIKING_REG_KEY}" ""
544 StrCmp $INSTDIR "" 0 instdir_done
546 ReadRegStr $INSTDIR HKLM "${VIKING_REG_KEY}" ""
548 StrCmp $INSTDIR "" 0 instdir_done
550 Call CheckUserInstallRights
553 StrCmp $R0 "HKLM" 0 user_dir
555 StrCpy $INSTDIR "$PROGRAMFILES64\Viking"
557 StrCpy $INSTDIR "$PROGRAMFILES\Viking" ; $PROGRAMFILES32 also works
562 ${GetParent} $SMPROGRAMS $R2
564 StrCpy $INSTDIR "$R2\Viking"
574 ;Check if viking is running
576 StrCpy $name "Viking ${VIKING_VERSION}"
578 ; Get stored language preference
579 !insertmacro MUI_UNGETLANGUAGE