a53cb2f4cd7e0b40134bd741c15abeeefa6cc9ce
[gpg4win.git] / src / installer-finish.nsi
1 # installer-finish.nsi - Installer for GPG4Win.      -*- coding: latin-1; -*-
2 # Copyright (C) 2005, 2008 g10 Code GmbH
3
4 # This file is part of GPG4Win.
5
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.
10
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.
15
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
19
20 Var MYTMP
21
22 Function SetupExtRegKeys
23   Pop $0
24   # .gpg
25   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.GPG" "" "$(T_File_Type_gpg_Name)"
26   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.GPG" "FriendlyTypeName" "$(T_File_Type_gpg_Name)"
27   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.GPG" "PercievedType" "Document"
28   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.GPG" "InfoTip" "$(T_File_Type_info_tip)"
29   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.GPG\CurVer" "" "${VERSION}"
30   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.GPG\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
31   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.GPG\DefaultIcon" "" "$INSTDIR\share\gpg4win\file-ext.ico"
32
33   WriteRegBin HKLM "Software\Classes\.gpg\OpenWithProgIDs" "gpg4win.AssocFile.$0.GPG" 0
34
35   # .asc
36   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.ASC" "" "$(T_File_Type_asc_Name)"
37   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.ASC" "FriendlyTypeName" "$(T_File_Type_asc_Name)"
38   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.ASC" "PercievedType" "Document"
39   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.ASC" "InfoTip" "$(T_File_Type_info_tip)"
40   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.ASC\CurVer" "" "${VERSION}"
41   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.ASC\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
42   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.ASC\DefaultIcon" "" "$INSTDIR\share\gpg4win\file-ext.ico"
43   WriteRegBin HKLM "Software\Classes\.asc\OpenWithProgIDs" "gpg4win.AssocFile.$0.ASC" 0
44
45   # .pgp
46   WriteRegBin HKLM "Software\Classes\.pgp\OpenWithProgIDs" "gpg4win.AssocFile.$0.GPG" 0
47
48   # .sig
49   WriteRegExpandStr HKLM "Software\Classes\gpg4win.AssocFile.$0.PGPSIG\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
50   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.PGPSIG" "FriendlyTypeName" "$(T_File_Type_sig_Name)"
51   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.PGPSIG" "PercievedType" "Document"
52   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.PGPSIG" "InfoTip" "$(T_File_Type_sig_info_tip)"
53   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.PGPSIG\CurVer" "" "${VERSION}"
54   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.PGPSIG\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
55   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.PGPSIG\DefaultIcon" "" "$INSTDIR\share\gpg4win\file-ext.ico"
56
57   WriteRegBin HKLM "Software\Classes\.sig\OpenWithProgIDs" "gpg4win.AssocFile.$0.PGPSIG" 0
58
59   # CMS
60   WriteRegExpandStr HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
61   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS" "FriendlyTypeName" "$(T_File_Type_pem_Name)"
62   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS" "PercievedType" "Document"
63   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS" "InfoTip" "$(T_File_Type_info_tip)"
64   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS\CurVer" "" "${VERSION}"
65   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
66   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS\DefaultIcon" "" "$INSTDIR\share\gpg4win\file-ext.ico"
67 #  WriteRegBin HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS" "AllowSilentDefaultTakeOver" 0
68
69   WriteRegBin HKLM "Software\Classes\.p7s\OpenWithProgIDs" "gpg4win.AssocFile.$0.CMS" 0
70   WriteRegBin HKLM "Software\Classes\.p7m\OpenWithProgIDs" "gpg4win.AssocFile.$0.CMS" 0
71   WriteRegBin HKLM "Software\Classes\.crl\OpenWithProgIDs" "gpg4win.AssocFile.$0.CMS" 0
72   WriteRegBin HKLM "Software\Classes\.pem\OpenWithProgIDs" "gpg4win.AssocFile.$0.CMS" 0
73   WriteRegBin HKLM "Software\Classes\.arl\OpenWithProgIDs" "gpg4win.AssocFile.$0.CMS" 0
74
75   # X509 Certificates
76   WriteRegExpandStr HKLM "Software\Classes\gpg4win.AssocFile.$0.X509\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
77   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.X509" "FriendlyTypeName" "$(T_File_Type_x509_Name)"
78   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.X509" "PercievedType" "Document"
79   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.X509" "InfoTip" "$(T_File_Type_x509_info_tip)"
80   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.X509\CurVer" "" "${VERSION}"
81   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.X509\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
82   WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.X509\DefaultIcon" "" "$INSTDIR\share\gpg4win\file-ext.ico"
83   WriteRegBin HKLM "Software\Classes\gpg4win.AssocFile.$0.X509" "AllowSilentDefaultTakeOver" 0
84
85   # Register capabilities
86   WriteRegStr HKLM "Software\RegisteredApplications" "Gpg4win.$0.${VERSION}" "SOFTWARE\Gpg4win\$0\Capabilities"
87
88   # File extensions
89   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".pgp" "gpg4win.AssocFile.$0.GPG"
90   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".asc" "gpg4win.AssocFile.$0.ASC"
91   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".gpg" "gpg4win.AssocFile.$0.GPG"
92   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".cer" "gpg4win.AssocFile.$0.X509"
93   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".p10" "gpg4win.AssocFile.$0.X509"
94   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".p12" "gpg4win.AssocFile.$0.X509"
95   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".p7c" "gpg4win.AssocFile.$0.X509"
96   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".pfx" "gpg4win.AssocFile.$0.X509"
97   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".crt" "gpg4win.AssocFile.$0.X509"
98   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".der" "gpg4win.AssocFile.$0.X509"
99   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".sig" "gpg4win.AssocFile.$0.PGPSIG"
100   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".arl" "gpg4win.AssocFile.$0.CMS"
101   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".crl" "gpg4win.AssocFile.$0.CMS"
102   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".p7m" "gpg4win.AssocFile.$0.CMS"
103   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".p7s" "gpg4win.AssocFile.$0.CMS"
104   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".pem" "gpg4win.AssocFile.$0.CMS"
105
106   WriteRegExpandStr HKLM "Software\Gpg4win\$0\Capabilities\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
107
108   # Mime extensions For PGP this is probably pretty useless
109   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/pgp" "gpg4win.AssocFile.$0.GPG"
110   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/pgp-keys" "gpg4win.AssocFile.$0.GPG"
111   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/pgp-encrypted" "gpg4win.AssocFile.$0.GPG"
112   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/pgp-signature" "gpg4win.AssocFile.$0.GPG"
113   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/pkcs7-mime" "gpg4win.AssocFile.$0.CMS"
114   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/pkix-cert" "gpg4win.AssocFile.$0.CMS"
115   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/x-x509-ca-cert" "gpg4win.AssocFile.$0.X509"
116   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/x-pkcs12" "gpg4win.AssocFile.$0.X509"
117
118 FunctionEnd
119
120 Function SetupExtensions
121   g4wihelp::config_fetch_bool "register_extensions"
122   StrCmp $R0 "1" reg_set  reg_extensions_not_one
123 reg_extensions_not_one:
124   StrCmp $R0 "0" leave 0
125
126 reg_set:
127   SetOutPath "$INSTDIR\share\gpg4win"
128   File "file-ext.ico"
129   !insertmacro SectionFlagIsSet ${SEC_kleopatra} \
130         ${SF_SELECTED} have_kleo 0
131   !insertmacro SectionFlagIsSet ${SEC_gpa} \
132         ${SF_SELECTED} have_gpa 0
133   goto leave
134 have_kleo:
135   DetailPrint "Registering file extensions"
136   # See:
137   # https://msdn.microsoft.com/en-us/library/windows/desktop/cc144104%28v=vs.85%29.aspx
138   # For documentation.
139
140   push kleopatra
141   call SetupExtRegKeys
142
143   !insertmacro SectionFlagIsSet ${SEC_gpa} \
144         ${SF_SELECTED} 0 leave2
145 have_gpa:
146   push gpa
147   call SetupExtRegKeys
148
149 leave2:
150 System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'
151 leave:
152 FunctionEnd
153
154 LangString T_File_Type_gpg_Name ${LANG_ENGLISH} \
155    "OpenPGP Binary File"
156
157 LangString T_File_Type_asc_Name ${LANG_ENGLISH} \
158    "OpenPGP Text File"
159
160 LangString T_File_Type_sig_Name ${LANG_ENGLISH} \
161    "OpenPGP Signature"
162
163 LangString T_File_Type_asc_Name ${LANG_ENGLISH} \
164    "CMS (S/MIME) File"
165
166 LangString T_File_Type_x509_Name ${LANG_ENGLISH} \
167    "X509 Certificate File"
168
169 LangString T_File_Type_x509_info_tip ${LANG_ENGLISH} \
170    "A certificate for CMS (S/MIME)."
171
172 LangString T_File_Type_info_tip ${LANG_ENGLISH} \
173    "This can be encrypted data, a signature or a certificate."
174
175 LangString T_File_Type_sig_info_tip ${LANG_ENGLISH} \
176    "A cryptographic signature to verify the authenticity of another file."
177
178 # Last section is a hidden one.
179 Section
180   WriteUninstaller "$INSTDIR\${PACKAGE}-uninstall.exe"
181
182   # Windows Add/Remove Programs support
183   # Note that the version is appended to the DisplayName, despite that
184   # this is not necessary as a click on "support information" gives
185   # the version number.  Some tools do that, other don't.  I don't
186   # like it but others want me to do that.  -wk
187   StrCpy $MYTMP "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRETTY_PACKAGE_SHORT}"
188   WriteRegExpandStr HKLM $MYTMP "UninstallString" '"$INSTDIR\${PACKAGE}-uninstall.exe"'
189   WriteRegExpandStr HKLM $MYTMP "InstallLocation" "$INSTDIR"
190   WriteRegStr       HKLM $MYTMP "DisplayName"     "${PRETTY_PACKAGE} (${VERSION})"
191   WriteRegStr       HKLM $MYTMP "DisplayIcon"     "$INSTDIR\bin\kleopatra.exe,0"
192   WriteRegStr       HKLM $MYTMP "DisplayVersion"  "${VERSION}"
193   WriteRegStr       HKLM $MYTMP "Publisher"       "The Gpg4win Project"
194   WriteRegStr       HKLM $MYTMP "URLInfoAbout"    "http://www.gpg4win.org/"
195   WriteRegDWORD     HKLM $MYTMP "NoModify"        "1"
196   WriteRegDWORD     HKLM $MYTMP "NoRepair"        "1"
197
198   WriteRegStr HKLM "Software\Classes\MIME\Database\Content Type\application/pgp" "Extension" ".gpg"
199   WriteRegStr HKLM "Software\Classes\MIME\Database\Content Type\application/pgp-signature" "Extension" ".sig"
200   WriteRegStr HKLM "Software\Classes\MIME\Database\Content Type\application/pgp-encrypted" "Extension" ".gpg"
201   WriteRegStr HKLM "Software\Classes\MIME\Database\Content Type\application/pgp-keys" "Extension" ".gpg"
202
203   call SetupExtensions
204 SectionEnd
205
206
207 Section Uninstall
208   # Make sure that the context of the automatic variables has been set to
209   # the "all users" shell folder.  This guarantees that the menu gets written
210   # for all users.  We have already checked that we are running as Admin; or
211   # we printed a warning that installation will not succeed.
212   SetShellVarContext all
213
214   #---------------------------------------------------
215   # Delete the menu entries and any empty parent menus
216   #---------------------------------------------------
217   Delete "$SMPROGRAMS\GPA.lnk"
218   Delete "$SMPROGRAMS\Kleopatra.lnk"
219
220   # Delete Desktop links.
221 !ifdef HAVE_PKG_GPA
222   Delete "$DESKTOP\GPA.lnk"
223 !endif
224 !ifdef HAVE_PKG_KLEOPATRA
225   Delete "$DESKTOP\Kleopatra.lnk"
226 !endif
227
228   Delete "$INSTDIR\${PACKAGE}-uninstall.exe"
229
230   Delete "$INSTDIR\share\gpg4win\file-ext.ico"
231   RMDir "$INSTDIR\share\gpg4win"
232   RMDir "$INSTDIR\share"
233   RMDir "$INSTDIR"
234
235   # If we installed in the default location, try to be really, really
236   # nice with sugar on it to clean up behind us.  In any case, try very
237   # hard to get rid of directories which could have REBOOTOK files.
238   RMDir /REBOOTOK "$INSTDIR\bin"
239   RMDir /REBOOTOK "$INSTDIR"
240
241   # Clean the registry.
242   DeleteRegValue HKLM "Software\${PRETTY_PACKAGE_SHORT}" \
243         "Install Directory"
244   DeleteRegKey /ifempty HKLM "Software\${PRETTY_PACKAGE_SHORT}"
245
246   # Remove Windows Add/Remove Programs support.
247   DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRETTY_PACKAGE_SHORT}"
248
249   DeleteRegKey HKLM "Software\Classes\MIME\Database\Content Type\application/pgp"
250   DeleteRegKey HKLM "Software\Classes\MIME\Database\Content Type\application/pgp-signature"
251   DeleteRegKey HKLM "Software\Classes\MIME\Database\Content Type\application/pgp-encrypted"
252   DeleteRegKey HKLM "Software\Classes\MIME\Database\Content Type\application/pgp-keys"
253
254
255 SectionEnd