impr: Make sure plugins are only loaded once
This commit is contained in:
parent
1c5d6cbe94
commit
cab329556c
@ -104,6 +104,8 @@ namespace hex {
|
||||
|
||||
static std::vector<Plugin> &getPlugins();
|
||||
static std::vector<std::fs::path> &getPluginPaths();
|
||||
|
||||
static bool isPluginLoaded(const std::fs::path &path);
|
||||
};
|
||||
|
||||
}
|
@ -217,6 +217,8 @@ namespace hex {
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool PluginManager::load(const std::fs::path &pluginFolder) {
|
||||
if (!wolv::io::fs::exists(pluginFolder))
|
||||
return false;
|
||||
@ -225,14 +227,20 @@ namespace hex {
|
||||
|
||||
// Load library plugins first
|
||||
for (auto &pluginPath : std::fs::directory_iterator(pluginFolder)) {
|
||||
if (pluginPath.is_regular_file() && pluginPath.path().extension() == ".hexpluglib")
|
||||
getPlugins().emplace_back(pluginPath.path());
|
||||
if (pluginPath.is_regular_file() && pluginPath.path().extension() == ".hexpluglib") {
|
||||
if (!isPluginLoaded(pluginPath.path())) {
|
||||
getPlugins().emplace_back(pluginPath.path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load regular plugins afterwards
|
||||
for (auto &pluginPath : std::fs::directory_iterator(pluginFolder)) {
|
||||
if (pluginPath.is_regular_file() && pluginPath.path().extension() == ".hexplug")
|
||||
getPlugins().emplace_back(pluginPath.path());
|
||||
if (pluginPath.is_regular_file() && pluginPath.path().extension() == ".hexplug") {
|
||||
if (!isPluginLoaded(pluginPath.path())) {
|
||||
getPlugins().emplace_back(pluginPath.path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::erase_if(getPlugins(), [](const Plugin &plugin) {
|
||||
@ -285,4 +293,11 @@ namespace hex {
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user