1 # installer.nsi - Installer for GnuPG 4 Windows. -*- coding: latin-1; -*-
2 # Copyright (C) 2005, 2007 g10 Code GmbH
4 # This file is part of GPG4Win.
6 # GPG4Win is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # GPG4Win is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 # No servicable parts beyond this line. Stay clear :)
22 !ifdef REQUIRE_W32_NSIS
23 !ifdef PACKAGE_LIBRARY
24 !include "Library.nsh"
27 !macro InstallLib libtype shared install localfile destfile tempbasedir
32 !include "WinMessages.nsh"
34 # Define for the registry key to change the environment. The
35 # commented one may be used if the setting should affect only the
37 !define Regkey_for_Env \
38 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
39 # !define Regkey_for_Env 'HKCU "Environment"'
42 # We use Memento to remember past installation choices.
44 !define MEMENTO_REGISTRY_ROOT HKLM
45 !define MEMENTO_REGISTRY_KEY \
46 Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRETTY_PACKAGE_SHORT}
49 # We use the modern UI.
52 # Set the package name. Note that this name should not be sufficed
53 # with the version because this would get displayed in the start menu.
54 Name "${PRETTY_PACKAGE}"
57 # Set the output filename.
59 OutFile "${PACKAGE}-light-${VERSION}.exe"
61 OutFile "${PACKAGE}-${VERSION}.exe"
64 Icon "${TOP_SRCDIR}/doc/logo/gpg4win-logo-icon.ico"
65 UninstallIcon "${TOP_SRCDIR}/doc/logo/gpg4win-logo-icon.ico"
67 # Set the installation directory.
69 !define INSTALL_DIR "${PACKAGE}"
71 InstallDir "$PROGRAMFILES\GNU\${INSTALL_DIR}"
74 InstallDirRegKey HKLM "Software\GNU\${PRETTY_PACKAGE_SHORT}" \
78 # Add version information to the file properties.
79 VIProductVersion "${PROD_VERSION}"
80 VIAddVersionKey "ProductName" "${PRETTY_PACKAGE_SHORT} (${VERSION})"
82 VIAddVersionKey "Comments" \
83 "${PRETTY_PACKAGE_SHORT} is Free Software; you can redistribute it \
84 and/or modify it under the terms of the GNU General Public License. \
85 You should have received a copy of the GNU General Public License \
86 along with this software; if not, write to the Free Software \
87 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, \
90 VIAddVersionKey "Comments" \
91 "${PRETTY_PACKAGE_SHORT} is Free Software; you can redistribute it \
92 and/or modify it under the terms of the GNU Lesser General Public \
93 License. You should have received a copy of the GNU Lesser General \
94 Public License along with this software; if not, write to the Free \
95 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, \
98 VIAddVersionKey "CompanyName" "${COMPANY}"
99 VIAddVersionKey "LegalTrademarks" ""
100 VIAddVersionKey "LegalCopyright" "${COPYRIGHT}"
101 VIAddVersionKey "FileDescription" "${DESCRIPTION}"
102 VIAddVersionKey "FileVersion" "${PROD_VERSION}"
104 # Set to the name of another GnuPG installation if one has been detected
105 Var OtherGnuPGDetected
109 # !define MUI_ABORTWARNING
110 !define MUI_FINISHPAGE_NOAUTOCLOSE
111 !define MUI_UNFINISHPAGE_NOAUTOCLOSE
113 #!define MUI_HEADERIMAGE
114 #!define MUI_HEADERIMAGE_BITMAP \
115 # "${TOP_SRCDIR}/doc/logo/gpg4win-logo-150x57.bmp"
116 !define MUI_WELCOMEFINISHPAGE_BITMAP \
117 "${TOP_SRCDIR}/doc/logo/gpg4win-logo-164x314.bmp"
119 # Remember the installer language
121 #!define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
122 #!define MUI_LANGDLL_REGISTRY_KEY "Software\GNU\${PRETTY_PACKAGE_SHORT}"
123 #!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
125 # The list of wizard pages.
127 !define MUI_WELCOMEPAGE_TITLE "${WELCOME_TITLE_STR}"
128 !define MUI_WELCOMEPAGE_TEXT "${ABOUT_STR}"
130 !insertmacro MUI_PAGE_WELCOME
132 !define MUI_LICENSEPAGE_BUTTON "$(^NextBtn)"
133 !define MUI_PAGE_HEADER_SUBTEXT "$(T_GPLHeader)"
134 !define MUI_LICENSEPAGE_TEXT_BOTTOM "$(T_GPLShort)"
135 !insertmacro MUI_PAGE_LICENSE "${TOP_SRCDIR}/COPYING"
137 !define MUI_PAGE_CUSTOMFUNCTION_SHOW PrintNonAdminWarning
138 !insertmacro MUI_PAGE_COMPONENTS
140 !define MUI_PAGE_CUSTOMFUNCTION_LEAVE CheckExistingVersion
141 !insertmacro MUI_PAGE_DIRECTORY
143 !ifdef HAVE_STARTMENU
145 Page custom CustomPageOptions
149 !define MUI_PAGE_CUSTOMFUNCTION_PRE CheckIfStartMenuWanted
150 !define MUI_STARTMENUPAGE_NODISABLE
151 !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKCU"
152 !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\GNU\${PRETTY_PACKAGE_SHORT}"
153 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
155 !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
159 !define MUI_PAGE_CUSTOMFUNCTION_PRE PrintCloseOtherApps
160 !insertmacro MUI_PAGE_INSTFILES
162 !define MUI_PAGE_CUSTOMFUNCTION_PRE ShowFinalWarnings
163 !define MUI_FINISHPAGE_SHOWREADME "share\gpg4win\README.$(T_LangCode).txt"
164 !define MUI_FINISHPAGE_SHOWREADME_TEXT "$(T_ShowReadme)"
165 #!define MUI_FINISHPAGE_RUN
166 #!define MUI_FINISHPAGE_RUN_FUNCTION RunOnFinish
167 #!define MUI_FINISHPAGE_RUN_TEXT "$(T_RunKeyManager)"
168 #!define MUI_FINISHPAGE_RUN_NOTCHECKED
169 !define MUI_FINISHPAGE_LINK "$(T_MoreInfo)"
170 !define MUI_FINISHPAGE_LINK_LOCATION "$(T_MoreInfoURL)"
171 !insertmacro MUI_PAGE_FINISH
176 !insertmacro MUI_UNPAGE_CONFIRM
177 !insertmacro MUI_UNPAGE_INSTFILES
184 #UninstPage uninstConfirm
185 #UninstPage instfiles
188 # Language support. This has to be done after defining the pages, but
189 # before defining the translation strings. Confusing.
191 !insertmacro MUI_LANGUAGE "English"
193 #!insertmacro MUI_RESERVEFILE_LANGDLL
194 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
195 ReserveFile "${BUILD_DIR}\g4wihelp.dll"
197 ReserveFile "${TOP_SRCDIR}\doc\logo\gpg4win-logo-400px.bmp"
198 ReserveFile "${TOP_SRCDIR}\src\gpg4win-splash.wav"
200 ReserveFile "${TOP_SRCDIR}\COPYING"
201 ReserveFile "installer-options.ini"
202 ReserveFile "${TOP_SRCDIR}\doc\logo\gpg4win-logo-164x314.bmp"
206 LangString T_LangCode ${LANG_ENGLISH} "en"
209 LangString T_GPLHeader ${LANG_ENGLISH} \
210 "This software is licensed under the terms of the GNU General Public \
211 License (GPL) which guarantees your freedom to share and change Free \
214 LangString T_GPLShort ${LANG_ENGLISH} \
215 "In short: You are allowed to run this software for any purpose. \
216 You may distribute it as long as you give the recipients the same \
217 rights you have received."
219 LangString T_RunKeyManager ${LANG_ENGLISH} \
220 "Run the key manager"
222 LangString T_MoreInfo ${LANG_ENGLISH} \
223 "Click here for the project's homepage"
224 LangString T_MoreInfoURL ${LANG_ENGLISH} "http://www.gpg4win.org"
226 LangString T_ShowReadme ${LANG_ENGLISH} \
227 "Show the README file"
229 LangString T_NoKeyManager ${LANG_ENGLISH} \
230 "No key manager has been installed, thus we can't run one now."
232 # Used as subdirectory name in Start Menu.
234 LangString DESC_Menu_manuals ${LANG_ENGLISH} \
237 # Used as subdirectory name on Desktop.
238 LangString DESC_Desktop_manuals ${LANG_ENGLISH} \
239 "Gpg4win Documentation"
244 # Custom functions and macros for gpg4win.
245 !include "g4wihelp.nsi"
248 # Control function for the Custom page to select special
251 Function CustomPageOptions
252 !insertmacro MUI_HEADER_TEXT "$(T_InstallOptions)" "$(T_InstallOptLinks)"
254 # Note that the default selection is done in the ini file.
255 !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
256 "Field 1" "Text" "$(T_InstOptLabelA)"
257 !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
258 "Field 2" "Text" "$(T_InstOptFieldA)"
259 !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
260 "Field 3" "Text" "$(T_InstOptFieldB)"
261 !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
262 "Field 4" "Text" "$(T_InstOptFieldC)"
263 !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
264 "Field 5" "Text" "$(T_InstOptLabelB)"
266 !insertmacro MUI_INSTALLOPTIONS_DISPLAY "installer-options.ini"
270 # Display a warning if GnuPP has been detected and allow the user to abort
272 Function PrintGnuPPWarning
273 MessageBox MB_YESNO "$(T_FoundOldGnuPP)" IDYES cont
276 StrCpy $OtherGnuPGDetected "GnuPP"
279 # Display a warning if GnuPT has been detected and allow the user to abort
281 Function PrintGnuPTWarning
282 MessageBox MB_YESNO "$(T_FoundOldGnuPT)" IDYES cont
285 StrCpy $OtherGnuPGDetected "GnuPT"
288 # Display a warning if the Sourceforge WinPT has been detected and
289 # allow the user to abort the installation.
290 Function PrintWinPTSFWarning
291 MessageBox MB_YESNO "$(T_FoundOldWinPTSF)" IDYES cont
294 StrCpy $OtherGnuPGDetected "WinPT-SF"
297 # Display a warning if GnuPG Pack has been detected and abort the
298 # the installation. This one clobbers our own Registry space.
299 Function PrintGnuPackWarning
300 MessageBox MB_OK "$(T_FoundOldGnuPack)"
305 # Check whether one of the other GnuPG systems has already been
306 # installed. We do this by looking at the registry.
307 Function CheckOtherGnuPGApps
308 StrCpy $OtherGnuPGDetected ""
310 ReadRegStr $0 HKLM "Software\GNU\GnuPP\Settings" "Path"
312 Call PrintGnuPPWarning
314 EnumRegKey $0 HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start Menu\Programs\GnuPT" 0
316 Call PrintGnuPTWarning
319 ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Windows Privacy Tools" "DisplayVersion"
321 Call PrintWinPTSFWarning
323 ReadRegStr $0 HKLM "Software\GNU\GnuPG" "Install Directory"
329 Call PrintGnuPackWarning
334 # Check whether gpg4win has already been installed. This is called as
335 # a leave function from the directory page. A call to abort will get
336 # back to the directory selection.
337 Function CheckExistingVersion
339 FileOpen $0 "$INSTDIR\VERSION" r
349 MessageBox MB_YESNO "$(T_FoundExistingVersion)" IDYES leave
354 ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GPG4Win" "DisplayVersion"
356 MessageBox MB_YESNO "$(T_FoundExistingVersionB)" IDYES leave
364 # PrintNonAdminWarning
366 # Check whether the current user is in the Administrator group or an
367 # OS version without the need for an Administrator is in use. Print a
368 # diagnostic if this is not the case and abort installation.
369 Function PrintNonAdminWarning
374 UserInfo::GetAccountType
376 StrCmp $1 "Admin" leave +1
377 MessageBox MB_OK "$(T_AdminNeeded)"
384 # Check whether the start menu is actually wanted.
386 Function CheckIfStartMenuWanted
387 !insertmacro MUI_INSTALLOPTIONS_READ $R0 "installer-options.ini" \
394 # Check whether this is a reinstall and popup a message box to explain
395 # that it is better to close other apps before continuing
396 Function PrintCloseOtherApps
397 IfFileExists $INSTDIR\gnupg.exe print_warning
398 IfFileExists $INSTDIR\winpt.exe print_warning
399 IfFileExists $INSTDIR\gpa.exe print_warning
400 IfFileExists $INSTDIR\gpgol.dll print_warning
401 IfFileExists $INSTDIR\gpgee.dll print_warning
402 IfFileExists $INSTDIR\dirmngr.exe print_warning
405 MessageBox MB_OK|MB_ICONEXCLAMATION "$(T_CloseOtherApps)"
406 IfFileExists $INSTDIR\winpt.exe 0 +3
407 MessageBox MB_OK "$(T_ShuttingDownWinPT)"
408 ExecWait '"$INSTDIR\winpt.exe" --stop'
409 IfFileExists $INSTDIR\dirmngr.exe 0 +3
410 MessageBox MB_OK "$(T_ShuttingDownDirMngr)"
411 g4wihelp::service_stop "DirMngr"
415 # Called right before the final page to show more warnings.
416 Function ShowFinalWarnings
417 StrCmp $OtherGnupgDetected "" +2
418 MessageBox MB_OK "$(T_FoundOldSeeManual)"
422 #-----------------------------------------------
423 # Strings pertaining to the install options page
424 #-----------------------------------------------
426 # Installation options title
427 LangString T_InstallOptions ${LANG_ENGLISH} "Install Options"
429 # Installation options subtitle 1
430 LangString T_InstallOptLinks ${LANG_ENGLISH} "Start links"
432 LangString T_InstOptLabelA ${LANG_ENGLISH} \
433 "Please select where Gpg4win shall install links:"
435 LangString T_InstOptLabelB ${LANG_ENGLISH} \
436 "(Only programs will be linked into the quick launch bar.)"
438 LangString T_InstOptFieldA ${LANG_ENGLISH} \
441 LangString T_InstOptFieldB ${LANG_ENGLISH} \
444 LangString T_InstOptFieldC ${LANG_ENGLISH} \
447 #------------------------------------------------
448 # String pertaining to the existing version check
449 #------------------------------------------------
450 LangString T_FoundExistingVersion ${LANG_ENGLISH} \
451 "Version $R1 has already been installed. $\r$\n\
452 Do you want to overwrite it with version ${VERSION}?"
453 LangString T_FoundExistingVersionB ${LANG_ENGLISH} \
454 "A version of Gpg4Win has already been installed on the system. \
455 There will be no problem installing and thus overwriting this \
458 Do you want to continue installing Gpg4win?"
461 #---------------------------------------------
462 # From the old installation checking functions
463 #---------------------------------------------
464 LangString T_FoundOldSeeManual ${LANG_ENGLISH} \
465 "Please see the Gpg4win user manual to learn how to migrate existing \
466 keys from other GnuPG based installations to Gpg4win."
469 LangString T_FoundOldGnuPP ${LANG_ENGLISH} \
470 "An old installation of GnuPP (GNU Privacy Project) has been been \
471 detected. That software is not maintained anymore and thus should \
474 Do you want to continue installing Gpg4win and take care of the old \
478 LangString T_FoundOldGnuPT ${LANG_ENGLISH} \
479 "An installation of GnuPT has been been detected. This may cause \
480 problems when used along with Gpg4win. $\r$\n\
482 Do you want to continue installing Gpg4win?"
485 LangString T_FoundOldWinPTSF ${LANG_ENGLISH} \
486 "An old installation of the Sourceforge hosted WinPT has been been \
487 detected. That software is not maintained anymore and should \
490 Do you want to continue installing Gpg4win and take care of the old \
495 LangString T_FoundOldGnuPack ${LANG_ENGLISH} \
496 "An installation of GnuPG-Pack has been been detected. You need to \
497 uninstall it before you can continue with Gpg4win installation. $\r$\n\
499 The installation will be aborted now!"
503 # From Function PrintNonAdminWarning
504 LangString T_AdminNeeded ${LANG_ENGLISH} \
505 "Warning: Administrator permissions required for a successful installation"
507 # From Function PrintCloseOtherApps
508 LangString T_CloseOtherApps ${LANG_ENGLISH} \
509 "Please make sure that other applications are not running. \
510 In particular you should close Outlook and all Explorer \
511 windows. Gpg4Win will try to install anyway but a reboot \
512 will be required then."
513 LangString T_ShuttingDownWinPT ${LANG_ENGLISH} \
514 "Trying to shutdown a possible running instance of WinPT."
515 LangString T_ShuttingDownDirMngr ${LANG_ENGLISH} \
516 "Trying to shutdown a possible running instance of DirMngr."
519 # FIXME: The GetAfterChar function comes from the NSIS wiki.
520 Function un.GetAfterChar
523 Exch $1 ; input string
546 Function un.SourceDelete
550 Delete "$INSTDIR\$R0"
554 # StrStr - taken from the NSIS reference
555 # input, top of stack = string to search for
556 # top of stack-1 = string to search in
557 # output, top of stack (replaces with the portion of the string remaining)
558 # modifies no other variables.
561 # Push "this is a long ass string"
565 # ($R0 at this point is "ass string")
569 Exch $R1 # st=haystack,old$R1, $R1=needle
570 Exch # st=old$R1,haystack
571 Exch $R2 # st=old$R1,old$R2, $R2=haystack
583 StrCpy $R5 $R2 $R3 $R4
589 StrCpy $R1 $R2 "" $R4
597 !insertmacro StrStr ""
598 !insertmacro StrStr "un."
601 # TrimNewlines - taken from the NSIS reference
602 # input, top of stack (e.g. whatever$\r$\n)
603 # output, top of stack (replaces, with e.g. whatever)
604 # modifies no other variables.
605 Function TrimNewlines
614 StrCmp $R2 "$\r" loop
615 StrCmp $R2 "$\n" loop
617 IntCmp $R1 0 no_trim_needed
627 # AddToPath - Adds the given dir to the search path.
628 # Input - head of the stack
631 g4wihelp::path_add "$0"
632 StrCmp $R5 "0" add_to_path_done
633 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
638 # RemoveFromPath - Remove a given dir from the path
639 # Input: head of the stack
640 Function un.RemoveFromPath
642 g4wihelp::path_remove "$0"
643 StrCmp $R5 "0" remove_from_path_done
644 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
645 remove_from_path_done: