diff --git a/cmake/sdk/CMakeLists.txt b/cmake/sdk/CMakeLists.txt index b1d818775..75f417f35 100644 --- a/cmake/sdk/CMakeLists.txt +++ b/cmake/sdk/CMakeLists.txt @@ -21,9 +21,10 @@ add_subdirectory(lib/third_party/imgui EXCLUDE_FROM_ALL) set(FMT_INSTALL OFF CACHE BOOL "" FORCE) add_subdirectory_if_exists(lib/third_party/fmt) -set(FMT_LIBRARIES fmt::fmt-header-only PARENT_SCOPE) +set(FMT_LIBRARIES fmt::fmt-header-only) add_subdirectory_if_exists(lib/third_party/nlohmann_json) +set(NLOHMANN_JSON_LIBRARIES nlohmann_json) add_subdirectory(lib/external/libwolv EXCLUDE_FROM_ALL) diff --git a/lib/external/libwolv b/lib/external/libwolv index a58bc52eb..7e90fc85e 160000 --- a/lib/external/libwolv +++ b/lib/external/libwolv @@ -1 +1 @@ -Subproject commit a58bc52eb69d440e1aa1df035fc405579644531b +Subproject commit 7e90fc85edad5c59eb82ce1d2727e1070fe4229b diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index fdfc90a48..a59e8c9b4 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -103,11 +103,11 @@ if (NOT IMHEX_EXTERNAL_PLUGIN_BUILD) target_link_libraries(libimhex PUBLIC ${FOUNDATION}) endif () - target_link_libraries(libimhex PRIVATE microtar libwolv ${NFD_LIBRARIES} magic dl ${NLOHMANN_JSON_LIBRARIES} ${MBEDTLS_LIBRARIES} ${JTHREAD_LIBRARIES}) + target_link_libraries(libimhex PRIVATE microtar libwolv ${NFD_LIBRARIES} magic dl ${MBEDTLS_LIBRARIES} ${JTHREAD_LIBRARIES}) target_link_libraries(libimhex PUBLIC libpl ${IMGUI_LIBRARIES}) endif() -target_link_libraries(libimhex ${LIBIMHEX_LIBRARY_TYPE} ${NLOHMANN_JSON_LIBRARIES} imgui_all_includes ${FMT_LIBRARIES}) +target_link_libraries(libimhex ${LIBIMHEX_LIBRARY_TYPE} nlohmann_json imgui_all_includes ${FMT_LIBRARIES}) set_property(TARGET libimhex PROPERTY INTERPROCEDURAL_OPTIMIZATION FALSE) diff --git a/lib/libimhex/include/hex/api/plugin_manager.hpp b/lib/libimhex/include/hex/api/plugin_manager.hpp index d0b70a83b..cbdcb0696 100644 --- a/lib/libimhex/include/hex/api/plugin_manager.hpp +++ b/lib/libimhex/include/hex/api/plugin_manager.hpp @@ -96,15 +96,18 @@ namespace hex { public: PluginManager() = delete; + static bool load(); static bool load(const std::fs::path &pluginFolder); static void unload(); static void reload(); static void initializeNewPlugins(); + static void addLoadPath(const std::fs::path &path); static void addPlugin(const std::string &name, PluginFunctions functions); static std::list &getPlugins(); static std::vector &getPluginPaths(); + static std::vector &getPluginLoadPaths(); static bool isPluginLoaded(const std::fs::path &path); }; diff --git a/lib/libimhex/source/api/plugin_manager.cpp b/lib/libimhex/source/api/plugin_manager.cpp index ea53b95b6..df8f4a2cc 100644 --- a/lib/libimhex/source/api/plugin_manager.cpp +++ b/lib/libimhex/source/api/plugin_manager.cpp @@ -226,6 +226,18 @@ namespace hex { #endif } + void PluginManager::addLoadPath(const std::fs::path& path) { + getPluginLoadPaths().emplace_back(path); + } + + + bool PluginManager::load() { + bool success = true; + for (const auto &loadPath : getPluginLoadPaths()) + success = PluginManager::load(loadPath) && success; + + return success; + } bool PluginManager::load(const std::fs::path &pluginFolder) { @@ -295,6 +307,12 @@ namespace hex { return pluginPaths; } + std::vector &PluginManager::getPluginLoadPaths() { + static std::vector pluginPaths; + + return pluginPaths; + } + bool PluginManager::isPluginLoaded(const std::fs::path &path) { return std::ranges::any_of(getPlugins(), [&path](const Plugin &plugin) { return plugin.getPath().filename() == path.filename(); diff --git a/lib/third_party/nlohmann_json/CMakeLists.txt b/lib/third_party/nlohmann_json/CMakeLists.txt index 88c42b963..cf7d04ad3 100644 --- a/lib/third_party/nlohmann_json/CMakeLists.txt +++ b/lib/third_party/nlohmann_json/CMakeLists.txt @@ -6,3 +6,4 @@ set(CMAKE_CXX_STANDARD 17) add_library(nlohmann_json INTERFACE) target_include_directories(nlohmann_json INTERFACE include) +add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json) \ No newline at end of file diff --git a/main/gui/source/init/tasks.cpp b/main/gui/source/init/tasks.cpp index b918727f5..f2b31176e 100644 --- a/main/gui/source/init/tasks.cpp +++ b/main/gui/source/init/tasks.cpp @@ -159,10 +159,13 @@ namespace hex::init { bool loadPlugins() { // Load all plugins + bool hasExtraPluginFolders = !PluginManager::getPluginLoadPaths().empty(); #if !defined(IMHEX_STATIC_LINK_PLUGINS) for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Plugins)) { - PluginManager::load(dir); + PluginManager::addLoadPath(dir); } + + PluginManager::load(); #endif // Get loaded plugins @@ -176,7 +179,7 @@ namespace hex::init { return false; } - const auto shouldLoadPlugin = [executablePath = wolv::io::fs::getExecutablePath()](const Plugin &plugin) { + const auto shouldLoadPlugin = [hasExtraPluginFolders, executablePath = wolv::io::fs::getExecutablePath()](const Plugin &plugin) { // In debug builds, ignore all plugins that are not part of the executable directory #if !defined(DEBUG) return true; @@ -185,6 +188,9 @@ namespace hex::init { if (!executablePath.has_value()) return true; + if (hasExtraPluginFolders) + return true; + // Check if the plugin is somewhere in the same directory tree as the executable return !std::fs::relative(plugin.getPath(), executablePath->parent_path()).string().starts_with(".."); }; @@ -276,6 +282,7 @@ namespace hex::init { bool unloadPlugins() { PluginManager::unload(); + PluginManager::getPluginLoadPaths().clear(); return true; } diff --git a/plugins/builtin/source/content/command_line_interface.cpp b/plugins/builtin/source/content/command_line_interface.cpp index a21daca9b..9a6a1e142 100644 --- a/plugins/builtin/source/content/command_line_interface.cpp +++ b/plugins/builtin/source/content/command_line_interface.cpp @@ -124,12 +124,9 @@ namespace hex::plugin::builtin { std::exit(EXIT_SUCCESS); } else { - TaskManager::doLater([args] { - for (const auto &arg : args) { - PluginManager::load(reinterpret_cast(arg.c_str())); - } - PluginManager::initializeNewPlugins(); - }); + for (const auto &arg : args) { + PluginManager::addLoadPath(reinterpret_cast(arg.c_str())); + } } }