summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/IModMetadata.cs10
-rw-r--r--src/SMAPI/Framework/ModLoading/ModMetadata.cs23
-rw-r--r--src/SMAPI/Framework/SCore.cs13
3 files changed, 33 insertions, 13 deletions
diff --git a/src/SMAPI/Framework/IModMetadata.cs b/src/SMAPI/Framework/IModMetadata.cs
index 1a007297..85d1b619 100644
--- a/src/SMAPI/Framework/IModMetadata.cs
+++ b/src/SMAPI/Framework/IModMetadata.cs
@@ -1,6 +1,8 @@
+using System.Collections.Generic;
using StardewModdingAPI.Framework.ModLoading;
using StardewModdingAPI.Toolkit.Framework.Clients.WebApi;
using StardewModdingAPI.Toolkit.Framework.ModData;
+using StardewModdingAPI.Toolkit.Framework.UpdateData;
namespace StardewModdingAPI.Framework
{
@@ -80,7 +82,11 @@ namespace StardewModdingAPI.Framework
/// <summary>Whether the mod has an ID (regardless of whether the ID is valid or the mod itself was loaded).</summary>
bool HasID();
- /// <summary>Whether the mod has at least one update key set.</summary>
- bool HasUpdateKeys();
+ /// <summary>Get the defined update keys.</summary>
+ /// <param name="validOnly">Only return valid update keys.</param>
+ IEnumerable<UpdateKey> GetUpdateKeys(bool validOnly = true);
+
+ /// <summary>Whether the mod has at least one valid update key set.</summary>
+ bool HasValidUpdateKeys();
}
}
diff --git a/src/SMAPI/Framework/ModLoading/ModMetadata.cs b/src/SMAPI/Framework/ModLoading/ModMetadata.cs
index 585debb4..c02f0830 100644
--- a/src/SMAPI/Framework/ModLoading/ModMetadata.cs
+++ b/src/SMAPI/Framework/ModLoading/ModMetadata.cs
@@ -1,7 +1,9 @@
using System;
+using System.Collections.Generic;
using System.Linq;
using StardewModdingAPI.Toolkit.Framework.Clients.WebApi;
using StardewModdingAPI.Toolkit.Framework.ModData;
+using StardewModdingAPI.Toolkit.Framework.UpdateData;
namespace StardewModdingAPI.Framework.ModLoading
{
@@ -141,13 +143,22 @@ namespace StardewModdingAPI.Framework.ModLoading
&& !string.IsNullOrWhiteSpace(this.Manifest.UniqueID);
}
- /// <summary>Whether the mod has at least one update key set.</summary>
- public bool HasUpdateKeys()
+ /// <summary>Get the defined update keys.</summary>
+ /// <param name="validOnly">Only return valid update keys.</param>
+ public IEnumerable<UpdateKey> GetUpdateKeys(bool validOnly = false)
{
- return
- this.HasManifest()
- && this.Manifest.UpdateKeys != null
- && this.Manifest.UpdateKeys.Any(key => !string.IsNullOrWhiteSpace(key));
+ foreach (string rawKey in this.Manifest?.UpdateKeys ?? new string[0])
+ {
+ UpdateKey updateKey = UpdateKey.Parse(rawKey);
+ if (updateKey.LooksValid || !validOnly)
+ yield return updateKey;
+ }
+ }
+
+ /// <summary>Whether the mod has at least one valid update key set.</summary>
+ public bool HasValidUpdateKeys()
+ {
+ return this.GetUpdateKeys(validOnly: true).Any();
}
}
}
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index af8df8a0..59ce3be7 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -575,11 +575,14 @@ namespace StardewModdingAPI.Framework
List<ModSearchEntryModel> searchMods = new List<ModSearchEntryModel>();
foreach (IModMetadata mod in mods)
{
- if (!mod.HasID())
+ if (!mod.HasID() || suppressUpdateChecks.Contains(mod.Manifest.UniqueID))
continue;
- string[] updateKeys = mod.Manifest.UpdateKeys ?? new string[0];
- searchMods.Add(new ModSearchEntryModel(mod.Manifest.UniqueID, updateKeys.Except(suppressUpdateChecks).ToArray()));
+ string[] updateKeys = mod
+ .GetUpdateKeys(validOnly: true)
+ .Select(p => p.ToString())
+ .ToArray();
+ searchMods.Add(new ModSearchEntryModel(mod.Manifest.UniqueID, updateKeys.ToArray()));
}
// fetch results
@@ -699,7 +702,7 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($" {metadata.DisplayName} (content pack, {PathUtilities.GetRelativePath(this.ModsPath, metadata.DirectoryPath)})...", LogLevel.Trace);
// show warning for missing update key
- if (metadata.HasManifest() && !metadata.HasUpdateKeys())
+ if (metadata.HasManifest() && !metadata.HasValidUpdateKeys())
metadata.SetWarning(ModWarning.NoUpdateKeys);
// validate status
@@ -745,7 +748,7 @@ namespace StardewModdingAPI.Framework
: $" {metadata.DisplayName}...", LogLevel.Trace);
// show warnings
- if (metadata.HasManifest() && !metadata.HasUpdateKeys() && !suppressUpdateChecks.Contains(metadata.Manifest.UniqueID))
+ if (metadata.HasManifest() && !metadata.HasValidUpdateKeys() && !suppressUpdateChecks.Contains(metadata.Manifest.UniqueID))
metadata.SetWarning(ModWarning.NoUpdateKeys);
// validate status