diff --git a/src/model/bundle/policybundle.cpp b/src/model/bundle/policybundle.cpp index add9c71..4dd5a08 100644 --- a/src/model/bundle/policybundle.cpp +++ b/src/model/bundle/policybundle.cpp @@ -69,6 +69,7 @@ public: QStandardItem* rootUserItem; std::vector items; std::map supportedOnMap; + QString languageDirectoryPath; }; PolicyBundle::PolicyBundle() @@ -95,10 +96,22 @@ std::unique_ptr PolicyBundle::loadFolder(const std::string& const QDir dir(path.c_str()); const QFileInfoList files = dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot); + const QFileInfoList directories = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); + + const QString qLanguage = QString::fromStdString(language).toLower(); + + for (const QFileInfo& subDir : directories) + { + if (subDir.fileName().toLower().endsWith(qLanguage)) + { + d->languageDirectoryPath = subDir.absoluteFilePath(); + break; + } + } for (const QFileInfo& file : files) { if (file.fileName().toLower().endsWith(".admx")) { - loadAdmxAndAdml(file, language); + loadAdmxAndAdml(file); } } @@ -140,12 +153,19 @@ std::unique_ptr loadPolicies(const QString& pluginName, const QFileIn return policies; } -QString PolicyBundle::constructFileName(const QFileInfo& fileName, const std::string& language) +QString PolicyBundle::constructFileName(const QFileInfo& fileName) { QString admlFileName = fileName.fileName(); admlFileName.replace(admlFileName.length() - 4, 4, "adml"); - admlFileName.prepend(QDir::separator() + QString::fromStdString(language) + QDir::separator()); - admlFileName.prepend(fileName.absolutePath()); + QDir admlDir(d->languageDirectoryPath); + for (const auto& file : admlDir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot)) + { + if (file.fileName().toLower().compare(admlFileName.toLower()) == 0) + { + return file.absoluteFilePath(); + } + } + return admlFileName; } @@ -215,14 +235,14 @@ void handlePresentation(const std::shared_ptr } } -bool PolicyBundle::loadAdmxAndAdml(const QFileInfo& admxFileName, const std::string& language) +bool PolicyBundle::loadAdmxAndAdml(const QFileInfo& admxFileName) { auto policyDefinitions = loadPolicies>("admx", admxFileName); if (!policyDefinitions.get()) { return false; } - QString admlFileName = constructFileName(admxFileName, language); + QString admlFileName = constructFileName(admxFileName); auto policyResources = loadPolicies>("adml", admlFileName); if (!policyResources.get()) { diff --git a/src/model/bundle/policybundle.h b/src/model/bundle/policybundle.h index cf4e5c2..9efc093 100644 --- a/src/model/bundle/policybundle.h +++ b/src/model/bundle/policybundle.h @@ -51,9 +51,9 @@ namespace model std::unique_ptr loadFolder(const std::string& path, const std::string& language); private: - bool loadAdmxAndAdml(const QFileInfo &admxFileName, const std::string& language); + bool loadAdmxAndAdml(const QFileInfo &admxFileName); - QString constructFileName(const QFileInfo &fileName, const std::string &language); + QString constructFileName(const QFileInfo &fileName); PolicyBundlePrivate* d;