From 06257a510f96db331855681c98d42af035fda018 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 4 Dec 2018 20:00:29 -0500 Subject: update version parsing code (#606) --- .../Converters/SemanticVersionConverter.cs | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/StardewModdingAPI.Toolkit/Serialisation/Converters') diff --git a/src/StardewModdingAPI.Toolkit/Serialisation/Converters/SemanticVersionConverter.cs b/src/StardewModdingAPI.Toolkit/Serialisation/Converters/SemanticVersionConverter.cs index e0e185c9..aca06849 100644 --- a/src/StardewModdingAPI.Toolkit/Serialisation/Converters/SemanticVersionConverter.cs +++ b/src/StardewModdingAPI.Toolkit/Serialisation/Converters/SemanticVersionConverter.cs @@ -63,14 +63,24 @@ namespace StardewModdingAPI.Toolkit.Serialisation.Converters /// The JSON object to read. private ISemanticVersion ReadObject(JObject obj) { - int major = obj.ValueIgnoreCase("MajorVersion"); - int minor = obj.ValueIgnoreCase("MinorVersion"); - int patch = obj.ValueIgnoreCase("PatchVersion"); - string build = obj.ValueIgnoreCase("Build"); - if (build == "0") - build = null; // '0' from incorrect examples in old SMAPI documentation + int major = obj.ValueIgnoreCase(nameof(ISemanticVersion.MajorVersion)); + int minor = obj.ValueIgnoreCase(nameof(ISemanticVersion.MinorVersion)); + int patch = obj.ValueIgnoreCase(nameof(ISemanticVersion.PatchVersion)); + string prereleaseTag = obj.ValueIgnoreCase(nameof(ISemanticVersion.PrereleaseTag)); +#if !SMAPI_3_0_STRICT + if (string.IsNullOrWhiteSpace(prereleaseTag)) + { + prereleaseTag = obj.ValueIgnoreCase("Build"); + if (prereleaseTag == "0") + prereleaseTag = null; // '0' from incorrect examples in old SMAPI documentation + } +#endif - return new SemanticVersion(major, minor, patch, build, isLegacyFormat: true); + return new SemanticVersion(major, minor, patch, prereleaseTag +#if !SMAPI_3_0_STRICT + , isLegacyFormat: true +#endif + ); } /// Read a JSON string. -- cgit