diff options
Diffstat (limited to 'src/SMAPI.Toolkit')
6 files changed, 46 insertions, 7 deletions
diff --git a/src/SMAPI.Toolkit/Framework/Clients/WebApi/ModEntryVersionModel.cs b/src/SMAPI.Toolkit/Framework/Clients/WebApi/ModEntryVersionModel.cs index dadb8c10..188db31d 100644 --- a/src/SMAPI.Toolkit/Framework/Clients/WebApi/ModEntryVersionModel.cs +++ b/src/SMAPI.Toolkit/Framework/Clients/WebApi/ModEntryVersionModel.cs @@ -1,3 +1,6 @@ +using Newtonsoft.Json; +using StardewModdingAPI.Toolkit.Serialization.Converters; + namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi { /// <summary>Metadata about a version.</summary> @@ -7,6 +10,7 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi ** Accessors *********/ /// <summary>The version number.</summary> + [JsonConverter(typeof(NonStandardSemanticVersionConverter))] public ISemanticVersion Version { get; set; } /// <summary>The mod page URL.</summary> diff --git a/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj b/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj index 16a97dbf..a7de7166 100644 --- a/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj +++ b/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj @@ -12,7 +12,7 @@ </PropertyGroup> <ItemGroup> - <PackageReference Include="HtmlAgilityPack" Version="1.11.18" /> + <PackageReference Include="HtmlAgilityPack" Version="1.11.20" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Pathoschild.Http.FluentClient" Version="3.3.1" /> <PackageReference Include="System.Management" Version="4.5.0" Condition="'$(OS)' == 'Windows_NT'" /> diff --git a/src/SMAPI.Toolkit/SemanticVersion.cs b/src/SMAPI.Toolkit/SemanticVersion.cs index 5ead6dc8..86db2820 100644 --- a/src/SMAPI.Toolkit/SemanticVersion.cs +++ b/src/SMAPI.Toolkit/SemanticVersion.cs @@ -199,18 +199,19 @@ namespace StardewModdingAPI.Toolkit /// <returns>Returns whether parsing the version succeeded.</returns> public static bool TryParse(string version, out ISemanticVersion parsed) { - return SemanticVersion.TryParseNonStandard(version, out parsed) && !parsed.IsNonStandard(); + return SemanticVersion.TryParse(version, allowNonStandard: false, out parsed); } - /// <summary>Parse a version string without throwing an exception if it fails, including support for non-standard extensions like <see cref="IPlatformSpecificVersion"/>.</summary> + /// <summary>Parse a version string without throwing an exception if it fails.</summary> /// <param name="version">The version string.</param> + /// <param name="allowNonStandard">Whether to allow non-standard extensions to semantic versioning.</param> /// <param name="parsed">The parsed representation.</param> /// <returns>Returns whether parsing the version succeeded.</returns> - public static bool TryParseNonStandard(string version, out ISemanticVersion parsed) + public static bool TryParse(string version, bool allowNonStandard, out ISemanticVersion parsed) { try { - parsed = new SemanticVersion(version, true); + parsed = new SemanticVersion(version, allowNonStandard); return true; } catch 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; } diff --git a/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs b/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs index 2a01fe4b..c45448f3 100644 --- a/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs +++ b/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs @@ -53,7 +53,19 @@ namespace StardewModdingAPI.Toolkit.Utilities } catch { } #endif - return (platform == Platform.Mac ? "MacOS " : "") + Environment.OSVersion; + + string name = Environment.OSVersion.ToString(); + switch (platform) + { + case Platform.Android: + name = $"Android {name}"; + break; + + case Platform.Mac: + name = $"MacOS {name}"; + break; + } + return name; } /// <summary>Get the name of the Stardew Valley executable.</summary> |