From 0ed70e359566f363e5216fd48f207886d96ed0ef Mon Sep 17 00:00:00 2001 From: morkt Date: Thu, 6 Sep 2018 10:25:49 +0400 Subject: [PATCH] (GameRes): added priorities to format imports. --- GameRes/FormatCatalog.cs | 15 ++++++++++++--- GameRes/GameRes.cs | 6 ++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/GameRes/FormatCatalog.cs b/GameRes/FormatCatalog.cs index 73c2b246..316db395 100644 --- a/GameRes/FormatCatalog.cs +++ b/GameRes/FormatCatalog.cs @@ -41,11 +41,8 @@ namespace GameRes private static readonly FormatCatalog m_instance = new FormatCatalog(); #pragma warning disable 649 - [ImportMany(typeof(ArchiveFormat))] private IEnumerable m_arc_formats; - [ImportMany(typeof(ImageFormat))] private IEnumerable m_image_formats; - [ImportMany(typeof(AudioFormat))] private IEnumerable m_audio_formats; [ImportMany(typeof(ScriptFormat))] private IEnumerable m_script_formats; @@ -100,8 +97,12 @@ namespace GameRes //Create the CompositionContainer with the parts in the catalog using (var container = new CompositionContainer (catalog)) { + m_arc_formats = ImportWithPriorities (container); + m_image_formats = ImportWithPriorities (container); + m_audio_formats = ImportWithPriorities (container); //Fill the imports of this object container.ComposeParts (this); + AddResourceImpl (m_image_formats, container); AddResourceImpl (m_arc_formats, container); AddResourceImpl (m_audio_formats, container); @@ -136,6 +137,14 @@ namespace GameRes } } + private IEnumerable ImportWithPriorities (ExportProvider provider) + { + return provider.GetExports() + .OrderByDescending (f => f.Metadata.Priority) + .Select (f => f.Value) + .ToArray(); + } + private void AddAliases (ExportProvider provider) { foreach (var alias in provider.GetExports()) diff --git a/GameRes/GameRes.cs b/GameRes/GameRes.cs index f8daa649..30958893 100644 --- a/GameRes/GameRes.cs +++ b/GameRes/GameRes.cs @@ -195,6 +195,12 @@ namespace GameRes string Type { get; } } + public interface IResourceMetadata + { + [DefaultValue(0)] + int Priority { get; } + } + public delegate void ParametersRequestEventHandler (object sender, ParametersRequestEventArgs e); public class ParametersRequestEventArgs : EventArgs