diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-24 19:55:34 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-24 19:55:34 -0400 |
commit | b105c97dda01441d503d31e8b8ac0b3fd35fef14 (patch) | |
tree | 1e92d4a56d9d3647319fd66a814b75f2292fc6b4 | |
parent | f84def385d3d1b537e7f19b6ae1f90096e136505 (diff) | |
download | SMAPI-b105c97dda01441d503d31e8b8ac0b3fd35fef14.tar.gz SMAPI-b105c97dda01441d503d31e8b8ac0b3fd35fef14.tar.bz2 SMAPI-b105c97dda01441d503d31e8b8ac0b3fd35fef14.zip |
add support for remapping legacy versions for update checks (#361)
-rw-r--r-- | src/StardewModdingAPI/Framework/Models/ModDataRecord.cs | 25 | ||||
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 9 | ||||
-rw-r--r-- | src/StardewModdingAPI/StardewModdingAPI.config.json | 5 |
3 files changed, 35 insertions, 4 deletions
diff --git a/src/StardewModdingAPI/Framework/Models/ModDataRecord.cs b/src/StardewModdingAPI/Framework/Models/ModDataRecord.cs index a2397fa8..0d033e82 100644 --- a/src/StardewModdingAPI/Framework/Models/ModDataRecord.cs +++ b/src/StardewModdingAPI/Framework/Models/ModDataRecord.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using StardewModdingAPI.Framework.Serialisation; @@ -24,6 +25,12 @@ namespace StardewModdingAPI.Framework.Models [JsonConverter(typeof(SFieldConverter))] 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 @@ -34,5 +41,23 @@ namespace StardewModdingAPI.Framework.Models { 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; + } } } diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 3e1db20c..7b3048c0 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -576,12 +576,13 @@ namespace StardewModdingAPI } // track update - ISemanticVersion version = new SemanticVersion(info.Version); - bool isUpdate = version.IsNewerThan(mod.Manifest.Version); - this.VerboseLog($" {mod.DisplayName} ({result.Key}): {(isUpdate ? $"{mod.Manifest.Version} => {info.Version}" : "OK")}."); + ISemanticVersion localVersion = new SemanticVersion(mod.DataRecord?.GetLocalVersionForUpdateChecks(mod.Manifest.Version.ToString())); + ISemanticVersion latestVersion = new SemanticVersion(mod.DataRecord?.GetRemoteVersionForUpdateChecks(info.Version)); + bool isUpdate = latestVersion.IsNewerThan(localVersion); + this.VerboseLog($" {mod.DisplayName} ({result.Key}): {(isUpdate ? $"{mod.Manifest.Version}{(!localVersion.Equals(mod.Manifest.Version) ? $" [{localVersion}]" : "")} => {info.Version}{(!latestVersion.Equals(new SemanticVersion(info.Version)) ? $" [{latestVersion}]" : "")}" : "OK")}."); if (isUpdate) { - if (!updatesByMod.TryGetValue(mod, out ModInfoModel other) || version.IsNewerThan(other.Version)) + if (!updatesByMod.TryGetValue(mod, out ModInfoModel other) || latestVersion.IsNewerThan(other.Version)) updatesByMod[mod] = info; } } diff --git a/src/StardewModdingAPI/StardewModdingAPI.config.json b/src/StardewModdingAPI/StardewModdingAPI.config.json index 3d156a15..a768c762 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.config.json +++ b/src/StardewModdingAPI/StardewModdingAPI.config.json @@ -63,6 +63,11 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha * if it detects incompatible code). * - 'ReasonPhrase' (optional) specifies a message to show to the player explaining why the * mod isn't loaded. This has no effect for AssumeCompatible. + * + * - 'MapLocalVersions' and 'MapRemoteVersions' substitute versions for update checks. For + * example, if the API returns version '1.1-1078', MapRemoteVersions can map it to '1.1' when + * comparing to the mod's current version. This is only intended to support legacy mods with + * injected update keys. */ "ModData": [ { |