Skip to content

Commit cb41f8a

Browse files
Temporary fix for solid archive detection until SharpCompress makes another release. (#24)
1 parent fcf003a commit cb41f8a

File tree

2 files changed

+78
-4
lines changed

2 files changed

+78
-4
lines changed

SabreTools.Serialization/Wrappers/RAR.Extraction.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,46 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu
4848
else if (rarFile.Entries.Count == 0)
4949
rarFile = RarArchive.Open(parts, readerOptions);
5050
}
51+
52+
// Explained in https://github.com/adamhathcock/sharpcompress/pull/661. in order to determine whether
53+
// a RAR or 7Z archive is solid or not, you must check the second file in the archive, as the first
54+
// file is always marked non-solid even for solid archives. This iteration is necessary since things
55+
// like directories aren't marked solid either.
56+
// This is only temporary, as solid detection has been fixed in upstream SolidCompress, but they likely
57+
// won't make a new release for a while, and this is too big an issue to leave unfixed.
58+
bool firstFile = true;
59+
bool isSolid = false;
60+
foreach (var entry in rarFile.Entries)
61+
{
62+
try
63+
{
64+
// If the entry is a directory
65+
if (entry.IsDirectory)
66+
continue;
67+
68+
// If the entry has an invalid key
69+
if (entry.Key == null)
70+
continue;
71+
72+
// If we have a partial entry due to an incomplete multi-part archive, skip it
73+
if (!entry.IsComplete)
74+
continue;
75+
76+
if (firstFile)
77+
firstFile = false;
78+
else
79+
{
80+
isSolid = entry.IsSolid;
81+
break;
82+
}
83+
}
84+
catch (Exception ex)
85+
{
86+
if (includeDebug) Console.WriteLine(ex);
87+
}
88+
}
5189

52-
if (rarFile.IsSolid)
90+
if (isSolid)
5391
return ExtractSolid(rarFile, outputDirectory, includeDebug);
5492
else
5593
return ExtractNonSolid(rarFile, outputDirectory, includeDebug);

SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,45 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu
4848
sevenZip = SevenZipArchive.Open(parts, readerOptions);
4949
}
5050

51-
// Currently doesn't flag solid 7z archives with only 1 solid block as solid, but practically speaking
52-
// this is not much of a concern.
53-
if (sevenZip.IsSolid)
51+
// Explained in https://github.com/adamhathcock/sharpcompress/pull/661. in order to determine whether
52+
// a RAR or 7Z archive is solid or not, you must check the second file in the archive, as the first
53+
// file is always marked non-solid even for solid archives. This iteration is necessary since things
54+
// like directories aren't marked solid either.
55+
// This is only temporary, as solid detection has been fixed in upstream SolidCompress, but they likely
56+
// won't make a new release for a while, and this is too big an issue to leave unfixed.
57+
bool firstFile = true;
58+
bool isSolid = false;
59+
foreach (var entry in sevenZip.Entries)
60+
{
61+
try
62+
{
63+
// If the entry is a directory
64+
if (entry.IsDirectory)
65+
continue;
66+
67+
// If the entry has an invalid key
68+
if (entry.Key == null)
69+
continue;
70+
71+
// If we have a partial entry due to an incomplete multi-part archive, skip it
72+
if (!entry.IsComplete)
73+
continue;
74+
75+
if (firstFile)
76+
firstFile = false;
77+
else
78+
{
79+
isSolid = entry.IsSolid;
80+
break;
81+
}
82+
}
83+
catch (Exception ex)
84+
{
85+
if (includeDebug) Console.WriteLine(ex);
86+
}
87+
}
88+
89+
if (isSolid)
5490
return ExtractSolid(sevenZip, outputDirectory, includeDebug);
5591
else
5692
return ExtractNonSolid(sevenZip, outputDirectory, includeDebug);

0 commit comments

Comments
 (0)