From 06c7e4e2b92849858002835ed41c7e9cce60fde4 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 29 Dec 2020 23:58:54 -0500 Subject: show details in TRACE logs when a mod is blocked by compatibility list --- src/SMAPI/Framework/ModLoading/ModResolver.cs | 36 +++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/SMAPI/Framework/ModLoading') diff --git a/src/SMAPI/Framework/ModLoading/ModResolver.cs b/src/SMAPI/Framework/ModLoading/ModResolver.cs index 08df7b76..af7d90f6 100644 --- a/src/SMAPI/Framework/ModLoading/ModResolver.cs +++ b/src/SMAPI/Framework/ModLoading/ModResolver.cs @@ -72,7 +72,7 @@ namespace StardewModdingAPI.Framework.ModLoading switch (mod.DataRecord?.Status) { case ModStatus.Obsolete: - mod.SetStatus(ModMetadataStatus.Failed, ModFailReason.Obsolete, $"it's obsolete: {mod.DataRecord.StatusReasonPhrase}"); + mod.SetStatus(ModMetadataStatus.Failed, ModFailReason.Obsolete, $"it's obsolete: {mod.DataRecord.StatusReasonPhrase}", this.GetTechnicalReasonForStatusOverride(mod)); continue; case ModStatus.AssumeBroken: @@ -102,7 +102,7 @@ namespace StardewModdingAPI.Framework.ModLoading error += $"version newer than {mod.DataRecord.StatusUpperVersion}"; error += " at " + string.Join(" or ", updateUrls); - mod.SetStatus(ModMetadataStatus.Failed, ModFailReason.Incompatible, error); + mod.SetStatus(ModMetadataStatus.Failed, ModFailReason.Incompatible, error, this.GetTechnicalReasonForStatusOverride(mod)); } continue; } @@ -409,6 +409,38 @@ namespace StardewModdingAPI.Framework.ModLoading yield return new ModDependency(manifest.ContentPackFor.UniqueID, manifest.ContentPackFor.MinimumVersion, FindMod(manifest.ContentPackFor.UniqueID), isRequired: true); } + /// Get a technical message indicating why a mod's compatibility status was overridden, if applicable. + /// The mod metadata. + private string GetTechnicalReasonForStatusOverride(IModMetadata mod) + { + // get compatibility list record + var data = mod.DataRecord; + if (data == null) + return null; + + // get status label + string statusLabel = data.Status switch + { + ModStatus.AssumeBroken => "'assume broken'", + ModStatus.AssumeCompatible => "'assume compatible'", + ModStatus.Obsolete => "obsolete", + _ => data.Status.ToString() + }; + + // get reason + string[] reasons = new[] { mod.DataRecord.StatusReasonPhrase, mod.DataRecord.StatusReasonDetails } + .Where(p => !string.IsNullOrWhiteSpace(p)) + .ToArray(); + + // build message + return + $"marked {statusLabel} in SMAPI's internal compatibility list for " + + (mod.DataRecord.StatusUpperVersion != null ? $"versions up to {mod.DataRecord.StatusUpperVersion}" : "all versions") + + ": " + + (reasons.Any() ? string.Join(": ", reasons) : "no reason given") + + "."; + } + /********* ** Private models -- cgit