diff options
author | saturneric <[email protected]> | 2025-05-01 14:54:48 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2025-05-01 14:54:48 +0000 |
commit | 72090625a3b136a6c6ad428a37f6fc0677e33333 (patch) | |
tree | b8926376f1af56b89e45c94c2d17352af77cbf3b /src/core/module/ModuleInit.cpp | |
parent | refactor: add cmake functions to register module and library (diff) | |
download | GpgFrontend-72090625a3b136a6c6ad428a37f6fc0677e33333.tar.gz GpgFrontend-72090625a3b136a6c6ad428a37f6fc0677e33333.zip |
fix: only load modules with suffix libgf_mod_
Diffstat (limited to 'src/core/module/ModuleInit.cpp')
-rw-r--r-- | src/core/module/ModuleInit.cpp | 35 |
1 files changed, 25 insertions, 10 deletions
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<QString, bool> { + QMap<QString, bool> 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<QString, bool> { - QMap<QString, bool> 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<QString, bool> { - 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<QString, bool> { 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 = |