diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-09-18 18:49:07 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-09-18 18:49:07 -0400 |
commit | 239173558c5a6b9d1340ed9d77edb7fce2cb19f9 (patch) | |
tree | 4f99357a9deadfa36e887eb017e9e97ec59a827d /src/SMAPI/Framework | |
parent | 2cd0c8130c5f9688db493d8b0acd07505c86a2aa (diff) | |
download | SMAPI-239173558c5a6b9d1340ed9d77edb7fce2cb19f9.tar.gz SMAPI-239173558c5a6b9d1340ed9d77edb7fce2cb19f9.tar.bz2 SMAPI-239173558c5a6b9d1340ed9d77edb7fce2cb19f9.zip |
fix dependencies not enforced if the dependency failed in the load phase
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 28994060..14380f7b 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -701,7 +701,7 @@ namespace StardewModdingAPI.Framework InterfaceProxyFactory proxyFactory = new InterfaceProxyFactory(); foreach (IModMetadata mod in mods) { - if (!this.TryLoadMod(mod, modAssemblyLoader, proxyFactory, jsonHelper, contentCore, modDatabase, suppressUpdateChecks, out string errorPhrase, out string errorDetails)) + if (!this.TryLoadMod(mod, mods, modAssemblyLoader, proxyFactory, jsonHelper, contentCore, modDatabase, suppressUpdateChecks, out string errorPhrase, out string errorDetails)) { skippedMods[mod] = Tuple.Create(errorPhrase, errorDetails); if (mod.Status != ModMetadataStatus.Failed) @@ -840,6 +840,7 @@ namespace StardewModdingAPI.Framework /// <summary>Load a given mod.</summary> /// <param name="mod">The mod to load.</param> + /// <param name="mods">The mods being loaded.</param> /// <param name="assemblyLoader">Preprocesses and loads mod assemblies</param> /// <param name="proxyFactory">Generates proxy classes to access mod APIs through an arbitrary interface.</param> /// <param name="jsonHelper">The JSON helper with which to read mods' JSON files.</param> @@ -849,7 +850,7 @@ namespace StardewModdingAPI.Framework /// <param name="errorReasonPhrase">The user-facing reason phrase explaining why the mod couldn't be loaded (if applicable).</param> /// <param name="errorDetails">More detailed details about the error intended for developers (if any).</param> /// <returns>Returns whether the mod was successfully loaded.</returns> - private bool TryLoadMod(IModMetadata mod, AssemblyLoader assemblyLoader, InterfaceProxyFactory proxyFactory, JsonHelper jsonHelper, ContentCoordinator contentCore, ModDatabase modDatabase, HashSet<string> suppressUpdateChecks, out string errorReasonPhrase, out string errorDetails) + private bool TryLoadMod(IModMetadata mod, IModMetadata[] mods, AssemblyLoader assemblyLoader, InterfaceProxyFactory proxyFactory, JsonHelper jsonHelper, ContentCoordinator contentCore, ModDatabase modDatabase, HashSet<string> suppressUpdateChecks, out string errorReasonPhrase, out string errorDetails) { errorDetails = null; @@ -875,6 +876,23 @@ namespace StardewModdingAPI.Framework return false; } + // validate dependencies + // Although dependences are validated before mods are loaded, a dependency may have failed. + if (mod.Manifest.Dependencies?.Any() == true) + { + foreach (IManifestDependency dependency in mod.Manifest.Dependencies) + { + if (this.ModRegistry.Get(dependency.UniqueID) == null) + { + string dependencyName = mods + .FirstOrDefault(p => dependency.UniqueID.Equals(p.Manifest.UniqueID, StringComparison.InvariantCultureIgnoreCase)) + ?.DisplayName ?? dependency.UniqueID; + errorReasonPhrase = $"it needs the '{dependencyName}' mod, which couldn't be loaded."; + return false; + } + } + } + // load as content pack if (mod.IsContentPack) { |