diff --git a/SabreTools.Helper/Tools/ArchiveTools.cs b/SabreTools.Helper/Tools/ArchiveTools.cs
index 5b92c4a7..14d16562 100644
--- a/SabreTools.Helper/Tools/ArchiveTools.cs
+++ b/SabreTools.Helper/Tools/ArchiveTools.cs
@@ -27,7 +27,6 @@ using ROMVault2.SupportedFiles.Zip;
using SevenZip;
using SharpCompress.Archives;
using SharpCompress.Archives.Rar;
-using SharpCompress.Archives.SevenZip;
using SharpCompress.Archives.Tar;
using SharpCompress.Common;
using SharpCompress.Readers;
@@ -58,6 +57,8 @@ namespace SabreTools.Helper.Tools
/// True if the extraction was a success, false otherwise
public static bool ExtractArchive(string input, string outDir, ArchiveScanLevel archiveScanLevel)
{
+ // Set internal variables
+ SevenZipBase.SetLibraryPath("7za.dll");
bool encounteredErrors = true;
// First get the archive type
@@ -80,12 +81,21 @@ namespace SabreTools.Helper.Tools
Directory.CreateDirectory(outDir);
// Extract all files to the temp directory
- SevenZipArchive sza = SevenZipArchive.Open(File.OpenRead(input));
- foreach (SevenZipArchiveEntry entry in sza.Entries)
+ SevenZipExtractor sza = new SevenZipExtractor(File.OpenRead(input))
{
- entry.WriteToDirectory(outDir, new ExtractionOptions{ PreserveFileTime = true, ExtractFullPath = true, Overwrite = true });
+ PreserveDirectoryStructure = true,
+ };
+
+ try
+ {
+ sza.ExtractArchive(outDir);
+ encounteredErrors = false;
}
- encounteredErrors = false;
+ catch
+ {
+ encounteredErrors = true;
+ }
+
sza.Dispose();
}
@@ -223,6 +233,8 @@ namespace SabreTools.Helper.Tools
/// Name of the extracted file, null on error
public static string ExtractItem(string input, string entryName, string tempDir)
{
+ // Set internal variables
+ SevenZipBase.SetLibraryPath("7za.dll");
string realEntry = "";
// Set the real entry name
@@ -242,13 +254,13 @@ namespace SabreTools.Helper.Tools
switch (at)
{
case ArchiveType.SevenZip:
- SevenZipArchive sza = SevenZipArchive.Open(input, new ReaderOptions { LeaveStreamOpen = false, });
- foreach (SevenZipArchiveEntry entry in sza.Entries)
+ SevenZipExtractor sza = new SevenZipExtractor(input);
+ foreach (ArchiveFileInfo entry in sza.ArchiveFileData)
{
- Globals.Logger.Verbose("Current entry name: '" + entry.Key + "'");
- if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName))
+ Globals.Logger.Verbose("Current entry name: '" + entry.FileName + "'");
+ if (entry != null && !entry.IsDirectory && entry.FileName.Contains(entryName))
{
- realEntry = entry.Key;
+ realEntry = entry.FileName;
// Get the output path
realEntry = Path.Combine(Path.GetFullPath(tempDir), realEntry);
@@ -258,7 +270,7 @@ namespace SabreTools.Helper.Tools
}
// Write the file out
- entry.WriteToFile(realEntry);
+ sza.ExtractFile(entry.Index, File.OpenWrite(realEntry));
break;
}
}
@@ -403,6 +415,8 @@ namespace SabreTools.Helper.Tools
/// List of RomData objects representing the found data
public static List GetArchiveFileInfo(string input)
{
+ // Set internal variables
+ SevenZipBase.SetLibraryPath("7za.dll");
List roms = new List();
string gamename = Path.GetFileNameWithoutExtension(input);
@@ -444,20 +458,20 @@ namespace SabreTools.Helper.Tools
switch (at)
{
case ArchiveType.SevenZip:
- SevenZipArchive sza = SevenZipArchive.Open(input, new ReaderOptions { LeaveStreamOpen = false });
- foreach (SevenZipArchiveEntry entry in sza.Entries)
+ SevenZipExtractor sza = new SevenZipExtractor(input);
+ foreach (ArchiveFileInfo entry in sza.ArchiveFileData)
{
if (entry != null && !entry.IsDirectory)
{
- Globals.Logger.Verbose("Entry found: '" + entry.Key + "': "
- + (size == 0 ? entry.Size : size) + ", "
+ Globals.Logger.Verbose("Entry found: '" + entry.FileName + "': "
+ + (size == 0 ? (long)entry.Size : size) + ", "
+ (crc == "" ? entry.Crc.ToString("X").ToLowerInvariant() : crc));
roms.Add(new Rom
{
Type = ItemType.Rom,
- Name = entry.Key,
- Size = (size == 0 ? entry.Size : size),
+ Name = entry.FileName,
+ Size = (size == 0 ? (long)entry.Size : size),
CRC = (crc == "" ? entry.Crc.ToString("X").ToLowerInvariant() : crc),
Machine = new Machine
@@ -1075,6 +1089,8 @@ namespace SabreTools.Helper.Tools
/// 0 if the file isn't 7z, 1 if the file is t7z, 2 if the file is 7z
public static int IsT7z(string filename)
{
+ // Set internal variables
+ SevenZipBase.SetLibraryPath("7za.dll");
int ist7z = 0;
if (File.Exists(filename))