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.5.0.0"
15 ;The name var is set in .onInit
18 OutFile "viking-${VIKING_VERSION}.exe"
20 SetCompressor /SOLID lzma
22 ShowUninstDetails show
25 ; $name and $INSTDIR are set in .onInit function..
28 !include "Sections.nsh"
30 !include "LogicLib.nsh"
31 ;; http://nsis.sourceforge.net/File_Association
32 !include "FileAssociation.nsh"
34 !include "FileFunc.nsh"
35 !insertmacro GetParameters
36 !insertmacro GetOptions
37 !insertmacro GetParent
39 !include "WordFunc.nsh"
41 ;--------------------------------
44 !define VIKING_NSIS_INCLUDE_PATH "."
46 ; Remove these and the stuff that uses them at some point
47 !define VIKING_REG_KEY "SOFTWARE\viking"
48 !define VIKING_UNINSTALL_KEY "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\viking"
50 !define HKLM_APP_PATHS_KEY "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\viking.exe"
51 !define VIKING_UNINST_EXE "viking-uninst.exe"
53 ;--------------------------------
55 VIProductVersion "${VIKING_VERSION}"
56 VIAddVersionKey "ProductName" "Viking"
57 VIAddVersionKey "FileVersion" "${VIKING_VERSION}"
58 VIAddVersionKey "ProductVersion" "${VIKING_VERSION}"
59 VIAddVersionKey "LegalCopyright" ""
60 VIAddVersionKey "FileDescription" "Viking Installer"
62 ;--------------------------------
63 ;Modern UI Configuration
65 !define MUI_ICON ".\pixmaps\viking_icon.ico"
66 !define MUI_UNICON ".\pixmaps\viking_icon.ico"
67 ; !define MUI_WELCOMEFINISHPAGE_BITMAP ".\pixmaps\viking-intro.bmp"
68 ; !define MUI_HEADERIMAGE
69 ; !define MUI_HEADERIMAGE_BITMAP ".\pixmaps\viking-header.bmp"
71 ; Alter License section
72 !define MUI_LICENSEPAGE_BUTTON $(VIKING_LICENSE_BUTTON)
73 !define MUI_LICENSEPAGE_TEXT_BOTTOM $(VIKING_LICENSE_BOTTOM_TEXT)
75 !define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
76 !define MUI_LANGDLL_REGISTRY_KEY ${VIKING_REG_KEY}
77 !define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
79 !define MUI_COMPONENTSPAGE_SMALLDESC
80 !define MUI_ABORTWARNING
83 !define MUI_FINISHPAGE_NOAUTOCLOSE
84 !define MUI_FINISHPAGE_RUN "$INSTDIR\viking.exe"
85 !define MUI_FINISHPAGE_RUN_NOTCHECKED
86 !define MUI_FINISHPAGE_LINK $(VIKING_FINISH_VISIT_WEB_SITE)
87 !define MUI_FINISHPAGE_LINK_LOCATION "http://viking.sourceforge.net"
89 ;--------------------------------
92 !insertmacro MUI_PAGE_WELCOME
93 !insertmacro MUI_PAGE_LICENSE ".\bin\COPYING_GPL.txt"
94 !insertmacro MUI_PAGE_COMPONENTS
96 ; Viking install dir page
97 !insertmacro MUI_PAGE_DIRECTORY
99 !insertmacro MUI_PAGE_INSTFILES
100 !insertmacro MUI_PAGE_FINISH
102 !insertmacro MUI_UNPAGE_WELCOME
103 !insertmacro MUI_UNPAGE_CONFIRM
104 !insertmacro MUI_UNPAGE_INSTFILES
105 !insertmacro MUI_UNPAGE_FINISH
107 ;--------------------------------
110 ;; English goes first because its the default. The rest are
111 ;; in alphabetical order (at least the strings actually displayed
114 !insertmacro MUI_LANGUAGE "English"
115 !insertmacro MUI_LANGUAGE "French"
116 !insertmacro MUI_LANGUAGE "Spanish"
118 ;--------------------------------
121 !define VIKING_DEFAULT_LANGFILE "${VIKING_NSIS_INCLUDE_PATH}\translations\english.nsh"
123 !include "${VIKING_NSIS_INCLUDE_PATH}\langmacros.nsh"
125 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "ENGLISH" "${VIKING_NSIS_INCLUDE_PATH}\translations\english.nsh"
126 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "FRENCH" "${VIKING_NSIS_INCLUDE_PATH}\translations\french.nsh"
127 !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "SPANISH" "${VIKING_NSIS_INCLUDE_PATH}\translations\spanish.nsh"
129 ;--------------------------------
131 ; Only need this if using bzip2 compression
133 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
134 !insertmacro MUI_RESERVEFILE_LANGDLL
135 ReserveFile "${NSISDIR}\Plugins\UserInfo.dll"
138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
139 ;; Start Install Sections ;;
140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
142 ;--------------------------------
143 ;Uninstall any old version of Viking
145 Section -SecUninstallOldViking
146 ; Check install rights..
147 Call CheckUserInstallRights
150 ;First try to uninstall Viking
151 StrCpy $R4 ${VIKING_REG_KEY}
152 StrCpy $R5 ${VIKING_UNINSTALL_KEY}
153 StrCpy $R6 ${VIKING_UNINST_EXE}
156 ;Determine user install rights
157 StrCmp $R0 "HKLM" compare_hklm
158 StrCmp $R0 "HKCU" compare_hkcu done
161 ReadRegStr $R1 HKCU $R4 ""
162 ReadRegStr $R2 HKCU $R4 "Version"
163 ReadRegStr $R3 HKCU "$R5" "UninstallString"
167 ReadRegStr $R1 HKLM $R4 ""
168 ReadRegStr $R2 HKLM $R4 "Version"
169 ReadRegStr $R3 HKLM "$R5" "UninstallString"
171 ; If a previous version exists, remove it
174 StrCmp $R2 "" uninstall_problem
175 ; Check if we have uninstall string..
176 IfFileExists $R3 0 uninstall_problem
177 ; Have uninstall string, go ahead and uninstall.
179 ; Need to copy uninstaller outside of the install dir
181 CopyFiles /SILENT $R3 "$TEMP\$R6"
183 IfErrors uninstall_problem
184 ; Ready to uninstall..
186 ExecWait '"$TEMP\$R6" /S _?=$R1'
193 Goto uninstall_problem
196 ; We can't uninstall. Either the user must manually uninstall or we ignore and reinstall over it.
197 MessageBox MB_OKCANCEL $(VIKING_PROMPT_CONTINUE_WITHOUT_UNINSTALL) /SD IDOK IDOK done
202 ;--------------------------------
203 ;Viking Install Section
205 Section $(VIKING_SECTION_TITLE) SecViking
208 ; Check install rights..
209 Call CheckUserInstallRights
211 StrCmp $R0 "NONE" viking_none
212 StrCmp $R0 "HKLM" viking_hklm viking_hkcu
214 ;Install rights for Local Machine
216 WriteRegStr HKLM "${HKLM_APP_PATHS_KEY}" "" "$INSTDIR\viking.exe"
217 WriteRegStr HKLM "${HKLM_APP_PATHS_KEY}" "Path" "$R1\bin"
218 WriteRegStr HKLM ${VIKING_REG_KEY} "" "$INSTDIR"
219 WriteRegStr HKLM ${VIKING_REG_KEY} "Version" "${VIKING_VERSION}"
220 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "DisplayName" "Viking"
221 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "DisplayVersion" "${VIKING_VERSION}"
222 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "HelpLink" "http://sourceforge.net/apps/mediawiki/viking/"
223 WriteRegDWORD HKLM "${VIKING_UNINSTALL_KEY}" "NoModify" 1
224 WriteRegDWORD HKLM "${VIKING_UNINSTALL_KEY}" "NoRepair" 1
225 WriteRegStr HKLM "${VIKING_UNINSTALL_KEY}" "UninstallString" "$INSTDIR\${VIKING_UNINST_EXE}"
226 ; Sets scope of the desktop and Start Menu entries for all users.
227 SetShellVarContext "all"
228 Goto viking_install_files
230 ;Install rights for Current User only
232 WriteRegStr HKCU ${VIKING_REG_KEY} "" "$INSTDIR"
233 WriteRegStr HKCU ${VIKING_REG_KEY} "Version" "${VIKING_VERSION}"
234 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "DisplayName" "Viking"
235 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "DisplayVersion" "${VIKING_VERSION}"
236 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "HelpLink" "http://sourceforge.net/apps/mediawiki/viking/"
237 WriteRegDWORD HKCU "${VIKING_UNINSTALL_KEY}" "NoModify" 1
238 WriteRegDWORD HKCU "${VIKING_UNINSTALL_KEY}" "NoRepair" 1
239 WriteRegStr HKCU "${VIKING_UNINSTALL_KEY}" "UninstallString" "$INSTDIR\${VIKING_UNINST_EXE}"
240 Goto viking_install_files
245 viking_install_files:
246 SetOutPath "$INSTDIR"
251 ; If we don't have install rights we're done
252 StrCmp $R0 "NONE" done
255 ; write out uninstaller
257 WriteUninstaller "$INSTDIR\${VIKING_UNINST_EXE}"
261 SectionEnd ; end of default Viking section
263 ;--------------------------------
266 SectionGroup /e $(VIKING_SHORTCUTS_SECTION_TITLE) SecShortcuts
268 Section /o $(VIKING_DESKTOP_SHORTCUT_SECTION_TITLE) SecDesktopShortcut
270 CreateShortCut "$DESKTOP\Viking.lnk" "$INSTDIR\viking.exe"
273 ;Start menu shortcuts
274 Section $(VIKING_STARTMENU_SHORTCUT_SECTION_TITLE) SecStartMenuShortcut
276 CreateDirectory "$SMPROGRAMS\Viking"
277 CreateShortCut "$SMPROGRAMS\Viking\Viking.lnk" "$INSTDIR\viking.exe"
278 CreateShortCut "$SMPROGRAMS\Viking\User Manual.lnk" "$INSTDIR\viking.pdf"
279 CreateShortCut "$SMPROGRAMS\Viking\Uninstall.lnk" "$INSTDIR\viking-uninst.exe"
284 ;--------------------------------
287 Section $(VIKING_FILE_ASSOCIATION_SECTION_TITLE) SecFileAssociation
288 ${registerExtension} "$INSTDIR\viking.exe" ".vik" "Viking File"
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 ;Simply wipe the Viking install dir
326 Delete "$DESKTOP\Viking.lnk"
329 ${unregisterExtension} ".vik" "Viking File"
334 MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_1) /SD IDOK
338 MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_2) /SD IDOK
342 SectionEnd ; end of uninstall section
344 ;--------------------------------
346 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
348 !insertmacro MUI_DESCRIPTION_TEXT ${SecViking} \
349 $(VIKING_SECTION_DESCRIPTION)
350 !insertmacro MUI_DESCRIPTION_TEXT ${SecShortcuts} \
351 $(VIKING_SHORTCUTS_SECTION_DESCRIPTION)
352 !insertmacro MUI_DESCRIPTION_TEXT ${SecDesktopShortcut} \
353 $(VIKING_DESKTOP_SHORTCUT_DESC)
354 !insertmacro MUI_DESCRIPTION_TEXT ${SecStartMenuShortcut} \
355 $(VIKING_STARTMENU_SHORTCUT_DESC)
356 !insertmacro MUI_DESCRIPTION_TEXT ${SecFileAssociation} \
357 $(VIKING_FILE_ASSOCIATION_DESC)
359 !insertmacro MUI_FUNCTION_DESCRIPTION_END
361 ;--------------------------------
364 ;Macro to determine user install rights
365 ;Will be used to determine where to install the program, shortcuts, ...
366 !macro CheckUserInstallRightsMacro UN
367 Function ${UN}CheckUserInstallRights
374 UserInfo::GetAccountType
377 StrCmp $1 "Admin" 0 +3
380 StrCmp $1 "Power" 0 +3
383 StrCmp $1 "User" 0 +3
386 StrCmp $1 "Guest" 0 +3
402 !insertmacro CheckUserInstallRightsMacro ""
403 !insertmacro CheckUserInstallRightsMacro "un."
405 ;Macro to determine if Viking is running before installation/unistallation
406 !macro RunCheckMacro UN
407 Function ${UN}RunCheck
408 FindProcDLL::FindProc "viking.exe"
409 IntCmp $R0 1 0 notRunning
410 MessageBox MB_OK|MB_ICONEXCLAMATION $(VIKING_IS_RUNNING) /SD IDOK
416 !insertmacro RunCheckMacro ""
417 !insertmacro RunCheckMacro "un."
419 ;Installer extra configuration at execution time: language, path, ...
421 ;Check if viking installer is already running
426 ;Check if viking is running
428 StrCpy $name "Viking ${VIKING_VERSION}"
431 ;Make sure that there was a previous installation
432 ReadRegStr $R0 HKCU "${VIKING_REG_KEY}" "Installer Language"
434 ;Preselect the "shortcuts" checkboxes according to the previous installation
435 !insertmacro SelectSection ${SecDesktopShortcut}
436 !insertmacro selectSection ${SecStartMenuShortcut}
438 ;Read command line parameters
440 ;Read language command line parameters
443 ${GetOptions} "$R0" "/L=" $R1
449 ; Display Language selection dialog
450 !insertmacro MUI_LANGDLL_DISPLAY
453 ;Read desktop shortcut command line options
455 ${GetOptions} "$R0" "/DS=" $R1
457 SectionGetFlags ${SecDesktopShortcut} $R2
459 IntOp $R2 $R2 | ${SF_SELECTED}
461 IntOp $R1 ${SF_SELECTED} ~
463 SectionSetFlags ${SecDesktopShortcut} $R2
465 ;Read start menu shortcuts command line options
467 ${GetOptions} "$R0" "/SMS=" $R1
469 SectionGetFlags ${SecStartMenuShortcut} $R2
471 IntOp $R2 $R2 | ${SF_SELECTED}
473 IntOp $R1 ${SF_SELECTED} ~
475 SectionSetFlags ${SecStartMenuShortcut} $R2
477 ; If install path was set on the command, use it.
478 StrCmp $INSTDIR "" 0 instdir_done
480 ; If viking is currently installed, we should default to where it is currently installed
482 ReadRegStr $INSTDIR HKCU "${VIKING_REG_KEY}" ""
484 StrCmp $INSTDIR "" 0 instdir_done
486 ReadRegStr $INSTDIR HKLM "${VIKING_REG_KEY}" ""
488 StrCmp $INSTDIR "" 0 instdir_done
490 Call CheckUserInstallRights
493 StrCmp $R0 "HKLM" 0 user_dir
494 StrCpy $INSTDIR "$PROGRAMFILES\Viking"
498 ${GetParent} $SMPROGRAMS $R2
500 StrCpy $INSTDIR "$R2\Viking"
510 ;Check if viking is running
512 StrCpy $name "Viking ${VIKING_VERSION}"
514 ; Get stored language preference
515 !insertmacro MUI_UNGETLANGUAGE