summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/GameVersion.cs30
1 files changed, 9 insertions, 21 deletions
diff --git a/src/SMAPI/Framework/GameVersion.cs b/src/SMAPI/Framework/GameVersion.cs
index 29cfbc39..07957624 100644
--- a/src/SMAPI/Framework/GameVersion.cs
+++ b/src/SMAPI/Framework/GameVersion.cs
@@ -3,8 +3,8 @@ using System.Collections.Generic;
namespace StardewModdingAPI.Framework
{
- /// <summary>An implementation of <see cref="ISemanticVersion"/> that correctly handles the non-semantic versions used by older Stardew Valley releases.</summary>
- internal class GameVersion : SemanticVersion
+ /// <summary>An extension of <see cref="ISemanticVersion"/> that correctly handles non-semantic versions used by Stardew Valley.</summary>
+ internal class GameVersion : Toolkit.SemanticVersion
{
/*********
** Private methods
@@ -18,11 +18,11 @@ namespace StardewModdingAPI.Framework
["1.03"] = "1.0.3",
["1.04"] = "1.0.4",
["1.05"] = "1.0.5",
- ["1.051"] = "1.0.6-prerelease1", // not a very good mapping, but good enough for SMAPI's purposes.
- ["1.051b"] = "1.0.6-prerelease2",
+ ["1.051"] = "1.0.5.1",
+ ["1.051b"] = "1.0.5.2",
["1.06"] = "1.0.6",
["1.07"] = "1.0.7",
- ["1.07a"] = "1.0.8-prerelease1",
+ ["1.07a"] = "1.0.7.1",
["1.08"] = "1.0.8",
["1.1"] = "1.1.0",
["1.2"] = "1.2.0",
@@ -36,7 +36,7 @@ namespace StardewModdingAPI.Framework
/// <summary>Construct an instance.</summary>
/// <param name="version">The game version string.</param>
public GameVersion(string version)
- : base(GameVersion.GetSemanticVersionString(version)) { }
+ : base(GameVersion.GetSemanticVersionString(version), allowNonStandard: true) { }
/// <summary>Get a string representation of the version.</summary>
public override string ToString()
@@ -53,33 +53,21 @@ namespace StardewModdingAPI.Framework
private static string GetSemanticVersionString(string gameVersion)
{
// mapped version
- if (GameVersion.VersionMap.TryGetValue(gameVersion, out string semanticVersion))
- return semanticVersion;
-
- // special case: four-part versions
- string[] parts = gameVersion.Split('.');
- if (parts.Length == 4)
- return $"{parts[0]}.{parts[1]}.{parts[2]}+{parts[3]}";
-
- return gameVersion;
+ return GameVersion.VersionMap.TryGetValue(gameVersion, out string semanticVersion)
+ ? semanticVersion
+ : gameVersion;
}
/// <summary>Convert a semantic version string to the equivalent game version string.</summary>
/// <param name="semanticVersion">The semantic version string.</param>
private static string GetGameVersionString(string semanticVersion)
{
- // mapped versions
foreach (var mapping in GameVersion.VersionMap)
{
if (mapping.Value.Equals(semanticVersion, StringComparison.InvariantCultureIgnoreCase))
return mapping.Key;
}
- // special case: four-part versions
- string[] parts = semanticVersion.Split('.', '+');
- if (parts.Length == 4)
- return $"{parts[0]}.{parts[1]}.{parts[2]}.{parts[3]}";
-
return semanticVersion;
}
}