using System.Text.RegularExpressions; using System.Threading.Tasks; using StardewModdingAPI.Toolkit.Framework.Clients.WebApi; namespace StardewModdingAPI.Web.Framework.ModRepositories { internal abstract class RepositoryBase : IModRepository { /********* ** Accessors *********/ /// The unique key for this vendor. public string VendorKey { get; } /********* ** Public methods *********/ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. public abstract void Dispose(); /// Get metadata about a mod in the repository. /// The mod ID in this repository. public abstract Task GetModInfoAsync(string id); /********* ** Protected methods *********/ /// Construct an instance. /// The unique key for this vendor. protected RepositoryBase(string vendorKey) { this.VendorKey = vendorKey; } /// Normalise a version string. /// The version to normalise. protected string NormaliseVersion(string version) { if (string.IsNullOrWhiteSpace(version)) return null; version = version.Trim(); if (Regex.IsMatch(version, @"^v\d", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)) // common version prefix version = version.Substring(1); return version; } } }