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"'
45 # We use the modern UI.
48 # Set the package name. Note that this name should not be sufficed
49 # with the version because this would get displayed in the start menu.
50 Name "${PRETTY_PACKAGE}"
53 # Set the output filename.
55 OutFile "${PACKAGE}-light-${VERSION}.exe"
57 OutFile "${PACKAGE}-${VERSION}.exe"
60 Icon "${TOP_SRCDIR}/doc/logo/gpg4win-logo-icon.ico"
61 UninstallIcon "${TOP_SRCDIR}/doc/logo/gpg4win-logo-icon.ico"
63 # Set the installation directory.
65 !define INSTALL_DIR "${PACKAGE}"
67 InstallDir "$PROGRAMFILES\GNU\${INSTALL_DIR}"
70 InstallDirRegKey HKLM "Software\GNU\${PRETTY_PACKAGE_SHORT}" \
74 # Add version information to the file properties.
75 VIProductVersion "${PROD_VERSION}"
76 VIAddVersionKey "ProductName" "${PRETTY_PACKAGE_SHORT} (${VERSION})"
78 VIAddVersionKey "Comments" \
79 "${PRETTY_PACKAGE_SHORT} is Free Software; you can redistribute it \
80 and/or modify it under the terms of the GNU General Public License. \
81 You should have received a copy of the GNU General Public License \
82 along with this software; if not, write to the Free Software \
83 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, \
86 VIAddVersionKey "Comments" \
87 "${PRETTY_PACKAGE_SHORT} is Free Software; you can redistribute it \
88 and/or modify it under the terms of the GNU Lesser General Public \
89 License. You should have received a copy of the GNU Lesser General \
90 Public License along with this software; if not, write to the Free \
91 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, \
94 VIAddVersionKey "CompanyName" "${COMPANY}"
95 VIAddVersionKey "LegalTrademarks" ""
96 VIAddVersionKey "LegalCopyright" "${COPYRIGHT}"
97 VIAddVersionKey "FileDescription" "${DESCRIPTION}"
98 VIAddVersionKey "FileVersion" "${PROD_VERSION}"
100 # Set to the name of another GnuPG installation if one has been detected
101 Var OtherGnuPGDetected
105 # !define MUI_ABORTWARNING
106 !define MUI_FINISHPAGE_NOAUTOCLOSE
107 !define MUI_UNFINISHPAGE_NOAUTOCLOSE
109 #!define MUI_HEADERIMAGE
110 #!define MUI_HEADERIMAGE_BITMAP \
111 # "${TOP_SRCDIR}/doc/logo/gpg4win-logo-150x57.bmp"
112 !define MUI_WELCOMEFINISHPAGE_BITMAP \
113 "${TOP_SRCDIR}/doc/logo/gpg4win-logo-164x314.bmp"
115 # Remember the installer language
117 #!define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
118 #!define MUI_LANGDLL_REGISTRY_KEY "Software\GNU\${PRETTY_PACKAGE_SHORT}"
119 #!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
121 # The list of wizard pages.
123 !define MUI_WELCOMEPAGE_TITLE "$(T_WelcomeTitle)"
124 !define MUI_WELCOMEPAGE_TEXT "$(T_About)"
125 !insertmacro MUI_PAGE_WELCOME
127 !define MUI_LICENSEPAGE_BUTTON "$(^NextBtn)"
128 !define MUI_PAGE_HEADER_SUBTEXT "$(T_GPLHeader)"
129 !define MUI_LICENSEPAGE_TEXT_BOTTOM "$(T_GPLShort)"
130 !insertmacro MUI_PAGE_LICENSE "${TOP_SRCDIR}/COPYING"
132 !define MUI_PAGE_CUSTOMFUNCTION_SHOW PrintNonAdminWarning
133 !insertmacro MUI_PAGE_COMPONENTS
135 !define MUI_PAGE_CUSTOMFUNCTION_LEAVE CheckExistingVersion
136 !insertmacro MUI_PAGE_DIRECTORY
138 !ifdef HAVE_STARTMENU
140 Page custom CustomPageOptions
144 !define MUI_PAGE_CUSTOMFUNCTION_PRE CheckIfStartMenuWanted
145 !define MUI_STARTMENUPAGE_NODISABLE
146 !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKCU"
147 !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\GNU\${PRETTY_PACKAGE_SHORT}"
148 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
150 !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
154 !define MUI_PAGE_CUSTOMFUNCTION_PRE PrintCloseOtherApps
155 !insertmacro MUI_PAGE_INSTFILES
157 !define MUI_PAGE_CUSTOMFUNCTION_PRE ShowFinalWarnings
158 !define MUI_FINISHPAGE_SHOWREADME "README.$(T_LangCode).txt"
159 !define MUI_FINISHPAGE_SHOWREADME_TEXT "$(T_ShowReadme)"
160 #!define MUI_FINISHPAGE_RUN
161 #!define MUI_FINISHPAGE_RUN_FUNCTION RunOnFinish
162 #!define MUI_FINISHPAGE_RUN_TEXT "$(T_RunKeyManager)"
163 #!define MUI_FINISHPAGE_RUN_NOTCHECKED
164 !define MUI_FINISHPAGE_LINK "$(T_MoreInfo)"
165 !define MUI_FINISHPAGE_LINK_LOCATION "$(T_MoreInfoURL)"
166 !insertmacro MUI_PAGE_FINISH
171 !insertmacro MUI_UNPAGE_CONFIRM
172 !insertmacro MUI_UNPAGE_INSTFILES
179 #UninstPage uninstConfirm
180 #UninstPage instfiles
183 # Language support. This has to be done after defining the pages, but
184 # before defining the translation strings. Confusing.
186 !insertmacro MUI_LANGUAGE "English"
188 #!insertmacro MUI_RESERVEFILE_LANGDLL
189 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
190 ReserveFile "${BUILD_DIR}\g4wihelp.dll"
192 ReserveFile "${TOP_SRCDIR}\doc\logo\gpg4win-logo-400px.bmp"
193 ReserveFile "${TOP_SRCDIR}\src\gpg4win-splash.wav"
195 ReserveFile "${TOP_SRCDIR}\COPYING"
196 ReserveFile "installer-options.ini"
197 ReserveFile "${TOP_SRCDIR}\doc\logo\gpg4win-logo-164x314.bmp"
201 LangString T_LangCode ${LANG_ENGLISH} "en"
203 # The WelcomeTitle is displayed on the first page.
204 LangString T_WelcomeTitle ${LANG_ENGLISH} "${WELCOME_TITLE_ENGLISH}"
206 # The About string as displayed on the first page.
207 LangString T_About ${LANG_ENGLISH} "${ABOUT_ENGLISH}"
210 LangString T_GPLHeader ${LANG_ENGLISH} \
211 "This software is licensed under the terms of the GNU General Public \
212 License (GPL) which guarantees your freedom to share and change Free \
215 LangString T_GPLShort ${LANG_ENGLISH} \
216 "In short: You are allowed to run this software for any purpose. \
217 You may distribute it as long as you give the recipients the same \
218 rights you have received."
220 LangString T_RunKeyManager ${LANG_ENGLISH} \
221 "Run the key manager"
223 LangString T_MoreInfo ${LANG_ENGLISH} \
224 "Click here for the project's homepage"
225 LangString T_MoreInfoURL ${LANG_ENGLISH} "http://www.gpg4win.org"
227 LangString T_ShowReadme ${LANG_ENGLISH} \
228 "Show the README file"
230 LangString T_NoKeyManager ${LANG_ENGLISH} \
231 "No key manager has been installed, thus we can't run one now."
236 # Custom functions and macros for gpg4win.
237 !include "g4wihelp.nsi"
240 # Control function for the Custom page to select special
243 Function CustomPageOptions
244 !insertmacro MUI_HEADER_TEXT "$(T_InstallOptions)" "$(T_InstallOptLinks)"
246 # Note that the default selection is done in the ini file.
247 !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
248 "Field 1" "Text" "$(T_InstOptLabelA)"
249 !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
250 "Field 2" "Text" "$(T_InstOptFieldA)"
251 !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
252 "Field 3" "Text" "$(T_InstOptFieldB)"
253 !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
254 "Field 4" "Text" "$(T_InstOptFieldC)"
255 !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
256 "Field 5" "Text" "$(T_InstOptLabelB)"
258 !insertmacro MUI_INSTALLOPTIONS_DISPLAY "installer-options.ini"
262 # Display a warning if GnuPP has been detected and allow the user to abort
264 Function PrintGnuPPWarning
265 MessageBox MB_YESNO "$(T_FoundOldGnuPP)" IDYES cont
268 StrCpy $OtherGnuPGDetected "GnuPP"
271 # Display a warning if GnuPT has been detected and allow the user to abort
273 Function PrintGnuPTWarning
274 MessageBox MB_YESNO "$(T_FoundOldGnuPT)" IDYES cont
277 StrCpy $OtherGnuPGDetected "GnuPT"
280 # Display a warning if the Sourceforge WinPT has been detected and
281 # allow the user to abort the installation.
282 Function PrintWinPTSFWarning
283 MessageBox MB_YESNO "$(T_FoundOldWinPTSF)" IDYES cont
286 StrCpy $OtherGnuPGDetected "WinPT-SF"
289 # Display a warning if GnuPG Pack has been detected and abort the
290 # the installation. This one clobbers our own Registry space.
291 Function PrintGnuPackWarning
292 MessageBox MB_OK "$(T_FoundOldGnuPack)"
297 # Check whether one of the other GnuPG systems has already been
298 # installed. We do this by looking at the registry.
299 Function CheckOtherGnuPGApps
300 StrCpy $OtherGnuPGDetected ""
302 ReadRegStr $0 HKLM "Software\GNU\GnuPP\Settings" "Path"
304 Call PrintGnuPPWarning
306 EnumRegKey $0 HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start Menu\Programs\GnuPT" 0
308 Call PrintGnuPTWarning
311 ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Windows Privacy Tools" "DisplayVersion"
313 Call PrintWinPTSFWarning
315 ReadRegStr $0 HKLM "Software\GNU\GnuPG" "Install Directory"
321 Call PrintGnuPackWarning
326 # Check whether gpg4win has already been installed. This is called as
327 # a leave function from the directory page. A call to abort will get
328 # back to the directory selection.
329 Function CheckExistingVersion
331 FileOpen $0 "$INSTDIR\VERSION" r
341 MessageBox MB_YESNO "$(T_FoundExistingVersion)" IDYES leave
346 ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GPG4Win" "DisplayVersion"
348 MessageBox MB_YESNO "$(T_FoundExistingVersionB)" IDYES leave
356 # PrintNonAdminWarning
358 # Check whether the current user is in the Administrator group or an
359 # OS version without the need for an Administrator is in use. Print a
360 # diagnostic if this is not the case and abort installation.
361 Function PrintNonAdminWarning
366 UserInfo::GetAccountType
368 StrCmp $1 "Admin" leave +1
369 MessageBox MB_OK "$(T_AdminNeeded)"
376 # Check whether the start menu is actually wanted.
378 Function CheckIfStartMenuWanted
379 !insertmacro MUI_INSTALLOPTIONS_READ $R0 "installer-options.ini" \
386 # Check whether this is a reinstall and popup a message box to explain
387 # that it is better to close other apps before continuing
388 Function PrintCloseOtherApps
389 IfFileExists $INSTDIR\gnupg.exe print_warning
390 IfFileExists $INSTDIR\winpt.exe print_warning
391 IfFileExists $INSTDIR\gpa.exe print_warning
392 IfFileExists $INSTDIR\gpgol.dll print_warning
393 IfFileExists $INSTDIR\gpgee.dll print_warning
394 IfFileExists $INSTDIR\dirmngr.exe print_warning
397 MessageBox MB_OK|MB_ICONEXCLAMATION "$(T_CloseOtherApps)"
398 IfFileExists $INSTDIR\winpt.exe 0 +3
399 MessageBox MB_OK "$(T_ShuttingDownWinPT)"
400 ExecWait '"$INSTDIR\winpt.exe" --stop'
401 IfFileExists $INSTDIR\dirmngr.exe 0 +3
402 MessageBox MB_OK "$(T_ShuttingDownDirMngr)"
403 g4wihelp::service_stop "DirMngr"
407 # Called right before the final page to show more warnings.
408 Function ShowFinalWarnings
409 StrCmp $OtherGnupgDetected "" +2
410 MessageBox MB_OK "$(T_FoundOldSeeManual)"
414 #-----------------------------------------------
415 # Strings pertaining to the install options page
416 #-----------------------------------------------
418 # Installation options title
419 LangString T_InstallOptions ${LANG_ENGLISH} "Install Options"
421 # Installation options subtitle 1
422 LangString T_InstallOptLinks ${LANG_ENGLISH} "Start links"
424 LangString T_InstOptLabelA ${LANG_ENGLISH} \
425 "Please select where Gpg4win shall install links:"
427 LangString T_InstOptLabelB ${LANG_ENGLISH} \
428 "(Only programs will be linked into the quick launch bar.)"
430 LangString T_InstOptFieldA ${LANG_ENGLISH} \
433 LangString T_InstOptFieldB ${LANG_ENGLISH} \
436 LangString T_InstOptFieldC ${LANG_ENGLISH} \
439 #------------------------------------------------
440 # String pertaining to the existing version check
441 #------------------------------------------------
442 LangString T_FoundExistingVersion ${LANG_ENGLISH} \
443 "Version $R1 has already been installed. $\r$\n\
444 Do you want to overwrite it with version ${VERSION}?"
445 LangString T_FoundExistingVersionB ${LANG_ENGLISH} \
446 "A version of Gpg4Win has already been installed on the system. \
447 There will be no problem installing and thus overwriting this \
450 Do you want to continue installing Gpg4win?"
453 #---------------------------------------------
454 # From the old installation checking functions
455 #---------------------------------------------
456 LangString T_FoundOldSeeManual ${LANG_ENGLISH} \
457 "Please see the Gpg4win user manual to learn how to migrate existing \
458 keys from other GnuPG based installations to Gpg4win."
461 LangString T_FoundOldGnuPP ${LANG_ENGLISH} \
462 "An old installation of GnuPP (GNU Privacy Project) has been been \
463 detected. That software is not maintained anymore and thus should \
466 Do you want to continue installing Gpg4win and take care of the old \
470 LangString T_FoundOldGnuPT ${LANG_ENGLISH} \
471 "An installation of GnuPT has been been detected. This may cause \
472 problems when used along with Gpg4win. $\r$\n\
474 Do you want to continue installing Gpg4win?"
477 LangString T_FoundOldWinPTSF ${LANG_ENGLISH} \
478 "An old installation of the Sourceforge hosted WinPT has been been \
479 detected. That software is not maintained anymore and should \
482 Do you want to continue installing Gpg4win and take care of the old \
487 LangString T_FoundOldGnuPack ${LANG_ENGLISH} \
488 "An installation of GnuPG-Pack has been been detected. You need to \
489 uninstall it before you can continue with Gpg4win installation. $\r$\n\
491 The installation will be aborted now!"
495 # From Function PrintNonAdminWarning
496 LangString T_AdminNeeded ${LANG_ENGLISH} \
497 "Warning: Administrator permissions required for a successful installation"
499 # From Function PrintCloseOtherApps
500 LangString T_CloseOtherApps ${LANG_ENGLISH} \
501 "Please make sure that other applications are not running. \
502 In particular you should close Outlook and all Explorer \
503 windows. Gpg4Win will try to install anyway but a reboot \
504 will be required then."
505 LangString T_ShuttingDownWinPT ${LANG_ENGLISH} \
506 "Trying to shutdown a possible running instance of WinPT."
507 LangString T_ShuttingDownDirMngr ${LANG_ENGLISH} \
508 "Trying to shutdown a possible running instance of DirMngr."
511 # FIXME: The GetAfterChar function comes from the NSIS wiki.
512 Function un.GetAfterChar
515 Exch $1 ; input string
538 Function un.SourceDelete
542 Delete "$INSTDIR\$R0"
546 # StrStr - taken from the NSIS reference
547 # input, top of stack = string to search for
548 # top of stack-1 = string to search in
549 # output, top of stack (replaces with the portion of the string remaining)
550 # modifies no other variables.
553 # Push "this is a long ass string"
557 # ($R0 at this point is "ass string")
561 Exch $R1 # st=haystack,old$R1, $R1=needle
562 Exch # st=old$R1,haystack
563 Exch $R2 # st=old$R1,old$R2, $R2=haystack
575 StrCpy $R5 $R2 $R3 $R4
581 StrCpy $R1 $R2 "" $R4
589 !insertmacro StrStr ""
590 !insertmacro StrStr "un."
593 # TrimNewlines - taken from the NSIS reference
594 # input, top of stack (e.g. whatever$\r$\n)
595 # output, top of stack (replaces, with e.g. whatever)
596 # modifies no other variables.
597 Function TrimNewlines
606 StrCmp $R2 "$\r" loop
607 StrCmp $R2 "$\n" loop
609 IntCmp $R1 0 no_trim_needed
620 # AddToPath - Adds the given dir to the search path.
621 # Input - head of the stack
622 # (Taken from Kichik's code at the NSIS Wiki)
630 # Don't add if the path doesn't exist
631 IfFileExists "$0\*.*" "" AddToPath_done
638 StrCmp $2 "" "" AddToPath_done
643 StrCmp $2 "" "" AddToPath_done
644 GetFullPathName /SHORT $3 $0
649 StrCmp $2 "" "" AddToPath_done
654 StrCmp $2 "" "" AddToPath_done
656 ReadRegStr $1 ${Regkey_for_Env} "PATH"
657 StrCmp $1 "" AddToPath_NTdoIt
659 # We do not need the follwing call
664 WriteRegExpandStr ${Regkey_for_Env} "PATH" $0
665 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
675 # RemoveFromPath - Remove a given dir from the path
676 # Input: head of the stack
677 # (Taken from Kichik's code at the NSIS Wiki)
679 Function un.RemoveFromPath
688 IntFmt $6 "%c" 26 # DOS EOF
690 ReadRegStr $1 ${Regkey_for_Env} "PATH"
691 StrCpy $5 $1 1 -1 # copy last char
692 StrCmp $5 ";" +2 # if last char != ;
693 StrCpy $1 "$1;" # append ;
696 Call un.StrStr # Find `$0;` in $1
697 Pop $2 ; pos of our dir
698 StrCmp $2 "" unRemoveFromPath_done
699 # else, it is in path
704 StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
705 StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
708 StrCpy $5 $3 1 -1 # copy last char
709 StrCmp $5 ";" 0 +2 # if last char == ;
710 StrCpy $3 $3 -1 # remove last char
712 WriteRegExpandStr ${Regkey_for_Env} "PATH" $3
713 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
715 unRemoveFromPath_done: