Simplify game settings branch upgrade handling

This commit is contained in:
Oliver Hamlet
2016-07-27 23:01:40 +01:00
parent bcdf5afdf5
commit c92769e5f4
3 changed files with 10 additions and 8 deletions
+7 -7
View File
@@ -35,6 +35,11 @@ using std::recursive_mutex;
using std::string;
namespace loot {
const std::set<std::string> LootSettings::oldDefaultBranches({
"master",
"v0.7",
});
LootSettings::WindowPosition::WindowPosition() : top(0), bottom(0), left(0), right(0) {}
LootSettings::LootSettings() :
@@ -253,17 +258,12 @@ void LootSettings::upgradeYaml(YAML::Node& yaml) {
for (auto node : yaml["games"]) {
if (node["url"]) {
node["repo"] = node["url"];
node["branch"] = "v0.8";
node["branch"] = "master"; // It'll get updated to the correct default
}
}
}
if (yaml["games"]) {
const std::set<string> oldDefaultBranches({
"master",
"v0.7",
});
// Handle exception if YAML is invalid, eg. if an unrecognised
// game type is used (which can happen if downgrading from a
// later version of LOOT that supports more game types).
@@ -280,7 +280,7 @@ void LootSettings::upgradeYaml(YAML::Node& yaml) {
// repositories are used.
if (settings.RepoURL() == GameSettings(settings.Type()).RepoURL()
&& oldDefaultBranches.count(settings.RepoBranch()) == 1) {
settings.SetRepoBranch("v0.8");
settings.SetRepoBranch(GameSettings(settings.Type()).RepoBranch());
}
}
+2
View File
@@ -71,6 +71,8 @@ public:
YAML::Node toYaml() const;
private:
static const std::set<std::string> oldDefaultBranches;
static void upgradeYaml(YAML::Node& yaml);
bool enableDebugLogging_;
+1 -1
View File
@@ -215,7 +215,7 @@ TEST_F(LootSettingsTest, loadingFromYamlShouldUpgradeFromVersion0Point6Format) {
EXPECT_EQ(Games[0].Name(), settings_.getGameSettings()[0].Name());
EXPECT_EQ(Games[0].RepoURL(), settings_.getGameSettings()[0].RepoURL());
EXPECT_EQ(Games[0].RepoBranch(), settings_.getGameSettings()[0].RepoBranch());
EXPECT_EQ("master", settings_.getGameSettings()[0].RepoBranch());
}
TEST_F(LootSettingsTest, loadingFromYamlShouldNotUpgradeVersion0Point6SettingsIfEquivalentsAlreadyExist) {