diff --git a/src/model/CMakeLists.txt b/src/model/CMakeLists.txt index 1565b11..813ee86 100644 --- a/src/model/CMakeLists.txt +++ b/src/model/CMakeLists.txt @@ -57,3 +57,4 @@ add_definitions( add_gpui_library(gpui-model ${SOURCES}) target_link_libraries(gpui-model Qt5::Core) +target_link_libraries(gpui-model gpui-io) diff --git a/src/model/bundle/policybundle.cpp b/src/model/bundle/policybundle.cpp index a3b6fcc..802f778 100644 --- a/src/model/bundle/policybundle.cpp +++ b/src/model/bundle/policybundle.cpp @@ -20,8 +20,16 @@ #include "policybundle.h" +#include "../pluginstorage.h" + +#include "../../plugins/admx/admxformat.h" +#include "../../plugins/adml/admlformat.h" +#include "../../io/genericfile.h" + #include +#include + namespace model { namespace bundle { @@ -35,7 +43,7 @@ std::shared_ptr PolicyBundle::loadFolder(const std::string& pat const std::string& fallbackLanguage) { const QDir dir(path.c_str()); - const QFileInfoList files = dir.entryInfoList(); + const QFileInfoList files = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot); for (const QFileInfo& file : files) { if (file.completeBaseName().toLower().endsWith(".admx")) { @@ -46,6 +54,33 @@ std::shared_ptr PolicyBundle::loadFolder(const std::string& pat return std::shared_ptr(nullptr); } +template +std::unique_ptr loadPolicies(const QString& pluginName, const QFileInfo& admxFileName) +{ + std::unique_ptr policies; + + TFormat* format = gpui::PluginStorage::instance()->createPluginClass(pluginName); + + if (!format) + { + return policies; + } + + std::ifstream file; + + file.open(admxFileName.absoluteFilePath().toStdString(), std::ifstream::in); + + if (file.good()) { + policies = std::make_unique(); + + reinterpret_cast*>(format)->read(file, policies.get()); + } + + file.close(); + + return policies; +} + bool PolicyBundle::loadAdmxAndAdml(const QFileInfo& admxFileName, const std::string& language, const std::string& fallbackLanguage) { @@ -53,6 +88,15 @@ bool PolicyBundle::loadAdmxAndAdml(const QFileInfo& admxFileName, const std::str Q_UNUSED(language); Q_UNUSED(fallbackLanguage); + auto policyDefinitions = loadPolicies("admx", admxFileName); + + QString admlFilePath = admxFileName.absolutePath(); + admlFilePath.replace(admlFilePath.length() - 4, 4, "adml"); + + qWarning() << admlFilePath; + + //auto policyResources = loadPolicies() + // TODO: Load admx and adml files. return false; } diff --git a/src/model/plugin.cpp b/src/model/plugin.cpp index 2b22126..e1072cc 100644 --- a/src/model/plugin.cpp +++ b/src/model/plugin.cpp @@ -30,7 +30,7 @@ namespace gpui { public: QString name; std::unique_ptr library; - std::map > pluginClasses; + std::map > pluginClasses; }; Plugin::~Plugin() @@ -55,7 +55,7 @@ namespace gpui { return d->library.get(); } - const std::map >& Plugin::getPluginClasses() const + const std::map >& Plugin::getPluginClasses() const { return d->pluginClasses; } @@ -72,7 +72,7 @@ namespace gpui { } - void Plugin::registerPluginClass(const QString &name, std::function constructor) + void Plugin::registerPluginClass(const QString &name, std::function constructor) { d->pluginClasses[name] = constructor; } diff --git a/src/model/plugin.h b/src/model/plugin.h index d7d2723..ba14429 100644 --- a/src/model/plugin.h +++ b/src/model/plugin.h @@ -46,13 +46,13 @@ namespace gpui { void setLibrary(std::unique_ptr library); QLibrary* getLibrary() const; - const std::map>& getPluginClasses() const; + const std::map > &getPluginClasses() const; protected: explicit Plugin(const QString& name); explicit Plugin(const char* name); - void registerPluginClass(const QString& name, std::function constructor); + void registerPluginClass(const QString& name, std::function constructor); private: PluginPrivate* d; diff --git a/src/model/pluginstorage.cpp b/src/model/pluginstorage.cpp index 33a9a2a..01c8565 100644 --- a/src/model/pluginstorage.cpp +++ b/src/model/pluginstorage.cpp @@ -33,7 +33,7 @@ class PluginStoragePrivate { public: std::map > pluginMap; - std::map > > classMap; + std::map > > classMap; }; PluginStorage::PluginStorage() @@ -144,26 +144,14 @@ void PluginStorage::loadDefaultPlugins() loadPluginDirectory("/lib64/gpui/plugins/"); } -template -T* PluginStorage::createPluginClass(const QString& pluginName) -{ - auto search = d->classMap.find(pluginName); - if (search != d->classMap.end()) - { - return search->second[typeid(T).name()](); - } - - return nullptr; -} - -void PluginStorage::registerPluginClass(const QString& pluginName, const QString& className, std::function constructor) +void PluginStorage::registerPluginClass(const QString& pluginName, const QString& className, std::function constructor) { auto search = d->classMap.find(pluginName); if (search == d->classMap.end()) { - d->classMap[pluginName] = std::map >(); + d->classMap[pluginName] = std::map >(); } - std::map >& pluginConstructors = d->classMap[pluginName]; + std::map >& pluginConstructors = d->classMap[pluginName]; pluginConstructors[className] = constructor; } @@ -182,4 +170,15 @@ bool PluginStorage::unregisterPluginClass(const QString& pluginName, const QStri return false; } +void* PluginStorage::createPluginClass(const QString &className, const QString &pluginName) +{ + auto search = d->classMap.find(pluginName); + if (search != d->classMap.end()) + { + return search->second[className](); + } + + return nullptr; +} + } diff --git a/src/model/pluginstorage.h b/src/model/pluginstorage.h index fc44302..10737e9 100644 --- a/src/model/pluginstorage.h +++ b/src/model/pluginstorage.h @@ -87,14 +87,19 @@ public: * \brief createPluginClass */ template - T* createPluginClass(const QString& pluginName); + T* createPluginClass(const QString& pluginName) + { + return reinterpret_cast(createPluginClass(typeid(T).name(), pluginName)); + } static PluginStorage* instance(); private: - void registerPluginClass(const QString& pluginName, const QString& className, std::function constructor); + void registerPluginClass(const QString& pluginName, const QString& className, std::function constructor); bool unregisterPluginClass(const QString& pluginName, const QString& className); + void *createPluginClass(const QString& className, const QString& pluginName); + PluginStorage(); ~PluginStorage(); diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt index 5cf478d..9ccae3f 100644 --- a/tests/auto/CMakeLists.txt +++ b/tests/auto/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(gui) add_subdirectory(io) +add_subdirectory(model) add_subdirectory(plugins) diff --git a/tests/auto/model/CMakeLists.txt b/tests/auto/model/CMakeLists.txt new file mode 100644 index 0000000..c098288 --- /dev/null +++ b/tests/auto/model/CMakeLists.txt @@ -0,0 +1,7 @@ +find_package(GPUI COMPONENTS model REQUIRED) +include_directories(${GPUI_INCLUDE_DIRS}) + +find_package(Qt5 COMPONENTS Core Test REQUIRED) +set(QT_USE_QTTEST TRUE) + +add_subdirectory(policybundle) diff --git a/tests/auto/model/policybundle/CMakeLists.txt b/tests/auto/model/policybundle/CMakeLists.txt new file mode 100644 index 0000000..e50617c --- /dev/null +++ b/tests/auto/model/policybundle/CMakeLists.txt @@ -0,0 +1,4 @@ +qt5_wrap_cpp(MOC_SOURCES policybundletest.h) +add_executable(policybundletest policybundletest.cpp ${MOC_SOURCES}) +target_link_libraries(policybundletest gpui-model Qt5::Core Qt5::Test) +add_gpui_test(model.policybundletest policybundletest) diff --git a/tests/auto/model/policybundle/policybundletest.cpp b/tests/auto/model/policybundle/policybundletest.cpp new file mode 100644 index 0000000..99c9c56 --- /dev/null +++ b/tests/auto/model/policybundle/policybundletest.cpp @@ -0,0 +1,30 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2021 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include "policybundletest.h" + +#include "../../../../src/io/policydefinitionsfile.h" +#include "../../../../src/model/bundle/policybundle.h" + +using namespace io; +using namespace model::admx; + +namespace tests { +} diff --git a/tests/auto/model/policybundle/policybundletest.h b/tests/auto/model/policybundle/policybundletest.h new file mode 100644 index 0000000..e69de29 diff --git a/tests/auto/plugins/adml/admltest.cpp b/tests/auto/plugins/adml/admltest.cpp index 447f6f5..ffb6891 100644 --- a/tests/auto/plugins/adml/admltest.cpp +++ b/tests/auto/plugins/adml/admltest.cpp @@ -43,7 +43,8 @@ void AdmlTest::read() std::ifstream file; - file.open (dataPath + "example.adml", std::ifstream::in); +// file.open (dataPath + "example.adml", std::ifstream::in); + file.open("/home/august/Downloads/ADMX/Program Files/Microsoft Group Policy/Windows 10 October 2020 Update (20H2)/PolicyDefinitions/ru-ru/ActiveXInstallService.adml", std::fstream::in); if (file.good()) {