add support for specifying default update fields, migrate mods already in mod list (#361)

This commit is contained in:
Jesse Plamondon-Willard 2017-09-24 02:33:33 -04:00
parent 8e0d1b8682
commit 0c06b129ca
6 changed files with 253 additions and 139 deletions

View File

@ -144,7 +144,7 @@ namespace StardewModdingAPI.Tests.Core
this.SetupMetadataForValidation(mock, new ModDataRecord
{
Compatibility = new[] { new ModCompatibility("~1.0", ModStatus.AssumeBroken, null) },
UpdateUrls = new[] { "http://example.org" }
AlternativeUrl = "http://example.org"
});
// act

View File

@ -53,17 +53,22 @@ namespace StardewModdingAPI.Framework.ModLoading
error = $"parsing its manifest failed:\n{ex.GetLogSummary()}";
}
// validate metadata
// get internal data record (if any)
ModDataRecord dataRecord = null;
if (manifest != null)
{
// get unique key for lookups
string key = !string.IsNullOrWhiteSpace(manifest.UniqueID) ? manifest.UniqueID : manifest.EntryDll;
// get data record
dataRecord = dataRecords.FirstOrDefault(record => record.ID.Matches(key, manifest));
}
// apply defaults
if (dataRecord?.Defaults != null)
{
manifest.ChucklefishID = manifest.ChucklefishID ?? dataRecord.Defaults.ChucklefishID;
manifest.GitHubProject = manifest.GitHubProject ?? dataRecord.Defaults.GitHubProject;
manifest.NexusID = manifest.NexusID ?? dataRecord.Defaults.NexusID;
}
// build metadata
string displayName = !string.IsNullOrWhiteSpace(manifest?.Name)
? manifest.Name
@ -100,13 +105,27 @@ namespace StardewModdingAPI.Framework.ModLoading
case ModStatus.AssumeBroken:
{
// get reason
string reasonPhrase = compatibility.ReasonPhrase ?? "it's no longer compatible";
// get update URLs
List<string> updateUrls = new List<string>();
if (!string.IsNullOrWhiteSpace(mod.Manifest.ChucklefishID))
updateUrls.Add($"https://community.playstarbound.com/resources/{mod.Manifest.ChucklefishID}");
if (!string.IsNullOrWhiteSpace(mod.Manifest.NexusID))
updateUrls.Add($"http://nexusmods.com/stardewvalley/mods/{mod.Manifest.NexusID}");
if (!string.IsNullOrWhiteSpace(mod.Manifest.GitHubProject))
updateUrls.Add($"https://github.com/{mod.Manifest.GitHubProject}/releases");
if (mod.DataRecord.AlternativeUrl != null)
updateUrls.Add(mod.DataRecord.AlternativeUrl);
// build error
string error = $"{reasonPhrase}. Please check for a ";
if (mod.Manifest.Version.Equals(compatibility.UpperVersion))
error += "newer version";
else
error += $"version newer than {compatibility.UpperVersion}";
error += " at " + string.Join(" or ", mod.DataRecord.UpdateUrls);
error += " at " + string.Join(" or ", updateUrls);
mod.SetStatus(ModMetadataStatus.Failed, error);
}

View File

@ -0,0 +1,18 @@
namespace StardewModdingAPI.Framework.Models
{
/// <summary>Default values for support fields to inject into the manifest.</summary>
internal class ModDataDefaults
{
/*********
** Accessors
*********/
/// <summary>The mod's unique ID in the Chucklefish mod site (if any), used for update checks.</summary>
public string ChucklefishID { get; set; }
/// <summary>The mod's unique ID in Nexus Mods (if any), used for update checks.</summary>
public string NexusID { get; set; }
/// <summary>The mod's organisation and project name on GitHub (if any), used for update checks.</summary>
public string GitHubProject { get; set; }
}
}

View File

@ -17,8 +17,11 @@ namespace StardewModdingAPI.Framework.Models
/// <summary>The mod name.</summary>
public string Name { get; set; }
/// <summary>The URLs the user can check for a newer version.</summary>
public string[] UpdateUrls { get; set; }
/// <summary>Default values for support fields to inject into the manifest.</summary>
public ModDataDefaults Defaults { 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(SFieldConverter))]

File diff suppressed because it is too large Load Diff

View File

@ -91,6 +91,7 @@
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Framework\Models\ModCompatibility.cs" />
<Compile Include="Framework\Models\ModDataDefaults.cs" />
<Compile Include="Framework\ModLoading\Finders\EventFinder.cs" />
<Compile Include="Framework\ModLoading\Finders\FieldFinder.cs" />
<Compile Include="Framework\ModLoading\Finders\MethodFinder.cs" />