(ArcFile.TryOpen): some tweaks.

This commit is contained in:
morkt 2016-08-13 23:52:59 +04:00
parent b3d74fb17c
commit 0a606433f4
2 changed files with 11 additions and 5 deletions

View File

@ -64,25 +64,30 @@ namespace GameRes
/// </returns>
public static ArcFile TryOpen (string filename)
{
var entry = VFS.FindFile (filename);
return TryOpen (VFS.FindFile (filename));
}
public static ArcFile TryOpen (Entry entry)
{
if (entry.Size < 4)
return null;
var filename = entry.Name;
var ext = new Lazy<string> (() => Path.GetExtension (filename).TrimStart ('.').ToLowerInvariant());
var file = VFS.OpenView (entry);
try
{
uint signature = file.View.ReadUInt32 (0);
var tried = new HashSet<ArchiveFormat>();
var tried = Enumerable.Empty<ArchiveFormat>();
for (;;)
{
var range = FormatCatalog.Instance.LookupSignature<ArchiveFormat> (signature);
if (tried.Any())
range = range.Except (tried);
// check formats that match filename extension first
if (range.Skip(1).Any()) // if range.Count() > 1
range = range.OrderByDescending (f => f.Extensions.Any (e => e == ext.Value));
foreach (var impl in range)
{
if (!tried.Add (impl))
continue;
try
{
var arc = impl.TryOpen (file);
@ -107,6 +112,7 @@ namespace GameRes
if (0 == signature)
break;
signature = 0;
tried = range;
}
}
finally

View File

@ -550,7 +550,7 @@ namespace GameRes
return;
}
Flush();
var arc = ArcFile.TryOpen (entry.Name);
var arc = ArcFile.TryOpen (entry);
if (null == arc)
{
if (FormatCatalog.Instance.LastError is OperationCanceledException)