diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-02-20 21:32:55 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-02-20 21:32:55 -0500 |
commit | dd27b3bf35d01e4fd0703e47d538bd8cec03652b (patch) | |
tree | 3f3b00c4c1b9cb5fafcfc975e8de7e999b1dc36b /src/SMAPI.Toolkit/Serialization | |
parent | 6a9bf10a81f4557d44668666117d99440d99d873 (diff) | |
download | SMAPI-dd27b3bf35d01e4fd0703e47d538bd8cec03652b.tar.gz SMAPI-dd27b3bf35d01e4fd0703e47d538bd8cec03652b.tar.bz2 SMAPI-dd27b3bf35d01e4fd0703e47d538bd8cec03652b.zip |
fix parsing four-part versions from the update-check API
Diffstat (limited to 'src/SMAPI.Toolkit/Serialization')
-rw-r--r-- | src/SMAPI.Toolkit/Serialization/Converters/NonStandardSemanticVersionConverter.cs | 15 | ||||
-rw-r--r-- | src/SMAPI.Toolkit/Serialization/Converters/SemanticVersionConverter.cs | 9 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/SMAPI.Toolkit/Serialization/Converters/NonStandardSemanticVersionConverter.cs b/src/SMAPI.Toolkit/Serialization/Converters/NonStandardSemanticVersionConverter.cs new file mode 100644 index 00000000..6f870bcf --- /dev/null +++ b/src/SMAPI.Toolkit/Serialization/Converters/NonStandardSemanticVersionConverter.cs @@ -0,0 +1,15 @@ +namespace StardewModdingAPI.Toolkit.Serialization.Converters +{ + /// <summary>Handles deserialization of <see cref="ISemanticVersion"/>, allowing for non-standard extensions.</summary> + internal class NonStandardSemanticVersionConverter : SemanticVersionConverter + { + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + public NonStandardSemanticVersionConverter() + { + this.AllowNonStandard = true; + } + } +} diff --git a/src/SMAPI.Toolkit/Serialization/Converters/SemanticVersionConverter.cs b/src/SMAPI.Toolkit/Serialization/Converters/SemanticVersionConverter.cs index e1b9db1d..3604956b 100644 --- a/src/SMAPI.Toolkit/Serialization/Converters/SemanticVersionConverter.cs +++ b/src/SMAPI.Toolkit/Serialization/Converters/SemanticVersionConverter.cs @@ -8,6 +8,13 @@ namespace StardewModdingAPI.Toolkit.Serialization.Converters internal class SemanticVersionConverter : JsonConverter { /********* + ** Fields + *********/ + /// <summary>Whether to allow non-standard extensions to semantic versioning.</summary> + protected bool AllowNonStandard { get; set; } + + + /********* ** Accessors *********/ /// <summary>Get whether this converter can read JSON.</summary> @@ -78,7 +85,7 @@ namespace StardewModdingAPI.Toolkit.Serialization.Converters { if (string.IsNullOrWhiteSpace(str)) return null; - if (!SemanticVersion.TryParse(str, out ISemanticVersion version)) + if (!SemanticVersion.TryParse(str, allowNonStandard: this.AllowNonStandard, out ISemanticVersion version)) throw new SParseException($"Can't parse semantic version from invalid value '{str}', should be formatted like 1.2, 1.2.30, or 1.2.30-beta (path: {path})."); return version; } |