summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ContentCoordinator.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-05-10 19:05:45 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-05-10 19:05:45 -0400
commit8000a5540a37804e3980ce165c7192d5badff585 (patch)
tree82c17b4384ed913070f8ed9a2812de574e70f909 /src/SMAPI/Framework/ContentCoordinator.cs
parentc05836040a7145c56f6af2dbc8fe4722efdf79c9 (diff)
downloadSMAPI-8000a5540a37804e3980ce165c7192d5badff585.tar.gz
SMAPI-8000a5540a37804e3980ce165c7192d5badff585.tar.bz2
SMAPI-8000a5540a37804e3980ce165c7192d5badff585.zip
fix various issues with content core rewrite (#488)
Diffstat (limited to 'src/SMAPI/Framework/ContentCoordinator.cs')
-rw-r--r--src/SMAPI/Framework/ContentCoordinator.cs28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs
index 86ebc5c3..397a9d90 100644
--- a/src/SMAPI/Framework/ContentCoordinator.cs
+++ b/src/SMAPI/Framework/ContentCoordinator.cs
@@ -30,6 +30,9 @@ namespace StardewModdingAPI.Framework
/// <summary>The loaded content managers (including the <see cref="MainContentManager"/>).</summary>
private readonly IList<SContentManager> ContentManagers = new List<SContentManager>();
+ /// <summary>Whether the content coordinator has been disposed.</summary>
+ private bool IsDisposed;
+
/*********
** Accessors
@@ -65,7 +68,7 @@ namespace StardewModdingAPI.Framework
this.Reflection = reflection;
this.FullRootDirectory = Path.Combine(Constants.ExecutionPath, rootDirectory);
this.ContentManagers.Add(
- this.MainContentManager = new SContentManager("Game1.content", serviceProvider, rootDirectory, currentCulture, this, monitor, reflection, isModFolder: false)
+ this.MainContentManager = new SContentManager("Game1.content", serviceProvider, rootDirectory, currentCulture, this, monitor, reflection, this.OnDisposing, isModFolder: false)
);
this.CoreAssets = new CoreAssetPropagator(this.MainContentManager.NormaliseAssetName, reflection);
}
@@ -76,7 +79,9 @@ namespace StardewModdingAPI.Framework
/// <param name="rootDirectory">The root directory to search for content (or <c>null</c>. for the default)</param>
public SContentManager CreateContentManager(string name, bool isModFolder, string rootDirectory = null)
{
- return new SContentManager(name, this.MainContentManager.ServiceProvider, rootDirectory ?? this.MainContentManager.RootDirectory, this.MainContentManager.CurrentCulture, this, this.Monitor, this.Reflection, isModFolder);
+ SContentManager manager = new SContentManager(name, this.MainContentManager.ServiceProvider, rootDirectory ?? this.MainContentManager.RootDirectory, this.MainContentManager.CurrentCulture, this, this.Monitor, this.Reflection, this.OnDisposing, isModFolder);
+ this.ContentManagers.Add(manager);
+ return manager;
}
/// <summary>Get the current content locale.</summary>
@@ -162,8 +167,9 @@ namespace StardewModdingAPI.Framework
/// <summary>Dispose held resources.</summary>
public void Dispose()
{
- if (this.MainContentManager == null)
- return; // already disposed
+ if (this.IsDisposed)
+ return;
+ this.IsDisposed = true;
this.Monitor.Log("Disposing the content coordinator. Content managers will no longer be usable after this point.", LogLevel.Trace);
foreach (SContentManager contentManager in this.ContentManagers)
@@ -171,5 +177,19 @@ namespace StardewModdingAPI.Framework
this.ContentManagers.Clear();
this.MainContentManager = null;
}
+
+
+ /*********
+ ** Private methods
+ *********/
+ /// <summary>A callback invoked when a content manager is disposed.</summary>
+ /// <param name="contentManager">The content manager being disposed.</param>
+ private void OnDisposing(SContentManager contentManager)
+ {
+ if (this.IsDisposed)
+ return;
+
+ this.ContentManagers.Remove(contentManager);
+ }
}
}