Clean up based on .NET Core 3.1 reccomendations

This commit is contained in:
Matt Nadareski
2020-12-14 16:01:28 -08:00
parent 8870e9b287
commit ebd1044454
29 changed files with 130 additions and 222 deletions

View File

@@ -46,10 +46,8 @@ namespace SabreTools.FileTypes.Aaru
/// <param name="filename">Filename respresenting the AaruFormat file</param>
public static AaruFormat Create(string filename)
{
using (FileStream fs = File.OpenRead(filename))
{
return Create(fs);
}
using FileStream fs = File.OpenRead(filename);
return Create(fs);
}
/// <summary>

View File

@@ -227,12 +227,11 @@ namespace SabreTools.FileTypes.Archives
if (this.AvailableHashes == Hash.CRC)
{
gzipEntryRom.Filename = gamename;
using (BinaryReader br = new BinaryReader(File.OpenRead(this.Filename)))
{
br.BaseStream.Seek(-8, SeekOrigin.End);
gzipEntryRom.CRC = br.ReadBytesBigEndian(4);
gzipEntryRom.Size = br.ReadInt32BigEndian();
}
using BinaryReader br = new BinaryReader(File.OpenRead(this.Filename));
br.BaseStream.Seek(-8, SeekOrigin.End);
gzipEntryRom.CRC = br.ReadBytesBigEndian(4);
gzipEntryRom.Size = br.ReadInt32BigEndian();
}
// Otherwise, use the stream directly
else

View File

@@ -178,10 +178,8 @@ namespace SabreTools.FileTypes.Archives
// Otherwise, use the stream directly
else
{
using (Stream entryStream = entry.OpenEntryStream())
{
rarEntryRom = GetInfo(entryStream, size: entry.Size, hashes: this.AvailableHashes);
}
using Stream entryStream = entry.OpenEntryStream();
rarEntryRom = GetInfo(entryStream, size: entry.Size, hashes: this.AvailableHashes);
}
// Fill in comon details and add to the list

View File

@@ -183,10 +183,8 @@ namespace SabreTools.FileTypes.Archives
// Otherwise, use the stream directly
else
{
using (Stream entryStream = entry.OpenEntryStream())
{
tarEntryRom = GetInfo(entryStream, size: entry.Size, hashes: this.AvailableHashes);
}
using Stream entryStream = entry.OpenEntryStream();
tarEntryRom = GetInfo(entryStream, size: entry.Size, hashes: this.AvailableHashes);
}
// Fill in comon details and add to the list

View File

@@ -211,12 +211,11 @@ namespace SabreTools.FileTypes.Archives
if (this.AvailableHashes == Hash.CRC)
{
xzEntryRom.Filename = gamename;
using (BinaryReader br = new BinaryReader(File.OpenRead(this.Filename)))
{
br.BaseStream.Seek(-8, SeekOrigin.End);
xzEntryRom.CRC = br.ReadBytesBigEndian(4);
xzEntryRom.Size = br.ReadInt32BigEndian();
}
using BinaryReader br = new BinaryReader(File.OpenRead(this.Filename));
br.BaseStream.Seek(-8, SeekOrigin.End);
xzEntryRom.CRC = br.ReadBytesBigEndian(4);
xzEntryRom.Size = br.ReadInt32BigEndian();
}
// Otherwise, use the stream directly
else

View File

@@ -99,26 +99,15 @@ namespace SabreTools.FileTypes
/// <returns>Archive object representing the inputs</returns>
public static BaseArchive Create(FileType archiveType)
{
switch (archiveType)
return archiveType switch
{
case FileType.GZipArchive:
return new GZipArchive();
case FileType.RarArchive:
return new RarArchive();
case FileType.SevenZipArchive:
return new SevenZipArchive();
case FileType.TapeArchive:
return new TapeArchive();
case FileType.ZipArchive:
return new ZipArchive();
default:
return null;
}
FileType.GZipArchive => new GZipArchive(),
FileType.RarArchive => new RarArchive(),
FileType.SevenZipArchive => new SevenZipArchive(),
FileType.TapeArchive => new TapeArchive(),
FileType.ZipArchive => new ZipArchive(),
_ => null,
};
}
#endregion

View File

@@ -29,10 +29,8 @@ namespace SabreTools.FileTypes.CHD
/// <param name="filename">Filename respresenting the CHD file</param>
public static CHDFile Create(string filename)
{
using (FileStream fs = File.OpenRead(filename))
{
return Create(fs);
}
using FileStream fs = File.OpenRead(filename);
return Create(fs);
}
/// <summary>
@@ -108,21 +106,15 @@ namespace SabreTools.FileTypes.CHD
if (!string.Equals(new string(tag), "MComprHD", StringComparison.Ordinal))
return 0;
switch (version)
return version switch
{
case 1:
return length == CHDFileV1.HeaderSize ? version : 0;
case 2:
return length == CHDFileV2.HeaderSize ? version : 0;
case 3:
return length == CHDFileV3.HeaderSize ? version : 0;
case 4:
return length == CHDFileV4.HeaderSize ? version : 0;
case 5:
return length == CHDFileV5.HeaderSize ? version : 0;
default:
return 0;
}
1 => length == CHDFileV1.HeaderSize ? version : 0,
2 => length == CHDFileV2.HeaderSize ? version : 0,
3 => length == CHDFileV3.HeaderSize ? version : 0,
4 => length == CHDFileV4.HeaderSize ? version : 0,
5 => length == CHDFileV5.HeaderSize ? version : 0,
_ => 0,
};
}
/// <summary>
@@ -133,21 +125,15 @@ namespace SabreTools.FileTypes.CHD
/// <returns>Populated CHD file, null on failure</returns>
private static CHDFile ReadAsVersion(Stream stream, uint version)
{
switch (version)
return version switch
{
case 1:
return CHDFileV1.Deserialize(stream);
case 2:
return CHDFileV2.Deserialize(stream);
case 3:
return CHDFileV3.Deserialize(stream);
case 4:
return CHDFileV4.Deserialize(stream);
case 5:
return CHDFileV5.Deserialize(stream);
default:
return null;
}
1 => CHDFileV1.Deserialize(stream),
2 => CHDFileV2.Deserialize(stream),
3 => CHDFileV3.Deserialize(stream),
4 => CHDFileV4.Deserialize(stream),
5 => CHDFileV5.Deserialize(stream),
_ => null,
};
}
#endregion

View File

@@ -32,7 +32,7 @@ namespace SabreTools.FileTypes
/// <summary>
/// Flag specific to Folder to omit Machine name from output path
/// </summary>
private bool writeToParent = false;
private readonly bool writeToParent = false;
#endregion