1 ; Installer script for Windows (32 & 64 bit) 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\x86-unicode\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
272 File /r
${BINARIES}\share
273 File /r
${BINARIES}\lib
275 ; Estimate install size based on files in $INSTDIR
276 ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
277 IntFmt $0 "0x%08X" $0
278 WriteRegDWORD SHCTX
"${VIKING_UNINSTALL_KEY}" "EstimatedSize" "$0"
280 ; If we don't have install rights we're done
281 StrCmp $R0 "NONE" done
284 ; write out uninstaller
286 WriteUninstaller "$INSTDIR\${VIKING_UNINST_EXE}"
289 ; Always associate Viking file type
290 ${registerExtension} "$INSTDIR\viking.exe" ".vik" "Viking File"
292 SectionEnd ; end of default Viking section
294 ;--------------------------------
297 SectionGroup
/e
$(VIKING_SHORTCUTS_SECTION_TITLE
) SecShortcuts
299 Section /o
$(VIKING_DESKTOP_SHORTCUT_SECTION_TITLE
) SecDesktopShortcut
301 CreateShortCut "$DESKTOP\Viking.lnk" "$INSTDIR\viking.exe"
304 ;Start menu shortcuts
305 Section $(VIKING_STARTMENU_SHORTCUT_SECTION_TITLE
) SecStartMenuShortcut
307 CreateDirectory "$SMPROGRAMS\Viking"
308 CreateShortCut "$SMPROGRAMS\Viking\Viking.lnk" "$INSTDIR\viking.exe"
309 CreateShortCut "$SMPROGRAMS\Viking\User Manual.lnk" "$INSTDIR\viking.pdf"
310 CreateShortCut "$SMPROGRAMS\Viking\Uninstall.lnk" "$INSTDIR\viking-uninst.exe"
315 ;--------------------------------
318 Section $(VIKING_FILE_ASSOCIATION_SECTION_TITLE
) SecFileAssociation
319 ${registerExtension} "$INSTDIR\viking.exe" ".gpx" "GPX File"
322 ;--------------------------------
323 ; GPSBabel Install Section
325 Section $(VIKING_GPSBABEL_SECTION_TITLE
) SecGPSBabel
326 File "${BINARIES}\Optional\GPSBabel-1.5.4-Setup.exe"
327 ExecWait '"$INSTDIR\GPSBabel-1.5.4-Setup.exe" /SILENT'
328 Delete "$INSTDIR\GPSBabel-1.5.4-Setup.exe"
331 ;--------------------------------
336 Call un
.CheckUserInstallRights
338 StrCmp $R0 "NONE" no_rights
339 StrCmp $R0 "HKCU" try_hkcu try_hklm
342 ReadRegStr $R0 HKCU ${VIKING_REG_KEY} ""
343 StrCmp $R0 $INSTDIR 0 cant_uninstall
344 ; HKCU install path matches our INSTDIR so uninstall
345 DeleteRegKey HKCU ${VIKING_REG_KEY}
346 DeleteRegKey HKCU "${VIKING_UNINSTALL_KEY}"
350 ReadRegStr $R0 HKLM ${VIKING_REG_KEY} ""
351 StrCmp $R0 $INSTDIR 0 try_hkcu
352 ; HKLM install path matches our INSTDIR so uninstall
353 DeleteRegKey HKLM ${VIKING_REG_KEY}
354 DeleteRegKey HKLM "${VIKING_UNINSTALL_KEY}"
355 DeleteRegKey HKLM "${HKLM_APP_PATHS_KEY}"
356 ; Sets start menu and desktop scope to all users..
357 SetShellVarContext
"all"
361 ; http://nsis.sourceforge.net/Docs/Chapter4.html
364 ; Warning: is not safe. Can delete entire Program Files directory!
366 ; TODO try this method instead:
367 ; http://nsis.sourceforge.net/Uninstall_only_installed_files
369 ; Specific remove files
370 ; Thus alsos leaves any files the user has saved (particularly .vik or .gpx) into the Viking directory
371 Delete "$INSTDIR\viking-cache.py"
372 Delete "$INSTDIR\viking.pdf"
373 Delete "$INSTDIR\viking_icon.ico"
374 Delete "$INSTDIR\*.exe"
375 Delete "$INSTDIR\*.dll"
376 Delete "$INSTDIR\*.txt"
377 Delete "$INSTDIR\magic.mgc"
378 Delete "$INSTDIR\data\*txt"
379 Delete "$INSTDIR\data\*xml"
380 RMDir "$INSTDIR\data"
381 RMDir /r
"$INSTDIR\locale"
382 RMDir /r
"$INSTDIR\lib"
383 RMDir /r
"$INSTDIR\share"
387 Delete "$DESKTOP\Viking.lnk"
390 ${unregisterExtension} ".vik" "Viking File"
391 ${unregisterExtension} ".gpx" "GPX File"
396 MessageBox MB_OK $(un
.VIKING_UNINSTALL_ERROR_1
) /SD
IDOK
400 MessageBox MB_OK $(un
.VIKING_UNINSTALL_ERROR_2
) /SD
IDOK
404 SectionEnd ; end of uninstall section
406 ;--------------------------------
408 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
410 !insertmacro MUI_DESCRIPTION_TEXT
${SecViking} \
411 $(VIKING_SECTION_DESCRIPTION
)
412 !insertmacro MUI_DESCRIPTION_TEXT
${SecShortcuts} \
413 $(VIKING_SHORTCUTS_SECTION_DESCRIPTION
)
414 !insertmacro MUI_DESCRIPTION_TEXT
${SecDesktopShortcut} \
415 $(VIKING_DESKTOP_SHORTCUT_DESC
)
416 !insertmacro MUI_DESCRIPTION_TEXT
${SecStartMenuShortcut} \
417 $(VIKING_STARTMENU_SHORTCUT_DESC
)
418 !insertmacro MUI_DESCRIPTION_TEXT
${SecFileAssociation} \
419 $(VIKING_FILE_ASSOCIATION_DESC
)
420 !insertmacro MUI_DESCRIPTION_TEXT
${SecGPSBabel} \
421 $(VIKING_INSTALL_GPSBABEL_DESC
)
423 !insertmacro MUI_FUNCTION_DESCRIPTION_END
425 ;--------------------------------
428 ;Macro to determine user install rights
429 ;Will be used to determine where to install the program, shortcuts, ...
430 !macro CheckUserInstallRightsMacro UN
431 Function ${UN}CheckUserInstallRights
438 UserInfo::GetAccountType
441 StrCmp $1 "Admin" 0 +3
444 StrCmp $1 "Power" 0 +3
447 StrCmp $1 "User" 0 +3
450 StrCmp $1 "Guest" 0 +3
466 !insertmacro CheckUserInstallRightsMacro
""
467 !insertmacro CheckUserInstallRightsMacro
"un."
469 ;Macro to determine if Viking is running before installation/unistallation
470 !macro RunCheckMacro UN
471 Function ${UN}RunCheck
472 FindProcDLL::FindProc
"viking.exe"
473 IntCmp $R0 1 0 notRunning
474 MessageBox MB_OK|
MB_ICONEXCLAMATION $(VIKING_IS_RUNNING
) /SD
IDOK
480 ;!insertmacro RunCheckMacro ""
481 ;!insertmacro RunCheckMacro "un."
483 ;Installer extra configuration at execution time: language, path, ...
485 ;Check if viking installer is already running
490 ;Check if viking is running
492 StrCpy $name "Viking ${VIKING_VERSION}"
495 ;Make sure that there was a previous installation
496 ReadRegStr $R0 HKCU "${VIKING_REG_KEY}" "Installer Language"
498 ;Preselect the "shortcuts" checkboxes according to the previous installation
499 !insertmacro SelectSection
${SecDesktopShortcut}
500 !insertmacro selectSection
${SecStartMenuShortcut}
502 ;Read command line parameters
504 ;Read language command line parameters
507 ${GetOptions} "$R0" "/L=" $R1
513 ; Display Language selection dialog
514 !insertmacro MUI_LANGDLL_DISPLAY
517 ;Read desktop shortcut command line options
519 ${GetOptions} "$R0" "/DS=" $R1
521 SectionGetFlags
${SecDesktopShortcut} $R2
523 IntOp $R2 $R2 |
${SF_SELECTED}
525 IntOp $R1 ${SF_SELECTED} ~
527 SectionSetFlags
${SecDesktopShortcut} $R2
529 ;Read start menu shortcuts command line options
531 ${GetOptions} "$R0" "/SMS=" $R1
533 SectionGetFlags
${SecStartMenuShortcut} $R2
535 IntOp $R2 $R2 |
${SF_SELECTED}
537 IntOp $R1 ${SF_SELECTED} ~
539 SectionSetFlags
${SecStartMenuShortcut} $R2
541 ; If install path was set on the command, use it.
542 StrCmp $INSTDIR "" 0 instdir_done
544 ; If viking is currently installed, we should default to where it is currently installed
546 ReadRegStr $INSTDIR HKCU "${VIKING_REG_KEY}" ""
548 StrCmp $INSTDIR "" 0 instdir_done
550 ReadRegStr $INSTDIR HKLM "${VIKING_REG_KEY}" ""
552 StrCmp $INSTDIR "" 0 instdir_done
554 Call CheckUserInstallRights
557 StrCmp $R0 "HKLM" 0 user_dir
559 StrCpy $INSTDIR "$PROGRAMFILES64\Viking"
561 StrCpy $INSTDIR "$PROGRAMFILES\Viking" ; $PROGRAMFILES32 also works
566 ${GetParent} $SMPROGRAMS $R2
568 StrCpy $INSTDIR "$R2\Viking"
578 ;Check if viking is running
580 StrCpy $name "Viking ${VIKING_VERSION}"
582 ; Get stored language preference
583 !insertmacro MUI_UNGETLANGUAGE