summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/release-notes.md1
-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
-rw-r--r--src/StardewModdingAPI.Toolkit/Framework/UpdateData/UpdateKey.cs8
5 files changed, 42 insertions, 13 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 5d0d8a4e..4fbb2e07 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -9,6 +9,7 @@
* Fixed installer duplicating bundled mods if you moved them after the last install.
* Fixed crash when a mod manifest is corrupted.
* Fixed error-handling when initialising paths.
+ * Fixed 'no update keys' warning not shown for mods with only invalid update keys.
* Updated compatibility list.
* For modders:
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
diff --git a/src/StardewModdingAPI.Toolkit/Framework/UpdateData/UpdateKey.cs b/src/StardewModdingAPI.Toolkit/Framework/UpdateData/UpdateKey.cs
index 49b7a272..865ebcf7 100644
--- a/src/StardewModdingAPI.Toolkit/Framework/UpdateData/UpdateKey.cs
+++ b/src/StardewModdingAPI.Toolkit/Framework/UpdateData/UpdateKey.cs
@@ -61,5 +61,13 @@ namespace StardewModdingAPI.Toolkit.Framework.UpdateData
return new UpdateKey(raw, repository, id);
}
+
+ /// <summary>Get a string that represents the current object.</summary>
+ public override string ToString()
+ {
+ return this.LooksValid
+ ? $"{this.Repository}:{this.ID}"
+ : this.RawText;
+ }
}
}