1
0
mirror of synced 2025-01-18 17:14:13 +01:00

sys: Don't load any external plugins in debug builds

Closes #833
This commit is contained in:
WerWolv 2022-11-25 10:28:05 +01:00
parent c194588118
commit 0f028db856

View File

@ -230,10 +230,28 @@ namespace hex::init {
return false;
}
const auto shouldLoadPlugin = [executablePath = hex::fs::getExecutablePath()](const Plugin &plugin) {
#if !defined(DEBUG)
return true;
#endif
if (!executablePath.has_value())
return true;
// In debug builds, ignore all plugins that are not part of the executable directory
return !std::fs::relative(plugin.getPath(), executablePath->parent_path()).string().starts_with("..");
};
u32 builtinPlugins = 0;
u32 loadErrors = 0;
for (const auto &plugin : plugins) {
if (!plugin.isBuiltinPlugin()) continue;
if (!shouldLoadPlugin(plugin)) {
log::debug("Skipping built-in plugin {}", plugin.getPath().string());
continue;
}
builtinPlugins++;
if (builtinPlugins > 1) continue;
@ -246,6 +264,11 @@ namespace hex::init {
for (const auto &plugin : plugins) {
if (plugin.isBuiltinPlugin()) continue;
if (!shouldLoadPlugin(plugin)) {
log::debug("Skipping plugin {}", plugin.getPath().string());
continue;
}
if (!plugin.initializePlugin()) {
log::error("Failed to initialize plugin {}", hex::toUTF8String(plugin.getPath().filename()));
loadErrors++;