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