diff --git a/GameRes/FormatCatalog.cs b/GameRes/FormatCatalog.cs index eebedb7e..73c2b246 100644 --- a/GameRes/FormatCatalog.cs +++ b/GameRes/FormatCatalog.cs @@ -2,7 +2,7 @@ //! \date Wed Sep 16 22:51:11 2015 //! \brief game resources formats catalog class. // -// Copyright (C) 2014-2015 by morkt +// Copyright (C) 2014-2018 by morkt // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to @@ -106,10 +106,12 @@ namespace GameRes AddResourceImpl (m_arc_formats, container); AddResourceImpl (m_audio_formats, container); AddResourceImpl (m_script_formats, container); + + AddAliases (container); } } - private void AddResourceImpl (IEnumerable formats, CompositionContainer container) + private void AddResourceImpl (IEnumerable formats, ICompositionService container) { foreach (var impl in formats) { @@ -134,6 +136,35 @@ namespace GameRes } } + private void AddAliases (ExportProvider provider) + { + foreach (var alias in provider.GetExports()) + { + var metadata = alias.Metadata; + IEnumerable target_list; + if (string.IsNullOrEmpty (metadata.Type)) + target_list = Formats; + else if ("archive" == metadata.Type) + target_list = ArcFormats; + else if ("image" == metadata.Type) + target_list = ImageFormats; + else if ("audio" == metadata.Type) + target_list = AudioFormats; + else if ("script" == metadata.Type) + target_list = ScriptFormats; + else + continue; + var ext = metadata.Extension; + var target = metadata.Target; + if (!string.IsNullOrEmpty (ext) && !string.IsNullOrEmpty (target)) + { + var target_res = target_list.FirstOrDefault (f => f.Tag == target); + if (target_res != null) + m_extension_map.Add (ext.ToUpperInvariant(), target_res); + } + } + } + public void UpgradeSettings () { if (Properties.Settings.Default.UpgradeRequired) diff --git a/GameRes/GameRes.cs b/GameRes/GameRes.cs index f09a4056..f8daa649 100644 --- a/GameRes/GameRes.cs +++ b/GameRes/GameRes.cs @@ -2,7 +2,7 @@ //! \date Mon Jun 30 20:12:13 2014 //! \brief game resources browser. // -// Copyright (C) 2014-2015 by morkt +// Copyright (C) 2014-2018 by morkt // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to @@ -26,6 +26,7 @@ using System; using System.IO; using System.Collections.Generic; +using System.ComponentModel; using GameRes.Strings; namespace GameRes @@ -179,6 +180,21 @@ namespace GameRes { } + public class ResourceAlias + { + } + + /// + /// Link filename extension to specific resource. + /// + public interface IResourceAliasMetadata + { + string Extension { get; } + string Target { get; } + [DefaultValue(null)] + string Type { get; } + } + public delegate void ParametersRequestEventHandler (object sender, ParametersRequestEventArgs e); public class ParametersRequestEventArgs : EventArgs