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

@@ -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