Fix NRE when enumerating archive members to HawkArchiveFileItems

SharpCompress does this for .tar.gz it seems
This commit is contained in:
YoshiRulz 2021-01-22 07:51:04 +10:00
parent 0fd7154eec
commit 0f21944755
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 20 additions and 5 deletions

View File

@ -39,10 +39,17 @@ namespace BizHawk.Client.Common
entryStream.CopyTo(stream);
}
public List<HawkArchiveFileItem> Scan()
public List<HawkArchiveFileItem>? Scan()
{
var files = EnumerateArchiveFiles();
return files.Select((e, i) => new HawkArchiveFileItem(e.Key.Replace('\\', '/'), e.Size, i, i)).ToList();
List<HawkArchiveFileItem> outFiles = new();
var entries = EnumerateArchiveFiles().ToList();
for (var i = 0; i < entries.Count; i++)
{
var entry = entries[i];
if (entry.Key == null) return null;
outFiles.Add(new HawkArchiveFileItem(entry.Key.Replace('\\', '/'), entry.Size, i, i));
}
return outFiles;
}
}
}

View File

@ -102,11 +102,12 @@ namespace BizHawk.Common
_extractor = DearchivalMethod.Construct(path);
try
{
_archiveItems = _extractor.Scan();
_archiveItems = _extractor.Scan() ?? throw new NullReferenceException();
IsArchive = true;
}
catch
{
Console.WriteLine($"Failed to scan file list of {FullPathWithoutMember}");
_archiveItems = null;
_extractor.Dispose();
_extractor = null;
@ -132,6 +133,12 @@ namespace BizHawk.Common
if (_extractor != null)
{
var scanResults = _extractor.Scan();
if (scanResults == null)
{
Console.WriteLine($"Failed to scan file list of {FullPathWithoutMember}");
Exists = false;
return;
}
for (int i = 0, l = scanResults.Count; i < l; i++)
{
if (string.Equals(scanResults[i].Name, autobind, StringComparison.InvariantCultureIgnoreCase))

View File

@ -9,6 +9,7 @@ namespace BizHawk.Common
{
void ExtractFile(int index, Stream stream);
List<HawkArchiveFileItem> Scan();
/// <returns><see langword="null"/> on failure</returns>
List<HawkArchiveFileItem>? Scan();
}
}