impr: Further improve interfacing with external plugins
This commit is contained in:
parent
00491c8d90
commit
b605c463a1
@ -21,9 +21,10 @@ add_subdirectory(lib/third_party/imgui EXCLUDE_FROM_ALL)
|
|||||||
|
|
||||||
set(FMT_INSTALL OFF CACHE BOOL "" FORCE)
|
set(FMT_INSTALL OFF CACHE BOOL "" FORCE)
|
||||||
add_subdirectory_if_exists(lib/third_party/fmt)
|
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)
|
add_subdirectory_if_exists(lib/third_party/nlohmann_json)
|
||||||
|
set(NLOHMANN_JSON_LIBRARIES nlohmann_json)
|
||||||
|
|
||||||
add_subdirectory(lib/external/libwolv EXCLUDE_FROM_ALL)
|
add_subdirectory(lib/external/libwolv EXCLUDE_FROM_ALL)
|
||||||
|
|
||||||
|
2
lib/external/libwolv
vendored
2
lib/external/libwolv
vendored
@ -1 +1 @@
|
|||||||
Subproject commit a58bc52eb69d440e1aa1df035fc405579644531b
|
Subproject commit 7e90fc85edad5c59eb82ce1d2727e1070fe4229b
|
@ -103,11 +103,11 @@ if (NOT IMHEX_EXTERNAL_PLUGIN_BUILD)
|
|||||||
target_link_libraries(libimhex PUBLIC ${FOUNDATION})
|
target_link_libraries(libimhex PUBLIC ${FOUNDATION})
|
||||||
endif ()
|
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})
|
target_link_libraries(libimhex PUBLIC libpl ${IMGUI_LIBRARIES})
|
||||||
endif()
|
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)
|
set_property(TARGET libimhex PROPERTY INTERPROCEDURAL_OPTIMIZATION FALSE)
|
||||||
|
|
||||||
|
@ -96,15 +96,18 @@ namespace hex {
|
|||||||
public:
|
public:
|
||||||
PluginManager() = delete;
|
PluginManager() = delete;
|
||||||
|
|
||||||
|
static bool load();
|
||||||
static bool load(const std::fs::path &pluginFolder);
|
static bool load(const std::fs::path &pluginFolder);
|
||||||
static void unload();
|
static void unload();
|
||||||
static void reload();
|
static void reload();
|
||||||
static void initializeNewPlugins();
|
static void initializeNewPlugins();
|
||||||
|
static void addLoadPath(const std::fs::path &path);
|
||||||
|
|
||||||
static void addPlugin(const std::string &name, PluginFunctions functions);
|
static void addPlugin(const std::string &name, PluginFunctions functions);
|
||||||
|
|
||||||
static std::list<Plugin> &getPlugins();
|
static std::list<Plugin> &getPlugins();
|
||||||
static std::vector<std::fs::path> &getPluginPaths();
|
static std::vector<std::fs::path> &getPluginPaths();
|
||||||
|
static std::vector<std::fs::path> &getPluginLoadPaths();
|
||||||
|
|
||||||
static bool isPluginLoaded(const std::fs::path &path);
|
static bool isPluginLoaded(const std::fs::path &path);
|
||||||
};
|
};
|
||||||
|
@ -226,6 +226,18 @@ namespace hex {
|
|||||||
#endif
|
#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) {
|
bool PluginManager::load(const std::fs::path &pluginFolder) {
|
||||||
@ -295,6 +307,12 @@ namespace hex {
|
|||||||
return pluginPaths;
|
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) {
|
bool PluginManager::isPluginLoaded(const std::fs::path &path) {
|
||||||
return std::ranges::any_of(getPlugins(), [&path](const Plugin &plugin) {
|
return std::ranges::any_of(getPlugins(), [&path](const Plugin &plugin) {
|
||||||
return plugin.getPath().filename() == path.filename();
|
return plugin.getPath().filename() == path.filename();
|
||||||
|
1
lib/third_party/nlohmann_json/CMakeLists.txt
vendored
1
lib/third_party/nlohmann_json/CMakeLists.txt
vendored
@ -6,3 +6,4 @@ set(CMAKE_CXX_STANDARD 17)
|
|||||||
add_library(nlohmann_json INTERFACE)
|
add_library(nlohmann_json INTERFACE)
|
||||||
|
|
||||||
target_include_directories(nlohmann_json INTERFACE include)
|
target_include_directories(nlohmann_json INTERFACE include)
|
||||||
|
add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json)
|
@ -159,10 +159,13 @@ namespace hex::init {
|
|||||||
|
|
||||||
bool loadPlugins() {
|
bool loadPlugins() {
|
||||||
// Load all plugins
|
// Load all plugins
|
||||||
|
bool hasExtraPluginFolders = !PluginManager::getPluginLoadPaths().empty();
|
||||||
#if !defined(IMHEX_STATIC_LINK_PLUGINS)
|
#if !defined(IMHEX_STATIC_LINK_PLUGINS)
|
||||||
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Plugins)) {
|
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Plugins)) {
|
||||||
PluginManager::load(dir);
|
PluginManager::addLoadPath(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PluginManager::load();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Get loaded plugins
|
// Get loaded plugins
|
||||||
@ -176,7 +179,7 @@ namespace hex::init {
|
|||||||
return false;
|
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
|
// In debug builds, ignore all plugins that are not part of the executable directory
|
||||||
#if !defined(DEBUG)
|
#if !defined(DEBUG)
|
||||||
return true;
|
return true;
|
||||||
@ -185,6 +188,9 @@ namespace hex::init {
|
|||||||
if (!executablePath.has_value())
|
if (!executablePath.has_value())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (hasExtraPluginFolders)
|
||||||
|
return true;
|
||||||
|
|
||||||
// Check if the plugin is somewhere in the same directory tree as the executable
|
// 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("..");
|
return !std::fs::relative(plugin.getPath(), executablePath->parent_path()).string().starts_with("..");
|
||||||
};
|
};
|
||||||
@ -276,6 +282,7 @@ namespace hex::init {
|
|||||||
|
|
||||||
bool unloadPlugins() {
|
bool unloadPlugins() {
|
||||||
PluginManager::unload();
|
PluginManager::unload();
|
||||||
|
PluginManager::getPluginLoadPaths().clear();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -124,12 +124,9 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
std::exit(EXIT_SUCCESS);
|
std::exit(EXIT_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
TaskManager::doLater([args] {
|
for (const auto &arg : args) {
|
||||||
for (const auto &arg : args) {
|
PluginManager::addLoadPath(reinterpret_cast<const char8_t*>(arg.c_str()));
|
||||||
PluginManager::load(reinterpret_cast<const char8_t*>(arg.c_str()));
|
}
|
||||||
}
|
|
||||||
PluginManager::initializeNewPlugins();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user