blob: 580acb70676c8f5d3482526941b9ff75c3ac8ffd (
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
52
53
54
55
56
57
58
59
60
61
62
63
|
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using StardewModdingAPI.Framework.Serialisation.SmapiConverters;
namespace StardewModdingAPI.Framework.Models
{
/// <summary>Metadata about a mod from SMAPI's internal data.</summary>
internal class ModDataRecord
{
/*********
** Accessors
*********/
/// <summary>The unique mod identifier.</summary>
[JsonConverter(typeof(ModDataIdConverter))]
public ModDataID ID { get; set; }
/// <summary>A value to inject into <see cref="IManifest.UpdateKeys"/> field if it's not already set.</summary>
public string[] UpdateKeys { get; set; }
/// <summary>The URL where the player can get an unofficial or alternative version of the mod if the official version isn't compatible.</summary>
public string AlternativeUrl { get; set; }
/// <summary>The compatibility of given mod versions (if any).</summary>
[JsonConverter(typeof(ModCompatibilityArrayConverter))]
public ModCompatibility[] Compatibility { get; set; } = new ModCompatibility[0];
/// <summary>Map local versions to a semantic version for update checks.</summary>
public IDictionary<string, string> MapLocalVersions { get; set; } = new Dictionary<string, string>();
/// <summary>Map remote versions to a semantic version for update checks.</summary>
public IDictionary<string, string> MapRemoteVersions { get; set; } = new Dictionary<string, string>();
/*********
** Public methods
*********/
/// <summary>Get the compatibility record for a given version, if any.</summary>
/// <param name="version">The mod version to check.</param>
public ModCompatibility GetCompatibility(ISemanticVersion version)
{
return this.Compatibility.FirstOrDefault(p => p.MatchesVersion(version));
}
/// <summary>Get a semantic local version for update checks.</summary>
/// <param name="version">The local version to normalise.</param>
public string GetLocalVersionForUpdateChecks(string version)
{
return this.MapLocalVersions != null && this.MapLocalVersions.TryGetValue(version, out string newVersion)
? newVersion
: version;
}
/// <summary>Get a semantic remote version for update checks.</summary>
/// <param name="version">The remote version to normalise.</param>
public string GetRemoteVersionForUpdateChecks(string version)
{
return this.MapRemoteVersions != null && this.MapRemoteVersions.TryGetValue(version, out string newVersion)
? newVersion
: version;
}
}
}
|