summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-09-23 21:48:53 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-09-23 21:48:53 -0400
commita89dbce8549abee867d0af65ac62155bb485a911 (patch)
tree1a67281b84d754f4b76b0ff2e45edeafeac29b29 /src/StardewModdingAPI/Framework
parent8bcc80a33d42f5c6f044533bb151d75901de912f (diff)
downloadSMAPI-a89dbce8549abee867d0af65ac62155bb485a911.tar.gz
SMAPI-a89dbce8549abee867d0af65ac62155bb485a911.tar.bz2
SMAPI-a89dbce8549abee867d0af65ac62155bb485a911.zip
unify disabled-mod and compatibility lists (#361)
Diffstat (limited to 'src/StardewModdingAPI/Framework')
-rw-r--r--src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs40
-rw-r--r--src/StardewModdingAPI/Framework/Models/DisabledMod.cs22
-rw-r--r--src/StardewModdingAPI/Framework/Models/ModStatus.cs9
-rw-r--r--src/StardewModdingAPI/Framework/Models/SConfig.cs3
4 files changed, 26 insertions, 48 deletions
diff --git a/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs b/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs
index 6a971c15..02fd85ea 100644
--- a/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs
+++ b/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs
@@ -18,12 +18,10 @@ namespace StardewModdingAPI.Framework.ModLoading
/// <param name="rootPath">The root path to search for mods.</param>
/// <param name="jsonHelper">The JSON helper with which to read manifests.</param>
/// <param name="compatibilityRecords">Metadata about mods that SMAPI should assume is compatible or broken, regardless of whether it detects incompatible code.</param>
- /// <param name="disabledMods">Metadata about mods that SMAPI should consider obsolete and not load.</param>
/// <returns>Returns the manifests by relative folder.</returns>
- public IEnumerable<IModMetadata> ReadManifests(string rootPath, JsonHelper jsonHelper, IEnumerable<ModCompatibility> compatibilityRecords, IEnumerable<DisabledMod> disabledMods)
+ public IEnumerable<IModMetadata> ReadManifests(string rootPath, JsonHelper jsonHelper, IEnumerable<ModCompatibility> compatibilityRecords)
{
compatibilityRecords = compatibilityRecords.ToArray();
- disabledMods = disabledMods.ToArray();
foreach (DirectoryInfo modDir in this.GetModFolders(rootPath))
{
@@ -62,18 +60,13 @@ namespace StardewModdingAPI.Framework.ModLoading
// get unique key for lookups
string key = !string.IsNullOrWhiteSpace(manifest.UniqueID) ? manifest.UniqueID : manifest.EntryDll;
- // check if mod should be disabled
- DisabledMod disabledMod = disabledMods.FirstOrDefault(mod => mod.ID.Contains(key, StringComparer.InvariantCultureIgnoreCase));
- if (disabledMod != null)
- error = $"it's obsolete: {disabledMod.ReasonPhrase}";
-
// get compatibility record
compatibility = (
from mod in compatibilityRecords
where
mod.ID.Any(p => p.Matches(key, manifest))
&& (mod.LowerVersion == null || !manifest.Version.IsOlderThan(mod.LowerVersion))
- && !manifest.Version.IsNewerThan(mod.UpperVersion)
+ && (mod.UpperVersion == null || !manifest.Version.IsNewerThan(mod.UpperVersion))
select mod
).FirstOrDefault();
}
@@ -107,18 +100,25 @@ namespace StardewModdingAPI.Framework.ModLoading
// validate compatibility
{
ModCompatibility compatibility = mod.Compatibility;
- if (compatibility?.Status == ModStatus.AssumeBroken)
+ switch (compatibility?.Status)
{
- string reasonPhrase = compatibility.ReasonPhrase ?? "it's no longer compatible";
- string error = $"{reasonPhrase}. Please check for a ";
- if (mod.Manifest.Version.Equals(compatibility.UpperVersion) && compatibility.UpperVersionLabel == null)
- error += "newer version";
- else
- error += $"version newer than {compatibility.UpperVersionLabel ?? compatibility.UpperVersion.ToString()}";
- error += " at " + string.Join(" or ", compatibility.UpdateUrls);
-
- mod.SetStatus(ModMetadataStatus.Failed, error);
- continue;
+ case ModStatus.Obsolete:
+ mod.SetStatus(ModMetadataStatus.Failed, $"it's obsolete: {compatibility.ReasonPhrase}");
+ continue;
+
+ case ModStatus.AssumeBroken:
+ {
+ string reasonPhrase = compatibility.ReasonPhrase ?? "it's no longer compatible";
+ string error = $"{reasonPhrase}. Please check for a ";
+ if (mod.Manifest.Version.Equals(compatibility.UpperVersion) && compatibility.UpperVersionLabel == null)
+ error += "newer version";
+ else
+ error += $"version newer than {compatibility.UpperVersionLabel ?? compatibility.UpperVersion.ToString()}";
+ error += " at " + string.Join(" or ", compatibility.UpdateUrls);
+
+ mod.SetStatus(ModMetadataStatus.Failed, error);
+ continue;
+ }
}
}
diff --git a/src/StardewModdingAPI/Framework/Models/DisabledMod.cs b/src/StardewModdingAPI/Framework/Models/DisabledMod.cs
deleted file mode 100644
index 170fa760..00000000
--- a/src/StardewModdingAPI/Framework/Models/DisabledMod.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-namespace StardewModdingAPI.Framework.Models
-{
- /// <summary>Metadata about for a mod that should never be loaded.</summary>
- internal class DisabledMod
- {
- /*********
- ** Accessors
- *********/
- /****
- ** From config
- ****/
- /// <summary>The unique mod IDs.</summary>
- public string[] ID { get; set; }
-
- /// <summary>The mod name.</summary>
- public string Name { get; set; }
-
- /// <summary>The reason phrase to show in the warning, or <c>null</c> to use the default value.</summary>
- /// <example>"this mod is no longer supported or used"</example>
- public string ReasonPhrase { get; set; }
- }
-}
diff --git a/src/StardewModdingAPI/Framework/Models/ModStatus.cs b/src/StardewModdingAPI/Framework/Models/ModStatus.cs
index 4ab0b790..343ccb7e 100644
--- a/src/StardewModdingAPI/Framework/Models/ModStatus.cs
+++ b/src/StardewModdingAPI/Framework/Models/ModStatus.cs
@@ -4,12 +4,15 @@ namespace StardewModdingAPI.Framework.Models
internal enum ModStatus
{
/// <summary>Don't override the status.</summary>
- None = 0,
+ None,
+
+ /// <summary>The mod is obsolete and shouldn't be used, regardless of version.</summary>
+ Obsolete,
/// <summary>Assume the mod is not compatible, even if SMAPI doesn't detect any incompatible code.</summary>
- AssumeBroken = 0,
+ AssumeBroken,
/// <summary>Assume the mod is compatible, even if SMAPI detects incompatible code.</summary>
- AssumeCompatible = 1
+ AssumeCompatible
}
}
diff --git a/src/StardewModdingAPI/Framework/Models/SConfig.cs b/src/StardewModdingAPI/Framework/Models/SConfig.cs
index 36799400..720d4a6d 100644
--- a/src/StardewModdingAPI/Framework/Models/SConfig.cs
+++ b/src/StardewModdingAPI/Framework/Models/SConfig.cs
@@ -23,8 +23,5 @@ namespace StardewModdingAPI.Framework.Models
/// <summary>A list of mod versions which should be considered compatible or incompatible regardless of whether SMAPI detects incompatible code.</summary>
public ModCompatibility[] ModCompatibility { get; set; }
-
- /// <summary>A list of mods which should be considered obsolete and not loaded.</summary>
- public DisabledMod[] DisabledMods { get; set; }
}
}