diff options
Diffstat (limited to 'src/StardewModdingAPI.Toolkit')
8 files changed, 73 insertions, 22 deletions
diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModExtendedMetadataModel.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModExtendedMetadataModel.cs index 247730d7..c9d9f916 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModExtendedMetadataModel.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModExtendedMetadataModel.cs @@ -28,6 +28,9 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi /// <summary>The mod ID in the Chucklefish mod repo.</summary> public int? ChucklefishID { get; set; } + /// <summary>The mod ID in the ModDrop mod repo.</summary> + public int? ModDropID { get; set; } + /// <summary>The GitHub repository in the form 'owner/repo'.</summary> public string GitHubRepo { get; set; } @@ -77,6 +80,7 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi this.Name = wiki.Name.FirstOrDefault(); this.NexusID = wiki.NexusID; this.ChucklefishID = wiki.ChucklefishID; + this.ModDropID = wiki.ModDropID; this.GitHubRepo = wiki.GitHubRepo; this.CustomSourceUrl = wiki.CustomSourceUrl; this.CustomUrl = wiki.CustomUrl; diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs index 7197bf2c..91078b08 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs @@ -52,6 +52,8 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki // fetch game versions string stableVersion = doc.DocumentNode.SelectSingleNode("div[@class='game-stable-version']")?.InnerText; string betaVersion = doc.DocumentNode.SelectSingleNode("div[@class='game-beta-version']")?.InnerText; + if (betaVersion == stableVersion) + betaVersion = null; // find mod entries HtmlNodeCollection modNodes = doc.DocumentNode.SelectNodes("table[@id='mod-list']//tr[@class='mod']"); @@ -91,6 +93,7 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki string[] warnings = this.GetAttributeAsCsv(node, "data-warnings"); int? nexusID = this.GetAttributeAsNullableInt(node, "data-nexus-id"); int? chucklefishID = this.GetAttributeAsNullableInt(node, "data-cf-id"); + int? modDropID = this.GetAttributeAsNullableInt(node, "data-moddrop-id"); string githubRepo = this.GetAttribute(node, "data-github"); string customSourceUrl = this.GetAttribute(node, "data-custom-source"); string customUrl = this.GetAttribute(node, "data-url"); @@ -131,6 +134,7 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki Author = authors, NexusID = nexusID, ChucklefishID = chucklefishID, + ModDropID = modDropID, GitHubRepo = githubRepo, CustomSourceUrl = customSourceUrl, CustomUrl = customUrl, diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModEntry.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModEntry.cs index ce8d6c5f..f7b7839b 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModEntry.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModEntry.cs @@ -21,6 +21,9 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki /// <summary>The mod ID in the Chucklefish mod repo.</summary> public int? ChucklefishID { get; set; } + /// <summary>The mod ID in the ModDrop mod repo.</summary> + public int? ModDropID { get; set; } + /// <summary>The GitHub repository in the form 'owner/repo'.</summary> public string GitHubRepo { get; set; } diff --git a/src/StardewModdingAPI.Toolkit/Framework/ModScanning/ModScanner.cs b/src/StardewModdingAPI.Toolkit/Framework/ModScanning/ModScanner.cs index 106c294f..61d0d6f2 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/ModScanning/ModScanner.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/ModScanning/ModScanner.cs @@ -90,6 +90,14 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning } } + // normalise display fields + if (manifest != null) + { + manifest.Name = this.StripNewlines(manifest.Name); + manifest.Description = this.StripNewlines(manifest.Description); + manifest.Author = this.StripNewlines(manifest.Author); + } + return new ModFolder(root, manifestFile.Directory, manifest, manifestError); } @@ -164,5 +172,12 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning { return !this.IgnoreFilesystemEntries.Contains(entry.Name); } + + /// <summary>Strip newlines from a string.</summary> + /// <param name="input">The input to strip.</param> + private string StripNewlines(string input) + { + return input?.Replace("\r", "").Replace("\n", ""); + } } } diff --git a/src/StardewModdingAPI.Toolkit/Framework/UpdateData/ModRepositoryKey.cs b/src/StardewModdingAPI.Toolkit/Framework/UpdateData/ModRepositoryKey.cs index 7ca32f04..f6c402d5 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/UpdateData/ModRepositoryKey.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/UpdateData/ModRepositoryKey.cs @@ -12,6 +12,9 @@ namespace StardewModdingAPI.Toolkit.Framework.UpdateData /// <summary>A GitHub project containing releases.</summary> GitHub, + /// <summary>The ModDrop mod repository.</summary> + ModDrop, + /// <summary>The Nexus Mods mod repository.</summary> Nexus } diff --git a/src/StardewModdingAPI.Toolkit/SemanticVersion.cs b/src/StardewModdingAPI.Toolkit/SemanticVersion.cs index a7990d13..19da0a76 100644 --- a/src/StardewModdingAPI.Toolkit/SemanticVersion.cs +++ b/src/StardewModdingAPI.Toolkit/SemanticVersion.cs @@ -40,14 +40,16 @@ namespace StardewModdingAPI.Toolkit public int PatchVersion { get; } /// <summary>An optional prerelease tag.</summary> - [Obsolete("Use " + nameof(ISemanticVersion.PrereleaseTag) + " instead")] - public string Build => this.PrereleaseTag; + public string PrereleaseTag { get; } +#if !SMAPI_3_0_STRICT /// <summary>An optional prerelease tag.</summary> - public string PrereleaseTag { get; } + [Obsolete("Use " + nameof(ISemanticVersion.PrereleaseTag) + " instead")] + public string Build => this.PrereleaseTag; /// <summary>Whether the version was parsed from the legacy object format.</summary> public bool IsLegacyFormat { get; } +#endif /********* @@ -57,15 +59,21 @@ namespace StardewModdingAPI.Toolkit /// <param name="major">The major version incremented for major API changes.</param> /// <param name="minor">The minor version incremented for backwards-compatible changes.</param> /// <param name="patch">The patch version for backwards-compatible fixes.</param> - /// <param name="tag">An optional prerelease tag.</param> + /// <param name="prereleaseTag">An optional prerelease tag.</param> /// <param name="isLegacyFormat">Whether the version was parsed from the legacy object format.</param> - public SemanticVersion(int major, int minor, int patch, string tag = null, bool isLegacyFormat = false) + public SemanticVersion(int major, int minor, int patch, string prereleaseTag = null +#if !SMAPI_3_0_STRICT + , bool isLegacyFormat = false +#endif + ) { this.MajorVersion = major; this.MinorVersion = minor; this.PatchVersion = patch; - this.PrereleaseTag = this.GetNormalisedTag(tag); + this.PrereleaseTag = this.GetNormalisedTag(prereleaseTag); +#if !SMAPI_3_0_STRICT this.IsLegacyFormat = isLegacyFormat; +#endif this.AssertValid(); } @@ -114,7 +122,7 @@ namespace StardewModdingAPI.Toolkit { if (other == null) throw new ArgumentNullException(nameof(other)); - return this.CompareTo(other.MajorVersion, other.MinorVersion, other.PatchVersion, other.Build); + return this.CompareTo(other.MajorVersion, other.MinorVersion, other.PatchVersion, other.PrereleaseTag); } /// <summary>Indicates whether the current object is equal to another object of the same type.</summary> @@ -128,7 +136,7 @@ namespace StardewModdingAPI.Toolkit /// <summary>Whether this is a pre-release version.</summary> public bool IsPrerelease() { - return !string.IsNullOrWhiteSpace(this.Build); + return !string.IsNullOrWhiteSpace(this.PrereleaseTag); } /// <summary>Get whether this version is older than the specified version.</summary> @@ -187,7 +195,7 @@ namespace StardewModdingAPI.Toolkit : $"{this.MajorVersion}.{this.MinorVersion}"; // tag - string tag = this.Build; + string tag = this.PrereleaseTag; if (tag != null) result += $"-{tag}"; return result; @@ -241,11 +249,11 @@ namespace StardewModdingAPI.Toolkit return this.MinorVersion.CompareTo(otherMinor); if (this.PatchVersion != otherPatch) return this.PatchVersion.CompareTo(otherPatch); - if (this.Build == otherTag) + if (this.PrereleaseTag == otherTag) return same; // stable supercedes pre-release - bool curIsStable = string.IsNullOrWhiteSpace(this.Build); + bool curIsStable = string.IsNullOrWhiteSpace(this.PrereleaseTag); bool otherIsStable = string.IsNullOrWhiteSpace(otherTag); if (curIsStable) return curNewer; @@ -253,7 +261,7 @@ namespace StardewModdingAPI.Toolkit return curOlder; // compare two pre-release tag values - string[] curParts = this.Build.Split('.', '-'); + string[] curParts = this.PrereleaseTag.Split('.', '-'); string[] otherParts = otherTag.Split('.', '-'); for (int i = 0; i < curParts.Length; i++) { @@ -292,11 +300,11 @@ namespace StardewModdingAPI.Toolkit throw new FormatException($"{this} isn't a valid semantic version. The major, minor, and patch numbers can't be negative."); if (this.MajorVersion == 0 && this.MinorVersion == 0 && this.PatchVersion == 0) throw new FormatException($"{this} isn't a valid semantic version. At least one of the major, minor, and patch numbers must be more than zero."); - if (this.Build != null) + if (this.PrereleaseTag != null) { - if (this.Build.Trim() == "") + if (this.PrereleaseTag.Trim() == "") throw new FormatException($"{this} isn't a valid semantic version. The tag cannot be a blank string (but may be omitted)."); - if (!Regex.IsMatch(this.Build, $"^{SemanticVersion.TagPattern}$", RegexOptions.IgnoreCase)) + if (!Regex.IsMatch(this.PrereleaseTag, $"^{SemanticVersion.TagPattern}$", RegexOptions.IgnoreCase)) throw new FormatException($"{this} isn't a valid semantic version. The tag is invalid."); } } 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 /// <param name="obj">The JSON object to read.</param> private ISemanticVersion ReadObject(JObject obj) { - int major = obj.ValueIgnoreCase<int>("MajorVersion"); - int minor = obj.ValueIgnoreCase<int>("MinorVersion"); - int patch = obj.ValueIgnoreCase<int>("PatchVersion"); - string build = obj.ValueIgnoreCase<string>("Build"); - if (build == "0") - build = null; // '0' from incorrect examples in old SMAPI documentation + int major = obj.ValueIgnoreCase<int>(nameof(ISemanticVersion.MajorVersion)); + int minor = obj.ValueIgnoreCase<int>(nameof(ISemanticVersion.MinorVersion)); + int patch = obj.ValueIgnoreCase<int>(nameof(ISemanticVersion.PatchVersion)); + string prereleaseTag = obj.ValueIgnoreCase<string>(nameof(ISemanticVersion.PrereleaseTag)); +#if !SMAPI_3_0_STRICT + if (string.IsNullOrWhiteSpace(prereleaseTag)) + { + prereleaseTag = obj.ValueIgnoreCase<string>("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 + ); } /// <summary>Read a JSON string.</summary> diff --git a/src/StardewModdingAPI.Toolkit/StardewModdingAPI.Toolkit.csproj b/src/StardewModdingAPI.Toolkit/StardewModdingAPI.Toolkit.csproj index 3fa28d19..29667b1e 100644 --- a/src/StardewModdingAPI.Toolkit/StardewModdingAPI.Toolkit.csproj +++ b/src/StardewModdingAPI.Toolkit/StardewModdingAPI.Toolkit.csproj @@ -7,6 +7,10 @@ <DocumentationFile>..\..\bin\$(Configuration)\SMAPI.Toolkit\$(TargetFramework)\StardewModdingAPI.Toolkit.xml</DocumentationFile> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)'=='Debug'"> + <DefineConstants>$(DefineConstants);SMAPI_3_0_STRICT</DefineConstants> + </PropertyGroup> + <ItemGroup> <Compile Include="..\..\build\GlobalAssemblyInfo.cs" Link="Properties\GlobalAssemblyInfo.cs" /> </ItemGroup> |