blob: 4a4a40cdc21faeb353f1a585bc7264eda3d7dd5d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
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
*********/
/// <summary>The unique key for this vendor.</summary>
public string VendorKey { get; }
/*********
** Public methods
*********/
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
public abstract void Dispose();
/// <summary>Get metadata about a mod in the repository.</summary>
/// <param name="id">The mod ID in this repository.</param>
public abstract Task<ModInfoModel> GetModInfoAsync(string id);
/*********
** Protected methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="vendorKey">The unique key for this vendor.</param>
protected RepositoryBase(string vendorKey)
{
this.VendorKey = vendorKey;
}
/// <summary>Normalise a version string.</summary>
/// <param name="version">The version to normalise.</param>
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;
}
}
}
|