From d2f8f361200b71d1f0a2480317ac8aba88ad2975 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Mon, 29 Jun 2015 21:31:15 +0100 Subject: [PATCH] Split GameSettings::SetDetails() up. It's clearer this way, and avoids a couple of cases of unnecessary arguments. --- src/api/api.cpp | 2 +- src/backend/game/game.cpp | 16 +++---- src/backend/game/game_settings.cpp | 71 ++++++++++++++---------------- src/backend/game/game_settings.h | 26 +++++------ src/gui/loot_state.cpp | 12 ++++- 5 files changed, 66 insertions(+), 61 deletions(-) diff --git a/src/api/api.cpp b/src/api/api.cpp index c20c9523..0fa1da23 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -100,7 +100,7 @@ struct _loot_db_int : public loot::Game { extStringArraySize(0), extRevisionID(nullptr), extRevisionDate(nullptr) { - this->SetDetails("", "", "", "", gamePath, ""); + this->SetGamePath(gamePath); this->Init(false, gameLocalDataPath); } diff --git a/src/backend/game/game.cpp b/src/backend/game/game.cpp index 8308dd67..3868edb7 100644 --- a/src/backend/game/game.cpp +++ b/src/backend/game/game.cpp @@ -43,12 +43,12 @@ namespace loot { Game::Game() {} Game::Game(const GameSettings& gameSettings) : GameSettings(gameSettings.Id(), gameSettings.FolderName()) { - this->SetDetails(gameSettings.Name(), - gameSettings.Master(), - gameSettings.RepoURL(), - gameSettings.RepoBranch(), - gameSettings.GamePath().string(), - gameSettings.RegistryKey()); + this->SetName(gameSettings.Name()) + .SetMaster(gameSettings.Master()) + .SetRepoURL(gameSettings.RepoURL()) + .SetRepoBranch(gameSettings.RepoBranch()) + .SetGamePath(gameSettings.GamePath()) + .SetRegistryKey(gameSettings.RegistryKey()); } Game::Game(const unsigned int gameCode, const std::string& folder) : GameSettings(gameCode, folder) {} @@ -203,8 +203,8 @@ namespace loot { void Game::CreateLOOTGameFolder() { //Make sure that the LOOT game path exists. try { - if (fs::exists(g_path_local) && !fs::exists(g_path_local / _lootFolderName)) - fs::create_directory(g_path_local / _lootFolderName); + if (fs::exists(g_path_local) && !fs::exists(g_path_local / FolderName())) + fs::create_directory(g_path_local / FolderName()); } catch (fs::filesystem_error& e) { BOOST_LOG_TRIVIAL(error) << "Could not create LOOT folder for game. Details: " << e.what(); diff --git a/src/backend/game/game_settings.cpp b/src/backend/game/game_settings.cpp index 24ec554a..7919709f 100644 --- a/src/backend/game/game_settings.cpp +++ b/src/backend/game/game_settings.cpp @@ -83,43 +83,6 @@ namespace loot { _lootFolderName = folder; } - GameSettings& GameSettings::SetDetails(const std::string& name, const std::string& masterFile, - const std::string& repositoryURL, const std::string& repositoryBranch, const std::string& path, const std::string& registry) { - BOOST_LOG_TRIVIAL(info) << "Setting new details for game: " << _name; - - if (!name.empty()) { - BOOST_LOG_TRIVIAL(trace) << '\t' << "Setting name to: " << name; - _name = name; - } - - if (!masterFile.empty()) { - BOOST_LOG_TRIVIAL(trace) << '\t' << "Setting master file to: " << masterFile; - _masterFile = masterFile; - } - - if (!repositoryURL.empty()) { - BOOST_LOG_TRIVIAL(trace) << '\t' << "Setting repo URL to: " << repositoryURL; - _repositoryURL = repositoryURL; - } - - if (!repositoryBranch.empty()) { - BOOST_LOG_TRIVIAL(trace) << '\t' << "Setting repo branch to: " << repositoryBranch; - _repositoryBranch = repositoryBranch; - } - - if (!path.empty()) { - BOOST_LOG_TRIVIAL(trace) << '\t' << "Setting game path to: " << path; - _gamePath = path; - } - - if (!registry.empty()) { - BOOST_LOG_TRIVIAL(trace) << '\t' << "Setting registry key to: " << registry; - _registryKey = registry; - } - - return *this; - } - bool GameSettings::IsInstalled() { try { BOOST_LOG_TRIVIAL(trace) << "Checking if game \"" << _name << "\" is installed."; @@ -201,6 +164,40 @@ namespace loot { return g_path_local / _lootFolderName / "userlist.yaml"; } + GameSettings& GameSettings::SetName(const std::string& name) { + BOOST_LOG_TRIVIAL(trace) << "Setting \"" << _name << "\" name to: " << name; + _name = name; + return *this; + } + + GameSettings& GameSettings::SetMaster(const std::string& masterFile) { + BOOST_LOG_TRIVIAL(trace) << "Setting \"" << _name << "\" master file to: " << masterFile; + _masterFile = masterFile; + return *this; + } + + GameSettings& GameSettings::SetRegistryKey(const std::string& registry) { + BOOST_LOG_TRIVIAL(trace) << "Setting \"" << _name << "\" registry key to: " << registry; + _registryKey = registry; + return *this; + } + + GameSettings& GameSettings::SetRepoURL(const std::string& repositoryURL) { + BOOST_LOG_TRIVIAL(trace) << "Setting \"" << _name << "\" repo URL to: " << repositoryURL; + _repositoryURL = repositoryURL; + return *this; + } + + GameSettings& GameSettings::SetRepoBranch(const std::string& repositoryBranch) { + BOOST_LOG_TRIVIAL(trace) << "Setting \"" << _name << "\" repo branch to: " << repositoryBranch; + _repositoryBranch = repositoryBranch; + return *this; + } + + GameSettings& GameSettings::SetGamePath(const boost::filesystem::path& path) { + BOOST_LOG_TRIVIAL(trace) << "Setting \"" << _name << "\" game path to: " << path; + _gamePath = path; + return *this; } std::list GetGameSettings(YAML::Node& settings) { diff --git a/src/backend/game/game_settings.h b/src/backend/game/game_settings.h index dc68dd3d..e7d69ab3 100644 --- a/src/backend/game/game_settings.h +++ b/src/backend/game/game_settings.h @@ -39,10 +39,6 @@ namespace loot { GameSettings(); //Sets game to LOOT_Game::autodetect, with all other vars being empty. GameSettings(const unsigned int baseGameCode, const std::string& lootFolder = ""); - GameSettings& SetDetails(const std::string& name, const std::string& masterFile, - const std::string& repositoryURL, const std::string& repositoryBranch, - const std::string& path, const std::string& registry); - bool IsInstalled(); //Sets gamePath if the current value is not valid and a valid path is found. bool operator == (const GameSettings& rhs) const; //Compares names and folder names. @@ -61,6 +57,13 @@ namespace loot { boost::filesystem::path MasterlistPath() const; boost::filesystem::path UserlistPath() const; + GameSettings& SetName(const std::string& name); + GameSettings& SetMaster(const std::string& masterFile); + GameSettings& SetRegistryKey(const std::string& registry); + GameSettings& SetRepoURL(const std::string& repositoryURL); + GameSettings& SetRepoBranch(const std::string& repositoryBranch); + GameSettings& SetGamePath(const boost::filesystem::path& path); + static const unsigned int autodetect; static const unsigned int tes4; static const unsigned int tes5; @@ -116,21 +119,18 @@ namespace YAML { else return false; - std::string name, master, repo, branch, path, registry; if (node["name"]) - name = node["name"].as(); + rhs.SetName(node["name"].as()); if (node["master"]) - master = node["master"].as(); + rhs.SetMaster(node["master"].as()); if (node["repo"]) - repo = node["repo"].as(); + rhs.SetRepoURL(node["repo"].as()); if (node["branch"]) - branch = node["branch"].as(); + rhs.SetRepoBranch(node["branch"].as()); if (node["path"]) - path = node["path"].as(); + rhs.SetGamePath(node["path"].as()); if (node["registry"]) - registry = node["registry"].as(); - - rhs.SetDetails(name, master, repo, branch, path, registry); + rhs.SetRegistryKey(node["registry"].as()); return true; } diff --git a/src/gui/loot_state.cpp b/src/gui/loot_state.cpp index 7859e35e..d4f3a3e6 100644 --- a/src/gui/loot_state.cpp +++ b/src/gui/loot_state.cpp @@ -183,7 +183,12 @@ namespace loot { auto pos = find(_games.begin(), _games.end(), game); if (pos != _games.end()) { - pos->SetDetails(game.Name(), game.Master(), game.RepoURL(), game.RepoBranch(), game.GamePath().string(), game.RegistryKey()); + pos->SetName(game.Name()) + .SetMaster(game.Master()) + .SetRepoURL(game.RepoURL()) + .SetRepoBranch(game.RepoBranch()) + .SetGamePath(game.GamePath()) + .SetRegistryKey(game.RegistryKey()); } else { BOOST_LOG_TRIVIAL(trace) << "Adding new game entry for: " << game.FolderName(); @@ -409,8 +414,11 @@ namespace loot { GetGameSettings(root); GameSettings settings(GameSettings::tes4, "Nehrim"); + settings.SetName("Nehrim - At Fate's Edge") + .SetMaster("Nehrim.esm") + .SetRegistryKey("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Nehrim - At Fate's Edge_is1\\InstallLocation"); - root["games"].push_back(settings.SetDetails("Nehrim - At Fate's Edge", "Nehrim.esm", settings.RepoURL(), settings.RepoBranch(), "", "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Nehrim - At Fate's Edge_is1\\InstallLocation")); + root["games"].push_back(settings); return root; }