(GameRes): added resource aliases.

This commit is contained in:
morkt 2018-09-05 13:24:28 +04:00
parent 7b0c7fef6c
commit cf6e2cca9a
2 changed files with 50 additions and 3 deletions

View File

@ -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<IResource> formats, CompositionContainer container)
private void AddResourceImpl (IEnumerable<IResource> 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<ResourceAlias, IResourceAliasMetadata>())
{
var metadata = alias.Metadata;
IEnumerable<IResource> 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)

View File

@ -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
{
}
/// <summary>
/// Link filename extension to specific resource.
/// </summary>
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