Skip to content

Commit

Permalink
Gui: take in account module-path argument
Browse files Browse the repository at this point in the history
Use paths passed with `--module-path` argument to search for preference
packs

Change-Id: If168dbd99a826757290ee6b918f5b712305fe2bb
  • Loading branch information
ein-shved authored and wwmayer committed Nov 27, 2024
1 parent fb7ce64 commit 8e04c0a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
16 changes: 9 additions & 7 deletions src/Gui/DlgPreferencePackManagementImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void DlgPreferencePackManagementImp::showEvent(QShowEvent* event)
// but can only disable individual installed packs (though we can completely uninstall the pack's
// containing Addon by redirecting to the Addon Manager).
auto savedPreferencePacksDirectory = fs::path(App::Application::getUserAppDataDir()) / "SavedPreferencePacks";
auto modDirectory = fs::path(App::Application::getUserAppDataDir()) / "Mod";
auto modDirectories = Application::Instance->prefPackManager()->modPaths();
auto resourcePath = fs::path(App::Application::getResourceDir()) / "Gui" / "PreferencePacks";

// The displayed tree has two levels: at the toplevel is either "User-Saved Packs" or the name
Expand All @@ -66,12 +66,14 @@ void DlgPreferencePackManagementImp::showEvent(QShowEvent* event)
auto builtinPacks = getPacksFromDirectory(resourcePath);

std::map<std::string, std::vector<std::string>> installedPacks;
if (fs::exists(modDirectory) && fs::is_directory(modDirectory)) {
for (const auto& mod : fs::directory_iterator(modDirectory)) {
auto packs = getPacksFromDirectory(mod);
if (!packs.empty()) {
auto modName = mod.path().filename().string();
installedPacks.emplace(modName, packs);
for (const auto& modDirectory : modDirectories) {
if (fs::exists(modDirectory) && fs::is_directory(modDirectory)) {
for (const auto& mod : fs::directory_iterator(modDirectory)) {
auto packs = getPacksFromDirectory(mod);
if (!packs.empty()) {
auto modName = mod.path().filename().string();
installedPacks.emplace(modName, packs);
}
}
}
}
Expand Down
39 changes: 30 additions & 9 deletions src/Gui/PreferencePackManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#endif

#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
#include <QDir>

#include "PreferencePackManager.h"
Expand Down Expand Up @@ -134,12 +135,11 @@ void PreferencePack::applyConfigChanges() const
}

PreferencePackManager::PreferencePackManager()
: _preferencePackPaths(modPaths())
{
auto modPath = fs::path(Base::FileInfo::stringToPath(App::Application::getUserAppDataDir())) / "Mod";
auto savedPath = fs::path(Base::FileInfo::stringToPath(App::Application::getUserAppDataDir())) / "SavedPreferencePacks";
auto resourcePath = fs::path(Base::FileInfo::stringToPath(App::Application::getResourceDir())) / "Gui" / "PreferencePacks";
_preferencePackPaths.push_back(resourcePath);
_preferencePackPaths.push_back(modPath);
_preferencePackPaths.insert(_preferencePackPaths.begin(), resourcePath);
_preferencePackPaths.push_back(savedPath);
rescan();

Expand Down Expand Up @@ -232,6 +232,26 @@ void Gui::PreferencePackManager::importConfig(const std::string& packName,
rescan();
}

// TODO(Shvedov): Is this suitable place for this method? It is more generic,
// and maybe more suitable place at Application?
std::vector<boost::filesystem::path> Gui::PreferencePackManager::modPaths() const
{
auto userModPath = fs::path(Base::FileInfo::stringToPath(App::Application::getUserAppDataDir())) / "Mod";

auto& config = App::Application::Config();
auto additionalModules = config.find("AdditionalModulePaths");
std::vector<boost::filesystem::path> result;

if (additionalModules != config.end()) {
boost::split(result,
additionalModules->second,
boost::is_any_of(";"),
boost::token_compress_on);
}
result.emplace_back(userModPath);
return result;
}

void Gui::PreferencePackManager::FindPreferencePacksInPackage(const fs::path &mod)
{
try {
Expand Down Expand Up @@ -528,19 +548,20 @@ std::vector<PreferencePackManager::TemplateFile> PreferencePackManager::template
// (alternate spellings are provided for packages using CamelCase and snake_case, and both major English dialects)

auto resourcePath = fs::path(Base::FileInfo::stringToPath(App::Application::getResourceDir())) / "Gui";
auto modPath = fs::path(Base::FileInfo::stringToPath(App::Application::getUserAppDataDir())) / "Mod";

std::string group = "Built-In";
if (fs::exists(resourcePath) && fs::is_directory(resourcePath)) {
const auto localFiles = scanForTemplateFiles(group, resourcePath);
std::copy(localFiles.begin(), localFiles.end(), std::back_inserter(_templateFiles));
}

if (fs::exists(modPath) && fs::is_directory(modPath)) {
for (const auto& mod : fs::directory_iterator(modPath)) {
group = Base::FileInfo::pathToString(mod.path().filename());
const auto localFiles = scanForTemplateFiles(group, mod);
std::copy(localFiles.begin(), localFiles.end(), std::back_inserter(_templateFiles));
for (const auto& modPath : modPaths()) {
if (fs::exists(modPath) && fs::is_directory(modPath)) {
for (const auto& mod : fs::directory_iterator(modPath)) {
group = Base::FileInfo::pathToString(mod.path().filename());
const auto localFiles = scanForTemplateFiles(group, mod);
std::copy(localFiles.begin(), localFiles.end(), std::back_inserter(_templateFiles));
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Gui/PreferencePackManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ namespace Gui {
*/
void importConfig(const std::string &packName, const boost::filesystem::path &path);

/**
* Get a list of all mod directories.
*/
std::vector<boost::filesystem::path> modPaths() const;

private:

void FindPreferencePacksInPackage(const boost::filesystem::path& mod);
Expand Down

0 comments on commit 8e04c0a

Please sign in to comment.