Maybe fix multipart 7z, RAR, and PKZIP archives

This commit is contained in:
Matt Nadareski
2025-08-25 13:19:28 -04:00
parent 66d80c8523
commit 2535e82618
3 changed files with 34 additions and 9 deletions

View File

@@ -100,9 +100,17 @@ namespace SabreTools.Serialization.Wrappers
var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader };
var zipFile = ZipArchive.Open(_dataSource, readerOptions);
// Try to read the file path if no entries are found
if (zipFile.Entries.Count == 0 && !string.IsNullOrEmpty(Filename) && File.Exists(Filename!))
zipFile = ZipArchive.Open(Filename!, readerOptions);
// If the file exists
if (!string.IsNullOrEmpty(Filename) && File.Exists(Filename!))
{
// Try to read the file path if no entries are found
if (zipFile.Entries.Count == 0)
zipFile = ZipArchive.Open(Filename!, readerOptions);
// If there's any multipart items, try reading the file as well
else if (System.Array.Exists([.. zipFile.Entries], e => !e.IsComplete))
zipFile = ZipArchive.Open(Filename!, readerOptions);
}
foreach (var entry in zipFile.Entries)
{

View File

@@ -103,9 +103,17 @@ namespace SabreTools.Serialization.Wrappers
var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader };
RarArchive rarFile = RarArchive.Open(_dataSource, readerOptions);
// Try to read the file path if no entries are found
if (rarFile.Entries.Count == 0 && !string.IsNullOrEmpty(Filename) && File.Exists(Filename!))
rarFile = RarArchive.Open(Filename!, readerOptions);
// If the file exists
if (!string.IsNullOrEmpty(Filename) && File.Exists(Filename!))
{
// Try to read the file path if no entries are found
if (rarFile.Entries.Count == 0)
rarFile = RarArchive.Open(Filename!, readerOptions);
// If there's any multipart items, try reading the file as well
else if (System.Array.Exists([.. rarFile.Entries], e => !e.IsComplete))
rarFile = RarArchive.Open(Filename!, readerOptions);
}
if (!rarFile.IsComplete)
return false;

View File

@@ -102,9 +102,18 @@ namespace SabreTools.Serialization.Wrappers
{
var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader };
var sevenZip = SevenZipArchive.Open(_dataSource, readerOptions);
// Try to read the file path if no entries are found
if (sevenZip.Entries.Count == 0 && !string.IsNullOrEmpty(Filename) && File.Exists(Filename!))
sevenZip = SevenZipArchive.Open(Filename!, readerOptions);
// If the file exists
if (!string.IsNullOrEmpty(Filename) && File.Exists(Filename!))
{
// Try to read the file path if no entries are found
if (sevenZip.Entries.Count == 0)
sevenZip = SevenZipArchive.Open(Filename!, readerOptions);
// If there's any multipart items, try reading the file as well
else if (System.Array.Exists([.. sevenZip.Entries], e => !e.IsComplete))
sevenZip = SevenZipArchive.Open(Filename!, readerOptions);
}
// Currently doesn't flag solid 7z archives with only 1 solid block as solid, but practically speaking
// this is not much of a concern.