]> git.street.me.uk Git - andy/viking.git/blob - win32/installer/viking-installer.nsi
Windows build installation steps in installer.bat script file.
[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\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"
364
365     ;Try to remove Viking install dir (only if empty)
366     RMDir "$INSTDIR"
367
368     ; Shortcuts..
369     Delete "$DESKTOP\Viking.lnk"
370
371     Goto done
372
373   cant_uninstall:
374     MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_1) /SD IDOK
375     Quit
376
377   no_rights:
378     MessageBox MB_OK $(un.VIKING_UNINSTALL_ERROR_2) /SD IDOK
379     Quit
380
381   done:
382 SectionEnd ; end of uninstall section
383
384 ;--------------------------------
385 ;Descriptions
386 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
387
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)
396
397 !insertmacro MUI_FUNCTION_DESCRIPTION_END
398
399 ;--------------------------------
400 ;Functions
401
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
406   Push $0
407   Push $1
408   ClearErrors
409   UserInfo::GetName
410   IfErrors Win9x
411   Pop $0
412   UserInfo::GetAccountType
413   Pop $1
414
415   StrCmp $1 "Admin" 0 +3
416     StrCpy $1 "HKLM"
417     Goto done
418   StrCmp $1 "Power" 0 +3
419     StrCpy $1 "HKLM"
420     Goto done
421   StrCmp $1 "User" 0 +3
422     StrCpy $1 "HKCU"
423     Goto done
424   StrCmp $1 "Guest" 0 +3
425     StrCpy $1 "NONE"
426     Goto done
427   ; Unknown error
428   StrCpy $1 "NONE"
429   Goto done
430
431   Win9x:
432     StrCpy $1 "HKLM"
433
434   done:
435     Exch $1
436     Exch
437     Pop $0
438 FunctionEnd
439 !macroend
440 !insertmacro CheckUserInstallRightsMacro ""
441 !insertmacro CheckUserInstallRightsMacro "un."
442
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
449     Abort
450   notRunning:
451 FunctionEnd
452 !macroend
453
454 !insertmacro RunCheckMacro ""
455 !insertmacro RunCheckMacro "un."
456
457 ;Installer extra configuration at execution time: language, path, ...
458 Function .onInit
459   ;Check if viking installer is already running
460   Push $R0
461   Push $R1
462   Push $R2
463
464   ;Check if viking is running
465   Call RunCheck
466   StrCpy $name "Viking ${VIKING_VERSION}"
467
468   ClearErrors
469   ;Make sure that there was a previous installation
470   ReadRegStr $R0 HKCU "${VIKING_REG_KEY}" "Installer Language"
471   
472   ;Preselect the "shortcuts" checkboxes according to the previous installation
473   !insertmacro SelectSection ${SecDesktopShortcut}
474   !insertmacro selectSection ${SecStartMenuShortcut}
475   
476   ;Read command line parameters
477   
478   ;Read language command line parameters
479   ${GetParameters} $R0
480   ClearErrors
481   ${GetOptions} "$R0" "/L=" $R1
482   IfErrors +3
483   StrCpy $LANGUAGE $R1
484   Goto skip_lang
485
486   ; Select Language
487     ; Display Language selection dialog
488     !insertmacro MUI_LANGDLL_DISPLAY
489     skip_lang:
490
491   ;Read desktop shortcut command line options
492   ClearErrors
493   ${GetOptions} "$R0" "/DS=" $R1
494   IfErrors +8
495   SectionGetFlags ${SecDesktopShortcut} $R2
496   StrCmp "1" $R1 0 +2
497   IntOp $R2 $R2 | ${SF_SELECTED}
498   StrCmp "0" $R1 0 +3
499   IntOp $R1 ${SF_SELECTED} ~
500   IntOp $R2 $R2 & $R1
501   SectionSetFlags ${SecDesktopShortcut} $R2
502
503   ;Read start menu shortcuts command line options
504   ClearErrors
505   ${GetOptions} "$R0" "/SMS=" $R1
506   IfErrors +8
507   SectionGetFlags ${SecStartMenuShortcut} $R2
508   StrCmp "1" $R1 0 +2
509   IntOp $R2 $R2 | ${SF_SELECTED}
510   StrCmp "0" $R1 0 +3
511   IntOp $R1 ${SF_SELECTED} ~
512   IntOp $R2 $R2 & $R1
513   SectionSetFlags ${SecStartMenuShortcut} $R2
514
515   ; If install path was set on the command, use it.
516   StrCmp $INSTDIR "" 0 instdir_done
517
518   ;  If viking is currently installed, we should default to where it is currently installed
519   ClearErrors
520   ReadRegStr $INSTDIR HKCU "${VIKING_REG_KEY}" ""
521   IfErrors +2
522   StrCmp $INSTDIR "" 0 instdir_done
523   ClearErrors
524   ReadRegStr $INSTDIR HKLM "${VIKING_REG_KEY}" ""
525   IfErrors +2
526   StrCmp $INSTDIR "" 0 instdir_done
527
528   Call CheckUserInstallRights
529   Pop $R0
530
531   StrCmp $R0 "HKLM" 0 user_dir
532     StrCpy $INSTDIR "$PROGRAMFILES\Viking"
533     Goto instdir_done
534   user_dir:
535     Push $SMPROGRAMS
536     ${GetParent} $SMPROGRAMS $R2
537     ${GetParent} $R2 $R2
538     StrCpy $INSTDIR "$R2\Viking"
539
540   instdir_done:
541 ;LogSet on
542   Pop $R2
543   Pop $R1
544   Pop $R0
545 FunctionEnd
546
547 Function un.onInit
548   ;Check if viking is running
549   Call un.RunCheck
550   StrCpy $name "Viking ${VIKING_VERSION}"
551
552   ; Get stored language preference
553   !insertmacro MUI_UNGETLANGUAGE
554
555 FunctionEnd