refactor: Rework features that use external libraries into optional plugins (#1470)

This commit is contained in:
Nik
2023-12-23 21:09:41 +01:00
committed by GitHub
parent 84bfd10416
commit 61bfe10bc2
149 changed files with 2940 additions and 2390 deletions

View File

@@ -5,6 +5,7 @@
#include <string>
#include <wolv/io/fs.hpp>
#include <hex/helpers/logger.hpp>
struct ImGuiContext;
@@ -18,6 +19,7 @@ namespace hex {
struct PluginFunctions {
using InitializePluginFunc = void (*)();
using InitializeLibraryFunc = void (*)();
using GetPluginNameFunc = const char *(*)();
using GetPluginAuthorFunc = const char *(*)();
using GetPluginDescriptionFunc = const char *(*)();
@@ -27,6 +29,7 @@ namespace hex {
using GetSubCommandsFunc = void* (*)();
InitializePluginFunc initializePluginFunction = nullptr;
InitializeLibraryFunc initializeLibraryFunction = nullptr;
GetPluginNameFunc getPluginNameFunction = nullptr;
GetPluginAuthorFunc getPluginAuthorFunction = nullptr;
GetPluginDescriptionFunc getPluginDescriptionFunction = nullptr;
@@ -38,8 +41,8 @@ namespace hex {
class Plugin {
public:
explicit Plugin(const std::fs::path &path);
explicit Plugin(PluginFunctions functions);
explicit Plugin(const std::fs::path &path, bool libraryPlugin);
explicit Plugin(PluginFunctions functions, bool libraryPlugin);
Plugin(const Plugin &) = delete;
Plugin(Plugin &&other) noexcept;
@@ -59,9 +62,12 @@ namespace hex {
[[nodiscard]] std::span<SubCommand> getSubCommands() const;
[[nodiscard]] bool isLibraryPlugin() const { return m_libraryPlugin; }
private:
uintptr_t m_handle = 0;
std::fs::path m_path;
bool m_libraryPlugin;
mutable bool m_initialized = false;

View File

@@ -22,6 +22,24 @@
* Name, Author and Description will be displayed in the in the plugin list on the Welcome screen.
*/
#define IMHEX_PLUGIN_SETUP(name, author, description) IMHEX_PLUGIN_SETUP_IMPL(name, author, description)
#define IMHEX_LIBRARY_SETUP() IMHEX_LIBRARY_SETUP_IMPL()
#define IMHEX_LIBRARY_SETUP_IMPL() \
IMHEX_PLUGIN_VISIBILITY_PREFIX void initializeLibrary(); \
extern "C" [[gnu::visibility("default")]] void WOLV_TOKEN_CONCAT(forceLinkPlugin_, IMHEX_PLUGIN_NAME)() { \
hex::PluginManager::addPlugin(hex::PluginFunctions { \
nullptr, \
initializeLibrary, \
nullptr, \
nullptr, \
nullptr, \
nullptr, \
nullptr, \
nullptr, \
nullptr \
}); \
} \
IMHEX_PLUGIN_VISIBILITY_PREFIX void initializeLibrary()
#define IMHEX_PLUGIN_SETUP_IMPL(name, author, description) \
IMHEX_PLUGIN_VISIBILITY_PREFIX const char *getPluginName() { return name; } \
@@ -36,6 +54,7 @@
extern "C" [[gnu::visibility("default")]] void WOLV_TOKEN_CONCAT(forceLinkPlugin_, IMHEX_PLUGIN_NAME)() { \
hex::PluginManager::addPlugin(hex::PluginFunctions { \
initializePlugin, \
nullptr, \
getPluginName, \
getPluginAuthor, \
getPluginDescription, \