summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-09-19 22:46:00 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-09-19 22:46:00 -0400
commit954de8c4f2683b39a3f5a11fd29c39130bc31bdb (patch)
treebd784d82ab7196cdcba1bbd26fd9b4d16016b9e4
parent8c5bd12f4793a9c866b6046c05482592a5c799bc (diff)
downloadSMAPI-954de8c4f2683b39a3f5a11fd29c39130bc31bdb.tar.gz
SMAPI-954de8c4f2683b39a3f5a11fd29c39130bc31bdb.tar.bz2
SMAPI-954de8c4f2683b39a3f5a11fd29c39130bc31bdb.zip
move monitor.LogOnce into internal extensions for reuse (#347)
-rw-r--r--src/StardewModdingAPI/Framework/InternalExtensions.cs16
-rw-r--r--src/StardewModdingAPI/Framework/ModLoading/AssemblyLoader.cs24
2 files changed, 20 insertions, 20 deletions
diff --git a/src/StardewModdingAPI/Framework/InternalExtensions.cs b/src/StardewModdingAPI/Framework/InternalExtensions.cs
index 2842bc83..3709e05d 100644
--- a/src/StardewModdingAPI/Framework/InternalExtensions.cs
+++ b/src/StardewModdingAPI/Framework/InternalExtensions.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@@ -71,6 +71,20 @@ namespace StardewModdingAPI.Framework
}
}
+ /// <summary>Log a message for the player or developer the first time it occurs.</summary>
+ /// <param name="monitor">The monitor through which to log the message.</param>
+ /// <param name="hash">The hash of logged messages.</param>
+ /// <param name="message">The message to log.</param>
+ /// <param name="level">The log severity level.</param>
+ public static void LogOnce(this IMonitor monitor, HashSet<string> hash, string message, LogLevel level = LogLevel.Trace)
+ {
+ if (!hash.Contains(message))
+ {
+ monitor.Log(message, level);
+ hash.Add(message);
+ }
+ }
+
/****
** Exceptions
****/
diff --git a/src/StardewModdingAPI/Framework/ModLoading/AssemblyLoader.cs b/src/StardewModdingAPI/Framework/ModLoading/AssemblyLoader.cs
index 27a81038..01dc602a 100644
--- a/src/StardewModdingAPI/Framework/ModLoading/AssemblyLoader.cs
+++ b/src/StardewModdingAPI/Framework/ModLoading/AssemblyLoader.cs
@@ -191,7 +191,7 @@ namespace StardewModdingAPI.Framework.ModLoading
// remove old assembly reference
if (this.AssemblyMap.RemoveNames.Any(name => module.AssemblyReferences[i].Name == name))
{
- this.LogOnce(this.Monitor, loggedMessages, $"{logPrefix}Rewriting {filename} for OS...");
+ this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Rewriting {filename} for OS...");
platformChanged = true;
module.AssemblyReferences.RemoveAt(i);
i--;
@@ -221,7 +221,7 @@ namespace StardewModdingAPI.Framework.ModLoading
{
if (rewriter.Rewrite(module, method, this.AssemblyMap, platformChanged))
{
- this.LogOnce(this.Monitor, loggedMessages, $"{logPrefix}Rewrote {filename} to fix {rewriter.NounPhrase}...");
+ this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Rewrote {filename} to fix {rewriter.NounPhrase}...");
anyRewritten = true;
}
}
@@ -229,7 +229,7 @@ namespace StardewModdingAPI.Framework.ModLoading
{
if (!assumeCompatible)
throw new IncompatibleInstructionException(rewriter.NounPhrase, $"Found an incompatible CIL instruction ({rewriter.NounPhrase}) while loading assembly {filename}.");
- this.LogOnce(this.Monitor, loggedMessages, $"{logPrefix}Found an incompatible CIL instruction ({rewriter.NounPhrase}) while loading assembly {filename}, but SMAPI is configured to allow it anyway. The mod may crash or behave unexpectedly.", LogLevel.Warn);
+ this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Found an incompatible CIL instruction ({rewriter.NounPhrase}) while loading assembly {filename}, but SMAPI is configured to allow it anyway. The mod may crash or behave unexpectedly.", LogLevel.Warn);
}
}
@@ -243,7 +243,7 @@ namespace StardewModdingAPI.Framework.ModLoading
{
if (rewriter.Rewrite(module, cil, instruction, this.AssemblyMap, platformChanged))
{
- this.LogOnce(this.Monitor, loggedMessages, $"{logPrefix}Rewrote {filename} to fix {rewriter.NounPhrase}...");
+ this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Rewrote {filename} to fix {rewriter.NounPhrase}...");
anyRewritten = true;
}
}
@@ -251,7 +251,7 @@ namespace StardewModdingAPI.Framework.ModLoading
{
if (!assumeCompatible)
throw new IncompatibleInstructionException(rewriter.NounPhrase, $"Found an incompatible CIL instruction ({rewriter.NounPhrase}) while loading assembly {filename}.");
- this.LogOnce(this.Monitor, loggedMessages, $"{logPrefix}Found an incompatible CIL instruction ({rewriter.NounPhrase}) while loading assembly {filename}, but SMAPI is configured to allow it anyway. The mod may crash or behave unexpectedly.", LogLevel.Warn);
+ this.Monitor.LogOnce(loggedMessages, $"{logPrefix}Found an incompatible CIL instruction ({rewriter.NounPhrase}) while loading assembly {filename}, but SMAPI is configured to allow it anyway. The mod may crash or behave unexpectedly.", LogLevel.Warn);
}
}
}
@@ -289,19 +289,5 @@ namespace StardewModdingAPI.Framework.ModLoading
select method
);
}
-
- /// <summary>Log a message for the player or developer the first time it occurs.</summary>
- /// <param name="monitor">The monitor through which to log the message.</param>
- /// <param name="hash">The hash of logged messages.</param>
- /// <param name="message">The message to log.</param>
- /// <param name="level">The log severity level.</param>
- private void LogOnce(IMonitor monitor, HashSet<string> hash, string message, LogLevel level = LogLevel.Trace)
- {
- if (!hash.Contains(message))
- {
- monitor.Log(message, level);
- hash.Add(message);
- }
- }
}
}