From 72090625a3b136a6c6ad428a37f6fc0677e33333 Mon Sep 17 00:00:00 2001 From: saturneric Date: Thu, 1 May 2025 16:54:48 +0200 Subject: fix: only load modules with suffix libgf_mod_ --- src/core/module/ModuleInit.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'src/core/module/ModuleInit.cpp') diff --git a/src/core/module/ModuleInit.cpp b/src/core/module/ModuleInit.cpp index ed9068c7..11a57d4c 100644 --- a/src/core/module/ModuleInit.cpp +++ b/src/core/module/ModuleInit.cpp @@ -36,21 +36,32 @@ #include "core/thread/Task.h" #include "core/thread/TaskRunnerGetter.h" -namespace GpgFrontend::Module { +namespace { + +auto SearchModuleFromPath(const QString& mods_path, bool integrated) + -> QMap { + QMap modules; + + QDir dir(mods_path); + if (!dir.exists()) return modules; + + const auto entries = dir.entryInfoList( + QStringList() << "*.so" << "*.dll" << "*.dylib", QDir::Files); + + const QRegularExpression rx(QStringLiteral("^libgf_mod_.+$")); -auto SearchModuleFromPath(const QString& mods_path, - bool integrated) -> QMap { - QMap m; - for (const auto& module_library_name : QDir(mods_path).entryList( - QStringList() << "*.so" << "*.dll" << "*.dylib", QDir::Files)) { - m[mods_path + "/" + module_library_name] = integrated; + for (const auto& info : entries) { + if (rx.match(info.fileName()).hasMatch()) { + modules.insert(info.absoluteFilePath(), integrated); + } } - return m; + + return modules; } auto LoadIntegratedMods() -> QMap { - const auto module_path = - GlobalSettingStation::GetInstance().GetIntegratedModulePath(); + const auto module_path = GpgFrontend::GlobalSettingStation::GetInstance() + .GetIntegratedModulePath(); LOG_I() << "loading integrated modules from path:" << module_path; if (!QDir(module_path).exists()) { @@ -75,6 +86,10 @@ auto LoadExternalMods() -> QMap { return SearchModuleFromPath(mods_path, false); } +} // namespace + +namespace GpgFrontend::Module { + void LoadGpgFrontendModules(ModuleInitArgs) { // give user ability to give up all modules auto disable_loading_all_modules = -- cgit v1.2.3