From 77bc45ca172073221933420ee091f3a004040561 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 22 Mar 2024 17:39:17 +0100 Subject: [PATCH] fix: View provider not correctly saving its state to a project file --- .../content/providers/view_provider.hpp | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/plugins/builtin/include/content/providers/view_provider.hpp b/plugins/builtin/include/content/providers/view_provider.hpp index 31064790b..51a00441a 100644 --- a/plugins/builtin/include/content/providers/view_provider.hpp +++ b/plugins/builtin/include/content/providers/view_provider.hpp @@ -101,8 +101,28 @@ namespace hex::plugin::builtin { return m_provider->getDataDescription(); } - void loadSettings(const nlohmann::json &settings) override { hex::unused(settings); } - [[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings) const override { return settings; } + void loadSettings(const nlohmann::json &settings) override { + auto id = settings.at("id").get(); + m_startAddress = settings.at("start_address").get(); + m_size = settings.at("size").get(); + + const auto &providers = ImHexApi::Provider::getProviders(); + auto provider = std::ranges::find_if(providers, [id](const prv::Provider *provider) { + return provider->getID() == id; + }); + + if (provider == providers.end()) + return; + + m_provider = *provider; + } + + [[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings) const override { + settings["id"] = m_provider->getID(); + settings["start_address"] = m_startAddress; + settings["size"] = m_size; + return settings; + } [[nodiscard]] std::string getTypeName() const override { return "hex.builtin.provider.view";