Perform mass cleanup

This is cleanup based on both new .NET functionality (in 6 and 7) as well as a ton of simplifications and things that were missed that were caught due to the cleanup.
This commit is contained in:
Matt Nadareski
2023-04-19 16:39:58 -04:00
parent fd5fd79b95
commit 728b5d6b27
95 changed files with 1353 additions and 1572 deletions

View File

@@ -118,9 +118,9 @@ namespace SabreTools.FileTypes.Aaru
{
try
{
AaruFormat aif = new AaruFormat();
AaruFormat aif = new();
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
using (BinaryReader br = new(stream, Encoding.Default, true))
{
aif.Identifier = br.ReadUInt64();
aif.Application = Encoding.Unicode.GetString(br.ReadBytes(64), 0, 64);

View File

@@ -162,7 +162,7 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override (MemoryStream, string) CopyToStream(string entryName)
{
MemoryStream ms = new MemoryStream();
MemoryStream ms = new();
string realEntry;
try
@@ -221,14 +221,14 @@ namespace SabreTools.FileTypes.Archives
try
{
// Create a blank item for the entry
BaseFile gzipEntryRom = new BaseFile();
BaseFile gzipEntryRom = new();
// Perform a quickscan, if flagged to
if (this.AvailableHashes == Hash.CRC)
{
gzipEntryRom.Filename = gamename;
using BinaryReader br = new BinaryReader(File.OpenRead(this.Filename));
using BinaryReader br = new(File.OpenRead(this.Filename));
br.BaseStream.Seek(-8, SeekOrigin.End);
gzipEntryRom.CRC = br.ReadBytesBigEndian(4);
gzipEntryRom.Size = br.ReadInt32BigEndian();
@@ -300,7 +300,7 @@ namespace SabreTools.FileTypes.Archives
}
// Get the Romba-specific header data
BinaryReader br = new BinaryReader(File.OpenRead(this.Filename));
BinaryReader br = new(File.OpenRead(this.Filename));
byte[] header = br.ReadBytes(12); // Get preamble header for checking
br.ReadBytes(16); // headermd5
br.ReadBytes(4); // headercrc
@@ -365,7 +365,7 @@ namespace SabreTools.FileTypes.Archives
byte[] headermd5; // MD5
byte[] headercrc; // CRC
ulong headersz; // Int64 size
BinaryReader br = new BinaryReader(File.OpenRead(this.Filename));
BinaryReader br = new(File.OpenRead(this.Filename));
header = br.ReadBytes(12);
headermd5 = br.ReadBytes(16);
headercrc = br.ReadBytes(4);
@@ -391,7 +391,7 @@ namespace SabreTools.FileTypes.Archives
// Now convert the data and get the right position
long extractedsize = (long)headersz;
BaseFile baseFile = new BaseFile
BaseFile baseFile = new()
{
Filename = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(),
Size = extractedsize,
@@ -457,7 +457,7 @@ namespace SabreTools.FileTypes.Archives
FileStream outputStream = File.Create(outfile);
// Open the output file for writing
BinaryWriter sw = new BinaryWriter(outputStream);
BinaryWriter sw = new(outputStream);
// Write standard header and TGZ info
byte[] data = TorrentGZHeader
@@ -468,7 +468,7 @@ namespace SabreTools.FileTypes.Archives
sw.Write((ulong)(baseFile.Size ?? 0)); // Long size (Unsigned, Mirrored)
// Now create a deflatestream from the input file
ZlibBaseStream ds = new ZlibBaseStream(outputStream, CompressionMode.Compress, CompressionLevel.BestCompression, ZlibStreamFlavor.DEFLATE, true);
ZlibBaseStream ds = new(outputStream, CompressionMode.Compress, CompressionLevel.BestCompression, ZlibStreamFlavor.DEFLATE, true);
// Copy the input stream to the output
byte[] ibuffer = new byte[_bufferSize];

View File

@@ -124,7 +124,7 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override (MemoryStream, string) CopyToStream(string entryName)
{
MemoryStream ms = new MemoryStream();
MemoryStream ms = new();
string realEntry = null;
try
@@ -158,7 +158,7 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override List<BaseFile> GetChildren()
{
List<BaseFile> found = new List<BaseFile>();
List<BaseFile> found = new();
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
try
@@ -167,7 +167,7 @@ namespace SabreTools.FileTypes.Archives
foreach (RarArchiveEntry entry in ra.Entries.Where(e => e != null && !e.IsDirectory))
{
// Create a blank item for the entry
BaseFile rarEntryRom = new BaseFile();
BaseFile rarEntryRom = new();
// Perform a quickscan, if flagged to
if (this.AvailableHashes == Hash.CRC)
@@ -204,7 +204,7 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override List<string> GetEmptyFolders()
{
List<string> empties = new List<string>();
List<string> empties = new();
try
{

View File

@@ -71,7 +71,7 @@ namespace SabreTools.FileTypes.Archives
Directory.CreateDirectory(outDir);
// Extract all files to the temp directory
SevenZ zf = new SevenZ();
SevenZ zf = new();
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
@@ -189,12 +189,12 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override (MemoryStream, string) CopyToStream(string entryName)
{
MemoryStream ms = new MemoryStream();
MemoryStream ms = new();
string realEntry = null;
try
{
SevenZ zf = new SevenZ();
SevenZ zf = new();
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
@@ -258,12 +258,12 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override List<BaseFile> GetChildren()
{
List<BaseFile> found = new List<BaseFile>();
List<BaseFile> found = new();
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
try
{
SevenZ zf = new SevenZ();
SevenZ zf = new();
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
@@ -293,7 +293,7 @@ namespace SabreTools.FileTypes.Archives
}
// Create a blank item for the entry
BaseFile zipEntryRom = new BaseFile();
BaseFile zipEntryRom = new();
// Perform a quickscan, if flagged to
if (this.AvailableHashes == Hash.CRC)
@@ -329,18 +329,18 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override List<string> GetEmptyFolders()
{
List<string> empties = new List<string>();
List<string> empties = new();
try
{
SevenZ zf = new SevenZ();
SevenZ zf = new();
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
throw new Exception(ZipUtils.ZipErrorMessageText(zr));
}
List<(string, bool)> zipEntries = new List<(string, bool)>();
List<(string, bool)> zipEntries = new();
for (int i = 0; i < zf.LocalFilesCount(); i++)
{
zipEntries.Add((zf.Filename(i), zf.IsDirectory(i)));
@@ -377,7 +377,7 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override bool IsTorrent()
{
SevenZ zf = new SevenZ();
SevenZ zf = new();
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
@@ -420,8 +420,8 @@ namespace SabreTools.FileTypes.Archives
// Set internal variables
Stream writeStream = null;
SevenZ oldZipFile = new SevenZ();
SevenZ zipFile = new SevenZ();
SevenZ oldZipFile = new();
SevenZ zipFile = new();
ZipReturn zipReturn = ZipReturn.ZipGood;
try
@@ -443,7 +443,7 @@ namespace SabreTools.FileTypes.Archives
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
{
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
TimeStamps ts = new TimeStamps { ModTime = msDosDateTime };
TimeStamps ts = new() { ModTime = msDosDateTime };
zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, ts);
}
else
@@ -470,7 +470,7 @@ namespace SabreTools.FileTypes.Archives
oldZipFile.ZipFileOpen(archiveFileName, -1, true);
// Map all inputs to index
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
Dictionary<string, int> inputIndexMap = new();
var oldZipFileContents = new List<string>();
for (int i = 0; i < oldZipFile.LocalFilesCount(); i++)
{
@@ -519,7 +519,7 @@ namespace SabreTools.FileTypes.Archives
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
{
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
TimeStamps ts = new TimeStamps { ModTime = msDosDateTime };
TimeStamps ts = new() { ModTime = msDosDateTime };
zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, ts);
}
else
@@ -617,8 +617,8 @@ namespace SabreTools.FileTypes.Archives
// Set internal variables
Stream writeStream = null;
SevenZ oldZipFile = new SevenZ();
SevenZ zipFile = new SevenZ();
SevenZ oldZipFile = new();
SevenZ zipFile = new();
ZipReturn zipReturn = ZipReturn.ZipGood;
try
@@ -635,7 +635,7 @@ namespace SabreTools.FileTypes.Archives
zipReturn = zipFile.ZipFileCreate(tempFile);
// Map all inputs to index
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
Dictionary<string, int> inputIndexMap = new();
for (int i = 0; i < inputFiles.Count; i++)
{
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), i);
@@ -659,7 +659,7 @@ namespace SabreTools.FileTypes.Archives
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date.Replace('\\', '/'), out dt))
{
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
TimeStamps ts = new TimeStamps { ModTime = msDosDateTime };
TimeStamps ts = new() { ModTime = msDosDateTime };
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[index].Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, ts);
}
else
@@ -688,7 +688,7 @@ namespace SabreTools.FileTypes.Archives
oldZipFile.ZipFileOpen(archiveFileName, -1, true);
// Map all inputs to index
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
Dictionary<string, int> inputIndexMap = new();
for (int i = 0; i < inputFiles.Count; i++)
{
var oldZipFileContents = new List<string>();
@@ -743,7 +743,7 @@ namespace SabreTools.FileTypes.Archives
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date.Replace('\\', '/'), out dt))
{
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
TimeStamps ts = new TimeStamps { ModTime = msDosDateTime };
TimeStamps ts = new() { ModTime = msDosDateTime };
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, ts);
}
else

View File

@@ -129,7 +129,7 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override (MemoryStream, string) CopyToStream(string entryName)
{
MemoryStream ms = new MemoryStream();
MemoryStream ms = new();
string realEntry = null;
try
@@ -163,7 +163,7 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override List<BaseFile> GetChildren()
{
List<BaseFile> found = new List<BaseFile>();
List<BaseFile> found = new();
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
try
@@ -172,7 +172,7 @@ namespace SabreTools.FileTypes.Archives
foreach (TarArchiveEntry entry in ta.Entries.Where(e => e != null && !e.IsDirectory))
{
// Create a blank item for the entry
BaseFile tarEntryRom = new BaseFile();
BaseFile tarEntryRom = new();
// Perform a quickscan, if flagged to
if (this.AvailableHashes == Hash.CRC)
@@ -209,7 +209,7 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override List<string> GetEmptyFolders()
{
List<string> empties = new List<string>();
List<string> empties = new();
try
{
@@ -309,7 +309,7 @@ namespace SabreTools.FileTypes.Archives
List<string> entries = oldTarFile.Entries.Select(i => i.Key).ToList();
// Map all inputs to index
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
Dictionary<string, int> inputIndexMap = new();
// If the old one doesn't contain the new file, then add it
if (!entries.Contains(baseFile.Filename.Replace('\\', '/')))
@@ -356,7 +356,7 @@ namespace SabreTools.FileTypes.Archives
{
// Get the stream from the original archive
TarArchiveEntry tae = oldTarFile.Entries.ElementAt(index);
MemoryStream entry = new MemoryStream();
MemoryStream entry = new();
tae.OpenEntryStream().CopyTo(entry);
// Copy the input stream to the output
@@ -436,7 +436,7 @@ namespace SabreTools.FileTypes.Archives
if (!File.Exists(archiveFileName))
{
// Map all inputs to index
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
Dictionary<string, int> inputIndexMap = new();
for (int i = 0; i < inputFiles.Count; i++)
{
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), i);
@@ -472,7 +472,7 @@ namespace SabreTools.FileTypes.Archives
List<string> entries = oldTarFile.Entries.Select(i => i.Key).ToList();
// Map all inputs to index
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
Dictionary<string, int> inputIndexMap = new();
for (int i = 0; i < inputFiles.Count; i++)
{
// If the old one contains the new file, then just skip out
@@ -524,7 +524,7 @@ namespace SabreTools.FileTypes.Archives
{
// Get the stream from the original archive
TarArchiveEntry tae = oldTarFile.Entries.ElementAt(index);
MemoryStream entry = new MemoryStream();
MemoryStream entry = new();
tae.OpenEntryStream().CopyTo(entry);
// Copy the input stream to the output

View File

@@ -148,7 +148,7 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override (MemoryStream, string) CopyToStream(string entryName)
{
MemoryStream ms = new MemoryStream();
MemoryStream ms = new();
string realEntry;
try
@@ -205,14 +205,14 @@ namespace SabreTools.FileTypes.Archives
try
{
// Create a blank item for the entry
BaseFile xzEntryRom = new BaseFile();
BaseFile xzEntryRom = new();
// Perform a quickscan, if flagged to
if (this.AvailableHashes == Hash.CRC)
{
xzEntryRom.Filename = gamename;
using BinaryReader br = new BinaryReader(File.OpenRead(this.Filename));
using BinaryReader br = new(File.OpenRead(this.Filename));
br.BaseStream.Seek(-8, SeekOrigin.End);
xzEntryRom.CRC = br.ReadBytesBigEndian(4);
xzEntryRom.Size = br.ReadInt32BigEndian();
@@ -286,7 +286,7 @@ namespace SabreTools.FileTypes.Archives
return null;
}
BaseFile baseFile = new BaseFile
BaseFile baseFile = new()
{
Filename = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(),
SHA1 = Utilities.StringToByteArray(Path.GetFileNameWithoutExtension(this.Filename)),
@@ -347,7 +347,7 @@ namespace SabreTools.FileTypes.Archives
if (!File.Exists(outfile))
{
// Compress the input stream
XZStream outputStream = new XZStream(File.Create(outfile));
XZStream outputStream = new(File.Create(outfile));
inputStream.CopyTo(outputStream);
// Dispose of everything

View File

@@ -80,7 +80,7 @@ namespace SabreTools.FileTypes.Archives
Directory.CreateDirectory(outDir);
// Extract all files to the temp directory
Zip zf = new Zip();
Zip zf = new();
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
@@ -200,12 +200,12 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override (MemoryStream, string) CopyToStream(string entryName)
{
MemoryStream ms = new MemoryStream();
MemoryStream ms = new();
string realEntry = null;
try
{
Zip zf = new Zip();
Zip zf = new();
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
@@ -269,12 +269,12 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override List<BaseFile> GetChildren()
{
List<BaseFile> found = new List<BaseFile>();
List<BaseFile> found = new();
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
try
{
Zip zf = new Zip();
Zip zf = new();
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
@@ -304,7 +304,7 @@ namespace SabreTools.FileTypes.Archives
}
// Create a blank item for the entry
BaseFile zipEntryRom = new BaseFile();
BaseFile zipEntryRom = new();
// Perform a quickscan, if flagged to
if (this.AvailableHashes == Hash.CRC)
@@ -341,18 +341,18 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override List<string> GetEmptyFolders()
{
List<string> empties = new List<string>();
List<string> empties = new();
try
{
Zip zf = new Zip();
Zip zf = new();
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
throw new Exception(ZipUtils.ZipErrorMessageText(zr));
}
List<(string, bool)> zipEntries = new List<(string, bool)>();
List<(string, bool)> zipEntries = new();
for (int i = 0; i < zf.LocalFilesCount(); i++)
{
zipEntries.Add((zf.Filename(i), zf.IsDirectory(i)));
@@ -389,7 +389,7 @@ namespace SabreTools.FileTypes.Archives
/// <inheritdoc/>
public override bool IsTorrent()
{
Zip zf = new Zip();
Zip zf = new();
ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true);
if (zr != ZipReturn.ZipGood)
{
@@ -432,8 +432,8 @@ namespace SabreTools.FileTypes.Archives
// Set internal variables
Stream writeStream = null;
Zip oldZipFile = new Zip();
Zip zipFile = new Zip();
Zip oldZipFile = new();
Zip zipFile = new();
ZipReturn zipReturn = ZipReturn.ZipGood;
try
@@ -455,7 +455,7 @@ namespace SabreTools.FileTypes.Archives
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
{
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
TimeStamps ts = new TimeStamps { ModTime = msDosDateTime };
TimeStamps ts = new() { ModTime = msDosDateTime };
zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
}
else
@@ -482,7 +482,7 @@ namespace SabreTools.FileTypes.Archives
oldZipFile.ZipFileOpen(archiveFileName, -1, true);
// Map all inputs to index
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
Dictionary<string, int> inputIndexMap = new();
var oldZipFileContents = new List<string>();
for (int i = 0; i < oldZipFile.LocalFilesCount(); i++)
{
@@ -529,7 +529,7 @@ namespace SabreTools.FileTypes.Archives
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
{
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
TimeStamps ts = new TimeStamps { ModTime = msDosDateTime };
TimeStamps ts = new() { ModTime = msDosDateTime };
zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
}
else
@@ -555,7 +555,7 @@ namespace SabreTools.FileTypes.Archives
// Instantiate the streams
oldZipFile.ZipFileOpenReadStream(index, false, out Stream zreadStream, out ulong istreamSize, out ushort icompressionMethod);
long msDosDateTime = oldZipFile.LastModified(index);
TimeStamps ts = new TimeStamps { ModTime = msDosDateTime };
TimeStamps ts = new() { ModTime = msDosDateTime };
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.Filename(index), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
// Copy the input stream to the output
@@ -629,8 +629,8 @@ namespace SabreTools.FileTypes.Archives
// Set internal variables
Stream writeStream = null;
Zip oldZipFile = new Zip();
Zip zipFile = new Zip();
Zip oldZipFile = new();
Zip zipFile = new();
ZipReturn zipReturn = ZipReturn.ZipGood;
try
@@ -647,7 +647,7 @@ namespace SabreTools.FileTypes.Archives
zipReturn = zipFile.ZipFileCreate(tempFile);
// Map all inputs to index
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
Dictionary<string, int> inputIndexMap = new();
for (int i = 0; i < inputFiles.Count; i++)
{
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), i);
@@ -671,7 +671,7 @@ namespace SabreTools.FileTypes.Archives
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date.Replace('\\', '/'), out dt))
{
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
TimeStamps ts = new TimeStamps { ModTime = msDosDateTime };
TimeStamps ts = new() { ModTime = msDosDateTime };
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[index].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
}
else
@@ -700,7 +700,7 @@ namespace SabreTools.FileTypes.Archives
oldZipFile.ZipFileOpen(archiveFileName, -1, true);
// Map all inputs to index
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
Dictionary<string, int> inputIndexMap = new();
for (int i = 0; i < inputFiles.Count; i++)
{
var oldZipFileContents = new List<string>();
@@ -755,7 +755,7 @@ namespace SabreTools.FileTypes.Archives
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date.Replace('\\', '/'), out dt))
{
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
TimeStamps ts = new TimeStamps { ModTime = msDosDateTime };
TimeStamps ts = new() { ModTime = msDosDateTime };
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
}
else
@@ -781,7 +781,7 @@ namespace SabreTools.FileTypes.Archives
// Instantiate the streams
oldZipFile.ZipFileOpenReadStream(index, false, out Stream zreadStream, out ulong istreamSize, out ushort icompressionMethod);
long msDosDateTime = oldZipFile.LastModified(index);
TimeStamps ts = new TimeStamps { ModTime = msDosDateTime };
TimeStamps ts = new() { ModTime = msDosDateTime };
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.Filename(index), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
// Copy the input stream to the output

View File

@@ -200,7 +200,7 @@ namespace SabreTools.FileTypes
return outFileType;
// Read the first bytes of the file and get the magic number
BinaryReader br = new BinaryReader(File.OpenRead(input));
BinaryReader br = new(File.OpenRead(input));
byte[] magic = br.ReadBytes(8);
br.Dispose();
@@ -291,7 +291,7 @@ namespace SabreTools.FileTypes
if (rule.Tests != null && rule.Tests.Length != 0)
{
// Create the output stream
MemoryStream outputStream = new MemoryStream();
MemoryStream outputStream = new();
// Transform the stream and get the information from it
rule.TransformStream(inputStream, outputStream, keepReadOpen: false, keepWriteOpen: true);
@@ -335,7 +335,7 @@ namespace SabreTools.FileTypes
try
{
// Get a list of hashers to run over the buffer
List<Hasher> hashers = new List<Hasher>();
List<Hasher> hashers = new();
if (hashes.HasFlag(Hash.CRC))
hashers.Add(new Hasher(Hash.CRC));
@@ -391,7 +391,7 @@ namespace SabreTools.FileTypes
Parallel.ForEach(hashers, Globals.ParallelOptions, h => h.Terminate());
// Get the results
BaseFile baseFile = new BaseFile()
BaseFile baseFile = new()
{
Size = size,
CRC = hashes.HasFlag(Hash.CRC) ? hashers.First(h => h.HashType == Hash.CRC).GetHash() : null,
@@ -433,35 +433,34 @@ namespace SabreTools.FileTypes
string ext = path.GetNormalizedExtension();
// Check against the list of known archive extensions
switch (ext)
return ext switch
{
// Aaruformat
case "aaru":
case "aaruf":
case "aaruformat":
case "aif":
case "dicf":
// Archives
case "7z":
case "gz":
case "lzma":
case "rar":
case "rev":
case "r00":
case "r01":
case "tar":
case "tgz":
case "tlz":
case "zip":
case "zipx":
"aaru" => true,
"aaruf" => true,
"aaruformat" => true,
"aif" => true,
"dicf" => true,
// Archive
"7z" => true,
"gz" => true,
"lzma" => true,
"rar" => true,
"rev" => true,
"r00" => true,
"r01" => true,
"tar" => true,
"tgz" => true,
"tlz" => true,
"zip" => true,
"zipx" => true,
// CHD
case "chd":
return true;
default:
return false;
}
"chd" => true,
_ => false,
};
}
#endregion

View File

@@ -95,7 +95,7 @@ namespace SabreTools.FileTypes.CHD
uint parsedLength = 0;
uint parsedVersion = 0;
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
using (BinaryReader br = new(stream, Encoding.Default, true))
{
parsedTag = br.ReadChars(8);
parsedLength = br.ReadUInt32BigEndian();

View File

@@ -58,9 +58,9 @@ namespace SabreTools.FileTypes.CHD
/// </summary>
public static CHDFileV1 Deserialize(Stream stream)
{
CHDFileV1 chd = new CHDFileV1();
CHDFileV1 chd = new();
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
using (BinaryReader br = new(stream, Encoding.Default, true))
{
chd.tag = br.ReadChars(8);
chd.length = br.ReadUInt32BigEndian();

View File

@@ -59,9 +59,9 @@ namespace SabreTools.FileTypes.CHD
/// </summary>
public static CHDFileV2 Deserialize(Stream stream)
{
CHDFileV2 chd = new CHDFileV2();
CHDFileV2 chd = new();
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
using (BinaryReader br = new(stream, Encoding.Default, true))
{
chd.tag = br.ReadChars(8);
chd.length = br.ReadUInt32BigEndian();

View File

@@ -63,9 +63,9 @@ namespace SabreTools.FileTypes.CHD
/// </summary>
public static CHDFileV3 Deserialize(Stream stream)
{
CHDFileV3 chd = new CHDFileV3();
CHDFileV3 chd = new();
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
using (BinaryReader br = new(stream, Encoding.Default, true))
{
chd.tag = br.ReadChars(8);
chd.length = br.ReadUInt32BigEndian();

View File

@@ -63,9 +63,9 @@ namespace SabreTools.FileTypes.CHD
/// </summary>
public static CHDFileV4 Deserialize(Stream stream)
{
CHDFileV4 chd = new CHDFileV4();
CHDFileV4 chd = new();
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
using (BinaryReader br = new(stream, Encoding.Default, true))
{
chd.tag = br.ReadChars(8);
chd.length = br.ReadUInt32BigEndian();

View File

@@ -27,7 +27,7 @@ namespace SabreTools.FileTypes
/// <summary>
/// Static logger for static methods
/// </summary>
protected static Logger staticLogger = new Logger();
protected static Logger staticLogger = new();
/// <summary>
/// Flag specific to Folder to omit Machine name from output path
@@ -70,49 +70,24 @@ namespace SabreTools.FileTypes
/// <returns>Archive object representing the inputs</returns>
public static Folder Create(OutputFormat outputFormat)
{
switch (outputFormat)
return outputFormat switch
{
case OutputFormat.Folder:
return new Folder(false);
case OutputFormat.ParentFolder:
return new Folder(true);
case OutputFormat.TapeArchive:
return new TapeArchive();
case OutputFormat.Torrent7Zip:
return new SevenZipArchive();
case OutputFormat.TorrentGzip:
case OutputFormat.TorrentGzipRomba:
return new GZipArchive();
case OutputFormat.TorrentLRZip:
return new LRZipArchive();
case OutputFormat.TorrentLZ4:
return new LZ4Archive();
case OutputFormat.TorrentRar:
return new RarArchive();
case OutputFormat.TorrentXZ:
case OutputFormat.TorrentXZRomba:
return new XZArchive();
case OutputFormat.TorrentZip:
return new ZipArchive();
case OutputFormat.TorrentZPAQ:
return new ZPAQArchive();
case OutputFormat.TorrentZstd:
return new ZstdArchive();
default:
return null;
}
OutputFormat.Folder => new Folder(false),
OutputFormat.ParentFolder => new Folder(true),
OutputFormat.TapeArchive => new TapeArchive(),
OutputFormat.Torrent7Zip => new SevenZipArchive(),
OutputFormat.TorrentGzip => new GZipArchive(),
OutputFormat.TorrentGzipRomba => new GZipArchive(),
OutputFormat.TorrentLRZip => new LRZipArchive(),
OutputFormat.TorrentLZ4 => new LZ4Archive(),
OutputFormat.TorrentRar => new RarArchive(),
OutputFormat.TorrentXZ => new XZArchive(),
OutputFormat.TorrentXZRomba => new XZArchive(),
OutputFormat.TorrentZip => new ZipArchive(),
OutputFormat.TorrentZPAQ => new ZPAQArchive(),
OutputFormat.TorrentZstd => new ZstdArchive(),
_ => null,
};
}
#endregion
@@ -148,7 +123,7 @@ namespace SabreTools.FileTypes
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
DirectoryInfo dir = new(sourceDirName);
if (!dir.Exists)
{
@@ -229,7 +204,7 @@ namespace SabreTools.FileTypes
/// <returns>MemoryStream representing the entry, null on error</returns>
public virtual (MemoryStream, string) CopyToStream(string entryName)
{
MemoryStream ms = new MemoryStream();
MemoryStream ms = new();
string realentry = null;
// Copy single file from the current folder to the output directory, if exists
@@ -281,7 +256,7 @@ namespace SabreTools.FileTypes
foreach (string dir in Directory.EnumerateDirectories(this.Filename, "*", SearchOption.TopDirectoryOnly))
{
Folder fl = new Folder(dir);
Folder fl = new(dir);
_children.Add(fl);
}
}