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"
38 ;; http://nsis.sourceforge.net/File_Association
39 !include "FileAssociation.nsh"
41 !include "FileFunc.nsh"
42 !insertmacro GetParameters
43 !insertmacro GetOptions
44 !insertmacro GetParent
46 !include "WordFunc.nsh"
48 ;--------------------------------
51 !define VIKING_NSIS_INCLUDE_PATH "."
53 ; Remove these and the stuff that uses them at some point
54 !define VIKING_REG_KEY "SOFTWARE\viking"
55 !define VIKING_UNINSTALL_KEY "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\viking"
57 !define HKLM_APP_PATHS_KEY "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\viking.exe"
58 !define VIKING_UNINST_EXE "viking-uninst.exe"
60 ;--------------------------------
62 VIProductVersion "${VIKING_VERSION}"
63 VIAddVersionKey "ProductName" "Viking"
64 VIAddVersionKey "FileVersion" "${VIKING_VERSION}"
65 VIAddVersionKey "ProductVersion" "${VIKING_VERSION}"
66 VIAddVersionKey "LegalCopyright" ""
67 VIAddVersionKey "FileDescription" "Viking Installer"
69 ;--------------------------------
70 ;Modern UI Configuration
72 !define MUI_ICON ".\pixmaps\viking_icon.ico"
73 !define MUI_UNICON ".\pixmaps\viking_icon.ico"
74 ; !define MUI_WELCOMEFINISHPAGE_BITMAP ".\pixmaps\viking-intro.bmp"
75 ; !define MUI_HEADERIMAGE
76 ; !define MUI_HEADERIMAGE_BITMAP ".\pixmaps\viking-header.bmp"
78 ; Alter License section
79 !define MUI_LICENSEPAGE_BUTTON $(VIKING_LICENSE_BUTTON)
80 !define MUI_LICENSEPAGE_TEXT_BOTTOM $(VIKING_LICENSE_BOTTOM_TEXT)
82 !define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
83 !define MUI_LANGDLL_REGISTRY_KEY ${VIKING_REG_KEY}
84 !define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
86 !define MUI_COMPONENTSPAGE_SMALLDESC
87 !define MUI_ABORTWARNING
90 !define MUI_FINISHPAGE_NOAUTOCLOSE
91 !define MUI_FINISHPAGE_RUN "$INSTDIR\viking.exe"
92 !define MUI_FINISHPAGE_RUN_NOTCHECKED
93 !define MUI_FINISHPAGE_LINK $(VIKING_FINISH_VISIT_WEB_SITE)
94 !define MUI_FINISHPAGE_LINK_LOCATION "http://viking.sourceforge.net"
96 ;--------------------------------
99 !insertmacro MUI_PAGE_WELCOME
100 !insertmacro MUI_PAGE_LICENSE "${BINARIES}\COPYING_GPL.txt"
101 !insertmacro MUI_PAGE_COMPONENTS
103 ; Viking install dir page
104 !insertmacro MUI_PAGE_DIRECTORY
106 !insertmacro MUI_PAGE_INSTFILES
107 !insertmacro MUI_PAGE_FINISH
109 !insertmacro MUI_UNPAGE_WELCOME
110 !insertmacro MUI_UNPAGE_CONFIRM
111 !insertmacro MUI_UNPAGE_INSTFILES
112 !insertmacro MUI_UNPAGE_FINISH
114 ;--------------------------------
117 ;; English goes first because its the default. The rest are
118 ;; in alphabetical order (at least the strings actually displayed
121 !insertmacro MUI_LANGUAGE "English"
122 !insertmacro MUI_LANGUAGE "French"
123 !insertmacro MUI_LANGUAGE "Spanish"
125 ;--------------------------------
128 !define VIKING_DEFAULT_LANGFILE "${VIKING_NSIS_INCLUDE_PATH}\translations\english.nsh"
130 !include "${VIKING_NSIS_INCLUDE_PATH}\langmacros.nsh"
132 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "ENGLISH" "${VIKING_NSIS_INCLUDE_PATH}\translations\english.nsh"
133 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "FRENCH" "${VIKING_NSIS_INCLUDE_PATH}\translations\french.nsh"
134 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "SPANISH" "${VIKING_NSIS_INCLUDE_PATH}\translations\spanish.nsh"
136 ;--------------------------------
138 ; Only need this if using bzip2 compression
140 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
141 !insertmacro MUI_RESERVEFILE_LANGDLL
142 ReserveFile "${NSISDIR}\Plugins\UserInfo.dll"
145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
146 ;; Start Install Sections ;;
147 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
149 LicenseData "${BINARIES}\COPYING_GPL.txt"
150 LicenseForceSelection checkbox
152 ;--------------------------------
153 ;Uninstall any old version of Viking
155 Section -SecUninstallOldViking
156 ; Check install rights..
157 Call CheckUserInstallRights
160 ;First try to uninstall Viking
161 StrCpy $R4 ${VIKING_REG_KEY}
162 StrCpy $R5 ${VIKING_UNINSTALL_KEY}
163 StrCpy $R6 ${VIKING_UNINST_EXE}
166 ;Determine user install rights
167 StrCmp $R0 "HKLM" compare_hklm
168 StrCmp $R0 "HKCU" compare_hkcu done
171 ReadRegStr $R1 HKCU $R4 ""
172 ReadRegStr $R2 HKCU $R4 "Version"
173 ReadRegStr $R3 HKCU "$R5" "UninstallString"
177 ReadRegStr $R1 HKLM $R4 ""
178 ReadRegStr $R2 HKLM $R4 "Version"
179 ReadRegStr $R3 HKLM "$R5" "UninstallString"
181 ; If a previous version exists, remove it
184 StrCmp $R2 "" uninstall_problem
185 ; Check if we have uninstall string..
186 IfFileExists $R3 0 uninstall_problem
187 ; Have uninstall string, go ahead and uninstall.
189 ; Need to copy uninstaller outside of the install dir
191 CopyFiles /SILENT $R3 "$TEMP\$R6"
193 IfErrors uninstall_problem
194 ; Ready to uninstall..
196 ExecWait '"$TEMP\$R6" /S _?=$R1'
203 Goto uninstall_problem
206 ; We can't uninstall. Either the user must manually uninstall or we ignore and reinstall over it.
207 MessageBox MB_OKCANCEL $(VIKING_PROMPT_CONTINUE_WITHOUT_UNINSTALL) /SD IDOK IDOK done
213 ;--------------------------------
214 ;Viking Install Section
216 Section $(VIKING_SECTION_TITLE) SecViking
219 ; Check install rights..
220 Call CheckUserInstallRights
222 StrCmp $R0 "NONE" viking_none
223 StrCmp $R0 "HKLM" viking_hklm viking_hkcu
225 ;Install rights for Local Machine
227 WriteRegStr HKLM "${HKLM_APP_PATHS_KEY}" "" "$INSTDIR\viking.exe"
228 WriteRegStr HKLM "${HKLM_APP_PATHS_KEY}" "Path" "$R1\bin"
229 ; Sets scope of the desktop and Start Menu entries for all users.
230 SetShellVarContext "all"
231 Goto viking_install_files
233 ;Install rights for Current User only
235 Goto viking_install_files
240 viking_install_files:
241 SetOutPath "$INSTDIR"
245 WriteRegStr SHCTX ${VIKING_REG_KEY} "" "$INSTDIR"
246 WriteRegStr SHCTX ${VIKING_REG_KEY} "Version" "${VIKING_VERSION}"
247 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "DisplayName" "Viking"
248 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "DisplayVersion" "${VIKING_VERSION}"
249 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "DisplayIcon" "$INSTDIR\viking_icon.ico"
250 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "HelpLink" "http://sourceforge.net/p/viking/wikiallura"
251 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "URLInfoAbout" "http://sourceforge.net/projects/viking/"
252 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "Publisher" "The Viking developer community"
253 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "Comments" "$(VIKING_UNINSTALL_COMMENTS)"
254 WriteRegDWORD SHCTX "${VIKING_UNINSTALL_KEY}" "NoModify" 1
255 WriteRegDWORD SHCTX "${VIKING_UNINSTALL_KEY}" "NoRepair" 1
256 WriteRegStr SHCTX "${VIKING_UNINSTALL_KEY}" "UninstallString" "$INSTDIR\${VIKING_UNINST_EXE}"
258 ; Copy only specific items as now some components (e.g. GPSBabel) are optional.
259 ; This is mostly to get a more accurate install size value (especially as saved into the registry)
260 File ${BINARIES}\viking*
261 File ${BINARIES}\g*.exe
262 File ${BINARIES}\*.dll
263 File ${BINARIES}\*.txt
264 File ${BINARIES}\magic.mgc
265 File /r ${BINARIES}\data
266 File /r ${BINARIES}\locale
268 ; Estimate install size based on files in $INSTDIR
269 ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
270 IntFmt $0 "0x%08X" $0
271 WriteRegDWORD SHCTX "${VIKING_UNINSTALL_KEY}" "EstimatedSize" "$0"
273 ; If we don't have install rights we're done
274 StrCmp $R0 "NONE" done
277 ; write out uninstaller
279 WriteUninstaller "$INSTDIR\${VIKING_UNINST_EXE}"
282 ; Always associate Viking file type
283 ${registerExtension} "$INSTDIR\viking.exe" ".vik" "Viking File"
285 SectionEnd ; end of default Viking section
287 ;--------------------------------
290 SectionGroup /e $(VIKING_SHORTCUTS_SECTION_TITLE) SecShortcuts
292 Section /o $(VIKING_DESKTOP_SHORTCUT_SECTION_TITLE) SecDesktopShortcut
294 CreateShortCut "$DESKTOP\Viking.lnk" "$INSTDIR\viking.exe"
297 ;Start menu shortcuts
298 Section $(VIKING_STARTMENU_SHORTCUT_SECTION_TITLE) SecStartMenuShortcut
300 CreateDirectory "$SMPROGRAMS\Viking"
301 CreateShortCut "$SMPROGRAMS\Viking\Viking.lnk" "$INSTDIR\viking.exe"
302 CreateShortCut "$SMPROGRAMS\Viking\User Manual.lnk" "$INSTDIR\viking.pdf"
303 CreateShortCut "$SMPROGRAMS\Viking\Uninstall.lnk" "$INSTDIR\viking-uninst.exe"
308 ;--------------------------------
311 Section $(VIKING_FILE_ASSOCIATION_SECTION_TITLE) SecFileAssociation
312 ${registerExtension} "$INSTDIR\viking.exe" ".gpx" "GPX File"
315 ;--------------------------------
316 ; GPSBabel Install Section
318 Section $(VIKING_GPSBABEL_SECTION_TITLE) SecGPSBabel
319 File "${BINARIES}\Optional\GPSBabel-1.5.2-Setup.exe"
320 ExecWait '"$INSTDIR\GPSBabel-1.5.2-Setup.exe" /SILENT'
321 Delete "$INSTDIR\GPSBabel-1.5.2-Setup.exe"
324 ;--------------------------------
329 Call un.CheckUserInstallRights
331 StrCmp $R0 "NONE" no_rights
332 StrCmp $R0 "HKCU" try_hkcu try_hklm
335 ReadRegStr $R0 HKCU ${VIKING_REG_KEY} ""
336 StrCmp $R0 $INSTDIR 0 cant_uninstall
337 ; HKCU install path matches our INSTDIR so uninstall
338 DeleteRegKey HKCU ${VIKING_REG_KEY}
339 DeleteRegKey HKCU "${VIKING_UNINSTALL_KEY}"
343 ReadRegStr $R0 HKLM ${VIKING_REG_KEY} ""
344 StrCmp $R0 $INSTDIR 0 try_hkcu
345 ; HKLM install path matches our INSTDIR so uninstall
346 DeleteRegKey HKLM ${VIKING_REG_KEY}
347 DeleteRegKey HKLM "${VIKING_UNINSTALL_KEY}"
348 DeleteRegKey HKLM "${HKLM_APP_PATHS_KEY}"
349 ; Sets start menu and desktop scope to all users..
350 SetShellVarContext "all"
354 ; http://nsis.sourceforge.net/Docs/Chapter4.html
357 ; Warning: is not safe. Can delete entire Program Files directory!
359 ; TODO try this method instead:
360 ; http://nsis.sourceforge.net/Uninstall_only_installed_files
362 ; Specific remove files
363 ; Thus alsos leaves any files the user has saved (particularly .vik or .gpx) into the Viking directory
364 Delete "$INSTDIR\viking-cache.py"
365 Delete "$INSTDIR\viking.pdf"
366 Delete "$INSTDIR\viking_icon.ico"
367 Delete "$INSTDIR\*.exe"
368 Delete "$INSTDIR\*.dll"
369 Delete "$INSTDIR\*.txt"
370 Delete "$INSTDIR\magic.mgc"
371 Delete "$INSTDIR\data\*txt"
372 Delete "$INSTDIR\data\*xml"
373 RMDir "$INSTDIR\data"
374 RMDir /r "$INSTDIR\locale"
378 Delete "$DESKTOP\Viking.lnk"
381 ${unregisterExtension} ".vik" "Viking File"
382 ${unregisterExtension} ".gpx" "GPX File"
387 MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_1) /SD IDOK
391 MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_2) /SD IDOK
395 SectionEnd ; end of uninstall section
397 ;--------------------------------
399 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
401 !insertmacro MUI_DESCRIPTION_TEXT ${SecViking} \
402 $(VIKING_SECTION_DESCRIPTION)
403 !insertmacro MUI_DESCRIPTION_TEXT ${SecShortcuts} \
404 $(VIKING_SHORTCUTS_SECTION_DESCRIPTION)
405 !insertmacro MUI_DESCRIPTION_TEXT ${SecDesktopShortcut} \
406 $(VIKING_DESKTOP_SHORTCUT_DESC)
407 !insertmacro MUI_DESCRIPTION_TEXT ${SecStartMenuShortcut} \
408 $(VIKING_STARTMENU_SHORTCUT_DESC)
409 !insertmacro MUI_DESCRIPTION_TEXT ${SecFileAssociation} \
410 $(VIKING_FILE_ASSOCIATION_DESC)
411 !insertmacro MUI_DESCRIPTION_TEXT ${SecGPSBabel} \
412 $(VIKING_INSTALL_GPSBABEL_DESC)
414 !insertmacro MUI_FUNCTION_DESCRIPTION_END
416 ;--------------------------------
419 ;Macro to determine user install rights
420 ;Will be used to determine where to install the program, shortcuts, ...
421 !macro CheckUserInstallRightsMacro UN
422 Function ${UN}CheckUserInstallRights
429 UserInfo::GetAccountType
432 StrCmp $1 "Admin" 0 +3
435 StrCmp $1 "Power" 0 +3
438 StrCmp $1 "User" 0 +3
441 StrCmp $1 "Guest" 0 +3
457 !insertmacro CheckUserInstallRightsMacro ""
458 !insertmacro CheckUserInstallRightsMacro "un."
460 ;Macro to determine if Viking is running before installation/unistallation
461 !macro RunCheckMacro UN
462 Function ${UN}RunCheck
463 FindProcDLL::FindProc "viking.exe"
464 IntCmp $R0 1 0 notRunning
465 MessageBox MB_OK|MB_ICONEXCLAMATION $(VIKING_IS_RUNNING) /SD IDOK
471 ;!insertmacro RunCheckMacro ""
472 ;!insertmacro RunCheckMacro "un."
474 ;Installer extra configuration at execution time: language, path, ...
476 ;Check if viking installer is already running
481 ;Check if viking is running
483 StrCpy $name "Viking ${VIKING_VERSION}"
486 ;Make sure that there was a previous installation
487 ReadRegStr $R0 HKCU "${VIKING_REG_KEY}" "Installer Language"
489 ;Preselect the "shortcuts" checkboxes according to the previous installation
490 !insertmacro SelectSection ${SecDesktopShortcut}
491 !insertmacro selectSection ${SecStartMenuShortcut}
493 ;Read command line parameters
495 ;Read language command line parameters
498 ${GetOptions} "$R0" "/L=" $R1
504 ; Display Language selection dialog
505 !insertmacro MUI_LANGDLL_DISPLAY
508 ;Read desktop shortcut command line options
510 ${GetOptions} "$R0" "/DS=" $R1
512 SectionGetFlags ${SecDesktopShortcut} $R2
514 IntOp $R2 $R2 | ${SF_SELECTED}
516 IntOp $R1 ${SF_SELECTED} ~
518 SectionSetFlags ${SecDesktopShortcut} $R2
520 ;Read start menu shortcuts command line options
522 ${GetOptions} "$R0" "/SMS=" $R1
524 SectionGetFlags ${SecStartMenuShortcut} $R2
526 IntOp $R2 $R2 | ${SF_SELECTED}
528 IntOp $R1 ${SF_SELECTED} ~
530 SectionSetFlags ${SecStartMenuShortcut} $R2
532 ; If install path was set on the command, use it.
533 StrCmp $INSTDIR "" 0 instdir_done
535 ; If viking is currently installed, we should default to where it is currently installed
537 ReadRegStr $INSTDIR HKCU "${VIKING_REG_KEY}" ""
539 StrCmp $INSTDIR "" 0 instdir_done
541 ReadRegStr $INSTDIR HKLM "${VIKING_REG_KEY}" ""
543 StrCmp $INSTDIR "" 0 instdir_done
545 Call CheckUserInstallRights
548 StrCmp $R0 "HKLM" 0 user_dir
549 StrCpy $INSTDIR "$PROGRAMFILES\Viking"
553 ${GetParent} $SMPROGRAMS $R2
555 StrCpy $INSTDIR "$R2\Viking"
565 ;Check if viking is running
567 StrCpy $name "Viking ${VIKING_VERSION}"
569 ; Get stored language preference
570 !insertmacro MUI_UNGETLANGUAGE