mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-23 05:35:34 +08:00
(GameRes): moved preferred formats logic to GetTypeFromName method.
This commit is contained in:
parent
47f7486efc
commit
b3ccb3cd50
@ -56,18 +56,10 @@ namespace GameRes
|
|||||||
/// characters.</exception>
|
/// characters.</exception>
|
||||||
public EntryType Create<EntryType> (string filename) where EntryType : Entry, new()
|
public EntryType Create<EntryType> (string filename) where EntryType : Entry, new()
|
||||||
{
|
{
|
||||||
EntryType entry = null;
|
return new EntryType {
|
||||||
var formats = FormatCatalog.Instance.LookupFileName (filename);
|
Name = filename,
|
||||||
if (formats.Any())
|
Type = FormatCatalog.Instance.GetTypeFromName (filename, ContainedFormats),
|
||||||
{
|
};
|
||||||
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>
|
||||||
@ -85,7 +77,10 @@ namespace GameRes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual Stream OpenEntry (ArcFile arc, Entry entry)
|
public virtual Stream OpenEntry (ArcFile arc, Entry entry)
|
||||||
{
|
{
|
||||||
return arc.File.CreateStream (entry.Offset, entry.Size, entry.Name);
|
if (entry.Size > 0)
|
||||||
|
return arc.File.CreateStream (entry.Offset, entry.Size, entry.Name);
|
||||||
|
else
|
||||||
|
return Stream.Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -274,22 +274,20 @@ namespace GameRes
|
|||||||
/// characters.</exception>
|
/// characters.</exception>
|
||||||
public EntryType Create<EntryType> (string filename) where EntryType : Entry, new()
|
public EntryType Create<EntryType> (string filename) where EntryType : Entry, new()
|
||||||
{
|
{
|
||||||
EntryType entry = null;
|
return new EntryType {
|
||||||
var formats = LookupFileName (filename);
|
Name = filename,
|
||||||
if (formats.Any())
|
Type = GetTypeFromName (filename),
|
||||||
entry = new EntryType { Type = formats.First().Type };
|
};
|
||||||
if (null == entry)
|
|
||||||
entry = new EntryType();
|
|
||||||
entry.Name = filename;
|
|
||||||
return entry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTypeFromName (string filename)
|
public string GetTypeFromName (string filename, IEnumerable<string> preferred_formats = null)
|
||||||
{
|
{
|
||||||
var formats = LookupFileName (filename);
|
var formats = LookupFileName (filename);
|
||||||
if (formats.Any())
|
if (!formats.Any())
|
||||||
return formats.First().Type;
|
return "";
|
||||||
return "";
|
if (preferred_formats != null && preferred_formats.Any())
|
||||||
|
formats = formats.OrderByDescending (f => preferred_formats.Contains (f.Tag));
|
||||||
|
return formats.First().Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InvokeParametersRequest (object source, ParametersRequestEventArgs args)
|
public void InvokeParametersRequest (object source, ParametersRequestEventArgs args)
|
||||||
|
Loading…
Reference in New Issue
Block a user