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