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 ;--------------------------------
13 ;The name var is set in .onInit
16 OutFile "viking-${VIKING_VERSION}.exe"
18 SetCompressor /SOLID lzma
20 ShowUninstDetails show
23 ; $name and $INSTDIR are set in .onInit function..
26 !include "Sections.nsh"
28 !include "LogicLib.nsh"
30 !include "FileFunc.nsh"
31 !insertmacro GetParameters
32 !insertmacro GetOptions
33 !insertmacro GetParent
35 !include "WordFunc.nsh"
37 ;--------------------------------
40 !define VIKING_NSIS_INCLUDE_PATH "."
42 ; Remove these and the stuff that uses them at some point
43 !define VIKING_REG_KEY "SOFTWARE\viking"
44 !define VIKING_UNINSTALL_KEY "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\viking"
46 !define HKLM_APP_PATHS_KEY "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\viking.exe"
47 !define VIKING_UNINST_EXE "viking-uninst.exe"
49 !define DOWNLOADER_URL "http://downloads.sourceforge.net/viking/"
51 ;--------------------------------
53 VIProductVersion "${VIKING_VERSION}"
54 VIAddVersionKey "ProductName" "Viking"
55 VIAddVersionKey "FileVersion" "${VIKING_VERSION}"
56 VIAddVersionKey "ProductVersion" "${VIKING_VERSION}"
57 VIAddVersionKey "LegalCopyright" ""
58 VIAddVersionKey "FileDescription" "Viking Installer"
60 ;--------------------------------
61 ;Modern UI Configuration
63 !define MUI_ICON ".\pixmaps\viking_icon.ico"
64 !define MUI_UNICON ".\pixmaps\viking_icon.ico"
65 ; !define MUI_WELCOMEFINISHPAGE_BITMAP ".\pixmaps\viking-intro.bmp"
66 ; !define MUI_HEADERIMAGE
67 ; !define MUI_HEADERIMAGE_BITMAP ".\pixmaps\viking-header.bmp"
69 ; Alter License section
70 !define MUI_LICENSEPAGE_BUTTON $(VIKING_LICENSE_BUTTON)
71 !define MUI_LICENSEPAGE_TEXT_BOTTOM $(VIKING_LICENSE_BOTTOM_TEXT)
73 !define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
74 !define MUI_LANGDLL_REGISTRY_KEY ${VIKING_REG_KEY}
75 !define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
77 !define MUI_COMPONENTSPAGE_SMALLDESC
78 !define MUI_ABORTWARNING
81 !define MUI_FINISHPAGE_NOAUTOCLOSE
82 !define MUI_FINISHPAGE_RUN "$INSTDIR\viking.exe"
83 !define MUI_FINISHPAGE_RUN_NOTCHECKED
84 !define MUI_FINISHPAGE_LINK $(VIKING_FINISH_VISIT_WEB_SITE)
85 !define MUI_FINISHPAGE_LINK_LOCATION "http://viking.sourceforge.net"
87 ;--------------------------------
90 !insertmacro MUI_PAGE_WELCOME
91 !insertmacro MUI_PAGE_LICENSE ".\bin\COPYING_GPL.txt"
92 !insertmacro MUI_PAGE_COMPONENTS
94 ; Viking install dir page
95 !insertmacro MUI_PAGE_DIRECTORY
97 !insertmacro MUI_PAGE_INSTFILES
98 !insertmacro MUI_PAGE_FINISH
100 !insertmacro MUI_UNPAGE_WELCOME
101 !insertmacro MUI_UNPAGE_CONFIRM
102 !insertmacro MUI_UNPAGE_INSTFILES
103 !insertmacro MUI_UNPAGE_FINISH
105 ;--------------------------------
108 ;; English goes first because its the default. The rest are
109 ;; in alphabetical order (at least the strings actually displayed
112 !insertmacro MUI_LANGUAGE "English"
113 !insertmacro MUI_LANGUAGE "French"
115 ;--------------------------------
118 !define VIKING_DEFAULT_LANGFILE "${VIKING_NSIS_INCLUDE_PATH}\translations\english.nsh"
120 !include "${VIKING_NSIS_INCLUDE_PATH}\langmacros.nsh"
122 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "ENGLISH" "${VIKING_NSIS_INCLUDE_PATH}\translations\english.nsh"
123 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "FRENCH" "${VIKING_NSIS_INCLUDE_PATH}\translations\french.nsh"
125 ;--------------------------------
127 ; Only need this if using bzip2 compression
129 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
130 !insertmacro MUI_RESERVEFILE_LANGDLL
131 ReserveFile "${NSISDIR}\Plugins\UserInfo.dll"
134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
135 ;; Start Install Sections ;;
136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
138 ;--------------------------------
139 ;Uninstall any old version of Viking
141 Section -SecUninstallOldViking
142 ; Check install rights..
143 Call CheckUserInstallRights
146 ;First try to uninstall Viking
147 StrCpy $R4 ${VIKING_REG_KEY}
148 StrCpy $R5 ${VIKING_UNINSTALL_KEY}
149 StrCpy $R6 ${VIKING_UNINST_EXE}
152 ;Determine user install rights
153 StrCmp $R0 "HKLM" compare_hklm
154 StrCmp $R0 "HKCU" compare_hkcu done
157 ReadRegStr $R1 HKCU $R4 ""
158 ReadRegStr $R2 HKCU $R4 "Version"
159 ReadRegStr $R3 HKCU "$R5" "UninstallString"
163 ReadRegStr $R1 HKLM $R4 ""
164 ReadRegStr $R2 HKLM $R4 "Version"
165 ReadRegStr $R3 HKLM "$R5" "UninstallString"
167 ; If a previous version exists, remove it
170 StrCmp $R2 "" uninstall_problem
171 ; Check if we have uninstall string..
172 IfFileExists $R3 0 uninstall_problem
173 ; Have uninstall string, go ahead and uninstall.
175 ; Need to copy uninstaller outside of the install dir
177 CopyFiles /SILENT $R3 "$TEMP\$R6"
179 IfErrors uninstall_problem
180 ; Ready to uninstall..
182 ExecWait '"$TEMP\$R6" /S _?=$R1'
189 Goto uninstall_problem
192 ; We can't uninstall. Either the user must manually uninstall or we ignore and reinstall over it.
193 MessageBox MB_OKCANCEL $(VIKING_PROMPT_CONTINUE_WITHOUT_UNINSTALL) /SD IDOK IDOK done
198 ;--------------------------------
199 ;Viking Install Section
201 Section $(VIKING_SECTION_TITLE) SecViking
204 ; Check install rights..
205 Call CheckUserInstallRights
207 StrCmp $R0 "NONE" viking_none
208 StrCmp $R0 "HKLM" viking_hklm viking_hkcu
210 ;Install rights for Local Machine
212 WriteRegStr HKLM "${HKLM_APP_PATHS_KEY}" "" "$INSTDIR\viking.exe"
213 WriteRegStr HKLM "${HKLM_APP_PATHS_KEY}" "Path" "$R1\bin"
214 WriteRegStr HKLM ${VIKING_REG_KEY} "" "$INSTDIR"
215 WriteRegStr HKLM ${VIKING_REG_KEY} "Version" "${VIKING_VERSION}"
216 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "DisplayName" "Viking"
217 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "DisplayVersion" "${VIKING_VERSION}"
218 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "HelpLink" "http://sourceforge.net/apps/mediawiki/viking/"
219 WriteRegDWORD HKLM "${VIKING_UNINSTALL_KEY}" "NoModify" 1
220 WriteRegDWORD HKLM "${VIKING_UNINSTALL_KEY}" "NoRepair" 1
221 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "UninstallString" "$INSTDIR\${VIKING_UNINST_EXE}"
222 ; Sets scope of the desktop and Start Menu entries for all users.
223 SetShellVarContext "all"
224 Goto viking_install_files
226 ;Install rights for Current User only
228 WriteRegStr HKCU ${VIKING_REG_KEY} "" "$INSTDIR"
229 WriteRegStr HKCU ${VIKING_REG_KEY} "Version" "${VIKING_VERSION}"
230 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "DisplayName" "Viking"
231 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "DisplayVersion" "${VIKING_VERSION}"
232 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "HelpLink" "http://sourceforge.net/apps/mediawiki/viking/"
233 WriteRegDWORD HKCU "${VIKING_UNINSTALL_KEY}" "NoModify" 1
234 WriteRegDWORD HKCU "${VIKING_UNINSTALL_KEY}" "NoRepair" 1
235 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "UninstallString" "$INSTDIR\${VIKING_UNINST_EXE}"
236 Goto viking_install_files
241 viking_install_files:
242 SetOutPath "$INSTDIR"
247 ; If we don't have install rights we're done
248 StrCmp $R0 "NONE" done
251 ; write out uninstaller
253 WriteUninstaller "$INSTDIR\${VIKING_UNINST_EXE}"
257 SectionEnd ; end of default Viking section
259 ;--------------------------------
262 SectionGroup /e $(VIKING_SHORTCUTS_SECTION_TITLE) SecShortcuts
264 Section /o $(VIKING_DESKTOP_SHORTCUT_SECTION_TITLE) SecDesktopShortcut
266 CreateShortCut "$DESKTOP\Viking.lnk" "$INSTDIR\viking.exe"
269 ;Start menu shortcuts
270 Section $(VIKING_STARTMENU_SHORTCUT_SECTION_TITLE) SecStartMenuShortcut
272 CreateDirectory "$SMPROGRAMS\Viking"
273 CreateShortCut "$SMPROGRAMS\Viking\Viking.lnk" "$INSTDIR\viking.exe"
274 CreateShortCut "$SMPROGRAMS\Viking\User Manual.lnk" "$INSTDIR\viking.pdf"
275 CreateShortCut "$SMPROGRAMS\Viking\Uninstall.lnk" "$INSTDIR\viking-uninst.exe"
291 ;--------------------------------
296 Call un.CheckUserInstallRights
298 StrCmp $R0 "NONE" no_rights
299 StrCmp $R0 "HKCU" try_hkcu try_hklm
302 ReadRegStr $R0 HKCU ${VIKING_REG_KEY} ""
303 StrCmp $R0 $INSTDIR 0 cant_uninstall
304 ; HKCU install path matches our INSTDIR so uninstall
305 DeleteRegKey HKCU ${VIKING_REG_KEY}
306 DeleteRegKey HKCU "${VIKING_UNINSTALL_KEY}"
310 ReadRegStr $R0 HKLM ${VIKING_REG_KEY} ""
311 StrCmp $R0 $INSTDIR 0 try_hkcu
312 ; HKLM install path matches our INSTDIR so uninstall
313 DeleteRegKey HKLM ${VIKING_REG_KEY}
314 DeleteRegKey HKLM "${VIKING_UNINSTALL_KEY}"
315 DeleteRegKey HKLM "${HKLM_APP_PATHS_KEY}"
316 ; Sets start menu and desktop scope to all users..
317 SetShellVarContext "all"
321 RMDir /r "$INSTDIR\etc"
322 RMDir /r "$INSTDIR\lib"
323 RMDir /r "$INSTDIR\locale"
324 RMDir /r "$INSTDIR\share"
325 Delete "$INSTDIR\AUTHORS.txt"
326 Delete "$INSTDIR\Changelog.txt"
327 Delete "$INSTDIR\COPYING_curl.txt"
328 Delete "$INSTDIR\COPYING_GPL.txt"
329 Delete "$INSTDIR\freetype6.dll"
330 Delete "$INSTDIR\gpsbabel.exe"
331 Delete "$INSTDIR\intl.dll"
332 Delete "$INSTDIR\libatk-1.0-0.dll"
333 Delete "$INSTDIR\libcairo-2.dll"
334 Delete "$INSTDIR\libcurl.dll"
335 Delete "$INSTDIR\libexpat.dll"
336 Delete "$INSTDIR\libexpat-1.dll"
337 Delete "$INSTDIR\libfontconfig-1.dll"
338 Delete "$INSTDIR\libgailutil-18.dll"
339 Delete "$INSTDIR\libgdk_pixbuf-2.0-0.dll"
340 Delete "$INSTDIR\libgdk-win32-2.0-0.dll"
341 Delete "$INSTDIR\libgio-2.0-0.dll"
342 Delete "$INSTDIR\libglib-2.0-0.dll"
343 Delete "$INSTDIR\libgmodule-2.0-0.dll"
344 Delete "$INSTDIR\libgobject-2.0-0.dll"
345 Delete "$INSTDIR\libgthread-2.0-0.dll"
346 Delete "$INSTDIR\libgtk-win32-2.0-0.dll"
347 Delete "$INSTDIR\libjpeg-7.dll"
348 Delete "$INSTDIR\libpango-1.0-0.dll"
349 Delete "$INSTDIR\libpangocairo-1.0-0.dll"
350 Delete "$INSTDIR\libpangoft2-1.0-0.dll"
351 Delete "$INSTDIR\libpangowin32-1.0-0.dll"
352 Delete "$INSTDIR\libpng12-0.dll"
353 Delete "$INSTDIR\libtiff-3.dll"
354 Delete "$INSTDIR\libtiffxx-3.dll"
355 Delete "$INSTDIR\NEWS.txt"
356 Delete "$INSTDIR\README.txt"
357 Delete "$INSTDIR\viking.exe"
358 Delete "$INSTDIR\viking.pdf"
359 Delete "$INSTDIR\zlib1.dll"
360 Delete "$INSTDIR\${VIKING_UNINST_EXE}"
361 Delete "$INSTDIR\install.log"
363 ;Try to remove Viking install dir (only if empty)
367 Delete "$DESKTOP\Viking.lnk"
372 MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_1) /SD IDOK
376 MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_2) /SD IDOK
380 SectionEnd ; end of uninstall section
382 ;--------------------------------
384 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
386 !insertmacro MUI_DESCRIPTION_TEXT ${SecViking} \
387 $(VIKING_SECTION_DESCRIPTION)
388 !insertmacro MUI_DESCRIPTION_TEXT ${SecShortcuts} \
389 $(VIKING_SHORTCUTS_SECTION_DESCRIPTION)
390 !insertmacro MUI_DESCRIPTION_TEXT ${SecDesktopShortcut} \
391 $(VIKING_DESKTOP_SHORTCUT_DESC)
392 !insertmacro MUI_DESCRIPTION_TEXT ${SecStartMenuShortcut} \
393 $(VIKING_STARTMENU_SHORTCUT_DESC)
395 !insertmacro MUI_FUNCTION_DESCRIPTION_END
397 ;--------------------------------
400 ;Macro to determine user install rights
401 ;Will be used to determine where to install the program, shortcuts, ...
402 !macro CheckUserInstallRightsMacro UN
403 Function ${UN}CheckUserInstallRights
410 UserInfo::GetAccountType
413 StrCmp $1 "Admin" 0 +3
416 StrCmp $1 "Power" 0 +3
419 StrCmp $1 "User" 0 +3
422 StrCmp $1 "Guest" 0 +3
438 !insertmacro CheckUserInstallRightsMacro ""
439 !insertmacro CheckUserInstallRightsMacro "un."
441 ;Macro to determine if Viking is running before installation/unistallation
442 !macro RunCheckMacro UN
443 Function ${UN}RunCheck
444 FindProcDLL::FindProc "viking.exe"
445 IntCmp $R0 1 0 notRunning
446 MessageBox MB_OK|MB_ICONEXCLAMATION $(VIKING_IS_RUNNING) /SD IDOK
452 !insertmacro RunCheckMacro ""
453 !insertmacro RunCheckMacro "un."
455 ;Installer extra configuration at execution time: language, path, ...
457 ;Check if viking installer is already running
462 ;Check if viking is running
464 StrCpy $name "Viking ${VIKING_VERSION}"
467 ;Make sure that there was a previous installation
468 ReadRegStr $R0 HKCU "${VIKING_REG_KEY}" "Installer Language"
470 ;Preselect the "shortcuts" checkboxes according to the previous installation
471 !insertmacro SelectSection ${SecDesktopShortcut}
472 !insertmacro selectSection ${SecStartMenuShortcut}
474 ;Read command line parameters
476 ;Read language command line parameters
479 ${GetOptions} "$R0" "/L=" $R1
485 ; Display Language selection dialog
486 !insertmacro MUI_LANGDLL_DISPLAY
489 ;Read desktop shortcut command line options
491 ${GetOptions} "$R0" "/DS=" $R1
493 SectionGetFlags ${SecDesktopShortcut} $R2
495 IntOp $R2 $R2 | ${SF_SELECTED}
497 IntOp $R1 ${SF_SELECTED} ~
499 SectionSetFlags ${SecDesktopShortcut} $R2
501 ;Read start menu shortcuts command line options
503 ${GetOptions} "$R0" "/SMS=" $R1
505 SectionGetFlags ${SecStartMenuShortcut} $R2
507 IntOp $R2 $R2 | ${SF_SELECTED}
509 IntOp $R1 ${SF_SELECTED} ~
511 SectionSetFlags ${SecStartMenuShortcut} $R2
513 ; If install path was set on the command, use it.
514 StrCmp $INSTDIR "" 0 instdir_done
516 ; If viking is currently installed, we should default to where it is currently installed
518 ReadRegStr $INSTDIR HKCU "${VIKING_REG_KEY}" ""
520 StrCmp $INSTDIR "" 0 instdir_done
522 ReadRegStr $INSTDIR HKLM "${VIKING_REG_KEY}" ""
524 StrCmp $INSTDIR "" 0 instdir_done
526 Call CheckUserInstallRights
529 StrCmp $R0 "HKLM" 0 user_dir
530 StrCpy $INSTDIR "$PROGRAMFILES\Viking"
534 ${GetParent} $SMPROGRAMS $R2
536 StrCpy $INSTDIR "$R2\Viking"
546 ;Check if viking is running
548 StrCpy $name "Viking ${VIKING_VERSION}"
550 ; Get stored language preference
551 !insertmacro MUI_UNGETLANGUAGE