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 most recent incompatible mod version.
public string Version { 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; }
/*********
** 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);
}
}
}