]> git.street.me.uk Git - andy/viking.git/blob - win32/installer/viking-installer.nsi
Spanish translation of the win32 installer
[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   !insertmacro VIKING_MACRO_INCLUDE_LANGFILE "SPANISH"          "${VIKING_NSIS_INCLUDE_PATH}\translations\spanish.nsh"
125
126 ;--------------------------------
127 ;Reserve Files
128   ; Only need this if using bzip2 compression
129
130   !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
131   !insertmacro MUI_RESERVEFILE_LANGDLL
132   ReserveFile "${NSISDIR}\Plugins\UserInfo.dll"
133
134
135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136 ;; Start Install Sections ;;
137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
138
139 ;--------------------------------
140 ;Uninstall any old version of Viking
141
142 Section -SecUninstallOldViking
143   ; Check install rights..
144   Call CheckUserInstallRights
145   Pop $R0
146
147   ;First try to uninstall Viking
148   StrCpy $R4 ${VIKING_REG_KEY}
149   StrCpy $R5 ${VIKING_UNINSTALL_KEY}
150   StrCpy $R6 ${VIKING_UNINST_EXE}
151   StrCpy $R7 "Viking"
152
153   ;Determine user install rights
154   StrCmp $R0 "HKLM" compare_hklm
155   StrCmp $R0 "HKCU" compare_hkcu done
156
157   compare_hkcu:
158       ReadRegStr $R1 HKCU $R4 ""
159       ReadRegStr $R2 HKCU $R4 "Version"
160       ReadRegStr $R3 HKCU "$R5" "UninstallString"
161       Goto try_uninstall
162
163   compare_hklm:
164       ReadRegStr $R1 HKLM $R4 ""
165       ReadRegStr $R2 HKLM $R4 "Version"
166       ReadRegStr $R3 HKLM "$R5" "UninstallString"
167
168   ; If a previous version exists, remove it
169   try_uninstall:
170     StrCmp $R1 "" done
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.
175           SetOverwrite on
176           ; Need to copy uninstaller outside of the install dir
177           ClearErrors
178           CopyFiles /SILENT $R3 "$TEMP\$R6"
179           SetOverwrite off
180           IfErrors uninstall_problem
181             ; Ready to uninstall..
182             ClearErrors
183             ExecWait '"$TEMP\$R6" /S _?=$R1'
184             IfErrors exec_error
185               Delete "$TEMP\$R6"
186             Goto done
187
188             exec_error:
189               Delete "$TEMP\$R6"
190               Goto uninstall_problem
191
192         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
195           Quit
196   done:
197 SectionEnd
198
199 ;--------------------------------
200 ;Viking Install Section
201
202 Section $(VIKING_SECTION_TITLE) SecViking
203   SectionIn 1 RO
204
205   ; Check install rights..
206   Call CheckUserInstallRights
207   Pop $R0
208   StrCmp $R0 "NONE" viking_none
209   StrCmp $R0 "HKLM" viking_hklm viking_hkcu
210
211   ;Install rights for Local Machine
212   viking_hklm:
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
226
227     ;Install rights for Current User only 
228   viking_hkcu:
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
238   
239   ;No install rights!
240   viking_none:
241
242   viking_install_files:
243     SetOutPath "$INSTDIR"
244     SetOverwrite on
245
246     File /r .\bin\*.*
247
248     ; If we don't have install rights we're done
249     StrCmp $R0 "NONE" done
250     SetOverwrite off
251
252     ; write out uninstaller
253     SetOverwrite on
254     WriteUninstaller "$INSTDIR\${VIKING_UNINST_EXE}"
255     SetOverwrite off
256
257   done:
258 SectionEnd ; end of default Viking section
259
260 ;--------------------------------
261 ;Shortcuts
262
263 SectionGroup /e $(VIKING_SHORTCUTS_SECTION_TITLE) SecShortcuts
264   ;Desktop shortcuts
265   Section /o $(VIKING_DESKTOP_SHORTCUT_SECTION_TITLE) SecDesktopShortcut
266     SetOverwrite on
267     CreateShortCut "$DESKTOP\Viking.lnk" "$INSTDIR\viking.exe"
268     SetOverwrite off
269   SectionEnd
270   ;Start menu shortcuts
271   Section $(VIKING_STARTMENU_SHORTCUT_SECTION_TITLE) SecStartMenuShortcut
272     SetOverwrite on
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"
277     SetOverwrite off
278   SectionEnd
279 SectionGroupEnd
280
281
282
283
284
285
286
287
288
289
290
291
292 ;--------------------------------
293 ;Uninstaller Section
294
295
296 Section Uninstall
297   Call un.CheckUserInstallRights
298   Pop $R0
299   StrCmp $R0 "NONE" no_rights
300   StrCmp $R0 "HKCU" try_hkcu try_hklm
301
302   try_hkcu:
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}"
308       Goto cont_uninstall
309
310   try_hklm:
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"
319
320   cont_uninstall:
321
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\libexpat.dll"
337     Delete "$INSTDIR\libexpat-1.dll"
338     Delete "$INSTDIR\libfontconfig-1.dll"
339     Delete "$INSTDIR\libgailutil-18.dll"
340     Delete "$INSTDIR\libgdk_pixbuf-2.0-0.dll"
341     Delete "$INSTDIR\libgdk-win32-2.0-0.dll"
342     Delete "$INSTDIR\libgio-2.0-0.dll"
343     Delete "$INSTDIR\libglib-2.0-0.dll"
344     Delete "$INSTDIR\libgmodule-2.0-0.dll"
345     Delete "$INSTDIR\libgobject-2.0-0.dll"
346     Delete "$INSTDIR\libgthread-2.0-0.dll"
347     Delete "$INSTDIR\libgtk-win32-2.0-0.dll"
348     Delete "$INSTDIR\libjpeg-7.dll"
349     Delete "$INSTDIR\libpango-1.0-0.dll"
350     Delete "$INSTDIR\libpangocairo-1.0-0.dll"
351     Delete "$INSTDIR\libpangoft2-1.0-0.dll"
352     Delete "$INSTDIR\libpangowin32-1.0-0.dll"
353     Delete "$INSTDIR\libpng12-0.dll"
354     Delete "$INSTDIR\libtiff-3.dll"
355     Delete "$INSTDIR\libtiffxx-3.dll"
356     Delete "$INSTDIR\NEWS.txt"
357     Delete "$INSTDIR\README.txt"
358     Delete "$INSTDIR\viking.exe"
359     Delete "$INSTDIR\viking.pdf"
360     Delete "$INSTDIR\zlib1.dll"
361     Delete "$INSTDIR\${VIKING_UNINST_EXE}"
362     Delete "$INSTDIR\install.log"
363
364     ;Try to remove Viking install dir (only if empty)
365     RMDir "$INSTDIR"
366
367     ; Shortcuts..
368     Delete "$DESKTOP\Viking.lnk"
369
370     Goto done
371
372   cant_uninstall:
373     MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_1) /SD IDOK
374     Quit
375
376   no_rights:
377     MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_2) /SD IDOK
378     Quit
379
380   done:
381 SectionEnd ; end of uninstall section
382
383 ;--------------------------------
384 ;Descriptions
385 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
386
387   !insertmacro MUI_DESCRIPTION_TEXT ${SecViking} \
388         $(VIKING_SECTION_DESCRIPTION)
389   !insertmacro MUI_DESCRIPTION_TEXT ${SecShortcuts} \
390         $(VIKING_SHORTCUTS_SECTION_DESCRIPTION)
391   !insertmacro MUI_DESCRIPTION_TEXT ${SecDesktopShortcut} \
392         $(VIKING_DESKTOP_SHORTCUT_DESC)
393   !insertmacro MUI_DESCRIPTION_TEXT ${SecStartMenuShortcut} \
394         $(VIKING_STARTMENU_SHORTCUT_DESC)
395
396 !insertmacro MUI_FUNCTION_DESCRIPTION_END
397
398 ;--------------------------------
399 ;Functions
400
401 ;Macro to determine user install rights
402 ;Will be used to determine where to install the program, shortcuts, ...
403 !macro CheckUserInstallRightsMacro UN
404 Function ${UN}CheckUserInstallRights
405   Push $0
406   Push $1
407   ClearErrors
408   UserInfo::GetName
409   IfErrors Win9x
410   Pop $0
411   UserInfo::GetAccountType
412   Pop $1
413
414   StrCmp $1 "Admin" 0 +3
415     StrCpy $1 "HKLM"
416     Goto done
417   StrCmp $1 "Power" 0 +3
418     StrCpy $1 "HKLM"
419     Goto done
420   StrCmp $1 "User" 0 +3
421     StrCpy $1 "HKCU"
422     Goto done
423   StrCmp $1 "Guest" 0 +3
424     StrCpy $1 "NONE"
425     Goto done
426   ; Unknown error
427   StrCpy $1 "NONE"
428   Goto done
429
430   Win9x:
431     StrCpy $1 "HKLM"
432
433   done:
434     Exch $1
435     Exch
436     Pop $0
437 FunctionEnd
438 !macroend
439 !insertmacro CheckUserInstallRightsMacro ""
440 !insertmacro CheckUserInstallRightsMacro "un."
441
442 ;Macro to determine if Viking is running before installation/unistallation
443 !macro RunCheckMacro UN
444 Function ${UN}RunCheck
445   FindProcDLL::FindProc "viking.exe"
446   IntCmp $R0 1 0 notRunning
447     MessageBox MB_OK|MB_ICONEXCLAMATION $(VIKING_IS_RUNNING) /SD IDOK
448     Abort
449   notRunning:
450 FunctionEnd
451 !macroend
452
453 !insertmacro RunCheckMacro ""
454 !insertmacro RunCheckMacro "un."
455
456 ;Installer extra configuration at execution time: language, path, ...
457 Function .onInit
458   ;Check if viking installer is already running
459   Push $R0
460   Push $R1
461   Push $R2
462
463   ;Check if viking is running
464   Call RunCheck
465   StrCpy $name "Viking ${VIKING_VERSION}"
466
467   ClearErrors
468   ;Make sure that there was a previous installation
469   ReadRegStr $R0 HKCU "${VIKING_REG_KEY}" "Installer Language"
470   
471   ;Preselect the "shortcuts" checkboxes according to the previous installation
472   !insertmacro SelectSection ${SecDesktopShortcut}
473   !insertmacro selectSection ${SecStartMenuShortcut}
474   
475   ;Read command line parameters
476   
477   ;Read language command line parameters
478   ${GetParameters} $R0
479   ClearErrors
480   ${GetOptions} "$R0" "/L=" $R1
481   IfErrors +3
482   StrCpy $LANGUAGE $R1
483   Goto skip_lang
484
485   ; Select Language
486     ; Display Language selection dialog
487     !insertmacro MUI_LANGDLL_DISPLAY
488     skip_lang:
489
490   ;Read desktop shortcut command line options
491   ClearErrors
492   ${GetOptions} "$R0" "/DS=" $R1
493   IfErrors +8
494   SectionGetFlags ${SecDesktopShortcut} $R2
495   StrCmp "1" $R1 0 +2
496   IntOp $R2 $R2 | ${SF_SELECTED}
497   StrCmp "0" $R1 0 +3
498   IntOp $R1 ${SF_SELECTED} ~
499   IntOp $R2 $R2 & $R1
500   SectionSetFlags ${SecDesktopShortcut} $R2
501
502   ;Read start menu shortcuts command line options
503   ClearErrors
504   ${GetOptions} "$R0" "/SMS=" $R1
505   IfErrors +8
506   SectionGetFlags ${SecStartMenuShortcut} $R2
507   StrCmp "1" $R1 0 +2
508   IntOp $R2 $R2 | ${SF_SELECTED}
509   StrCmp "0" $R1 0 +3
510   IntOp $R1 ${SF_SELECTED} ~
511   IntOp $R2 $R2 & $R1
512   SectionSetFlags ${SecStartMenuShortcut} $R2
513
514   ; If install path was set on the command, use it.
515   StrCmp $INSTDIR "" 0 instdir_done
516
517   ;  If viking is currently installed, we should default to where it is currently installed
518   ClearErrors
519   ReadRegStr $INSTDIR HKCU "${VIKING_REG_KEY}" ""
520   IfErrors +2
521   StrCmp $INSTDIR "" 0 instdir_done
522   ClearErrors
523   ReadRegStr $INSTDIR HKLM "${VIKING_REG_KEY}" ""
524   IfErrors +2
525   StrCmp $INSTDIR "" 0 instdir_done
526
527   Call CheckUserInstallRights
528   Pop $R0
529
530   StrCmp $R0 "HKLM" 0 user_dir
531     StrCpy $INSTDIR "$PROGRAMFILES\Viking"
532     Goto instdir_done
533   user_dir:
534     Push $SMPROGRAMS
535     ${GetParent} $SMPROGRAMS $R2
536     ${GetParent} $R2 $R2
537     StrCpy $INSTDIR "$R2\Viking"
538
539   instdir_done:
540 ;LogSet on
541   Pop $R2
542   Pop $R1
543   Pop $R0
544 FunctionEnd
545
546 Function un.onInit
547   ;Check if viking is running
548   Call un.RunCheck
549   StrCpy $name "Viking ${VIKING_VERSION}"
550
551   ; Get stored language preference
552   !insertmacro MUI_UNGETLANGUAGE
553
554 FunctionEnd