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"
124 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "SPANISH" "${VIKING_NSIS_INCLUDE_PATH}\translations\spanish.nsh"
126 ;--------------------------------
128 ; Only need this if using bzip2 compression
130 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
131 !insertmacro MUI_RESERVEFILE_LANGDLL
132 ReserveFile "${NSISDIR}\Plugins\UserInfo.dll"
135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136 ;; Start Install Sections ;;
137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
139 ;--------------------------------
140 ;Uninstall any old version of Viking
142 Section -SecUninstallOldViking
143 ; Check install rights..
144 Call CheckUserInstallRights
147 ;First try to uninstall Viking
148 StrCpy $R4 ${VIKING_REG_KEY}
149 StrCpy $R5 ${VIKING_UNINSTALL_KEY}
150 StrCpy $R6 ${VIKING_UNINST_EXE}
153 ;Determine user install rights
154 StrCmp $R0 "HKLM" compare_hklm
155 StrCmp $R0 "HKCU" compare_hkcu done
158 ReadRegStr $R1 HKCU $R4 ""
159 ReadRegStr $R2 HKCU $R4 "Version"
160 ReadRegStr $R3 HKCU "$R5" "UninstallString"
164 ReadRegStr $R1 HKLM $R4 ""
165 ReadRegStr $R2 HKLM $R4 "Version"
166 ReadRegStr $R3 HKLM "$R5" "UninstallString"
168 ; If a previous version exists, remove it
171 StrCmp $R2 "" uninstall_problem
172 ; Check if we have uninstall string..
173 IfFileExists $R3 0 uninstall_problem
174 ; Have uninstall string, go ahead and uninstall.
176 ; Need to copy uninstaller outside of the install dir
178 CopyFiles /SILENT $R3 "$TEMP\$R6"
180 IfErrors uninstall_problem
181 ; Ready to uninstall..
183 ExecWait '"$TEMP\$R6" /S _?=$R1'
190 Goto uninstall_problem
193 ; We can't uninstall. Either the user must manually uninstall or we ignore and reinstall over it.
194 MessageBox MB_OKCANCEL $(VIKING_PROMPT_CONTINUE_WITHOUT_UNINSTALL) /SD IDOK IDOK done
199 ;--------------------------------
200 ;Viking Install Section
202 Section $(VIKING_SECTION_TITLE) SecViking
205 ; Check install rights..
206 Call CheckUserInstallRights
208 StrCmp $R0 "NONE" viking_none
209 StrCmp $R0 "HKLM" viking_hklm viking_hkcu
211 ;Install rights for Local Machine
213 WriteRegStr HKLM "${HKLM_APP_PATHS_KEY}" "" "$INSTDIR\viking.exe"
214 WriteRegStr HKLM "${HKLM_APP_PATHS_KEY}" "Path" "$R1\bin"
215 WriteRegStr HKLM ${VIKING_REG_KEY} "" "$INSTDIR"
216 WriteRegStr HKLM ${VIKING_REG_KEY} "Version" "${VIKING_VERSION}"
217 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "DisplayName" "Viking"
218 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "DisplayVersion" "${VIKING_VERSION}"
219 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "HelpLink" "http://sourceforge.net/apps/mediawiki/viking/"
220 WriteRegDWORD HKLM "${VIKING_UNINSTALL_KEY}" "NoModify" 1
221 WriteRegDWORD HKLM "${VIKING_UNINSTALL_KEY}" "NoRepair" 1
222 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "UninstallString" "$INSTDIR\${VIKING_UNINST_EXE}"
223 ; Sets scope of the desktop and Start Menu entries for all users.
224 SetShellVarContext "all"
225 Goto viking_install_files
227 ;Install rights for Current User only
229 WriteRegStr HKCU ${VIKING_REG_KEY} "" "$INSTDIR"
230 WriteRegStr HKCU ${VIKING_REG_KEY} "Version" "${VIKING_VERSION}"
231 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "DisplayName" "Viking"
232 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "DisplayVersion" "${VIKING_VERSION}"
233 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "HelpLink" "http://sourceforge.net/apps/mediawiki/viking/"
234 WriteRegDWORD HKCU "${VIKING_UNINSTALL_KEY}" "NoModify" 1
235 WriteRegDWORD HKCU "${VIKING_UNINSTALL_KEY}" "NoRepair" 1
236 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "UninstallString" "$INSTDIR\${VIKING_UNINST_EXE}"
237 Goto viking_install_files
242 viking_install_files:
243 SetOutPath "$INSTDIR"
248 ; If we don't have install rights we're done
249 StrCmp $R0 "NONE" done
252 ; write out uninstaller
254 WriteUninstaller "$INSTDIR\${VIKING_UNINST_EXE}"
258 SectionEnd ; end of default Viking section
260 ;--------------------------------
263 SectionGroup /e $(VIKING_SHORTCUTS_SECTION_TITLE) SecShortcuts
265 Section /o $(VIKING_DESKTOP_SHORTCUT_SECTION_TITLE) SecDesktopShortcut
267 CreateShortCut "$DESKTOP\Viking.lnk" "$INSTDIR\viking.exe"
270 ;Start menu shortcuts
271 Section $(VIKING_STARTMENU_SHORTCUT_SECTION_TITLE) SecStartMenuShortcut
273 CreateDirectory "$SMPROGRAMS\Viking"
274 CreateShortCut "$SMPROGRAMS\Viking\Viking.lnk" "$INSTDIR\viking.exe"
275 CreateShortCut "$SMPROGRAMS\Viking\User Manual.lnk" "$INSTDIR\viking.pdf"
276 CreateShortCut "$SMPROGRAMS\Viking\Uninstall.lnk" "$INSTDIR\viking-uninst.exe"
292 ;--------------------------------
297 Call un.CheckUserInstallRights
299 StrCmp $R0 "NONE" no_rights
300 StrCmp $R0 "HKCU" try_hkcu try_hklm
303 ReadRegStr $R0 HKCU ${VIKING_REG_KEY} ""
304 StrCmp $R0 $INSTDIR 0 cant_uninstall
305 ; HKCU install path matches our INSTDIR so uninstall
306 DeleteRegKey HKCU ${VIKING_REG_KEY}
307 DeleteRegKey HKCU "${VIKING_UNINSTALL_KEY}"
311 ReadRegStr $R0 HKLM ${VIKING_REG_KEY} ""
312 StrCmp $R0 $INSTDIR 0 try_hkcu
313 ; HKLM install path matches our INSTDIR so uninstall
314 DeleteRegKey HKLM ${VIKING_REG_KEY}
315 DeleteRegKey HKLM "${VIKING_UNINSTALL_KEY}"
316 DeleteRegKey HKLM "${HKLM_APP_PATHS_KEY}"
317 ; Sets start menu and desktop scope to all users..
318 SetShellVarContext "all"
322 RMDir /r "$INSTDIR\etc"
323 RMDir /r "$INSTDIR\lib"
324 RMDir /r "$INSTDIR\locale"
325 RMDir /r "$INSTDIR\share"
326 Delete "$INSTDIR\AUTHORS.txt"
327 Delete "$INSTDIR\Changelog.txt"
328 Delete "$INSTDIR\COPYING_curl.txt"
329 Delete "$INSTDIR\COPYING_GPL.txt"
330 Delete "$INSTDIR\freetype6.dll"
331 Delete "$INSTDIR\gpsbabel.exe"
332 Delete "$INSTDIR\intl.dll"
333 Delete "$INSTDIR\libatk-1.0-0.dll"
334 Delete "$INSTDIR\libcairo-2.dll"
335 Delete "$INSTDIR\libcurl.dll"
336 Delete "$INSTDIR\libexif-12.dll"
337 Delete "$INSTDIR\libexpat.dll"
338 Delete "$INSTDIR\libexpat-1.dll"
339 Delete "$INSTDIR\libfontconfig-1.dll"
340 Delete "$INSTDIR\libgailutil-18.dll"
341 Delete "$INSTDIR\libgdk_pixbuf-2.0-0.dll"
342 Delete "$INSTDIR\libgdk-win32-2.0-0.dll"
343 Delete "$INSTDIR\libgio-2.0-0.dll"
344 Delete "$INSTDIR\libglib-2.0-0.dll"
345 Delete "$INSTDIR\libgmodule-2.0-0.dll"
346 Delete "$INSTDIR\libgobject-2.0-0.dll"
347 Delete "$INSTDIR\libgthread-2.0-0.dll"
348 Delete "$INSTDIR\libgtk-win32-2.0-0.dll"
349 Delete "$INSTDIR\libjpeg-7.dll"
350 Delete "$INSTDIR\libpango-1.0-0.dll"
351 Delete "$INSTDIR\libpangocairo-1.0-0.dll"
352 Delete "$INSTDIR\libpangoft2-1.0-0.dll"
353 Delete "$INSTDIR\libpangowin32-1.0-0.dll"
354 Delete "$INSTDIR\libpng12-0.dll"
355 Delete "$INSTDIR\libtiff-3.dll"
356 Delete "$INSTDIR\libtiffxx-3.dll"
357 Delete "$INSTDIR\NEWS.txt"
358 Delete "$INSTDIR\README.txt"
359 Delete "$INSTDIR\viking.exe"
360 Delete "$INSTDIR\viking.pdf"
361 Delete "$INSTDIR\zlib1.dll"
362 Delete "$INSTDIR\${VIKING_UNINST_EXE}"
363 Delete "$INSTDIR\install.log"
365 ;Try to remove Viking install dir (only if empty)
369 Delete "$DESKTOP\Viking.lnk"
374 MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_1) /SD IDOK
378 MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_2) /SD IDOK
382 SectionEnd ; end of uninstall section
384 ;--------------------------------
386 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
388 !insertmacro MUI_DESCRIPTION_TEXT ${SecViking} \
389 $(VIKING_SECTION_DESCRIPTION)
390 !insertmacro MUI_DESCRIPTION_TEXT ${SecShortcuts} \
391 $(VIKING_SHORTCUTS_SECTION_DESCRIPTION)
392 !insertmacro MUI_DESCRIPTION_TEXT ${SecDesktopShortcut} \
393 $(VIKING_DESKTOP_SHORTCUT_DESC)
394 !insertmacro MUI_DESCRIPTION_TEXT ${SecStartMenuShortcut} \
395 $(VIKING_STARTMENU_SHORTCUT_DESC)
397 !insertmacro MUI_FUNCTION_DESCRIPTION_END
399 ;--------------------------------
402 ;Macro to determine user install rights
403 ;Will be used to determine where to install the program, shortcuts, ...
404 !macro CheckUserInstallRightsMacro UN
405 Function ${UN}CheckUserInstallRights
412 UserInfo::GetAccountType
415 StrCmp $1 "Admin" 0 +3
418 StrCmp $1 "Power" 0 +3
421 StrCmp $1 "User" 0 +3
424 StrCmp $1 "Guest" 0 +3
440 !insertmacro CheckUserInstallRightsMacro ""
441 !insertmacro CheckUserInstallRightsMacro "un."
443 ;Macro to determine if Viking is running before installation/unistallation
444 !macro RunCheckMacro UN
445 Function ${UN}RunCheck
446 FindProcDLL::FindProc "viking.exe"
447 IntCmp $R0 1 0 notRunning
448 MessageBox MB_OK|MB_ICONEXCLAMATION $(VIKING_IS_RUNNING) /SD IDOK
454 !insertmacro RunCheckMacro ""
455 !insertmacro RunCheckMacro "un."
457 ;Installer extra configuration at execution time: language, path, ...
459 ;Check if viking installer is already running
464 ;Check if viking is running
466 StrCpy $name "Viking ${VIKING_VERSION}"
469 ;Make sure that there was a previous installation
470 ReadRegStr $R0 HKCU "${VIKING_REG_KEY}" "Installer Language"
472 ;Preselect the "shortcuts" checkboxes according to the previous installation
473 !insertmacro SelectSection ${SecDesktopShortcut}
474 !insertmacro selectSection ${SecStartMenuShortcut}
476 ;Read command line parameters
478 ;Read language command line parameters
481 ${GetOptions} "$R0" "/L=" $R1
487 ; Display Language selection dialog
488 !insertmacro MUI_LANGDLL_DISPLAY
491 ;Read desktop shortcut command line options
493 ${GetOptions} "$R0" "/DS=" $R1
495 SectionGetFlags ${SecDesktopShortcut} $R2
497 IntOp $R2 $R2 | ${SF_SELECTED}
499 IntOp $R1 ${SF_SELECTED} ~
501 SectionSetFlags ${SecDesktopShortcut} $R2
503 ;Read start menu shortcuts command line options
505 ${GetOptions} "$R0" "/SMS=" $R1
507 SectionGetFlags ${SecStartMenuShortcut} $R2
509 IntOp $R2 $R2 | ${SF_SELECTED}
511 IntOp $R1 ${SF_SELECTED} ~
513 SectionSetFlags ${SecStartMenuShortcut} $R2
515 ; If install path was set on the command, use it.
516 StrCmp $INSTDIR "" 0 instdir_done
518 ; If viking is currently installed, we should default to where it is currently installed
520 ReadRegStr $INSTDIR HKCU "${VIKING_REG_KEY}" ""
522 StrCmp $INSTDIR "" 0 instdir_done
524 ReadRegStr $INSTDIR HKLM "${VIKING_REG_KEY}" ""
526 StrCmp $INSTDIR "" 0 instdir_done
528 Call CheckUserInstallRights
531 StrCmp $R0 "HKLM" 0 user_dir
532 StrCpy $INSTDIR "$PROGRAMFILES\Viking"
536 ${GetParent} $SMPROGRAMS $R2
538 StrCpy $INSTDIR "$R2\Viking"
548 ;Check if viking is running
550 StrCpy $name "Viking ${VIKING_VERSION}"
552 ; Get stored language preference
553 !insertmacro MUI_UNGETLANGUAGE