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