diff --git a/lib/libimhex/include/hex/api/plugin_manager.hpp b/lib/libimhex/include/hex/api/plugin_manager.hpp index f315ed95e..20a390156 100644 --- a/lib/libimhex/include/hex/api/plugin_manager.hpp +++ b/lib/libimhex/include/hex/api/plugin_manager.hpp @@ -48,6 +48,9 @@ namespace hex { Plugin(Plugin &&other) noexcept; ~Plugin(); + Plugin& operator=(const Plugin &) = delete; + Plugin& operator=(Plugin &&other) noexcept; + [[nodiscard]] bool initializePlugin() const; [[nodiscard]] std::string getPluginName() const; [[nodiscard]] std::string getPluginAuthor() const; @@ -58,6 +61,7 @@ namespace hex { [[nodiscard]] const std::fs::path &getPath() const; + [[nodiscard]] bool isValid() const; [[nodiscard]] bool isLoaded() const; [[nodiscard]] std::span getSubCommands() const; diff --git a/lib/libimhex/source/api/plugin_manager.cpp b/lib/libimhex/source/api/plugin_manager.cpp index d85783817..fb915f195 100644 --- a/lib/libimhex/source/api/plugin_manager.cpp +++ b/lib/libimhex/source/api/plugin_manager.cpp @@ -58,13 +58,25 @@ namespace hex { other.m_handle = 0; m_libraryPlugin = other.m_libraryPlugin; - - m_path = std::move(other.m_path); + m_path = std::move(other.m_path); m_functions = other.m_functions; other.m_functions = {}; } + Plugin& Plugin::operator=(Plugin &&other) noexcept { + m_handle = other.m_handle; + other.m_handle = 0; + + m_libraryPlugin = other.m_libraryPlugin; + m_path = std::move(other.m_path); + + m_functions = other.m_functions; + other.m_functions = {}; + + return *this; + } + Plugin::~Plugin() { #if defined(OS_WINDOWS) if (m_handle != 0) @@ -164,6 +176,10 @@ namespace hex { return m_path; } + bool Plugin::isValid() const { + return m_handle != 0; + } + bool Plugin::isLoaded() const { return m_initialized; } @@ -203,6 +219,10 @@ namespace hex { getPlugins().emplace_back(pluginPath.path(), false); } + std::erase_if(getPlugins(), [](const Plugin &plugin) { + return !plugin.isValid(); + }); + if (getPlugins().empty()) return false;