Register file extensions and AppIDs in Windows
authorAndre Heinecke <aheinecke@intevation.de>
Wed, 13 Apr 2016 14:46:07 +0000 (16:46 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Wed, 13 Apr 2016 15:31:09 +0000 (17:31 +0200)
* src/inst-gpa.nsi, src/inst-kleopatra.nsi: Set up AppIDs.
* src/installer-finish.nsi: Register mime types and extensions for
Kleopatra and or GPA.
* src/uninst-gpa.nsi, src/uninst-kleopatra.nsi: Clean up afterwards.
* src/file-ext.ico: New. Icon for file extensions.

--
This might take over .pgp, .sig, .asc, .gpg, .p7m, .p7s,
.arl, .crl by default.

For the certificate types .cer, crt, .der, .p10, .p12, .p7c .pfx
GPA and Kleopatra are only listed as supported applications
in the OpenWith menu.

src/file-ext.ico [new file with mode: 0644]
src/inst-gpa.nsi
src/inst-kleopatra.nsi
src/installer-finish.nsi
src/uninst-gpa.nsi
src/uninst-kleopatra.nsi

diff --git a/src/file-ext.ico b/src/file-ext.ico
new file mode 100644 (file)
index 0000000..f65324e
Binary files /dev/null and b/src/file-ext.ico differ
index 28a40cb..58a147c 100644 (file)
 
   no_config_gpa_files:
 
+  WriteRegStr HKLM "Software\Gpg4win\gpa\Capabilities" "ApplicationDescription" "$(DESC_SEC_gpa)"
+  WriteRegStr HKLM "Software\Gpg4win\gpa\Capabilities" "ApplicationIcon" "$INSTDIR\bin\gpa.exe,0"
+  WriteRegStr HKLM "Software\Gpg4win\gpa\Capabilities" "ApplicationName" "$(DESC_SEC_gpa)"
+
 !endif
 ${MementoSectionEnd}
 
index b84b029..8bc09a6 100644 (file)
@@ -223,7 +223,9 @@ ${MementoSection} "Kleopatra" SEC_kleopatra
   FileClose $1
   pop $1
 
-
+  WriteRegStr HKLM "Software\Gpg4win\kleopatra\Capabilities" "ApplicationDescription" "$(DESC_SEC_kleopatra)"
+  WriteRegStr HKLM "Software\Gpg4win\kleopatra\Capabilities" "ApplicationIcon" "$INSTDIR\bin\kleopatra.exe,0"
+  WriteRegStr HKLM "Software\Gpg4win\kleopatra\Capabilities" "ApplicationName" "Kleopatra"
 
 !endif
 ${MementoSectionEnd}
index 60996e7..21cf941 100644 (file)
 
 Var MYTMP
 
+Function SetupExtRegKeys
+  Pop $0
+  # .gpg
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.GPG" "" "$(T_File_Type_gpg_Name)"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.GPG" "FriendlyTypeName" "$(T_File_Type_gpg_Name)"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.GPG" "PercievedType" "Document"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.GPG" "InfoTip" "$(T_File_Type_info_tip)"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.GPG\CurVer" "" "${VERSION}"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.GPG\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.GPG\DefaultIcon" "" "$INSTDIR\share\gpg4win\file-ext.ico"
+
+  WriteRegBin HKLM "Software\Classes\.gpg\OpenWithProgIDs" "gpg4win.AssocFile.$0.GPG" 0
+
+  # .asc
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.ASC" "" "$(T_File_Type_asc_Name)"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.ASC" "FriendlyTypeName" "$(T_File_Type_asc_Name)"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.ASC" "PercievedType" "Document"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.ASC" "InfoTip" "$(T_File_Type_info_tip)"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.ASC\CurVer" "" "${VERSION}"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.ASC\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.ASC\DefaultIcon" "" "$INSTDIR\share\gpg4win\file-ext.ico"
+  WriteRegBin HKLM "Software\Classes\.asc\OpenWithProgIDs" "gpg4win.AssocFile.$0.ASC" 0
+
+  # .pgp
+  WriteRegBin HKLM "Software\Classes\.pgp\OpenWithProgIDs" "gpg4win.AssocFile.$0.GPG" 0
+
+  # .sig
+  WriteRegExpandStr HKLM "Software\Classes\gpg4win.AssocFile.$0.PGPSIG\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.PGPSIG" "FriendlyTypeName" "$(T_File_Type_sig_Name)"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.PGPSIG" "PercievedType" "Document"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.PGPSIG" "InfoTip" "$(T_File_Type_sig_info_tip)"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.PGPSIG\CurVer" "" "${VERSION}"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.PGPSIG\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.PGPSIG\DefaultIcon" "" "$INSTDIR\share\gpg4win\file-ext.ico"
+
+  WriteRegBin HKLM "Software\Classes\.sig\OpenWithProgIDs" "gpg4win.AssocFile.$0.PGPSIG" 0
+
+  # CMS
+  WriteRegExpandStr HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS" "FriendlyTypeName" "$(T_File_Type_pem_Name)"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS" "PercievedType" "Document"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS" "InfoTip" "$(T_File_Type_info_tip)"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS\CurVer" "" "${VERSION}"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS\DefaultIcon" "" "$INSTDIR\share\gpg4win\file-ext.ico"
+#  WriteRegBin HKLM "Software\Classes\gpg4win.AssocFile.$0.CMS" "AllowSilentDefaultTakeOver" 0
+
+  WriteRegBin HKLM "Software\Classes\.p7s\OpenWithProgIDs" "gpg4win.AssocFile.$0.CMS" 0
+  WriteRegBin HKLM "Software\Classes\.p7m\OpenWithProgIDs" "gpg4win.AssocFile.$0.CMS" 0
+  WriteRegBin HKLM "Software\Classes\.crl\OpenWithProgIDs" "gpg4win.AssocFile.$0.CMS" 0
+  WriteRegBin HKLM "Software\Classes\.pem\OpenWithProgIDs" "gpg4win.AssocFile.$0.CMS" 0
+  WriteRegBin HKLM "Software\Classes\.arl\OpenWithProgIDs" "gpg4win.AssocFile.$0.CMS" 0
+
+  # X509 Certificates
+  WriteRegExpandStr HKLM "Software\Classes\gpg4win.AssocFile.$0.X509\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.X509" "FriendlyTypeName" "$(T_File_Type_x509_Name)"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.X509" "PercievedType" "Document"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.X509" "InfoTip" "$(T_File_Type_x509_info_tip)"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.X509\CurVer" "" "${VERSION}"
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.X509\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
+  WriteRegStr HKLM "Software\Classes\gpg4win.AssocFile.$0.X509\DefaultIcon" "" "$INSTDIR\share\gpg4win\file-ext.ico"
+  WriteRegBin HKLM "Software\Classes\gpg4win.AssocFile.$0.X509" "AllowSilentDefaultTakeOver" 0
+
+  # Register capabilities
+  WriteRegStr HKLM "Software\RegisteredApplications" "Gpg4win.$0.${VERSION}" "SOFTWARE\Gpg4win\$0\Capabilities"
+
+  # File extensions
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".pgp" "gpg4win.AssocFile.$0.GPG"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".asc" "gpg4win.AssocFile.$0.ASC"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".gpg" "gpg4win.AssocFile.$0.GPG"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".cer" "gpg4win.AssocFile.$0.X509"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".p10" "gpg4win.AssocFile.$0.X509"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".p12" "gpg4win.AssocFile.$0.X509"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".p7c" "gpg4win.AssocFile.$0.X509"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".pfx" "gpg4win.AssocFile.$0.X509"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".crt" "gpg4win.AssocFile.$0.X509"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".der" "gpg4win.AssocFile.$0.X509"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".sig" "gpg4win.AssocFile.$0.PGPSIG"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".arl" "gpg4win.AssocFile.$0.CMS"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".crl" "gpg4win.AssocFile.$0.CMS"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".p7m" "gpg4win.AssocFile.$0.CMS"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".p7s" "gpg4win.AssocFile.$0.CMS"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\FileAssociations" ".pem" "gpg4win.AssocFile.$0.CMS"
+
+  WriteRegExpandStr HKLM "Software\Gpg4win\$0\Capabilities\shell\open\command" "" "$\"$INSTDIR\bin\$0.exe$\" $\"%1$\""
+
+  # Mime extensions For PGP this is probably pretty useless
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/pgp" "gpg4win.AssocFile.$0.GPG"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/pgp-encrypted" "gpg4win.AssocFile.$0.GPG"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/pgp-signature" "gpg4win.AssocFile.$0.GPG"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/pkcs7-mime" "gpg4win.AssocFile.$0.CMS"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/pkix-cert" "gpg4win.AssocFile.$0.CMS"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/x-x509-ca-cert" "gpg4win.AssocFile.$0.X509"
+  WriteRegStr HKLM "Software\Gpg4win\$0\Capabilities\MimeAssociations" "application/x-pkcs12" "gpg4win.AssocFile.$0.X509"
+
+FunctionEnd
+
+Function SetupExtensions
+  g4wihelp::config_fetch_bool "register_extensions"
+  StrCmp $R0 "1" reg_set  reg_extensions_not_one
+reg_extensions_not_one:
+  StrCmp $R0 "0" leave 0
+
+reg_set:
+  SetOutPath "$INSTDIR\share\gpg4win"
+  File "file-ext.ico"
+  !insertmacro SectionFlagIsSet ${SEC_kleopatra} \
+        ${SF_SELECTED} have_kleo 0
+  !insertmacro SectionFlagIsSet ${SEC_gpa} \
+        ${SF_SELECTED} have_gpa 0
+  goto leave
+have_kleo:
+  DetailPrint "Registering file extensions"
+  # See:
+  # https://msdn.microsoft.com/en-us/library/windows/desktop/cc144104%28v=vs.85%29.aspx
+  # For documentation.
+
+  push kleopatra
+  call SetupExtRegKeys
+
+  !insertmacro SectionFlagIsSet ${SEC_gpa} \
+        ${SF_SELECTED} 0 leave2
+have_gpa:
+  push gpa
+  call SetupExtRegKeys
+
+leave2:
+System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'
+leave:
+FunctionEnd
+
+LangString T_File_Type_gpg_Name ${LANG_ENGLISH} \
+   "OpenPGP Binary File"
+
+LangString T_File_Type_asc_Name ${LANG_ENGLISH} \
+   "OpenPGP Text File"
+
+LangString T_File_Type_sig_Name ${LANG_ENGLISH} \
+   "OpenPGP Signature"
+
+LangString T_File_Type_asc_Name ${LANG_ENGLISH} \
+   "CMS (S/MIME) File"
+
+LangString T_File_Type_x509_Name ${LANG_ENGLISH} \
+   "X509 Certificate File"
+
+LangString T_File_Type_x509_info_tip ${LANG_ENGLISH} \
+   "A certificate for CMS (S/MIME)."
+
+LangString T_File_Type_info_tip ${LANG_ENGLISH} \
+   "This can be encrypted data, a signature or a certificate."
+
+LangString T_File_Type_sig_info_tip ${LANG_ENGLISH} \
+   "A cryptographic signature to verify the authenticity of another file."
+
 # Last section is a hidden one.
 Section
   WriteUninstaller "$INSTDIR\${PACKAGE}-uninstall.exe"
@@ -38,11 +193,12 @@ Section
   WriteRegStr       HKLM $MYTMP "URLInfoAbout"    "http://www.gpg4win.org/"
   WriteRegDWORD     HKLM $MYTMP "NoModify"        "1"
   WriteRegDWORD     HKLM $MYTMP "NoRepair"        "1"
+
+  call SetupExtensions
 SectionEnd
 
 
 Section Uninstall
-
   # Make sure that the context of the automatic variables has been set to
   # the "all users" shell folder.  This guarantees that the menu gets written
   # for all users.  We have already checked that we are running as Admin; or
@@ -64,6 +220,10 @@ Section Uninstall
 !endif
 
   Delete "$INSTDIR\${PACKAGE}-uninstall.exe"
+
+  Delete "$INSTDIR\share\gpg4win\file-ext.ico"
+  RMDir "$INSTDIR\share\gpg4win"
+  RMDir "$INSTDIR\share"
   RMDir "$INSTDIR"
 
   # If we installed in the default location, try to be really, really
index 8b58177..95a35e0 100644 (file)
@@ -44,5 +44,24 @@ Section "-un.gpa"
   Delete "$INSTDIR\share\gpa\gpa.png"
   RMDir "$INSTDIR\share\gpa"
 
+  DeleteRegKey HKLM "Software\Classes\gpg4win.AssocFile.gpa.GPG"
+  DeleteRegKey HKLM "Software\Classes\gpg4win.AssocFile.gpa.ASC"
+  DeleteRegKey HKLM "Software\Classes\gpg4win.AssocFile.gpa.CMS"
+  DeleteRegKey HKLM "Software\Classes\gpg4win.AssocFile.gpa.X509"
+  DeleteRegKey HKLM "Software\Classes\gpg4win.AssocFile.gpa.PGPSIG"
+  DeleteRegKey HKLM "Software\Gpg4win\gpa"
+  DeleteRegValue HKLM "Software\RegisteredApplications" "Gpg4win.gpa.${VERSION}"
+  DeleteRegValue HKLM "Software\Classes\.gpg" "gpg4win.AssocFile.gpa.GPG"
+  DeleteRegValue HKLM "Software\Classes\.asc" "gpg4win.AssocFile.gpa.ASC"
+  DeleteRegValue HKLM "Software\Classes\.pgp" "gpg4win.AssocFile.gpa.PGP"
+  DeleteRegValue HKLM "Software\Classes\.cer" "gpg4win.AssocFile.gpa.X509"
+  DeleteRegValue HKLM "Software\Classes\.pem" "gpg4win.AssocFile.gpa.CMS"
+
+  DeleteRegKey /ifempty HKLM "Software\Classes\.gpg"
+  DeleteRegKey /ifempty HKLM "Software\Classes\.asc"
+  DeleteRegKey /ifempty HKLM "Software\Classes\.pgp"
+  DeleteRegKey /ifempty HKLM "Software\Classes\.pem"
+  DeleteRegKey /ifempty HKLM "Software\Classes\.sig"
+
 !endif
 SectionEnd
index 374c348..88e10ec 100644 (file)
@@ -202,5 +202,25 @@ Section "-un.kleopatra"
   RMDir "$INSTDIR\share"
   RMDir "$INSTDIR"
 
+  DetailPrint "Unregistering file extensions"
+
+  DeleteRegKey HKLM "Software\Classes\gpg4win.AssocFile.kleopatra.GPG"
+  DeleteRegKey HKLM "Software\Classes\gpg4win.AssocFile.kleopatra.ASC"
+  DeleteRegKey HKLM "Software\Classes\gpg4win.AssocFile.kleopatra.CMS"
+  DeleteRegKey HKLM "Software\Classes\gpg4win.AssocFile.kleopatra.X509"
+  DeleteRegKey HKLM "Software\Classes\gpg4win.AssocFile.kleopatra.PGPSIG"
+  DeleteRegKey HKLM "Software\Gpg4win\kleopatra"
+  DeleteRegValue HKLM "Software\RegisteredApplications" "Gpg4win.kleopatra.${VERSION}"
+  DeleteRegValue HKLM "Software\Classes\.gpg" "gpg4win.AssocFile.kleopatra.GPG"
+  DeleteRegValue HKLM "Software\Classes\.asc" "gpg4win.AssocFile.kleopatra.ASC"
+  DeleteRegValue HKLM "Software\Classes\.pgp" "gpg4win.AssocFile.kleopatra.PGP"
+  DeleteRegValue HKLM "Software\Classes\.cer" "gpg4win.AssocFile.kleopatra.X509"
+  DeleteRegValue HKLM "Software\Classes\.pem" "gpg4win.AssocFile.kleopatra.CMS"
+
+  DeleteRegKey /ifempty HKLM "Software\Classes\.gpg"
+  DeleteRegKey /ifempty HKLM "Software\Classes\.asc"
+  DeleteRegKey /ifempty HKLM "Software\Classes\.pgp"
+  DeleteRegKey /ifempty HKLM "Software\Classes\.pem"
+  DeleteRegKey /ifempty HKLM "Software\Classes\.sig"
 !endif
 SectionEnd