Split GameSettings::SetDetails() up.

It's clearer this way, and avoids a couple of cases of unnecessary
arguments.
This commit is contained in:
Oliver Hamlet
2015-07-12 18:37:14 +01:00
parent 2db5519375
commit d2f8f36120
5 changed files with 66 additions and 61 deletions
+1 -1
View File
@@ -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);
}
+8 -8
View File
@@ -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();
+34 -37
View File
@@ -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<GameSettings> GetGameSettings(YAML::Node& settings) {
+13 -13
View File
@@ -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<std::string>();
rhs.SetName(node["name"].as<std::string>());
if (node["master"])
master = node["master"].as<std::string>();
rhs.SetMaster(node["master"].as<std::string>());
if (node["repo"])
repo = node["repo"].as<std::string>();
rhs.SetRepoURL(node["repo"].as<std::string>());
if (node["branch"])
branch = node["branch"].as<std::string>();
rhs.SetRepoBranch(node["branch"].as<std::string>());
if (node["path"])
path = node["path"].as<std::string>();
rhs.SetGamePath(node["path"].as<std::string>());
if (node["registry"])
registry = node["registry"].as<std::string>();
rhs.SetDetails(name, master, repo, branch, path, registry);
rhs.SetRegistryKey(node["registry"].as<std::string>());
return true;
}
+10 -2
View File
@@ -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;
}