From c7a08d08db3305a7cfd3a6438beda48b0791eaac Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 22 Dec 2016 22:34:49 -0500 Subject: add support for unofficial updates which suffix the official version number with a pre-release label (#192) --- .../Framework/Models/IncompatibleMod.cs | 23 ++++++++++++++++++++++ src/StardewModdingAPI/Program.cs | 18 ++++++++--------- src/StardewModdingAPI/StardewModdingAPI.data.json | 12 +++++++---- 3 files changed, 40 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs b/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs index f3ee7d0b..9bf06552 100644 --- a/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs +++ b/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs @@ -1,3 +1,5 @@ +using System.Text.RegularExpressions; + namespace StardewModdingAPI.Framework.Models { /// Contains abstract metadata about an incompatible mod. @@ -20,5 +22,26 @@ namespace StardewModdingAPI.Framework.Models /// The URL the user can check for an unofficial updated version. public string UnofficialUpdateUrl { get; set; } + + /// A regular expression matching version strings to consider compatible, even if they technically precede . + public string ForceCompatibleVersion { get; set; } + + + /********* + ** Public methods + *********/ + /// Get whether the specified version is compatible according to this metadata. + /// The current version of the matching mod. + public bool IsCompatible(ISemanticVersion version) + { + ISemanticVersion incompatibleVersion = new SemanticVersion(this.Version); + + // allow newer versions + if (version.IsNewerThan(incompatibleVersion)) + return true; + + // allow versions matching override + return !string.IsNullOrWhiteSpace(this.ForceCompatibleVersion) && Regex.IsMatch(version.ToString(), this.ForceCompatibleVersion, RegexOptions.IgnoreCase); + } } } \ No newline at end of file diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index c3bd1646..0c232b1d 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -384,23 +384,23 @@ namespace StardewModdingAPI } // validate known incompatible mods - IncompatibleMod incompatible; - if (incompatibleMods.TryGetValue(manifest.UniqueID ?? $"{manifest.Name}|{manifest.Author}|{manifest.EntryDll}", out incompatible)) + IncompatibleMod compatibility; + if (incompatibleMods.TryGetValue(manifest.UniqueID ?? $"{manifest.Name}|{manifest.Author}|{manifest.EntryDll}", out compatibility)) { - if (!manifest.Version.IsNewerThan(new SemanticVersion(incompatible.Version))) + if (!compatibility.IsCompatible(manifest.Version)) { - string warning = $"Skipped {incompatible.Name} ≤v{incompatible.Version} because this version is not compatible with the latest version of the game. Please check for a newer version of the mod here:"; - if (!string.IsNullOrWhiteSpace(incompatible.UpdateUrl)) - warning += $"{Environment.NewLine}- official mod: {incompatible.UpdateUrl}"; - if (!string.IsNullOrWhiteSpace(incompatible.UnofficialUpdateUrl)) - warning += $"{Environment.NewLine}- unofficial update: {incompatible.UnofficialUpdateUrl}"; + string warning = $"Skipped {compatibility.Name} ≤v{compatibility.Version} because this version is not compatible with the latest version of the game. Please check for a newer version of the mod here:"; + if (!string.IsNullOrWhiteSpace(compatibility.UpdateUrl)) + warning += $"{Environment.NewLine}- official mod: {compatibility.UpdateUrl}"; + if (!string.IsNullOrWhiteSpace(compatibility.UnofficialUpdateUrl)) + warning += $"{Environment.NewLine}- unofficial update: {compatibility.UnofficialUpdateUrl}"; Program.Monitor.Log(warning, LogLevel.Error); continue; } } - // validate version + // validate SMAPI version if (!string.IsNullOrWhiteSpace(manifest.MinimumApiVersion)) { try diff --git a/src/StardewModdingAPI/StardewModdingAPI.data.json b/src/StardewModdingAPI/StardewModdingAPI.data.json index 2f1d67e8..49b45018 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.data.json +++ b/src/StardewModdingAPI/StardewModdingAPI.data.json @@ -11,27 +11,31 @@ This file contains advanced metadata for SMAPI. You shouldn't change this file. "Name": "Better Sprinklers", "Version": "2.1", "UpdateUrl": "http://www.nexusmods.com/stardewvalley/mods/41", - "UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031" + "UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031", + "ForceCompatibleVersion": "^2.1-EntoPatch" }, { "ID": "SPDChestLabel", "Name": "Chest Label System", "Version": "1.5", "UpdateUrl": "http://www.nexusmods.com/stardewvalley/mods/242", - "UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031" + "UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031", + "ForceCompatibleVersion": "^1.5-EntoPatch" }, { "ID": "CJBCheatsMenu", "Name": "CJB Cheats Menu", "Version": "1.12", "UpdateUrl": "http://www.nexusmods.com/stardewvalley/mods/4", - "UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031" + "UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031", + "ForceCompatibleVersion": "^1.12-EntoPatch" }, { "ID": "CJBItemSpawner", "Name": "CJB Item Spawner", "Version": "1.5", "UpdateUrl": "http://www.nexusmods.com/stardewvalley/mods/93", - "UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031" + "UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031", + "ForceCompatibleVersion": "^1.5-EntoPatch" } ] -- cgit