using System.Text.RegularExpressions;
namespace StardewModdingAPI.Framework.Models
{
/// Contains abstract metadata about an incompatible mod.
internal class IncompatibleMod
{
/*********
** Accessors
*********/
/// The unique mod ID.
public string ID { get; set; }
/// The mod name.
public string Name { get; set; }
/// The oldest incompatible mod version, or null for all past versions.
public string LowerVersion { get; set; }
/// The most recent incompatible mod version.
public string UpperVersion { get; set; }
/// The URL the user can check for an official updated version.
public string UpdateUrl { get; set; }
/// 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; }
/// The reason phrase to show in the warning, or null to use the default value.
/// "this version is incompatible with the latest version of the game"
public string ReasonPhrase { 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 lowerVersion = this.LowerVersion != null ? new SemanticVersion(this.LowerVersion) : null;
ISemanticVersion upperVersion = new SemanticVersion(this.UpperVersion);
// ignore versions not in range
if (lowerVersion != null && version.IsOlderThan(lowerVersion))
return true;
if (version.IsNewerThan(upperVersion))
return true;
// allow versions matching override
return !string.IsNullOrWhiteSpace(this.ForceCompatibleVersion) && Regex.IsMatch(version.ToString(), this.ForceCompatibleVersion, RegexOptions.IgnoreCase);
}
}
}