mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Reduce unncessary use of this.
This commit is contained in:
@@ -36,7 +36,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
try
|
||||
{
|
||||
// Deserialize the input file
|
||||
var metadataFile = Serialization.Deserializers.ClrMamePro.DeserializeFile(filename, this._quotes);
|
||||
var metadataFile = Serialization.Deserializers.ClrMamePro.DeserializeFile(filename, _quotes);
|
||||
var metadata = new Serialization.CrossModel.ClrMamePro().Serialize(metadataFile);
|
||||
|
||||
// Convert to the internal format
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
return new BaseFile()
|
||||
{
|
||||
Filename = this.GetName(),
|
||||
Filename = GetName(),
|
||||
Parent = GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey),
|
||||
MD5 = GetStringFieldValue(Models.Metadata.Disk.MD5Key).FromHexString(),
|
||||
SHA1 = GetStringFieldValue(Models.Metadata.Disk.SHA1Key).FromHexString(),
|
||||
@@ -106,7 +106,7 @@ namespace SabreTools.DatItems.Formats
|
||||
public Rom ConvertToRom()
|
||||
{
|
||||
var rom = new Rom(_internal.ConvertToRom()!);
|
||||
rom.GetFieldValue<DataArea?>(Rom.DataAreaKey)?.SetName(this.GetFieldValue<DiskArea?>(Disk.DiskAreaKey)?.GetName());
|
||||
rom.GetFieldValue<DataArea?>(Rom.DataAreaKey)?.SetName(GetFieldValue<DiskArea?>(Disk.DiskAreaKey)?.GetName());
|
||||
rom.SetFieldValue<DupeType>(DatItem.DupeTypeKey, GetFieldValue<DupeType>(DatItem.DupeTypeKey));
|
||||
rom.SetFieldValue<Machine>(DatItem.MachineKey, GetFieldValue<Machine>(DatItem.MachineKey)!.Clone() as Machine ?? new Machine());
|
||||
rom.SetFieldValue<bool?>(DatItem.RemoveKey, GetBoolFieldValue(DatItem.RemoveKey));
|
||||
|
||||
@@ -168,7 +168,7 @@ namespace SabreTools.DatItems.Formats
|
||||
public Rom ConvertToRom()
|
||||
{
|
||||
var rom = new Rom();
|
||||
rom.SetName($"{this.Id}.{this.Extension}");
|
||||
rom.SetName($"{Id}.{Extension}");
|
||||
rom.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey, CRC);
|
||||
rom.SetFieldValue<DupeType>(DatItem.DupeTypeKey, GetFieldValue<DupeType>(DatItem.DupeTypeKey));
|
||||
rom.SetFieldValue<Machine>(DatItem.MachineKey, GetFieldValue<Machine>(DatItem.MachineKey)!.Clone() as Machine ?? new Machine());
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
return new BaseFile()
|
||||
{
|
||||
Filename = this.GetName(),
|
||||
Filename = GetName(),
|
||||
Parent = GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey),
|
||||
MD5 = GetStringFieldValue(Models.Metadata.Media.MD5Key).FromHexString(),
|
||||
SHA1 = GetStringFieldValue(Models.Metadata.Media.SHA1Key).FromHexString(),
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
bool encounteredErrors = true;
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
if (Filename == null)
|
||||
return true;
|
||||
|
||||
try
|
||||
@@ -87,9 +87,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// Decompress the _filename stream
|
||||
FileStream outstream = File.Create(Path.Combine(outDir, Path.GetFileNameWithoutExtension(this.Filename)));
|
||||
FileStream outstream = File.Create(Path.Combine(outDir, Path.GetFileNameWithoutExtension(Filename)));
|
||||
var gz = new gZip();
|
||||
ZipReturn ret = gz.ZipFileOpen(this.Filename);
|
||||
ZipReturn ret = gz.ZipFileOpen(Filename);
|
||||
ret = gz.ZipFileOpenReadStream(0, out Stream? gzstream, out ulong streamSize);
|
||||
byte[] buffer = new byte[32768];
|
||||
int read;
|
||||
@@ -172,15 +172,15 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override (Stream?, string?) GetEntryStream(string entryName)
|
||||
{
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
if (Filename == null)
|
||||
return (null, null);
|
||||
|
||||
try
|
||||
{
|
||||
// Open the entry stream
|
||||
string realEntry = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
string realEntry = Path.GetFileNameWithoutExtension(Filename);
|
||||
var gz = new gZip();
|
||||
ZipReturn ret = gz.ZipFileOpen(this.Filename);
|
||||
ZipReturn ret = gz.ZipFileOpen(Filename);
|
||||
ret = gz.ZipFileOpenReadStream(0, out Stream? stream, out ulong streamSize);
|
||||
|
||||
// Return the stream
|
||||
@@ -201,7 +201,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override List<BaseFile>? GetChildren()
|
||||
{
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
if (Filename == null)
|
||||
return null;
|
||||
|
||||
// If we have children cached already
|
||||
@@ -210,7 +210,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
|
||||
_children = [];
|
||||
|
||||
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
string gamename = Path.GetFileNameWithoutExtension(Filename);
|
||||
|
||||
BaseFile? possibleTgz = GetTorrentGZFileInfo();
|
||||
|
||||
@@ -227,11 +227,11 @@ namespace SabreTools.FileTypes.Archives
|
||||
BaseFile gzipEntryRom = new();
|
||||
|
||||
// Perform a quickscan, if flagged to
|
||||
if (this.AvailableHashTypes.Length == 1 && this.AvailableHashTypes[0] == HashType.CRC32)
|
||||
if (AvailableHashTypes.Length == 1 && AvailableHashTypes[0] == HashType.CRC32)
|
||||
{
|
||||
gzipEntryRom.Filename = gamename;
|
||||
|
||||
using BinaryReader br = new(File.OpenRead(this.Filename));
|
||||
using BinaryReader br = new(File.OpenRead(Filename));
|
||||
br.BaseStream.Seek(-8, SeekOrigin.End);
|
||||
gzipEntryRom.CRC = br.ReadBytesBigEndian(4);
|
||||
gzipEntryRom.Size = br.ReadInt32BigEndian();
|
||||
@@ -240,9 +240,9 @@ namespace SabreTools.FileTypes.Archives
|
||||
else
|
||||
{
|
||||
var gz = new gZip();
|
||||
ZipReturn ret = gz.ZipFileOpen(this.Filename);
|
||||
ZipReturn ret = gz.ZipFileOpen(Filename);
|
||||
ret = gz.ZipFileOpenReadStream(0, out Stream? gzstream, out ulong streamSize);
|
||||
gzipEntryRom = GetInfo(gzstream, hashes: this.AvailableHashTypes);
|
||||
gzipEntryRom = GetInfo(gzstream, hashes: AvailableHashTypes);
|
||||
gzipEntryRom.Filename = gz.GetLocalFile(0).Filename;
|
||||
gzipEntryRom.Parent = gamename;
|
||||
gzipEntryRom.Date = (gz.TimeStamp > 0 ? gz.TimeStamp.ToString() : null);
|
||||
@@ -273,35 +273,35 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
// Check for the file existing first
|
||||
if (this.Filename == null || !File.Exists(this.Filename))
|
||||
if (Filename == null || !File.Exists(Filename))
|
||||
return false;
|
||||
|
||||
string datum = Path.GetFileName(this.Filename).ToLowerInvariant();
|
||||
long filesize = new FileInfo(this.Filename).Length;
|
||||
string datum = Path.GetFileName(Filename).ToLowerInvariant();
|
||||
long filesize = new FileInfo(Filename).Length;
|
||||
|
||||
// If we have the romba depot files, just skip them gracefully
|
||||
if (datum == ".romba_size" || datum == ".romba_size.backup")
|
||||
{
|
||||
logger.Verbose($"Romba depot file found, skipping: {this.Filename}");
|
||||
logger.Verbose($"Romba depot file found, skipping: {Filename}");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the name is the right length
|
||||
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz"))
|
||||
{
|
||||
logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'");
|
||||
logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(Filename)}'");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the file is at least the minimum length
|
||||
if (filesize < 40 /* bytes */)
|
||||
{
|
||||
logger.Warning($"Possibly corrupt file '{Path.GetFullPath(this.Filename)}' with size {filesize}");
|
||||
logger.Warning($"Possibly corrupt file '{Path.GetFullPath(Filename)}' with size {filesize}");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the Romba-specific header data
|
||||
BinaryReader br = new(File.OpenRead(this.Filename));
|
||||
BinaryReader br = new(File.OpenRead(Filename));
|
||||
byte[] header = br.ReadBytes(12); // Get preamble header for checking
|
||||
br.ReadBytes(16); // headermd5
|
||||
br.ReadBytes(4); // headercrc
|
||||
@@ -334,30 +334,30 @@ namespace SabreTools.FileTypes.Archives
|
||||
public BaseFile? GetTorrentGZFileInfo()
|
||||
{
|
||||
// Check for the file existing first
|
||||
if (this.Filename == null || !File.Exists(this.Filename))
|
||||
if (Filename == null || !File.Exists(Filename))
|
||||
return null;
|
||||
|
||||
string datum = Path.GetFileName(this.Filename).ToLowerInvariant();
|
||||
long filesize = new FileInfo(this.Filename).Length;
|
||||
string datum = Path.GetFileName(Filename).ToLowerInvariant();
|
||||
long filesize = new FileInfo(Filename).Length;
|
||||
|
||||
// If we have the romba depot files, just skip them gracefully
|
||||
if (datum == ".romba_size" || datum == ".romba_size.backup")
|
||||
{
|
||||
logger.Verbose($"Romba depot file found, skipping: {this.Filename}");
|
||||
logger.Verbose($"Romba depot file found, skipping: {Filename}");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if the name is the right length
|
||||
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz"))
|
||||
{
|
||||
logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'");
|
||||
logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(Filename)}'");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if the file is at least the minimum length
|
||||
if (filesize < 40 /* bytes */)
|
||||
{
|
||||
logger.Warning($"Possibly corrupt file '{Path.GetFullPath(this.Filename)}' with size {filesize}");
|
||||
logger.Warning($"Possibly corrupt file '{Path.GetFullPath(Filename)}' with size {filesize}");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
byte[] headermd5; // MD5
|
||||
byte[] headercrc; // CRC
|
||||
ulong headersz; // Int64 size
|
||||
BinaryReader br = new(File.OpenRead(this.Filename));
|
||||
BinaryReader br = new(File.OpenRead(Filename));
|
||||
header = br.ReadBytes(12);
|
||||
headermd5 = br.ReadBytes(16);
|
||||
headercrc = br.ReadBytes(4);
|
||||
@@ -395,13 +395,13 @@ namespace SabreTools.FileTypes.Archives
|
||||
|
||||
BaseFile baseFile = new()
|
||||
{
|
||||
Filename = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(),
|
||||
Filename = Path.GetFileNameWithoutExtension(Filename).ToLowerInvariant(),
|
||||
Size = extractedsize,
|
||||
CRC = headercrc,
|
||||
MD5 = headermd5,
|
||||
SHA1 = Path.GetFileNameWithoutExtension(this.Filename).FromHexString(),
|
||||
SHA1 = Path.GetFileNameWithoutExtension(Filename).FromHexString(),
|
||||
|
||||
Parent = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(),
|
||||
Parent = Path.GetFileNameWithoutExtension(Filename).ToLowerInvariant(),
|
||||
};
|
||||
|
||||
return baseFile;
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
bool encounteredErrors = true;
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
if (Filename == null)
|
||||
return true;
|
||||
|
||||
try
|
||||
@@ -58,7 +58,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// Extract all files to the temp directory
|
||||
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(this.Filename);
|
||||
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(Filename);
|
||||
foreach (RarArchiveEntry entry in ra.Entries)
|
||||
{
|
||||
entry.WriteToDirectory(outDir, new SharpCompress.Common.ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true });
|
||||
@@ -136,7 +136,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
if (Filename == null)
|
||||
return (null, null);
|
||||
|
||||
try
|
||||
@@ -144,7 +144,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
Stream? stream = null;
|
||||
string? realEntry = null;
|
||||
|
||||
var ra = SharpCompress.Archives.Rar.RarArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false, });
|
||||
var ra = SharpCompress.Archives.Rar.RarArchive.Open(Filename, new ReaderOptions { LeaveStreamOpen = false, });
|
||||
foreach (RarArchiveEntry entry in ra.Entries)
|
||||
{
|
||||
// Skip invalid entries
|
||||
@@ -188,22 +188,22 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
if (Filename == null)
|
||||
return null;
|
||||
|
||||
List<BaseFile> found = [];
|
||||
string? gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
string? gamename = Path.GetFileNameWithoutExtension(Filename);
|
||||
|
||||
try
|
||||
{
|
||||
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(File.OpenRead(this.Filename));
|
||||
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(File.OpenRead(Filename));
|
||||
foreach (RarArchiveEntry entry in ra.Entries.Where(e => e != null && !e.IsDirectory))
|
||||
{
|
||||
// Create a blank item for the entry
|
||||
BaseFile rarEntryRom = new();
|
||||
|
||||
// Perform a quickscan, if flagged to
|
||||
if (this.AvailableHashTypes.Length == 1 && this.AvailableHashTypes[0] == HashType.CRC32)
|
||||
if (AvailableHashTypes.Length == 1 && AvailableHashTypes[0] == HashType.CRC32)
|
||||
{
|
||||
rarEntryRom.Size = entry.Size;
|
||||
rarEntryRom.CRC = BitConverter.GetBytes(entry.Crc);
|
||||
@@ -212,7 +212,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
else
|
||||
{
|
||||
using Stream entryStream = entry.OpenEntryStream();
|
||||
rarEntryRom = GetInfo(entryStream, size: entry.Size, hashes: this.AvailableHashTypes);
|
||||
rarEntryRom = GetInfo(entryStream, size: entry.Size, hashes: AvailableHashTypes);
|
||||
}
|
||||
|
||||
// Fill in common details and add to the list
|
||||
@@ -245,12 +245,12 @@ namespace SabreTools.FileTypes.Archives
|
||||
List<string> empties = [];
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
if (Filename == null)
|
||||
return empties;
|
||||
|
||||
try
|
||||
{
|
||||
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false });
|
||||
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(Filename, new ReaderOptions { LeaveStreamOpen = false });
|
||||
List<RarArchiveEntry> rarEntries = [.. ra.Entries.OrderBy(e => e.Key ?? string.Empty, new NaturalReversedComparer())];
|
||||
string? lastRarEntry = null;
|
||||
foreach (RarArchiveEntry entry in rarEntries)
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
bool encounteredErrors = true;
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
if (Filename == null)
|
||||
return true;
|
||||
|
||||
try
|
||||
@@ -64,7 +64,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
|
||||
// Extract all files to the temp directory
|
||||
var zf = new SevenZ();
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
|
||||
ZipReturn zr = zf.ZipFileOpen(Filename, -1, true);
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override (Stream?, string?) GetEntryStream(string entryName)
|
||||
{
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
if (Filename == null)
|
||||
return (null, null);
|
||||
|
||||
try
|
||||
@@ -190,7 +190,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
string? realEntry = null;
|
||||
|
||||
var zf = new SevenZ();
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
|
||||
ZipReturn zr = zf.ZipFileOpen(Filename, -1, true);
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
|
||||
|
||||
@@ -237,15 +237,15 @@ namespace SabreTools.FileTypes.Archives
|
||||
List<BaseFile> found = [];
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
if (Filename == null)
|
||||
return null;
|
||||
|
||||
string? gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
string? gamename = Path.GetFileNameWithoutExtension(Filename);
|
||||
|
||||
try
|
||||
{
|
||||
var zf = new SevenZ();
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
|
||||
ZipReturn zr = zf.ZipFileOpen(Filename, -1, true);
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
|
||||
|
||||
@@ -266,7 +266,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
// If we get a read error, log it and continue
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
{
|
||||
logger.Warning($"An error occurred while reading archive {this.Filename}: Zip Error - {zr}");
|
||||
logger.Warning($"An error occurred while reading archive {Filename}: Zip Error - {zr}");
|
||||
zr = zf.ZipFileCloseReadStream();
|
||||
continue;
|
||||
}
|
||||
@@ -275,7 +275,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
BaseFile zipEntryRom = new();
|
||||
|
||||
// Perform a quickscan, if flagged to
|
||||
if (this.AvailableHashTypes.Length == 1 && this.AvailableHashTypes[0] == HashType.CRC32)
|
||||
if (AvailableHashTypes.Length == 1 && AvailableHashTypes[0] == HashType.CRC32)
|
||||
{
|
||||
zipEntryRom.Size = (long)zf.GetLocalFile(i).UncompressedSize;
|
||||
zipEntryRom.CRC = zf.GetLocalFile(i).CRC;
|
||||
@@ -283,7 +283,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
zipEntryRom = GetInfo(readStream, size: (long)zf.GetLocalFile(i).UncompressedSize, hashes: this.AvailableHashTypes, keepReadOpen: true);
|
||||
zipEntryRom = GetInfo(readStream, size: (long)zf.GetLocalFile(i).UncompressedSize, hashes: AvailableHashTypes, keepReadOpen: true);
|
||||
}
|
||||
|
||||
// Fill in common details and add to the list
|
||||
@@ -311,13 +311,13 @@ namespace SabreTools.FileTypes.Archives
|
||||
List<string> empties = [];
|
||||
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
if (Filename == null)
|
||||
return empties;
|
||||
|
||||
try
|
||||
{
|
||||
var zf = new SevenZ();
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
|
||||
ZipReturn zr = zf.ZipFileOpen(Filename, -1, true);
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
|
||||
|
||||
@@ -358,11 +358,11 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
if (Filename == null)
|
||||
return false;
|
||||
|
||||
SevenZ zf = new();
|
||||
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
|
||||
ZipReturn zr = zf.ZipFileOpen(Filename, -1, true);
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
throw new Exception(CompressUtils.ZipErrorMessageText(zr));
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// Extract all files to the temp directory
|
||||
TarArchive ta = TarArchive.Open(this.Filename!);
|
||||
TarArchive ta = TarArchive.Open(Filename!);
|
||||
foreach (TarArchiveEntry entry in ta.Entries)
|
||||
{
|
||||
entry.WriteToDirectory(outDir, new ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true });
|
||||
@@ -141,7 +141,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
Stream? stream = null;
|
||||
string? realEntry = null;
|
||||
|
||||
var ta = TarArchive.Open(this.Filename!, new ReaderOptions { LeaveStreamOpen = false, });
|
||||
var ta = TarArchive.Open(Filename!, new ReaderOptions { LeaveStreamOpen = false, });
|
||||
foreach (TarArchiveEntry entry in ta.Entries)
|
||||
{
|
||||
// Skip invalid entries
|
||||
@@ -185,18 +185,18 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
List<BaseFile> found = [];
|
||||
string? gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
string? gamename = Path.GetFileNameWithoutExtension(Filename);
|
||||
|
||||
try
|
||||
{
|
||||
TarArchive ta = TarArchive.Open(File.OpenRead(this.Filename!));
|
||||
TarArchive ta = TarArchive.Open(File.OpenRead(Filename!));
|
||||
foreach (TarArchiveEntry entry in ta.Entries.Where(e => e != null && !e.IsDirectory))
|
||||
{
|
||||
// Create a blank item for the entry
|
||||
BaseFile tarEntryRom = new();
|
||||
|
||||
// Perform a quickscan, if flagged to
|
||||
if (this.AvailableHashTypes.Length == 1 && this.AvailableHashTypes[0] == HashType.CRC32)
|
||||
if (AvailableHashTypes.Length == 1 && AvailableHashTypes[0] == HashType.CRC32)
|
||||
{
|
||||
tarEntryRom.Size = entry.Size;
|
||||
tarEntryRom.CRC = BitConverter.GetBytes(entry.Crc);
|
||||
@@ -205,7 +205,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
else
|
||||
{
|
||||
using Stream entryStream = entry.OpenEntryStream();
|
||||
tarEntryRom = GetInfo(entryStream, size: entry.Size, hashes: this.AvailableHashTypes);
|
||||
tarEntryRom = GetInfo(entryStream, size: entry.Size, hashes: AvailableHashTypes);
|
||||
}
|
||||
|
||||
// Fill in common details and add to the list
|
||||
@@ -239,7 +239,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
|
||||
try
|
||||
{
|
||||
TarArchive ta = TarArchive.Open(this.Filename!, new ReaderOptions { LeaveStreamOpen = false });
|
||||
TarArchive ta = TarArchive.Open(Filename!, new ReaderOptions { LeaveStreamOpen = false });
|
||||
List<TarArchiveEntry> tarEntries = ta.Entries.OrderBy(e => e.Key ?? string.Empty, new NaturalReversedComparer()).ToList();
|
||||
string? lastTarEntry = null;
|
||||
foreach (TarArchiveEntry entry in tarEntries)
|
||||
|
||||
@@ -69,8 +69,8 @@ namespace SabreTools.FileTypes.Archives
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// Decompress the _filename stream
|
||||
FileStream outstream = File.Create(Path.Combine(outDir, Path.GetFileNameWithoutExtension(this.Filename)!));
|
||||
var xz = new XZStream(File.OpenRead(this.Filename!));
|
||||
FileStream outstream = File.Create(Path.Combine(outDir, Path.GetFileNameWithoutExtension(Filename)!));
|
||||
var xz = new XZStream(File.OpenRead(Filename!));
|
||||
xz.CopyTo(outstream);
|
||||
|
||||
// Dispose of the streams
|
||||
@@ -149,14 +149,14 @@ namespace SabreTools.FileTypes.Archives
|
||||
{
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
// If we have an invalid file
|
||||
if (this.Filename == null)
|
||||
if (Filename == null)
|
||||
return (null, null);
|
||||
|
||||
try
|
||||
{
|
||||
// Open the entry stream
|
||||
string realEntry = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
var stream = new XZStream(File.OpenRead(this.Filename));
|
||||
string realEntry = Path.GetFileNameWithoutExtension(Filename);
|
||||
var stream = new XZStream(File.OpenRead(Filename));
|
||||
|
||||
// Return the stream
|
||||
return (stream, realEntry);
|
||||
@@ -186,7 +186,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
#if NET462_OR_GREATER || NETCOREAPP
|
||||
_children = [];
|
||||
|
||||
string? gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
string? gamename = Path.GetFileNameWithoutExtension(Filename);
|
||||
BaseFile? possibleTxz = GetTorrentXZFileInfo();
|
||||
|
||||
// If it was, then add it to the outputs and continue
|
||||
@@ -202,11 +202,11 @@ namespace SabreTools.FileTypes.Archives
|
||||
BaseFile xzEntryRom = new();
|
||||
|
||||
// Perform a quickscan, if flagged to
|
||||
if (this.AvailableHashTypes.Length == 1 && this.AvailableHashTypes[0] == HashType.CRC32)
|
||||
if (AvailableHashTypes.Length == 1 && AvailableHashTypes[0] == HashType.CRC32)
|
||||
{
|
||||
xzEntryRom.Filename = gamename;
|
||||
|
||||
using BinaryReader br = new(File.OpenRead(this.Filename!));
|
||||
using BinaryReader br = new(File.OpenRead(Filename!));
|
||||
br.BaseStream.Seek(-8, SeekOrigin.End);
|
||||
xzEntryRom.CRC = br.ReadBytesBigEndian(4);
|
||||
xzEntryRom.Size = br.ReadInt32BigEndian();
|
||||
@@ -214,8 +214,8 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
var xzStream = new XZStream(File.OpenRead(this.Filename!));
|
||||
xzEntryRom = GetInfo(xzStream, hashes: this.AvailableHashTypes);
|
||||
var xzStream = new XZStream(File.OpenRead(Filename!));
|
||||
xzEntryRom = GetInfo(xzStream, hashes: AvailableHashTypes);
|
||||
xzEntryRom.Filename = gamename;
|
||||
xzStream.Dispose();
|
||||
}
|
||||
@@ -248,15 +248,15 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
// Check for the file existing first
|
||||
if (this.Filename == null || !File.Exists(this.Filename))
|
||||
if (Filename == null || !File.Exists(Filename))
|
||||
return false;
|
||||
|
||||
string datum = Path.GetFileName(this.Filename).ToLowerInvariant();
|
||||
string datum = Path.GetFileName(Filename).ToLowerInvariant();
|
||||
|
||||
// Check if the name is the right length
|
||||
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.xz"))
|
||||
{
|
||||
logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'");
|
||||
logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(Filename)}'");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -270,24 +270,24 @@ namespace SabreTools.FileTypes.Archives
|
||||
public BaseFile? GetTorrentXZFileInfo()
|
||||
{
|
||||
// Check for the file existing first
|
||||
if (this.Filename == null || !File.Exists(this.Filename))
|
||||
if (Filename == null || !File.Exists(Filename))
|
||||
return null;
|
||||
|
||||
string datum = Path.GetFileName(this.Filename).ToLowerInvariant();
|
||||
string datum = Path.GetFileName(Filename).ToLowerInvariant();
|
||||
|
||||
// Check if the name is the right length
|
||||
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.xz"))
|
||||
{
|
||||
logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'");
|
||||
logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(Filename)}'");
|
||||
return null;
|
||||
}
|
||||
|
||||
BaseFile baseFile = new()
|
||||
{
|
||||
Filename = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(),
|
||||
SHA1 = Path.GetFileNameWithoutExtension(this.Filename).FromHexString(),
|
||||
Filename = Path.GetFileNameWithoutExtension(Filename).ToLowerInvariant(),
|
||||
SHA1 = Path.GetFileNameWithoutExtension(Filename).FromHexString(),
|
||||
|
||||
Parent = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(),
|
||||
Parent = Path.GetFileNameWithoutExtension(Filename).ToLowerInvariant(),
|
||||
};
|
||||
|
||||
return baseFile;
|
||||
|
||||
@@ -910,9 +910,9 @@ Reset the internal state: reset();";
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
this.Index = 0;
|
||||
this.DatFile = DatFile.Create();
|
||||
this.OutputDirectory = null;
|
||||
Index = 0;
|
||||
DatFile = DatFile.Create();
|
||||
OutputDirectory = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user