diff --git a/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs b/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs index 0d6ab1d3..d2c57ebe 100644 --- a/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs @@ -58,6 +58,14 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu // If the entry is partial due to an incomplete multi-part archive, skip it if (!entry.IsComplete) continue; + + // If the entry is password-protected, skip it + if (entry.IsEncrypted) + { + if (includeDebug) Console.WriteLine($"File {entry.Key} in zip is password-protected!"); + + continue; + } // Ensure directory separators are consistent string filename = entry.Key; diff --git a/SabreTools.Serialization/Wrappers/RAR.Extraction.cs b/SabreTools.Serialization/Wrappers/RAR.Extraction.cs index 0b78de3a..c257954f 100644 --- a/SabreTools.Serialization/Wrappers/RAR.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/RAR.Extraction.cs @@ -74,12 +74,25 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu continue; if (firstFile) + { firstFile = false; - else + continue; + } + + if (entry.IsSolid) { - isSolid = entry.IsSolid; - break; + // If the RAR is solid and the first entry is password-protected, you won't be able to + // extract the rest of the entries anyway, so just return early. + if (entry.IsEncrypted) + { + if (includeDebug) Console.WriteLine("RAR is password-protected!"); + return false; + } + + isSolid = true; } + + break; } catch (Exception ex) { @@ -215,6 +228,14 @@ private static bool ExtractNonSolid(RarArchive rarFile, string outDir, bool incl // If we have a partial entry due to an incomplete multi-part archive, skip it if (!entry.IsComplete) continue; + + // If the entry is password-protected, skip it + if (entry.IsEncrypted) + { + if (includeDebug) Console.WriteLine($"File {entry.Key} in RAR is password-protected!"); + + continue; + } // Ensure directory separators are consistent string filename = entry.Key; diff --git a/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs b/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs index 7b0c1971..fb6df68e 100644 --- a/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs @@ -73,12 +73,25 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu continue; if (firstFile) + { firstFile = false; - else + continue; + } + + if (entry.IsSolid) { - isSolid = entry.IsSolid; - break; + // If the 7z is solid and the first entry is password-protected, you won't be able to + // extract the rest of the entries anyway, so just return early. + if (entry.IsEncrypted) + { + if (includeDebug) Console.WriteLine("7z is password-protected!"); + return false; + } + + isSolid = true; } + + break; } catch (Exception ex) { @@ -183,6 +196,14 @@ private static bool ExtractNonSolid(SevenZipArchive sevenZip, string outputDirec // If we have a partial entry due to an incomplete multi-part archive, skip it if (!entry.IsComplete) continue; + + // If the entry is password-protected, skip it + if (entry.IsEncrypted) + { + if (includeDebug) Console.WriteLine($"File {entry.Key} in 7z is password-protected!"); + + continue; + } // Ensure directory separators are consistent string filename = entry.Key;