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

@@ -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;
}