summaryrefslogtreecommitdiff
path: root/src/SMAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-12-26 10:41:39 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-12-26 10:41:39 -0500
commit8895021696fd2129af6de775e275f3bd83edf034 (patch)
treea0fbd9fe0e25309accc7d031afcd9f76260c2cf3 /src/SMAPI
parent49c192fc4772417428d490dabf93b790f82c94c9 (diff)
downloadSMAPI-8895021696fd2129af6de775e275f3bd83edf034.tar.gz
SMAPI-8895021696fd2129af6de775e275f3bd83edf034.tar.bz2
SMAPI-8895021696fd2129af6de775e275f3bd83edf034.zip
rewrite migration to avoid repeating game checks
Diffstat (limited to 'src/SMAPI')
-rw-r--r--src/SMAPI/Framework/SCore.cs34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index 6b8098cd..e05213f0 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -1061,33 +1061,29 @@ namespace StardewModdingAPI.Framework
private void ApplySaveFixes()
{
// get last SMAPI version used with this save
- const string migrationKey = "Pathoschild.SMAPI/last-version";
- if (!Game1.CustomData.TryGetValue(migrationKey, out string rawVersion) || !SemanticVersion.TryParse(rawVersion, out ISemanticVersion lastVersionRun))
- lastVersionRun = new SemanticVersion(3, 8, 0);
+ const string migrationKey = "Pathoschild.SMAPI/api-version";
+ if (!Game1.CustomData.TryGetValue(migrationKey, out string rawVersion) || !SemanticVersion.TryParse(rawVersion, out ISemanticVersion lastVersion))
+ lastVersion = new SemanticVersion(3, 8, 0);
// fix bundle corruption in SMAPI 3.8.0
// For non-English players who created a new save in SMAPI 3.8.0, bundle data was
// incorrectly translated which caused the code to crash whenever the game tried to
// read it.
- if (lastVersionRun.IsOlderThan(new SemanticVersion(3, 8, 1)))
+ if (lastVersion.IsOlderThan(new SemanticVersion(3, 8, 1)) && Game1.netWorldState?.Value?.BundleData != null)
{
- bool? hasInvalidBundleData = Game1.netWorldState?.Value
- ?.BundleData
- ?.Values
- ?.Any(raw => raw != null && raw.Split('/').Length > 5);
+ var oldData = new Dictionary<string, string>(Game1.netWorldState.Value.BundleData);
- if (hasInvalidBundleData == true)
+ try
{
- try
- {
- Game1.applySaveFix(SaveGame.SaveFixes.FixBotchedBundleData);
- this.Monitor.Log("Found corrupted community center data due to a previous version of SMAPI, and fixed it automatically.", LogLevel.Info);
- }
- catch (Exception ex)
- {
- this.Monitor.Log("Found corrupted community center data due to a previous version of SMAPI, but was unable to fix it automatically.", LogLevel.Error);
- this.Monitor.Log($"Technical details: {ex}");
- }
+ Game1.applySaveFix(SaveGame.SaveFixes.FixBotchedBundleData);
+ bool changed = Game1.netWorldState.Value.BundleData.Any(p => oldData.TryGetValue(p.Key, out string oldValue) && oldValue != p.Value);
+ if (changed)
+ this.Monitor.Log("Found broken community center bundles and fixed them automatically.", LogLevel.Info);
+ }
+ catch (Exception ex)
+ {
+ this.Monitor.Log("Failed to verify community center data.", LogLevel.Error); // should never happen
+ this.Monitor.Log($"Technical details: {ex}");
}
}