|
| 1 | +From 23ddb6ff148ec5c27da050ba0eb7a2e449b8450b Mon Sep 17 00:00:00 2001 |
| 2 | +From: Yury Shvedov < [email protected]> |
| 3 | +Date: Mon, 4 Nov 2024 14:22:22 +0300 |
| 4 | +Subject: [PATCH] Gui: take in account module-path argument |
| 5 | + |
| 6 | +Use paths passed with `--module-path` argument to search for preference |
| 7 | +packs |
| 8 | + |
| 9 | +Change-Id: If168dbd99a826757290ee6b918f5b712305fe2bb |
| 10 | +--- |
| 11 | + src/Gui/DlgPreferencePackManagementImp.cpp | 16 +++++---- |
| 12 | + src/Gui/PreferencePackManager.cpp | 39 +++++++++++++++++----- |
| 13 | + src/Gui/PreferencePackManager.h | 5 +++ |
| 14 | + 3 files changed, 44 insertions(+), 16 deletions(-) |
| 15 | + |
| 16 | +diff --git a/src/Gui/DlgPreferencePackManagementImp.cpp b/src/Gui/DlgPreferencePackManagementImp.cpp |
| 17 | +index a1a0dad41a..50f3982f21 100644 |
| 18 | +--- a/src/Gui/DlgPreferencePackManagementImp.cpp |
| 19 | ++++ b/src/Gui/DlgPreferencePackManagementImp.cpp |
| 20 | +@@ -54,7 +54,7 @@ void DlgPreferencePackManagementImp::showEvent(QShowEvent* event) |
| 21 | + // but can only disable individual installed packs (though we can completely uninstall the pack's |
| 22 | + // containing Addon by redirecting to the Addon Manager). |
| 23 | + auto savedPreferencePacksDirectory = fs::path(App::Application::getUserAppDataDir()) / "SavedPreferencePacks"; |
| 24 | +- auto modDirectory = fs::path(App::Application::getUserAppDataDir()) / "Mod"; |
| 25 | ++ auto modDirectories = Application::Instance->prefPackManager()->modPaths(); |
| 26 | + auto resourcePath = fs::path(App::Application::getResourceDir()) / "Gui" / "PreferencePacks"; |
| 27 | + |
| 28 | + // The displayed tree has two levels: at the toplevel is either "User-Saved Packs" or the name |
| 29 | +@@ -66,12 +66,14 @@ void DlgPreferencePackManagementImp::showEvent(QShowEvent* event) |
| 30 | + auto builtinPacks = getPacksFromDirectory(resourcePath); |
| 31 | + |
| 32 | + std::map<std::string, std::vector<std::string>> installedPacks; |
| 33 | +- if (fs::exists(modDirectory) && fs::is_directory(modDirectory)) { |
| 34 | +- for (const auto& mod : fs::directory_iterator(modDirectory)) { |
| 35 | +- auto packs = getPacksFromDirectory(mod); |
| 36 | +- if (!packs.empty()) { |
| 37 | +- auto modName = mod.path().filename().string(); |
| 38 | +- installedPacks.emplace(modName, packs); |
| 39 | ++ for (const auto& modDirectory : modDirectories) { |
| 40 | ++ if (fs::exists(modDirectory) && fs::is_directory(modDirectory)) { |
| 41 | ++ for (const auto& mod : fs::directory_iterator(modDirectory)) { |
| 42 | ++ auto packs = getPacksFromDirectory(mod); |
| 43 | ++ if (!packs.empty()) { |
| 44 | ++ auto modName = mod.path().filename().string(); |
| 45 | ++ installedPacks.emplace(modName, packs); |
| 46 | ++ } |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | +diff --git a/src/Gui/PreferencePackManager.cpp b/src/Gui/PreferencePackManager.cpp |
| 51 | +index dfc54240c0..83e32fa05e 100644 |
| 52 | +--- a/src/Gui/PreferencePackManager.cpp |
| 53 | ++++ b/src/Gui/PreferencePackManager.cpp |
| 54 | +@@ -30,6 +30,7 @@ |
| 55 | + #endif |
| 56 | + |
| 57 | + #include <boost/filesystem.hpp> |
| 58 | ++#include <boost/algorithm/string.hpp> |
| 59 | + #include <QDir> |
| 60 | + |
| 61 | + #include "PreferencePackManager.h" |
| 62 | +@@ -134,12 +135,11 @@ void PreferencePack::applyConfigChanges() const |
| 63 | + } |
| 64 | + |
| 65 | + PreferencePackManager::PreferencePackManager() |
| 66 | ++ : _preferencePackPaths(modPaths()) |
| 67 | + { |
| 68 | +- auto modPath = fs::path(App::Application::getUserAppDataDir()) / "Mod"; |
| 69 | + auto savedPath = fs::path(App::Application::getUserAppDataDir()) / "SavedPreferencePacks"; |
| 70 | + auto resourcePath = fs::path(App::Application::getResourceDir()) / "Gui" / "PreferencePacks"; |
| 71 | +- _preferencePackPaths.push_back(resourcePath); |
| 72 | +- _preferencePackPaths.push_back(modPath); |
| 73 | ++ _preferencePackPaths.insert(_preferencePackPaths.begin(), resourcePath); |
| 74 | + _preferencePackPaths.push_back(savedPath); |
| 75 | + rescan(); |
| 76 | + |
| 77 | +@@ -232,6 +232,26 @@ void Gui::PreferencePackManager::importConfig(const std::string& packName, |
| 78 | + rescan(); |
| 79 | + } |
| 80 | + |
| 81 | ++// TODO(Shvedov): Is this suitable place for this method? It is more generic, |
| 82 | ++// and maybe more suitable place at Application? |
| 83 | ++std::vector<boost::filesystem::path> Gui::PreferencePackManager::modPaths() const |
| 84 | ++{ |
| 85 | ++ auto userModPath = fs::path(App::Application::getUserAppDataDir()) / "Mod"; |
| 86 | ++ |
| 87 | ++ auto& config = App::Application::Config(); |
| 88 | ++ auto additionalModules = config.find("AdditionalModulePaths"); |
| 89 | ++ std::vector<boost::filesystem::path> result; |
| 90 | ++ |
| 91 | ++ if (additionalModules != config.end()) { |
| 92 | ++ boost::split(result, |
| 93 | ++ additionalModules->second, |
| 94 | ++ boost::is_any_of(";"), |
| 95 | ++ boost::token_compress_on); |
| 96 | ++ } |
| 97 | ++ result.emplace_back(userModPath); |
| 98 | ++ return result; |
| 99 | ++} |
| 100 | ++ |
| 101 | + void Gui::PreferencePackManager::FindPreferencePacksInPackage(const fs::path &mod) |
| 102 | + { |
| 103 | + try { |
| 104 | +@@ -528,7 +548,6 @@ std::vector<PreferencePackManager::TemplateFile> PreferencePackManager::template |
| 105 | + // (alternate spellings are provided for packages using CamelCase and snake_case, and both major English dialects) |
| 106 | + |
| 107 | + auto resourcePath = fs::path(App::Application::getResourceDir()) / "Gui"; |
| 108 | +- auto modPath = fs::path(App::Application::getUserAppDataDir()) / "Mod"; |
| 109 | + |
| 110 | + std::string group = "Built-In"; |
| 111 | + if (fs::exists(resourcePath) && fs::is_directory(resourcePath)) { |
| 112 | +@@ -536,11 +555,13 @@ std::vector<PreferencePackManager::TemplateFile> PreferencePackManager::template |
| 113 | + std::copy(localFiles.begin(), localFiles.end(), std::back_inserter(_templateFiles)); |
| 114 | + } |
| 115 | + |
| 116 | +- if (fs::exists(modPath) && fs::is_directory(modPath)) { |
| 117 | +- for (const auto& mod : fs::directory_iterator(modPath)) { |
| 118 | +- group = mod.path().filename().string(); |
| 119 | +- const auto localFiles = scanForTemplateFiles(group, mod); |
| 120 | +- std::copy(localFiles.begin(), localFiles.end(), std::back_inserter(_templateFiles)); |
| 121 | ++ for (const auto& modPath : modPaths()) { |
| 122 | ++ if (fs::exists(modPath) && fs::is_directory(modPath)) { |
| 123 | ++ for (const auto& mod : fs::directory_iterator(modPath)) { |
| 124 | ++ group = mod.path().filename().string(); |
| 125 | ++ const auto localFiles = scanForTemplateFiles(group, mod); |
| 126 | ++ std::copy(localFiles.begin(), localFiles.end(), std::back_inserter(_templateFiles)); |
| 127 | ++ } |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | +diff --git a/src/Gui/PreferencePackManager.h b/src/Gui/PreferencePackManager.h |
| 132 | +index 301e160df2..e5776e47a0 100644 |
| 133 | +--- a/src/Gui/PreferencePackManager.h |
| 134 | ++++ b/src/Gui/PreferencePackManager.h |
| 135 | +@@ -191,6 +191,11 @@ namespace Gui { |
| 136 | + */ |
| 137 | + void importConfig(const std::string &packName, const boost::filesystem::path &path); |
| 138 | + |
| 139 | ++ /** |
| 140 | ++ * Get a list of all mod directories. |
| 141 | ++ */ |
| 142 | ++ std::vector<boost::filesystem::path> modPaths() const; |
| 143 | ++ |
| 144 | + private: |
| 145 | + |
| 146 | + void FindPreferencePacksInPackage(const boost::filesystem::path& mod); |
| 147 | +-- |
| 148 | +2.44.1 |
| 149 | + |
0 commit comments