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>
|
||||
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;
|
||||
return new EntryType {
|
||||
Name = filename,
|
||||
Type = FormatCatalog.Instance.GetTypeFromName (filename, ContainedFormats),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -85,7 +77,10 @@ namespace GameRes
|
||||
/// </summary>
|
||||
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>
|
||||
|
@ -274,22 +274,20 @@ namespace GameRes
|
||||
/// characters.</exception>
|
||||
public EntryType Create<EntryType> (string filename) where EntryType : Entry, new()
|
||||
{
|
||||
EntryType entry = null;
|
||||
var formats = LookupFileName (filename);
|
||||
if (formats.Any())
|
||||
entry = new EntryType { Type = formats.First().Type };
|
||||
if (null == entry)
|
||||
entry = new EntryType();
|
||||
entry.Name = filename;
|
||||
return entry;
|
||||
return new EntryType {
|
||||
Name = filename,
|
||||
Type = GetTypeFromName (filename),
|
||||
};
|
||||
}
|
||||
|
||||
public string GetTypeFromName (string filename)
|
||||
public string GetTypeFromName (string filename, IEnumerable<string> preferred_formats = null)
|
||||
{
|
||||
var formats = LookupFileName (filename);
|
||||
if (formats.Any())
|
||||
return formats.First().Type;
|
||||
return "";
|
||||
if (!formats.Any())
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user