mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
(ArchiveFormat): added ContainedFormats property.
This commit is contained in:
@@ -43,6 +43,9 @@ namespace GameRes
|
|||||||
/// <summary>Short archive format description.</summary>
|
/// <summary>Short archive format description.</summary>
|
||||||
public string Description { get { return m_interface.Description; } }
|
public string Description { get { return m_interface.Description; } }
|
||||||
|
|
||||||
|
/// <summary>Tags of formats related to this archive format (could be null).</summary>
|
||||||
|
public IEnumerable<string> ContainedFormats { get { return m_interface.ContainedFormats; } }
|
||||||
|
|
||||||
/// <summary>Memory-mapped view of the archive.</summary>
|
/// <summary>Memory-mapped view of the archive.</summary>
|
||||||
public ArcView File { get { return m_arc; } }
|
public ArcView File { get { return m_arc; } }
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace GameRes
|
namespace GameRes
|
||||||
{
|
{
|
||||||
@@ -41,8 +42,34 @@ namespace GameRes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract bool IsHierarchic { get; }
|
public abstract bool IsHierarchic { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tags of formats related to this archive format (could be null).
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<string> ContainedFormats { get; protected set; }
|
||||||
|
|
||||||
public abstract ArcFile TryOpen (ArcView view);
|
public abstract ArcFile TryOpen (ArcView view);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create GameRes.Entry corresponding to <paramref name="filename"/> extension.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="System.ArgumentException">May be thrown if filename contains invalid
|
||||||
|
/// characters.</exception>
|
||||||
|
public EntryType Create<EntryType> (string filename) where EntryType : Entry, new()
|
||||||
|
{
|
||||||
|
EntryType entry = null;
|
||||||
|
var formats = FormatCatalog.Instance.LookupFileName (filename);
|
||||||
|
if (formats.Any())
|
||||||
|
{
|
||||||
|
if (ContainedFormats != null && ContainedFormats.Any())
|
||||||
|
formats = formats.OrderByDescending (f => ContainedFormats.Contains (f.Tag));
|
||||||
|
entry = new EntryType { Type = formats.First().Type };
|
||||||
|
}
|
||||||
|
if (null == entry)
|
||||||
|
entry = new EntryType();
|
||||||
|
entry.Name = filename;
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Extract file referenced by <paramref name="entry"/> into current directory.
|
/// Extract file referenced by <paramref name="entry"/> into current directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -239,6 +239,13 @@ namespace GameRes
|
|||||||
{
|
{
|
||||||
var ext = new Lazy<string> (() => Path.GetExtension (filename).TrimStart ('.').ToLowerInvariant(), false);
|
var ext = new Lazy<string> (() => Path.GetExtension (filename).TrimStart ('.').ToLowerInvariant(), false);
|
||||||
var tried = Enumerable.Empty<ResourceType>();
|
var tried = Enumerable.Empty<ResourceType>();
|
||||||
|
IEnumerable<string> preferred = null;
|
||||||
|
if (VFS.IsVirtual)
|
||||||
|
{
|
||||||
|
var arc_fs = VFS.Top as ArchiveFileSystem;
|
||||||
|
if (arc_fs != null)
|
||||||
|
preferred = arc_fs.Source.ContainedFormats;
|
||||||
|
}
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
var range = LookupSignature<ResourceType> (signature);
|
var range = LookupSignature<ResourceType> (signature);
|
||||||
@@ -247,6 +254,8 @@ namespace GameRes
|
|||||||
// check formats that match filename extension first
|
// check formats that match filename extension first
|
||||||
if (range.Skip (1).Any()) // if range.Count() > 1
|
if (range.Skip (1).Any()) // if range.Count() > 1
|
||||||
range = range.OrderByDescending (f => f.Extensions.Any (e => e == ext.Value));
|
range = range.OrderByDescending (f => f.Extensions.Any (e => e == ext.Value));
|
||||||
|
if (preferred != null && preferred.Any())
|
||||||
|
range = range.OrderByDescending (f => preferred.Contains (f.Tag));
|
||||||
foreach (var impl in range)
|
foreach (var impl in range)
|
||||||
{
|
{
|
||||||
yield return impl;
|
yield return impl;
|
||||||
@@ -268,7 +277,7 @@ namespace GameRes
|
|||||||
EntryType entry = null;
|
EntryType entry = null;
|
||||||
var formats = LookupFileName (filename);
|
var formats = LookupFileName (filename);
|
||||||
if (formats.Any())
|
if (formats.Any())
|
||||||
entry = formats.First().Create<EntryType>();
|
entry = new EntryType { Type = formats.First().Type };
|
||||||
if (null == entry)
|
if (null == entry)
|
||||||
entry = new EntryType();
|
entry = new EntryType();
|
||||||
entry.Name = filename;
|
entry.Name = filename;
|
||||||
|
|||||||
@@ -109,14 +109,6 @@ namespace GameRes
|
|||||||
/// <summary>Resource access scheme suitable for serialization.</summary>
|
/// <summary>Resource access scheme suitable for serialization.</summary>
|
||||||
public virtual ResourceScheme Scheme { get; set; }
|
public virtual ResourceScheme Scheme { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create empty Entry that corresponds to implemented resource.
|
|
||||||
/// </summary>
|
|
||||||
public EntryType Create<EntryType> () where EntryType : Entry, new()
|
|
||||||
{
|
|
||||||
return new EntryType { Type = this.Type };
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IResource ()
|
protected IResource ()
|
||||||
{
|
{
|
||||||
Extensions = new string[] { GetDefaultExtension() };
|
Extensions = new string[] { GetDefaultExtension() };
|
||||||
|
|||||||
Reference in New Issue
Block a user