add support for unofficial updates which suffix the official version number with a pre-release label (#192)

This commit is contained in:
Jesse Plamondon-Willard 2016-12-22 22:34:49 -05:00
parent f6f52b653e
commit c7a08d08db
3 changed files with 40 additions and 13 deletions

View File

@ -1,3 +1,5 @@
using System.Text.RegularExpressions;
namespace StardewModdingAPI.Framework.Models
{
/// <summary>Contains abstract metadata about an incompatible mod.</summary>
@ -20,5 +22,26 @@ namespace StardewModdingAPI.Framework.Models
/// <summary>The URL the user can check for an unofficial updated version.</summary>
public string UnofficialUpdateUrl { get; set; }
/// <summary>A regular expression matching version strings to consider compatible, even if they technically precede <see cref="Version"/>.</summary>
public string ForceCompatibleVersion { get; set; }
/*********
** Public methods
*********/
/// <summary>Get whether the specified version is compatible according to this metadata.</summary>
/// <param name="version">The current version of the matching mod.</param>
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);
}
}
}

View File

@ -384,23 +384,23 @@ namespace StardewModdingAPI
}
// validate known incompatible mods
IncompatibleMod incompatible;
if (incompatibleMods.TryGetValue(manifest.UniqueID ?? $"{manifest.Name}|{manifest.Author}|{manifest.EntryDll}", out incompatible))
IncompatibleMod compatibility;
if (incompatibleMods.TryGetValue(manifest.UniqueID ?? $"{manifest.Name}|{manifest.Author}|{manifest.EntryDll}", out compatibility))
{
if (!manifest.Version.IsNewerThan(new SemanticVersion(incompatible.Version)))
if (!compatibility.IsCompatible(manifest.Version))
{
string warning = $"Skipped {incompatible.Name} ≤v{incompatible.Version} because this version is not compatible with the latest version of the game. Please check for a newer version of the mod here:";
if (!string.IsNullOrWhiteSpace(incompatible.UpdateUrl))
warning += $"{Environment.NewLine}- official mod: {incompatible.UpdateUrl}";
if (!string.IsNullOrWhiteSpace(incompatible.UnofficialUpdateUrl))
warning += $"{Environment.NewLine}- unofficial update: {incompatible.UnofficialUpdateUrl}";
string warning = $"Skipped {compatibility.Name} ≤v{compatibility.Version} because this version is not compatible with the latest version of the game. Please check for a newer version of the mod here:";
if (!string.IsNullOrWhiteSpace(compatibility.UpdateUrl))
warning += $"{Environment.NewLine}- official mod: {compatibility.UpdateUrl}";
if (!string.IsNullOrWhiteSpace(compatibility.UnofficialUpdateUrl))
warning += $"{Environment.NewLine}- unofficial update: {compatibility.UnofficialUpdateUrl}";
Program.Monitor.Log(warning, LogLevel.Error);
continue;
}
}
// validate version
// validate SMAPI version
if (!string.IsNullOrWhiteSpace(manifest.MinimumApiVersion))
{
try

View File

@ -11,27 +11,31 @@ This file contains advanced metadata for SMAPI. You shouldn't change this file.
"Name": "Better Sprinklers",
"Version": "2.1",
"UpdateUrl": "http://www.nexusmods.com/stardewvalley/mods/41",
"UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031"
"UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031",
"ForceCompatibleVersion": "^2.1-EntoPatch"
},
{
"ID": "SPDChestLabel",
"Name": "Chest Label System",
"Version": "1.5",
"UpdateUrl": "http://www.nexusmods.com/stardewvalley/mods/242",
"UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031"
"UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031",
"ForceCompatibleVersion": "^1.5-EntoPatch"
},
{
"ID": "CJBCheatsMenu",
"Name": "CJB Cheats Menu",
"Version": "1.12",
"UpdateUrl": "http://www.nexusmods.com/stardewvalley/mods/4",
"UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031"
"UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031",
"ForceCompatibleVersion": "^1.12-EntoPatch"
},
{
"ID": "CJBItemSpawner",
"Name": "CJB Item Spawner",
"Version": "1.5",
"UpdateUrl": "http://www.nexusmods.com/stardewvalley/mods/93",
"UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031"
"UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031",
"ForceCompatibleVersion": "^1.5-EntoPatch"
}
]