From 8a3739ee1cbd2ad29c161007a61431099bb197a1 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 8 May 2024 22:30:53 +0200 Subject: [PATCH] impr: Display background scripts in about page --- lib/libimhex/include/hex/plugin.hpp | 6 ++-- .../decompress/source/plugin_decompress.cpp | 2 +- .../script_loader/include/loaders/loader.hpp | 5 ++-- .../source/loaders/dotnet/dotnet_loader.cpp | 6 ++-- .../source/plugin_script_loader.cpp | 29 +++++++++++++++---- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/lib/libimhex/include/hex/plugin.hpp b/lib/libimhex/include/hex/plugin.hpp index 600a1c5d3..7f370ee20 100644 --- a/lib/libimhex/include/hex/plugin.hpp +++ b/lib/libimhex/include/hex/plugin.hpp @@ -131,8 +131,8 @@ void* PluginSubCommandsFunctionHelper::getSubCommands() { std::vector g_subCommands #define IMHEX_FEATURE_ENABLED(feature) WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(IMHEX_PLUGIN_, IMHEX_PLUGIN_NAME), _FEATURE_), feature) -#define IMHEX_PLUGIN_FEATURES() IMHEX_PLUGIN_FEATURES_IMPL() -#define IMHEX_PLUGIN_FEATURES_IMPL() \ +#define IMHEX_DEFINE_PLUGIN_FEATURES() IMHEX_DEFINE_PLUGIN_FEATURES_IMPL() +#define IMHEX_DEFINE_PLUGIN_FEATURES_IMPL() \ extern std::vector g_features; \ template<> \ struct PluginFeatureFunctionHelper { \ @@ -142,3 +142,5 @@ void* PluginSubCommandsFunctionHelper::getSubCommands() { return &g_features; \ } \ std::vector g_features + +#define IMHEX_PLUGIN_FEATURES g_features diff --git a/plugins/decompress/source/plugin_decompress.cpp b/plugins/decompress/source/plugin_decompress.cpp index 9f6262800..a322e6c79 100644 --- a/plugins/decompress/source/plugin_decompress.cpp +++ b/plugins/decompress/source/plugin_decompress.cpp @@ -14,7 +14,7 @@ namespace hex::plugin::decompress { using namespace hex; using namespace hex::plugin::decompress; -IMHEX_PLUGIN_FEATURES() { +IMHEX_DEFINE_PLUGIN_FEATURES() { { "bzip2 Support", IMHEX_FEATURE_ENABLED(BZIP2) }, { "zlib Support", IMHEX_FEATURE_ENABLED(ZLIB) }, { "LZMA Support", IMHEX_FEATURE_ENABLED(LIBLZMA) }, diff --git a/plugins/script_loader/include/loaders/loader.hpp b/plugins/script_loader/include/loaders/loader.hpp index 47483096f..52a30cc2b 100644 --- a/plugins/script_loader/include/loaders/loader.hpp +++ b/plugins/script_loader/include/loaders/loader.hpp @@ -8,6 +8,7 @@ namespace hex::script::loader { struct Script { std::string name; + bool background; std::function entryPoint; }; @@ -19,8 +20,8 @@ namespace hex::script::loader { virtual bool initialize() = 0; virtual bool loadAll() = 0; - void addScript(std::string name, std::function entryPoint) { - m_scripts.emplace_back(std::move(name), std::move(entryPoint)); + void addScript(std::string name, bool background, std::function entryPoint) { + m_scripts.emplace_back(std::move(name), background, std::move(entryPoint)); } const auto& getScripts() const { diff --git a/plugins/script_loader/source/loaders/dotnet/dotnet_loader.cpp b/plugins/script_loader/source/loaders/dotnet/dotnet_loader.cpp index e8437694e..639c77ac2 100644 --- a/plugins/script_loader/source/loaders/dotnet/dotnet_loader.cpp +++ b/plugins/script_loader/source/loaders/dotnet/dotnet_loader.cpp @@ -262,13 +262,15 @@ namespace hex::script::loader { continue; if (m_methodExists("Main", scriptPath)) { - this->addScript(entry.path().stem().string(), [this, scriptPath] { + this->addScript(entry.path().stem().string(), false, [this, scriptPath] { hex::unused(m_runMethod("Main", false, scriptPath)); }); } if (m_methodExists("OnLoad", scriptPath)) { - hex::unused(m_runMethod("OnLoad", true, scriptPath)); + this->addScript(entry.path().stem().string(), true, [this, scriptPath] { + hex::unused(m_runMethod("OnLoad", true, scriptPath)); + }); } } } diff --git a/plugins/script_loader/source/plugin_script_loader.cpp b/plugins/script_loader/source/plugin_script_loader.cpp index addb4f729..dbeb4ac4b 100644 --- a/plugins/script_loader/source/plugin_script_loader.cpp +++ b/plugins/script_loader/source/plugin_script_loader.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -20,6 +21,8 @@ using ScriptLoaders = std::tuple< #endif >; +IMHEX_DEFINE_PLUGIN_FEATURES(){ }; + namespace { ScriptLoaders s_loaders; @@ -32,17 +35,29 @@ namespace { } std::vector loadAllScripts() { - std::vector plugins; + std::vector scripts; try { - std::apply([&plugins](auto&&... args) { - (loadScript(plugins, args), ...); + std::apply([&scripts](auto&&... args) { + (loadScript(scripts, args), ...); }, s_loaders); } catch (const std::exception &e) { log::error("Error when loading scripts: {}", e.what()); } - return plugins; + { + std::vector features; + for (const auto &script : scripts) { + if (!script->background) + continue; + + features.emplace_back(script->name, true); + } + + IMHEX_PLUGIN_FEATURES = features; + } + + return scripts; } void initializeLoader(u32 &count, auto &loader) { @@ -74,7 +89,7 @@ namespace { hex::ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.extras" }, 5000, [] { static bool menuJustOpened = true; - if (ImGui::BeginMenu("hex.script_loader.menu.run_script"_lang)) { + if (ImGui::BeginMenuEx("hex.script_loader.menu.run_script"_lang, ICON_VS_LIBRARY)) { if (menuJustOpened) { menuJustOpened = false; if (!updaterTask.isRunning()) { @@ -91,7 +106,9 @@ namespace { } for (const auto &script : scripts) { - const auto &[name, entryPoint] = *script; + const auto &[name, background, entryPoint] = *script; + if (background) + continue; if (ImGui::MenuItem(name.c_str())) { runnerTask = TaskManager::createTask("Running script...", TaskManager::NoProgress, [entryPoint](auto&) {