]> git.street.me.uk Git - andy/viking.git/blob - win32/installer/viking-installer.nsi
Add used geo-* scripts as they are public domain.
[andy/viking.git] / win32 / installer / viking-installer.nsi
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>
5
6 ;--------------------------------
7 ;Global Variables
8 Var name
9
10 ;--------------------------------
11 ;Configuration
12
13 ;The name var is set in .onInit
14 Name $name
15
16 OutFile "viking-${VIKING_VERSION}.exe"
17
18 SetCompressor /SOLID lzma
19 ShowInstDetails show
20 ShowUninstDetails show
21 SetDateSave on
22
23 ; $name and $INSTDIR are set in .onInit function..
24
25 !include "MUI.nsh"
26 !include "Sections.nsh"
27 !include "WinVer.nsh"
28 !include "LogicLib.nsh"
29
30 !include "FileFunc.nsh"
31 !insertmacro GetParameters
32 !insertmacro GetOptions
33 !insertmacro GetParent
34
35 !include "WordFunc.nsh"
36
37 ;--------------------------------
38 ;Defines
39
40 !define VIKING_NSIS_INCLUDE_PATH                "."
41
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"
45
46 !define HKLM_APP_PATHS_KEY                      "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\viking.exe"
47 !define VIKING_UNINST_EXE                       "viking-uninst.exe"
48
49 !define DOWNLOADER_URL                          "http://downloads.sourceforge.net/viking/"
50
51 ;--------------------------------
52 ;Version resource
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"
59
60 ;--------------------------------
61 ;Modern UI Configuration
62
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"
68
69   ; Alter License section
70   !define MUI_LICENSEPAGE_BUTTON                $(VIKING_LICENSE_BUTTON)
71   !define MUI_LICENSEPAGE_TEXT_BOTTOM           $(VIKING_LICENSE_BOTTOM_TEXT)
72
73   !define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
74   !define MUI_LANGDLL_REGISTRY_KEY ${VIKING_REG_KEY}
75   !define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
76
77   !define MUI_COMPONENTSPAGE_SMALLDESC
78   !define MUI_ABORTWARNING
79
80   ;Finish Page config
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"
86
87 ;--------------------------------
88 ;Pages
89
90   !insertmacro MUI_PAGE_WELCOME
91   !insertmacro MUI_PAGE_LICENSE                 ".\bin\COPYING_GPL.txt"
92   !insertmacro MUI_PAGE_COMPONENTS
93
94   ; Viking install dir page
95   !insertmacro MUI_PAGE_DIRECTORY
96
97   !insertmacro MUI_PAGE_INSTFILES
98   !insertmacro MUI_PAGE_FINISH
99
100   !insertmacro MUI_UNPAGE_WELCOME
101   !insertmacro MUI_UNPAGE_CONFIRM
102   !insertmacro MUI_UNPAGE_INSTFILES
103   !insertmacro MUI_UNPAGE_FINISH
104
105 ;--------------------------------
106 ;Languages
107
108   ;; English goes first because its the default. The rest are
109   ;; in alphabetical order (at least the strings actually displayed
110   ;; will be).
111
112   !insertmacro MUI_LANGUAGE "English"
113   !insertmacro MUI_LANGUAGE "French"
114
115 ;--------------------------------
116 ;Translations
117
118   !define VIKING_DEFAULT_LANGFILE "${VIKING_NSIS_INCLUDE_PATH}\translations\english.nsh"
119
120   !include "${VIKING_NSIS_INCLUDE_PATH}\langmacros.nsh"
121
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
125 ;--------------------------------
126 ;Reserve Files
127   ; Only need this if using bzip2 compression
128
129   !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
130   !insertmacro MUI_RESERVEFILE_LANGDLL
131   ReserveFile "${NSISDIR}\Plugins\UserInfo.dll"
132
133
134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
135 ;; Start Install Sections ;;
136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
137
138 ;--------------------------------
139 ;Uninstall any old version of Viking
140
141 Section -SecUninstallOldViking
142   ; Check install rights..
143   Call CheckUserInstallRights
144   Pop $R0
145
146   ;First try to uninstall Viking
147   StrCpy $R4 ${VIKING_REG_KEY}
148   StrCpy $R5 ${VIKING_UNINSTALL_KEY}
149   StrCpy $R6 ${VIKING_UNINST_EXE}
150   StrCpy $R7 "Viking"
151
152   ;Determine user install rights
153   StrCmp $R0 "HKLM" compare_hklm
154   StrCmp $R0 "HKCU" compare_hkcu done
155
156   compare_hkcu:
157       ReadRegStr $R1 HKCU $R4 ""
158       ReadRegStr $R2 HKCU $R4 "Version"
159       ReadRegStr $R3 HKCU "$R5" "UninstallString"
160       Goto try_uninstall
161
162   compare_hklm:
163       ReadRegStr $R1 HKLM $R4 ""
164       ReadRegStr $R2 HKLM $R4 "Version"
165       ReadRegStr $R3 HKLM "$R5" "UninstallString"
166
167   ; If a previous version exists, remove it
168   try_uninstall:
169     StrCmp $R1 "" done
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.
174           SetOverwrite on
175           ; Need to copy uninstaller outside of the install dir
176           ClearErrors
177           CopyFiles /SILENT $R3 "$TEMP\$R6"
178           SetOverwrite off
179           IfErrors uninstall_problem
180             ; Ready to uninstall..
181             ClearErrors
182             ExecWait '"$TEMP\$R6" /S _?=$R1'
183             IfErrors exec_error
184               Delete "$TEMP\$R6"
185             Goto done
186
187             exec_error:
188               Delete "$TEMP\$R6"
189               Goto uninstall_problem
190
191         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
194           Quit
195   done:
196 SectionEnd
197
198 ;--------------------------------
199 ;Viking Install Section
200
201 Section $(VIKING_SECTION_TITLE) SecViking
202   SectionIn 1 RO
203
204   ; Check install rights..
205   Call CheckUserInstallRights
206   Pop $R0
207   StrCmp $R0 "NONE" viking_none
208   StrCmp $R0 "HKLM" viking_hklm viking_hkcu
209
210   ;Install rights for Local Machine
211   viking_hklm:
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
225
226     ;Install rights for Current User only 
227   viking_hkcu:
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
237   
238   ;No install rights!
239   viking_none:
240
241   viking_install_files:
242     SetOutPath "$INSTDIR"
243     SetOverwrite on
244
245     File /r .\bin\*.*
246
247     ; If we don't have install rights we're done
248     StrCmp $R0 "NONE" done
249     SetOverwrite off
250
251     ; write out uninstaller
252     SetOverwrite on
253     WriteUninstaller "$INSTDIR\${VIKING_UNINST_EXE}"
254     SetOverwrite off
255
256   done:
257 SectionEnd ; end of default Viking section
258
259 ;--------------------------------
260 ;Shortcuts
261
262 SectionGroup /e $(VIKING_SHORTCUTS_SECTION_TITLE) SecShortcuts
263   ;Desktop shortcuts
264   Section /o $(VIKING_DESKTOP_SHORTCUT_SECTION_TITLE) SecDesktopShortcut
265     SetOverwrite on
266     CreateShortCut "$DESKTOP\Viking.lnk" "$INSTDIR\viking.exe"
267     SetOverwrite off
268   SectionEnd
269   ;Start menu shortcuts
270   Section $(VIKING_STARTMENU_SHORTCUT_SECTION_TITLE) SecStartMenuShortcut
271     SetOverwrite on
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"
276     SetOverwrite off
277   SectionEnd
278 SectionGroupEnd
279
280
281
282
283
284
285
286
287
288
289
290
291 ;--------------------------------
292 ;Uninstaller Section
293
294
295 Section Uninstall
296   Call un.CheckUserInstallRights
297   Pop $R0
298   StrCmp $R0 "NONE" no_rights
299   StrCmp $R0 "HKCU" try_hkcu try_hklm
300
301   try_hkcu:
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}"
307       Goto cont_uninstall
308
309   try_hklm:
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"
318
319   cont_uninstall:
320
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"
362
363     ;Try to remove Viking install dir (only if empty)
364     RMDir "$INSTDIR"
365
366     ; Shortcuts..
367     Delete "$DESKTOP\Viking.lnk"
368
369     Goto done
370
371   cant_uninstall:
372     MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_1) /SD IDOK
373     Quit
374
375   no_rights:
376     MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_2) /SD IDOK
377     Quit
378
379   done:
380 SectionEnd ; end of uninstall section
381
382 ;--------------------------------
383 ;Descriptions
384 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
385
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)
394
395 !insertmacro MUI_FUNCTION_DESCRIPTION_END
396
397 ;--------------------------------
398 ;Functions
399
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
404   Push $0
405   Push $1
406   ClearErrors
407   UserInfo::GetName
408   IfErrors Win9x
409   Pop $0
410   UserInfo::GetAccountType
411   Pop $1
412
413   StrCmp $1 "Admin" 0 +3
414     StrCpy $1 "HKLM"
415     Goto done
416   StrCmp $1 "Power" 0 +3
417     StrCpy $1 "HKLM"
418     Goto done
419   StrCmp $1 "User" 0 +3
420     StrCpy $1 "HKCU"
421     Goto done
422   StrCmp $1 "Guest" 0 +3
423     StrCpy $1 "NONE"
424     Goto done
425   ; Unknown error
426   StrCpy $1 "NONE"
427   Goto done
428
429   Win9x:
430     StrCpy $1 "HKLM"
431
432   done:
433     Exch $1
434     Exch
435     Pop $0
436 FunctionEnd
437 !macroend
438 !insertmacro CheckUserInstallRightsMacro ""
439 !insertmacro CheckUserInstallRightsMacro "un."
440
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
447     Abort
448   notRunning:
449 FunctionEnd
450 !macroend
451
452 !insertmacro RunCheckMacro ""
453 !insertmacro RunCheckMacro "un."
454
455 ;Installer extra configuration at execution time: language, path, ...
456 Function .onInit
457   ;Check if viking installer is already running
458   Push $R0
459   Push $R1
460   Push $R2
461
462   ;Check if viking is running
463   Call RunCheck
464   StrCpy $name "Viking ${VIKING_VERSION}"
465
466   ClearErrors
467   ;Make sure that there was a previous installation
468   ReadRegStr $R0 HKCU "${VIKING_REG_KEY}" "Installer Language"
469   
470   ;Preselect the "shortcuts" checkboxes according to the previous installation
471   !insertmacro SelectSection ${SecDesktopShortcut}
472   !insertmacro selectSection ${SecStartMenuShortcut}
473   
474   ;Read command line parameters
475   
476   ;Read language command line parameters
477   ${GetParameters} $R0
478   ClearErrors
479   ${GetOptions} "$R0" "/L=" $R1
480   IfErrors +3
481   StrCpy $LANGUAGE $R1
482   Goto skip_lang
483
484   ; Select Language
485     ; Display Language selection dialog
486     !insertmacro MUI_LANGDLL_DISPLAY
487     skip_lang:
488
489   ;Read desktop shortcut command line options
490   ClearErrors
491   ${GetOptions} "$R0" "/DS=" $R1
492   IfErrors +8
493   SectionGetFlags ${SecDesktopShortcut} $R2
494   StrCmp "1" $R1 0 +2
495   IntOp $R2 $R2 | ${SF_SELECTED}
496   StrCmp "0" $R1 0 +3
497   IntOp $R1 ${SF_SELECTED} ~
498   IntOp $R2 $R2 & $R1
499   SectionSetFlags ${SecDesktopShortcut} $R2
500
501   ;Read start menu shortcuts command line options
502   ClearErrors
503   ${GetOptions} "$R0" "/SMS=" $R1
504   IfErrors +8
505   SectionGetFlags ${SecStartMenuShortcut} $R2
506   StrCmp "1" $R1 0 +2
507   IntOp $R2 $R2 | ${SF_SELECTED}
508   StrCmp "0" $R1 0 +3
509   IntOp $R1 ${SF_SELECTED} ~
510   IntOp $R2 $R2 & $R1
511   SectionSetFlags ${SecStartMenuShortcut} $R2
512
513   ; If install path was set on the command, use it.
514   StrCmp $INSTDIR "" 0 instdir_done
515
516   ;  If viking is currently installed, we should default to where it is currently installed
517   ClearErrors
518   ReadRegStr $INSTDIR HKCU "${VIKING_REG_KEY}" ""
519   IfErrors +2
520   StrCmp $INSTDIR "" 0 instdir_done
521   ClearErrors
522   ReadRegStr $INSTDIR HKLM "${VIKING_REG_KEY}" ""
523   IfErrors +2
524   StrCmp $INSTDIR "" 0 instdir_done
525
526   Call CheckUserInstallRights
527   Pop $R0
528
529   StrCmp $R0 "HKLM" 0 user_dir
530     StrCpy $INSTDIR "$PROGRAMFILES\Viking"
531     Goto instdir_done
532   user_dir:
533     Push $SMPROGRAMS
534     ${GetParent} $SMPROGRAMS $R2
535     ${GetParent} $R2 $R2
536     StrCpy $INSTDIR "$R2\Viking"
537
538   instdir_done:
539 ;LogSet on
540   Pop $R2
541   Pop $R1
542   Pop $R0
543 FunctionEnd
544
545 Function un.onInit
546   ;Check if viking is running
547   Call un.RunCheck
548   StrCpy $name "Viking ${VIKING_VERSION}"
549
550   ; Get stored language preference
551   !insertmacro MUI_UNGETLANGUAGE
552
553 FunctionEnd