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