(GameRes): moved preferred formats logic to GetTypeFromName method.

This commit is contained in:
morkt 2018-09-23 03:52:53 +04:00
parent 47f7486efc
commit b3ccb3cd50
2 changed files with 18 additions and 25 deletions

View File

@ -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>

View File

@ -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)