Refactor old repository branches storage

This commit is contained in:
Oliver Hamlet
2016-10-22 11:41:16 +01:00
parent 2c8b7e455d
commit 829fac4acf
5 changed files with 27 additions and 9 deletions
+1 -7
View File
@@ -35,12 +35,6 @@ using std::recursive_mutex;
using std::string;
namespace loot {
const std::set<std::string> LootSettings::oldDefaultBranches({
"master",
"v0.7",
"v0.8",
});
LootSettings::WindowPosition::WindowPosition() : top(0), bottom(0), left(0), right(0) {}
LootSettings::LootSettings() :
@@ -280,7 +274,7 @@ void LootSettings::upgradeYaml(YAML::Node& yaml) {
// Update existing default branch, if the default
// repositories are used.
if (settings.RepoURL() == GameSettings(settings.Type()).RepoURL()
&& oldDefaultBranches.count(settings.RepoBranch()) == 1) {
&& settings.IsRepoBranchOldDefault()) {
settings.SetRepoBranch(GameSettings(settings.Type()).RepoBranch());
}
}
-2
View File
@@ -71,8 +71,6 @@ public:
YAML::Node toYaml() const;
private:
static const std::set<std::string> oldDefaultBranches;
static void upgradeYaml(YAML::Node& yaml);
bool enableDebugLogging_;
+10
View File
@@ -34,6 +34,12 @@
namespace fs = boost::filesystem;
namespace loot {
const std::set<std::string> GameSettings::oldDefaultBranches({
"master",
"v0.7",
"v0.8",
});
GameSettings::GameSettings() : type_(GameType::tes4) {}
GameSettings::GameSettings(const GameType gameCode, const std::string& folder) : type_(gameCode), repositoryBranch_("v0.10") {
@@ -101,6 +107,10 @@ bool GameSettings::IsInstalled() {
return false;
}
bool GameSettings::IsRepoBranchOldDefault() const {
return oldDefaultBranches.count(repositoryBranch_) == 1;
}
bool GameSettings::operator == (const GameSettings& rhs) const {
return (boost::iequals(name_, rhs.Name()) || boost::iequals(lootFolderName_, rhs.FolderName()));
}
+3
View File
@@ -41,6 +41,7 @@ public:
GameSettings(const GameType gameType, const std::string& lootFolder = "");
bool IsInstalled(); //Sets gamePath if the current value is not valid and a valid path is found.
bool IsRepoBranchOldDefault() const;
bool operator == (const GameSettings& rhs) const; //Compares names and folder names.
@@ -68,6 +69,8 @@ public:
GameSettings& SetGamePath(const boost::filesystem::path& path);
private:
static const std::set<std::string> oldDefaultBranches;
GameType type_;
std::string name_;
std::string masterFile_;
@@ -98,6 +98,19 @@ TEST_P(GameSettingsTest, isInstalledShouldBeTrueIfGamePathIsValid) {
EXPECT_TRUE(settings_.IsInstalled());
}
TEST_P(GameSettingsTest, isRepoBranchOldDefaultShouldBeTrueIfValueIsMaster) {
settings_ = GameSettings(GameType::tes5);
settings_.SetRepoBranch("master");
EXPECT_TRUE(settings_.IsRepoBranchOldDefault());
}
TEST_P(GameSettingsTest, isRepoBranchOldDefaultShouldBeFalseIfValueIsTheDefault) {
settings_ = GameSettings(GameType::tes5);
EXPECT_FALSE(settings_.IsRepoBranchOldDefault());
}
TEST_P(GameSettingsTest, gameSettingsWithTheSameIdsShouldBeEqual) {
GameSettings game1 = GameSettings(GameType::tes5, "game1")
.SetMaster("master1")