summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/DeprecationManager.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-11-07 12:36:38 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-11-07 12:36:38 -0500
commita379726ad9dbc8a8b85dd698a742343a9a163e46 (patch)
treea774b451e7b0090a95290efe49250f976326c5a9 /src/SMAPI/Framework/DeprecationManager.cs
parentc0738296273304e71183ddc537aaf9ffc6d3da46 (diff)
downloadSMAPI-a379726ad9dbc8a8b85dd698a742343a9a163e46.tar.gz
SMAPI-a379726ad9dbc8a8b85dd698a742343a9a163e46.tar.bz2
SMAPI-a379726ad9dbc8a8b85dd698a742343a9a163e46.zip
print deprecation messages in batches for easier reading
Diffstat (limited to 'src/SMAPI/Framework/DeprecationManager.cs')
-rw-r--r--src/SMAPI/Framework/DeprecationManager.cs49
1 files changed, 32 insertions, 17 deletions
diff --git a/src/SMAPI/Framework/DeprecationManager.cs b/src/SMAPI/Framework/DeprecationManager.cs
index 7a824a05..0fde67ee 100644
--- a/src/SMAPI/Framework/DeprecationManager.cs
+++ b/src/SMAPI/Framework/DeprecationManager.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Linq;
namespace StardewModdingAPI.Framework
{
@@ -18,6 +19,9 @@ namespace StardewModdingAPI.Framework
/// <summary>Tracks the installed mods.</summary>
private readonly ModRegistry ModRegistry;
+ /// <summary>The queued deprecation warnings to display.</summary>
+ private readonly IList<DeprecationWarning> QueuedWarnings = new List<DeprecationWarning>();
+
/*********
** Public methods
@@ -51,29 +55,40 @@ namespace StardewModdingAPI.Framework
if (!this.MarkWarned(source ?? "<unknown>", nounPhrase, version))
return;
- // build message
- string message = $"{source ?? "An unknown mod"} uses deprecated code ({nounPhrase} is deprecated since SMAPI {version}).";
- if (source == null)
- message += $"{Environment.NewLine}{Environment.StackTrace}";
+ // queue warning
+ this.QueuedWarnings.Add(new DeprecationWarning(source, nounPhrase, version, severity));
+ }
- // log message
- switch (severity)
+ /// <summary>Print any queued messages.</summary>
+ public void PrintQueued()
+ {
+ foreach (DeprecationWarning warning in this.QueuedWarnings.OrderBy(p => p.ModName).ThenBy(p => p.NounPhrase))
{
- case DeprecationLevel.Notice:
- this.Monitor.Log(message, LogLevel.Trace);
- break;
+ // build message
+ string message = $"{warning.ModName ?? "An unknown mod"} uses deprecated code ({warning.NounPhrase} is deprecated since SMAPI {warning.Version}).";
+ if (warning.ModName == null)
+ message += $"{Environment.NewLine}{Environment.StackTrace}";
+
+ // log message
+ switch (warning.Level)
+ {
+ case DeprecationLevel.Notice:
+ this.Monitor.Log(message, LogLevel.Trace);
+ break;
- case DeprecationLevel.Info:
- this.Monitor.Log(message, LogLevel.Debug);
- break;
+ case DeprecationLevel.Info:
+ this.Monitor.Log(message, LogLevel.Debug);
+ break;
- case DeprecationLevel.PendingRemoval:
- this.Monitor.Log(message, LogLevel.Warn);
- break;
+ case DeprecationLevel.PendingRemoval:
+ this.Monitor.Log(message, LogLevel.Warn);
+ break;
- default:
- throw new NotSupportedException($"Unknown deprecation level '{severity}'");
+ default:
+ throw new NotSupportedException($"Unknown deprecation level '{warning.Level}'.");
+ }
}
+ this.QueuedWarnings.Clear();
}
/// <summary>Mark a deprecation warning as already logged.</summary>