From 7032473ecf70083a240956648cec749e2bc0eb81 Mon Sep 17 00:00:00 2001 From: BioTheWolff <47079795+BioTheWolff@users.noreply.github.com> Date: Tue, 3 Dec 2024 23:02:40 +0100 Subject: [PATCH] impr: Added MIME types for project files on UNIX systems (#1980) ### Problem description This PR addresses issue #491 regarding the inability to open ImHex project files (`.hexproj`) directly from various UNIX Desktop Environments. _NB: This PR's scope is limited to UNIX systems, as I have no access to MacOS systems and could not find a way to automatically create file associations on Windows._ ### Implementation description In order for project files to be recognised as such, we need to create a new MIME type. According to [RFC 6838 section 3.2](https://www.rfc-editor.org/rfc/rfc6838#section-3.2), additional application MIME types should be defined with a vendor prefix. _NB: This is preferred over the deprecated `x-` prefix, although RFC 6838 states that the vendor should be "a well known producer"_ This PR proposes a new mime type for ImHex project files: `application/vnd.imhex.proj`, and associates it with the file format `*.hexproj`. It also implements small changes in the Arch Linux and RPM builds, in order to correctly ship the MIME XML file during installation. ### Additional things The implemented change has been manually tested in the following UNIX systems and graphical environments: - Arch Linux, with Gnome 47.2 - Arch Linux, with XFCE4 - Fedora 41 Workstation Edition, with Gnome 47.0 - Fedora 41 Plasma, with KDE Plasma 24.08.2 - Ubuntu 22.04.5, with Gnome 42.9 Which tests the functionality of the following build types: - Arch Linux's `.zst` packages - Debian `.deb` packages - RPM packages For Arch Linux and RPM packages, this has been tested to ensure that post-installation hooks (such as regeneration of the MIME database) is correctly executed (which it is). No further changes than those implemented in the PR are needed. --------- Signed-off-by: BioTheWolff <47079795+BioTheWolff@users.noreply.github.com> --- cmake/build_helpers.cmake | 1 + dist/Arch/PKGBUILD | 2 +- dist/imhex.desktop | 1 + dist/imhex.mime.xml | 8 ++++++++ dist/rpm/imhex.spec | 1 + 5 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 dist/imhex.mime.xml diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index 81d5d4eac..0136c120e 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -225,6 +225,7 @@ macro(createPackage) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE DESTINATION ${CMAKE_INSTALL_PREFIX}/share/licenses/imhex) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dist/imhex.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dist/imhex.mime.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/mime/packages RENAME imhex.xml) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resources/icon.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps RENAME imhex.png) downloadImHexPatternsFiles("./share/imhex") diff --git a/dist/Arch/PKGBUILD b/dist/Arch/PKGBUILD index 59bc3a7ec..8acc2a483 100644 --- a/dist/Arch/PKGBUILD +++ b/dist/Arch/PKGBUILD @@ -26,5 +26,5 @@ package() { install -d "$pkgdir/usr/share/imhex" cp -r "$srcdir/usr/share/imhex/"{constants,encodings,includes,magic,patterns} "$pkgdir/usr/share/imhex" - cp -r "$srcdir/usr/share/"{applications,licenses,pixmaps} "$pkgdir/usr/share" + cp -r "$srcdir/usr/share/"{applications,licenses,pixmaps,mime} "$pkgdir/usr/share" } diff --git a/dist/imhex.desktop b/dist/imhex.desktop index 5e02c8ace..d02f96f11 100644 --- a/dist/imhex.desktop +++ b/dist/imhex.desktop @@ -9,3 +9,4 @@ StartupNotify=true Categories=Development;IDE; StartupWMClass=imhex Keywords=static-analysis;reverse-engineering;disassembler;disassembly;hacking;forensics;hex-editor;cybersecurity;security;binary-analysis; +MimeType=application/vnd.imhex.proj; diff --git a/dist/imhex.mime.xml b/dist/imhex.mime.xml new file mode 100644 index 000000000..cddc55494 --- /dev/null +++ b/dist/imhex.mime.xml @@ -0,0 +1,8 @@ + + + + + ImHex Project + + + diff --git a/dist/rpm/imhex.spec b/dist/rpm/imhex.spec index 17ce0ad97..56c67ee75 100644 --- a/dist/rpm/imhex.spec +++ b/dist/rpm/imhex.spec @@ -125,6 +125,7 @@ cp -a lib/third_party/xdgpp/LICENSE %{buildroot %{_bindir}/imhex-updater %{_datadir}/pixmaps/%{name}.png %{_datadir}/applications/%{name}.desktop +%{_datadir}/mime/packages/%{name}.xml %{_libdir}/libimhex.so* %{_libdir}/%{name}/ %{_metainfodir}/net.werwolv.%{name}.metainfo.xml \ No newline at end of file