From 175e66a60e4ea0e4d429aa44e41811988556dc5a Mon Sep 17 00:00:00 2001 From: iTrooz Date: Fri, 25 Aug 2023 15:35:15 +0200 Subject: [PATCH] feat: Do not save memory providers as recent entries (#1259) --- lib/libimhex/include/hex/providers/provider.hpp | 6 ++++++ .../include/content/providers/memory_file_provider.hpp | 1 + plugins/builtin/source/content/recent.cpp | 3 +++ 3 files changed, 10 insertions(+) diff --git a/lib/libimhex/include/hex/providers/provider.hpp b/lib/libimhex/include/hex/providers/provider.hpp index 70eb3449f..d2f5d1d2b 100644 --- a/lib/libimhex/include/hex/providers/provider.hpp +++ b/lib/libimhex/include/hex/providers/provider.hpp @@ -61,6 +61,12 @@ namespace hex::prv { */ [[nodiscard]] virtual bool isDumpable() const; + /** + * @brief Controls whether this provider can be saved as a recent entry + * Tipitcally used for providers that do not retain data, e.g. the memory provider + */ + [[nodiscard]] virtual bool isSavableAsRecent() const { return true; } + /** * @brief Read data from this provider, applying overlays and patches * @param offset offset to start reading the data diff --git a/plugins/builtin/include/content/providers/memory_file_provider.hpp b/plugins/builtin/include/content/providers/memory_file_provider.hpp index 4bff898ab..248e5a2b6 100644 --- a/plugins/builtin/include/content/providers/memory_file_provider.hpp +++ b/plugins/builtin/include/content/providers/memory_file_provider.hpp @@ -15,6 +15,7 @@ namespace hex::plugin::builtin { [[nodiscard]] bool isWritable() const override { return !this->m_readOnly; } [[nodiscard]] bool isResizable() const override { return !this->m_readOnly; } [[nodiscard]] bool isSavable() const override { return this->m_name.empty(); } + [[nodiscard]] bool isSavableAsRecent() const override { return false; } [[nodiscard]] bool open() override; void close() override { } diff --git a/plugins/builtin/source/content/recent.cpp b/plugins/builtin/source/content/recent.cpp index 96647f51f..04e04d310 100644 --- a/plugins/builtin/source/content/recent.cpp +++ b/plugins/builtin/source/content/recent.cpp @@ -33,6 +33,9 @@ namespace hex::plugin::builtin::recent { // do not save to recents if the provider is part of a project if (ProjectFile::hasPath()) return; + // do not save to recents if the provider doesnt want it + if (!provider->isSavableAsRecent()) return; + // The recent provider is saved to every "recent" directory for (const auto &recentPath : fs::getDefaultPaths(fs::ImHexPath::Recent)) { wolv::io::File recentFile(recentPath / fileName, wolv::io::File::Mode::Create);