diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-04-29 01:30:30 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-04-29 01:30:30 -0400 |
commit | 9fecaa79890ab7e6a38768aa840cfcbd8f6272b1 (patch) | |
tree | da979079d14835475b9830921588d212c0919f53 | |
parent | ee5351c38e9657a7b7a2d929d5704c3439456a39 (diff) | |
download | SMAPI-9fecaa79890ab7e6a38768aa840cfcbd8f6272b1.tar.gz SMAPI-9fecaa79890ab7e6a38768aa840cfcbd8f6272b1.tar.bz2 SMAPI-9fecaa79890ab7e6a38768aa840cfcbd8f6272b1.zip |
make mod helpers disposable (#257)
-rw-r--r-- | src/StardewModdingAPI/Framework/ModHelper.cs | 11 | ||||
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 6 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/StardewModdingAPI/Framework/ModHelper.cs b/src/StardewModdingAPI/Framework/ModHelper.cs index c8c44dba..52e482f2 100644 --- a/src/StardewModdingAPI/Framework/ModHelper.cs +++ b/src/StardewModdingAPI/Framework/ModHelper.cs @@ -6,7 +6,7 @@ using StardewModdingAPI.Framework.Serialisation; namespace StardewModdingAPI.Framework { /// <summary>Provides simplified APIs for writing mods.</summary> - internal class ModHelper : IModHelper + internal class ModHelper : IModHelper, IDisposable { /********* ** Properties @@ -107,5 +107,14 @@ namespace StardewModdingAPI.Framework path = Path.Combine(this.DirectoryPath, path); this.JsonHelper.WriteJsonFile(path, model); } + + /**** + ** Disposal + ****/ + /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary> + public void Dispose() + { + // nothing to dispose yet + } } } diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index ed8fb592..7fa78dce 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -204,10 +204,16 @@ namespace StardewModdingAPI /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary> public void Dispose() { + // skip if already disposed if (this.IsDisposed) return; this.IsDisposed = true; + // dispose mod helpers + foreach (var mod in this.ModRegistry.GetMods()) + (mod.Helper as IDisposable)?.Dispose(); + + // dispose core components this.IsGameRunning = false; this.LogFile?.Dispose(); this.ConsoleManager?.Dispose(); |