From d97b11060c310f1fa6064f02496e6a6162a44573 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 24 May 2020 00:21:51 -0400 Subject: add update subkeys --- src/SMAPI.Web/Framework/ModSiteManager.cs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/SMAPI.Web/Framework') diff --git a/src/SMAPI.Web/Framework/ModSiteManager.cs b/src/SMAPI.Web/Framework/ModSiteManager.cs index eaae7935..68b4c6ac 100644 --- a/src/SMAPI.Web/Framework/ModSiteManager.cs +++ b/src/SMAPI.Web/Framework/ModSiteManager.cs @@ -54,9 +54,10 @@ namespace StardewModdingAPI.Web.Framework /// Parse version info for the given mod page info. /// The mod page info. + /// The optional update subkey to match in available files. (If no file names or descriptions contain the subkey, it'll be ignored.) /// Maps remote versions to a semantic version for update checks. /// Whether to allow non-standard versions. - public ModInfoModel GetPageVersions(IModPage page, bool allowNonStandardVersions, IDictionary mapRemoteVersions) + public ModInfoModel GetPageVersions(IModPage page, string subkey, bool allowNonStandardVersions, IDictionary mapRemoteVersions) { // get base model ModInfoModel model = new ModInfoModel() @@ -66,7 +67,10 @@ namespace StardewModdingAPI.Web.Framework return model; // fetch versions - if (!this.TryGetLatestVersions(page, allowNonStandardVersions, mapRemoteVersions, out ISemanticVersion mainVersion, out ISemanticVersion previewVersion)) + bool hasVersions = this.TryGetLatestVersions(page, subkey, allowNonStandardVersions, mapRemoteVersions, out ISemanticVersion mainVersion, out ISemanticVersion previewVersion); + if (!hasVersions && subkey != null) + hasVersions = this.TryGetLatestVersions(page, null, allowNonStandardVersions, mapRemoteVersions, out mainVersion, out previewVersion); + if (!hasVersions) return model.SetError(RemoteModStatus.InvalidData, $"The {page.Site} mod with ID '{page.Id}' has no valid versions."); // return info @@ -96,11 +100,12 @@ namespace StardewModdingAPI.Web.Framework *********/ /// Get the mod version numbers for the given mod. /// The mod to check. + /// The optional update subkey to match in available files. (If no file names or descriptions contain the subkey, it'll be ignored.) /// Whether to allow non-standard versions. /// Maps remote versions to a semantic version for update checks. /// The main mod version. /// The latest prerelease version, if newer than . - private bool TryGetLatestVersions(IModPage mod, bool allowNonStandardVersions, IDictionary mapRemoteVersions, out ISemanticVersion main, out ISemanticVersion preview) + private bool TryGetLatestVersions(IModPage mod, string subkey, bool allowNonStandardVersions, IDictionary mapRemoteVersions, out ISemanticVersion main, out ISemanticVersion preview) { main = null; preview = null; @@ -113,14 +118,23 @@ namespace StardewModdingAPI.Web.Framework if (mod != null) { - // get versions - main = ParseVersion(mod.Version); - foreach (string rawVersion in mod.Downloads.Select(p => p.Version)) + // get mod version + if (subkey == null) + main = ParseVersion(mod.Version); + + // get file versions + foreach (IModDownload download in mod.Downloads) { - ISemanticVersion cur = ParseVersion(rawVersion); + // check for subkey if specified + if (subkey != null && download.Name?.Contains(subkey, StringComparison.OrdinalIgnoreCase) != true && download.Description?.Contains(subkey, StringComparison.OrdinalIgnoreCase) != true) + continue; + + // parse version + ISemanticVersion cur = ParseVersion(download.Version); if (cur == null) continue; + // track highest versions if (main == null || cur.IsNewerThan(main)) main = cur; if (cur.IsPrerelease() && (preview == null || cur.IsNewerThan(preview))) -- cgit