diff --git a/lib/libimhex/include/hex/api/plugin_manager.hpp b/lib/libimhex/include/hex/api/plugin_manager.hpp index 5eccc5450..b3d9939d5 100644 --- a/lib/libimhex/include/hex/api/plugin_manager.hpp +++ b/lib/libimhex/include/hex/api/plugin_manager.hpp @@ -77,11 +77,14 @@ namespace hex { [[nodiscard]] bool isLibraryPlugin() const; + [[nodiscard]] bool wasAddedManually() const; + private: uintptr_t m_handle = 0; std::fs::path m_path; mutable bool m_initialized = false; + bool m_addedManually = false; PluginFunctions m_functions = {}; diff --git a/lib/libimhex/source/api/plugin_manager.cpp b/lib/libimhex/source/api/plugin_manager.cpp index b31de4773..3d5d1a11e 100644 --- a/lib/libimhex/source/api/plugin_manager.cpp +++ b/lib/libimhex/source/api/plugin_manager.cpp @@ -55,6 +55,7 @@ namespace hex { m_handle = 0; m_functions = functions; m_path = name; + m_addedManually = true; } @@ -63,6 +64,7 @@ namespace hex { other.m_handle = 0; m_path = std::move(other.m_path); + m_addedManually = other.m_addedManually; m_functions = other.m_functions; other.m_functions = {}; @@ -73,6 +75,7 @@ namespace hex { other.m_handle = 0; m_path = std::move(other.m_path); + m_addedManually = other.m_addedManually; m_functions = other.m_functions; other.m_functions = {}; @@ -220,6 +223,11 @@ namespace hex { m_functions.initializePluginFunction == nullptr; } + bool Plugin::wasAddedManually() const { + return m_addedManually; + } + + void *Plugin::getPluginFunction(const std::string &symbol) const { @@ -287,9 +295,15 @@ namespace hex { // Unload plugins in reverse order auto &plugins = getPlugins(); + + std::list savedPlugins; while (!plugins.empty()) { + if (plugins.back().wasAddedManually()) + savedPlugins.emplace_front(std::move(plugins.back())); plugins.pop_back(); } + + getPlugins() = std::move(savedPlugins); } void PluginManager::addPlugin(const std::string &name, hex::PluginFunctions functions) {