mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-24 03:44:13 +08:00
(ArcFile.TryOpen): some tweaks.
This commit is contained in:
parent
b3d74fb17c
commit
0a606433f4
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user