]> git.street.me.uk Git - andy/viking.git/blob - win32/installer/viking-installer.nsi
Make the Spanish version of the Windows Installer actually selectable.
[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 ;Needs to be 4 numbers:  W.X.Y.Z
13 !define VIKING_VERSION  "1.3.2.1"
14
15 ;The name var is set in .onInit
16 Name $name
17
18 OutFile "viking-${VIKING_VERSION}.exe"
19
20 SetCompressor /SOLID lzma
21 ShowInstDetails show
22 ShowUninstDetails show
23 SetDateSave on
24
25 ; $name and $INSTDIR are set in .onInit function..
26
27 !include "MUI.nsh"
28 !include "Sections.nsh"
29 !include "WinVer.nsh"
30 !include "LogicLib.nsh"
31
32 !include "FileFunc.nsh"
33 !insertmacro GetParameters
34 !insertmacro GetOptions
35 !insertmacro GetParent
36
37 !include "WordFunc.nsh"
38
39 ;--------------------------------
40 ;Defines
41
42 !define VIKING_NSIS_INCLUDE_PATH                "."
43
44 ; Remove these and the stuff that uses them at some point
45 !define VIKING_REG_KEY                          "SOFTWARE\viking"
46 !define VIKING_UNINSTALL_KEY                    "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\viking"
47
48 !define HKLM_APP_PATHS_KEY                      "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\viking.exe"
49 !define VIKING_UNINST_EXE                       "viking-uninst.exe"
50
51 !define DOWNLOADER_URL                          "http://downloads.sourceforge.net/viking/"
52
53 ;--------------------------------
54 ;Version resource
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"
61
62 ;--------------------------------
63 ;Modern UI Configuration
64
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"
70
71   ; Alter License section
72   !define MUI_LICENSEPAGE_BUTTON                $(VIKING_LICENSE_BUTTON)
73   !define MUI_LICENSEPAGE_TEXT_BOTTOM           $(VIKING_LICENSE_BOTTOM_TEXT)
74
75   !define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
76   !define MUI_LANGDLL_REGISTRY_KEY ${VIKING_REG_KEY}
77   !define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
78
79   !define MUI_COMPONENTSPAGE_SMALLDESC
80   !define MUI_ABORTWARNING
81
82   ;Finish Page config
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"
88
89 ;--------------------------------
90 ;Pages
91
92   !insertmacro MUI_PAGE_WELCOME
93   !insertmacro MUI_PAGE_LICENSE                 ".\bin\COPYING_GPL.txt"
94   !insertmacro MUI_PAGE_COMPONENTS
95
96   ; Viking install dir page
97   !insertmacro MUI_PAGE_DIRECTORY
98
99   !insertmacro MUI_PAGE_INSTFILES
100   !insertmacro MUI_PAGE_FINISH
101
102   !insertmacro MUI_UNPAGE_WELCOME
103   !insertmacro MUI_UNPAGE_CONFIRM
104   !insertmacro MUI_UNPAGE_INSTFILES
105   !insertmacro MUI_UNPAGE_FINISH
106
107 ;--------------------------------
108 ;Languages
109
110   ;; English goes first because its the default. The rest are
111   ;; in alphabetical order (at least the strings actually displayed
112   ;; will be).
113
114   !insertmacro MUI_LANGUAGE "English"
115   !insertmacro MUI_LANGUAGE "French"
116   !insertmacro MUI_LANGUAGE "Spanish"
117
118 ;--------------------------------
119 ;Translations
120
121   !define VIKING_DEFAULT_LANGFILE "${VIKING_NSIS_INCLUDE_PATH}\translations\english.nsh"
122
123   !include "${VIKING_NSIS_INCLUDE_PATH}\langmacros.nsh"
124
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"
128
129 ;--------------------------------
130 ;Reserve Files
131   ; Only need this if using bzip2 compression
132
133   !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
134   !insertmacro MUI_RESERVEFILE_LANGDLL
135   ReserveFile "${NSISDIR}\Plugins\UserInfo.dll"
136
137
138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
139 ;; Start Install Sections ;;
140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
141
142 ;--------------------------------
143 ;Uninstall any old version of Viking
144
145 Section -SecUninstallOldViking
146   ; Check install rights..
147   Call CheckUserInstallRights
148   Pop $R0
149
150   ;First try to uninstall Viking
151   StrCpy $R4 ${VIKING_REG_KEY}
152   StrCpy $R5 ${VIKING_UNINSTALL_KEY}
153   StrCpy $R6 ${VIKING_UNINST_EXE}
154   StrCpy $R7 "Viking"
155
156   ;Determine user install rights
157   StrCmp $R0 "HKLM" compare_hklm
158   StrCmp $R0 "HKCU" compare_hkcu done
159
160   compare_hkcu:
161       ReadRegStr $R1 HKCU $R4 ""
162       ReadRegStr $R2 HKCU $R4 "Version"
163       ReadRegStr $R3 HKCU "$R5" "UninstallString"
164       Goto try_uninstall
165
166   compare_hklm:
167       ReadRegStr $R1 HKLM $R4 ""
168       ReadRegStr $R2 HKLM $R4 "Version"
169       ReadRegStr $R3 HKLM "$R5" "UninstallString"
170
171   ; If a previous version exists, remove it
172   try_uninstall:
173     StrCmp $R1 "" done
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.
178           SetOverwrite on
179           ; Need to copy uninstaller outside of the install dir
180           ClearErrors
181           CopyFiles /SILENT $R3 "$TEMP\$R6"
182           SetOverwrite off
183           IfErrors uninstall_problem
184             ; Ready to uninstall..
185             ClearErrors
186             ExecWait '"$TEMP\$R6" /S _?=$R1'
187             IfErrors exec_error
188               Delete "$TEMP\$R6"
189             Goto done
190
191             exec_error:
192               Delete "$TEMP\$R6"
193               Goto uninstall_problem
194
195         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
198           Quit
199   done:
200 SectionEnd
201
202 ;--------------------------------
203 ;Viking Install Section
204
205 Section $(VIKING_SECTION_TITLE) SecViking
206   SectionIn 1 RO
207
208   ; Check install rights..
209   Call CheckUserInstallRights
210   Pop $R0
211   StrCmp $R0 "NONE" viking_none
212   StrCmp $R0 "HKLM" viking_hklm viking_hkcu
213
214   ;Install rights for Local Machine
215   viking_hklm:
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
229
230     ;Install rights for Current User only 
231   viking_hkcu:
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
241   
242   ;No install rights!
243   viking_none:
244
245   viking_install_files:
246     SetOutPath "$INSTDIR"
247     SetOverwrite on
248
249     File /r .\bin\*.*
250
251     ; If we don't have install rights we're done
252     StrCmp $R0 "NONE" done
253     SetOverwrite off
254
255     ; write out uninstaller
256     SetOverwrite on
257     WriteUninstaller "$INSTDIR\${VIKING_UNINST_EXE}"
258     SetOverwrite off
259
260   done:
261 SectionEnd ; end of default Viking section
262
263 ;--------------------------------
264 ;Shortcuts
265
266 SectionGroup /e $(VIKING_SHORTCUTS_SECTION_TITLE) SecShortcuts
267   ;Desktop shortcuts
268   Section /o $(VIKING_DESKTOP_SHORTCUT_SECTION_TITLE) SecDesktopShortcut
269     SetOverwrite on
270     CreateShortCut "$DESKTOP\Viking.lnk" "$INSTDIR\viking.exe"
271     SetOverwrite off
272   SectionEnd
273   ;Start menu shortcuts
274   Section $(VIKING_STARTMENU_SHORTCUT_SECTION_TITLE) SecStartMenuShortcut
275     SetOverwrite on
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"
280     SetOverwrite off
281   SectionEnd
282 SectionGroupEnd
283
284
285
286
287
288
289
290
291
292
293
294
295 ;--------------------------------
296 ;Uninstaller Section
297
298
299 Section Uninstall
300   Call un.CheckUserInstallRights
301   Pop $R0
302   StrCmp $R0 "NONE" no_rights
303   StrCmp $R0 "HKCU" try_hkcu try_hklm
304
305   try_hkcu:
306     ReadRegStr $R0 HKCU ${VIKING_REG_KEY} ""
307     StrCmp $R0 $INSTDIR 0 cant_uninstall
308       ; HKCU install path matches our INSTDIR so uninstall
309       DeleteRegKey HKCU ${VIKING_REG_KEY}
310       DeleteRegKey HKCU "${VIKING_UNINSTALL_KEY}"
311       Goto cont_uninstall
312
313   try_hklm:
314     ReadRegStr $R0 HKLM ${VIKING_REG_KEY} ""
315     StrCmp $R0 $INSTDIR 0 try_hkcu
316       ; HKLM install path matches our INSTDIR so uninstall
317       DeleteRegKey HKLM ${VIKING_REG_KEY}
318       DeleteRegKey HKLM "${VIKING_UNINSTALL_KEY}"
319       DeleteRegKey HKLM "${HKLM_APP_PATHS_KEY}"
320       ; Sets start menu and desktop scope to all users..
321       SetShellVarContext "all"
322
323   cont_uninstall:
324
325     RMDir /r "$INSTDIR\etc"
326     RMDir /r "$INSTDIR\lib"
327     RMDir /r "$INSTDIR\locale"
328     RMDir /r "$INSTDIR\share"
329     Delete "$INSTDIR\AUTHORS.txt"
330     Delete "$INSTDIR\Changelog.txt"
331     Delete "$INSTDIR\COPYING_curl.txt"
332     Delete "$INSTDIR\COPYING_GPL.txt"
333     Delete "$INSTDIR\freetype6.dll"
334     Delete "$INSTDIR\gpsbabel.exe"
335     Delete "$INSTDIR\intl.dll"
336     Delete "$INSTDIR\libatk-1.0-0.dll"
337     Delete "$INSTDIR\libcairo-2.dll"
338     Delete "$INSTDIR\libcurl.dll"
339     Delete "$INSTDIR\libexif-12.dll"
340     Delete "$INSTDIR\libexpat.dll"
341     Delete "$INSTDIR\libexpat-1.dll"
342     Delete "$INSTDIR\libfontconfig-1.dll"
343     Delete "$INSTDIR\libgailutil-18.dll"
344     Delete "$INSTDIR\libgdk_pixbuf-2.0-0.dll"
345     Delete "$INSTDIR\libgdk-win32-2.0-0.dll"
346     Delete "$INSTDIR\libgio-2.0-0.dll"
347     Delete "$INSTDIR\libglib-2.0-0.dll"
348     Delete "$INSTDIR\libgmodule-2.0-0.dll"
349     Delete "$INSTDIR\libgobject-2.0-0.dll"
350     Delete "$INSTDIR\libgthread-2.0-0.dll"
351     Delete "$INSTDIR\libgtk-win32-2.0-0.dll"
352     Delete "$INSTDIR\libjpeg-7.dll"
353     Delete "$INSTDIR\libpango-1.0-0.dll"
354     Delete "$INSTDIR\libpangocairo-1.0-0.dll"
355     Delete "$INSTDIR\libpangoft2-1.0-0.dll"
356     Delete "$INSTDIR\libpangowin32-1.0-0.dll"
357     Delete "$INSTDIR\libpng12-0.dll"
358     Delete "$INSTDIR\libtiff-3.dll"
359     Delete "$INSTDIR\libtiffxx-3.dll"
360     Delete "$INSTDIR\NEWS.txt"
361     Delete "$INSTDIR\README.txt"
362     Delete "$INSTDIR\viking.exe"
363     Delete "$INSTDIR\viking.pdf"
364     Delete "$INSTDIR\zlib1.dll"
365     Delete "$INSTDIR\${VIKING_UNINST_EXE}"
366     Delete "$INSTDIR\install.log"
367
368     ;Try to remove Viking install dir (only if empty)
369     RMDir "$INSTDIR"
370
371     ; Shortcuts..
372     Delete "$DESKTOP\Viking.lnk"
373
374     Goto done
375
376   cant_uninstall:
377     MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_1) /SD IDOK
378     Quit
379
380   no_rights:
381     MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_2) /SD IDOK
382     Quit
383
384   done:
385 SectionEnd ; end of uninstall section
386
387 ;--------------------------------
388 ;Descriptions
389 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
390
391   !insertmacro MUI_DESCRIPTION_TEXT ${SecViking} \
392         $(VIKING_SECTION_DESCRIPTION)
393   !insertmacro MUI_DESCRIPTION_TEXT ${SecShortcuts} \
394         $(VIKING_SHORTCUTS_SECTION_DESCRIPTION)
395   !insertmacro MUI_DESCRIPTION_TEXT ${SecDesktopShortcut} \
396         $(VIKING_DESKTOP_SHORTCUT_DESC)
397   !insertmacro MUI_DESCRIPTION_TEXT ${SecStartMenuShortcut} \
398         $(VIKING_STARTMENU_SHORTCUT_DESC)
399
400 !insertmacro MUI_FUNCTION_DESCRIPTION_END
401
402 ;--------------------------------
403 ;Functions
404
405 ;Macro to determine user install rights
406 ;Will be used to determine where to install the program, shortcuts, ...
407 !macro CheckUserInstallRightsMacro UN
408 Function ${UN}CheckUserInstallRights
409   Push $0
410   Push $1
411   ClearErrors
412   UserInfo::GetName
413   IfErrors Win9x
414   Pop $0
415   UserInfo::GetAccountType
416   Pop $1
417
418   StrCmp $1 "Admin" 0 +3
419     StrCpy $1 "HKLM"
420     Goto done
421   StrCmp $1 "Power" 0 +3
422     StrCpy $1 "HKLM"
423     Goto done
424   StrCmp $1 "User" 0 +3
425     StrCpy $1 "HKCU"
426     Goto done
427   StrCmp $1 "Guest" 0 +3
428     StrCpy $1 "NONE"
429     Goto done
430   ; Unknown error
431   StrCpy $1 "NONE"
432   Goto done
433
434   Win9x:
435     StrCpy $1 "HKLM"
436
437   done:
438     Exch $1
439     Exch
440     Pop $0
441 FunctionEnd
442 !macroend
443 !insertmacro CheckUserInstallRightsMacro ""
444 !insertmacro CheckUserInstallRightsMacro "un."
445
446 ;Macro to determine if Viking is running before installation/unistallation
447 !macro RunCheckMacro UN
448 Function ${UN}RunCheck
449   FindProcDLL::FindProc "viking.exe"
450   IntCmp $R0 1 0 notRunning
451     MessageBox MB_OK|MB_ICONEXCLAMATION $(VIKING_IS_RUNNING) /SD IDOK
452     Abort
453   notRunning:
454 FunctionEnd
455 !macroend
456
457 !insertmacro RunCheckMacro ""
458 !insertmacro RunCheckMacro "un."
459
460 ;Installer extra configuration at execution time: language, path, ...
461 Function .onInit
462   ;Check if viking installer is already running
463   Push $R0
464   Push $R1
465   Push $R2
466
467   ;Check if viking is running
468   Call RunCheck
469   StrCpy $name "Viking ${VIKING_VERSION}"
470
471   ClearErrors
472   ;Make sure that there was a previous installation
473   ReadRegStr $R0 HKCU "${VIKING_REG_KEY}" "Installer Language"
474   
475   ;Preselect the "shortcuts" checkboxes according to the previous installation
476   !insertmacro SelectSection ${SecDesktopShortcut}
477   !insertmacro selectSection ${SecStartMenuShortcut}
478   
479   ;Read command line parameters
480   
481   ;Read language command line parameters
482   ${GetParameters} $R0
483   ClearErrors
484   ${GetOptions} "$R0" "/L=" $R1
485   IfErrors +3
486   StrCpy $LANGUAGE $R1
487   Goto skip_lang
488
489   ; Select Language
490     ; Display Language selection dialog
491     !insertmacro MUI_LANGDLL_DISPLAY
492     skip_lang:
493
494   ;Read desktop shortcut command line options
495   ClearErrors
496   ${GetOptions} "$R0" "/DS=" $R1
497   IfErrors +8
498   SectionGetFlags ${SecDesktopShortcut} $R2
499   StrCmp "1" $R1 0 +2
500   IntOp $R2 $R2 | ${SF_SELECTED}
501   StrCmp "0" $R1 0 +3
502   IntOp $R1 ${SF_SELECTED} ~
503   IntOp $R2 $R2 & $R1
504   SectionSetFlags ${SecDesktopShortcut} $R2
505
506   ;Read start menu shortcuts command line options
507   ClearErrors
508   ${GetOptions} "$R0" "/SMS=" $R1
509   IfErrors +8
510   SectionGetFlags ${SecStartMenuShortcut} $R2
511   StrCmp "1" $R1 0 +2
512   IntOp $R2 $R2 | ${SF_SELECTED}
513   StrCmp "0" $R1 0 +3
514   IntOp $R1 ${SF_SELECTED} ~
515   IntOp $R2 $R2 & $R1
516   SectionSetFlags ${SecStartMenuShortcut} $R2
517
518   ; If install path was set on the command, use it.
519   StrCmp $INSTDIR "" 0 instdir_done
520
521   ;  If viking is currently installed, we should default to where it is currently installed
522   ClearErrors
523   ReadRegStr $INSTDIR HKCU "${VIKING_REG_KEY}" ""
524   IfErrors +2
525   StrCmp $INSTDIR "" 0 instdir_done
526   ClearErrors
527   ReadRegStr $INSTDIR HKLM "${VIKING_REG_KEY}" ""
528   IfErrors +2
529   StrCmp $INSTDIR "" 0 instdir_done
530
531   Call CheckUserInstallRights
532   Pop $R0
533
534   StrCmp $R0 "HKLM" 0 user_dir
535     StrCpy $INSTDIR "$PROGRAMFILES\Viking"
536     Goto instdir_done
537   user_dir:
538     Push $SMPROGRAMS
539     ${GetParent} $SMPROGRAMS $R2
540     ${GetParent} $R2 $R2
541     StrCpy $INSTDIR "$R2\Viking"
542
543   instdir_done:
544 ;LogSet on
545   Pop $R2
546   Pop $R1
547   Pop $R0
548 FunctionEnd
549
550 Function un.onInit
551   ;Check if viking is running
552   Call un.RunCheck
553   StrCpy $name "Viking ${VIKING_VERSION}"
554
555   ; Get stored language preference
556   !insertmacro MUI_UNGETLANGUAGE
557
558 FunctionEnd