impr: Further improve interfacing with external plugins

This commit is contained in:
WerWolv
2024-01-22 23:35:00 +01:00
parent 00491c8d90
commit b605c463a1
8 changed files with 39 additions and 12 deletions

View File

@@ -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)

View File

@@ -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<Plugin> &getPlugins();
static std::vector<std::fs::path> &getPluginPaths();
static std::vector<std::fs::path> &getPluginLoadPaths();
static bool isPluginLoaded(const std::fs::path &path);
};

View File

@@ -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<std::fs::path> &PluginManager::getPluginLoadPaths() {
static std::vector<std::fs::path> 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();

View File

@@ -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)