diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-12-22 22:34:49 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-12-22 22:34:49 -0500 |
commit | c7a08d08db3305a7cfd3a6438beda48b0791eaac (patch) | |
tree | 630fa3316dc1cde3351dfdd84dfba0c3b8c3c54c /src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs | |
parent | f6f52b653e59778f9e0b2684faa1ad554acce02f (diff) | |
download | SMAPI-c7a08d08db3305a7cfd3a6438beda48b0791eaac.tar.gz SMAPI-c7a08d08db3305a7cfd3a6438beda48b0791eaac.tar.bz2 SMAPI-c7a08d08db3305a7cfd3a6438beda48b0791eaac.zip |
add support for unofficial updates which suffix the official version number with a pre-release label (#192)
Diffstat (limited to 'src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs')
-rw-r--r-- | src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs | 23 |
1 files changed, 23 insertions, 0 deletions
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 { /// <summary>Contains abstract metadata about an incompatible mod.</summary> @@ -20,5 +22,26 @@ namespace StardewModdingAPI.Framework.Models /// <summary>The URL the user can check for an unofficial updated version.</summary> public string UnofficialUpdateUrl { get; set; } + + /// <summary>A regular expression matching version strings to consider compatible, even if they technically precede <see cref="Version"/>.</summary> + public string ForceCompatibleVersion { get; set; } + + + /********* + ** Public methods + *********/ + /// <summary>Get whether the specified version is compatible according to this metadata.</summary> + /// <param name="version">The current version of the matching mod.</param> + 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 |