Register file extensions and AppIDs in Windows
[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-encrypted" "gpg4win.AssocFile.$0.GPG"
111   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/pgp-signature" "gpg4win.AssocFile.$0.GPG"
112   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/pkcs7-mime" "gpg4win.AssocFile.$0.CMS"
113   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/pkix-cert" "gpg4win.AssocFile.$0.CMS"
114   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/x-x509-ca-cert" "gpg4win.AssocFile.$0.X509"
115   WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/x-pkcs12" "gpg4win.AssocFile.$0.X509"
116
117 FunctionEnd
118
119 Function SetupExtensions
120   g4wihelp::config_fetch_bool "register_extensions"
121   StrCmp $R0 "1" reg_set  reg_extensions_not_one
122 reg_extensions_not_one:
123   StrCmp $R0 "0" leave 0
124
125 reg_set:
126   SetOutPath "$INSTDIR\share\gpg4win"
127   File "file-ext.ico"
128   !insertmacro SectionFlagIsSet ${SEC_kleopatra} \
129         ${SF_SELECTED} have_kleo 0
130   !insertmacro SectionFlagIsSet ${SEC_gpa} \
131         ${SF_SELECTED} have_gpa 0
132   goto leave
133 have_kleo:
134   DetailPrint "Registering file extensions"
135   # See:
136   # https://msdn.microsoft.com/en-us/library/windows/desktop/cc144104%28v=vs.85%29.aspx
137   # For documentation.
138
139   push kleopatra
140   call SetupExtRegKeys
141
142   !insertmacro SectionFlagIsSet ${SEC_gpa} \
143         ${SF_SELECTED} 0 leave2
144 have_gpa:
145   push gpa
146   call SetupExtRegKeys
147
148 leave2:
149 System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'
150 leave:
151 FunctionEnd
152
153 LangString T_File_Type_gpg_Name ${LANG_ENGLISH} \
154    "OpenPGP Binary File"
155
156 LangString T_File_Type_asc_Name ${LANG_ENGLISH} \
157    "OpenPGP Text File"
158
159 LangString T_File_Type_sig_Name ${LANG_ENGLISH} \
160    "OpenPGP Signature"
161
162 LangString T_File_Type_asc_Name ${LANG_ENGLISH} \
163    "CMS (S/MIME) File"
164
165 LangString T_File_Type_x509_Name ${LANG_ENGLISH} \
166    "X509 Certificate File"
167
168 LangString T_File_Type_x509_info_tip ${LANG_ENGLISH} \
169    "A certificate for CMS (S/MIME)."
170
171 LangString T_File_Type_info_tip ${LANG_ENGLISH} \
172    "This can be encrypted data, a signature or a certificate."
173
174 LangString T_File_Type_sig_info_tip ${LANG_ENGLISH} \
175    "A cryptographic signature to verify the authenticity of another file."
176
177 # Last section is a hidden one.
178 Section
179   WriteUninstaller "$INSTDIR\${PACKAGE}-uninstall.exe"
180
181   # Windows Add/Remove Programs support
182   # Note that the version is appended to the DisplayName, despite that
183   # this is not necessary as a click on "support information" gives
184   # the version number.  Some tools do that, other don't.  I don't
185   # like it but others want me to do that.  -wk
186   StrCpy $MYTMP "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRETTY_PACKAGE_SHORT}"
187   WriteRegExpandStr HKLM $MYTMP "UninstallString" '"$INSTDIR\${PACKAGE}-uninstall.exe"'
188   WriteRegExpandStr HKLM $MYTMP "InstallLocation" "$INSTDIR"
189   WriteRegStr       HKLM $MYTMP "DisplayName"     "${PRETTY_PACKAGE} (${VERSION})"
190   WriteRegStr       HKLM $MYTMP "DisplayIcon"     "$INSTDIR\bin\kleopatra.exe,0"
191   WriteRegStr       HKLM $MYTMP "DisplayVersion"  "${VERSION}"
192   WriteRegStr       HKLM $MYTMP "Publisher"       "The Gpg4win Project"
193   WriteRegStr       HKLM $MYTMP "URLInfoAbout"    "http://www.gpg4win.org/"
194   WriteRegDWORD     HKLM $MYTMP "NoModify"        "1"
195   WriteRegDWORD     HKLM $MYTMP "NoRepair"        "1"
196
197   call SetupExtensions
198 SectionEnd
199
200
201 Section Uninstall
202   # Make sure that the context of the automatic variables has been set to
203   # the "all users" shell folder.  This guarantees that the menu gets written
204   # for all users.  We have already checked that we are running as Admin; or
205   # we printed a warning that installation will not succeed.
206   SetShellVarContext all
207
208   #---------------------------------------------------
209   # Delete the menu entries and any empty parent menus
210   #---------------------------------------------------
211   Delete "$SMPROGRAMS\GPA.lnk"
212   Delete "$SMPROGRAMS\Kleopatra.lnk"
213
214   # Delete Desktop links.
215 !ifdef HAVE_PKG_GPA
216   Delete "$DESKTOP\GPA.lnk"
217 !endif
218 !ifdef HAVE_PKG_KLEOPATRA
219   Delete "$DESKTOP\Kleopatra.lnk"
220 !endif
221
222   Delete "$INSTDIR\${PACKAGE}-uninstall.exe"
223
224   Delete "$INSTDIR\share\gpg4win\file-ext.ico"
225   RMDir "$INSTDIR\share\gpg4win"
226   RMDir "$INSTDIR\share"
227   RMDir "$INSTDIR"
228
229   # If we installed in the default location, try to be really, really
230   # nice with sugar on it to clean up behind us.  In any case, try very
231   # hard to get rid of directories which could have REBOOTOK files.
232   RMDir /REBOOTOK "$INSTDIR\bin"
233   RMDir /REBOOTOK "$INSTDIR"
234
235   # Clean the registry.
236   DeleteRegValue HKLM "Software\${PRETTY_PACKAGE_SHORT}" \
237         "Install Directory"
238   DeleteRegKey /ifempty HKLM "Software\${PRETTY_PACKAGE_SHORT}"
239
240   # Remove Windows Add/Remove Programs support.
241   DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRETTY_PACKAGE_SHORT}"
242 SectionEnd