More pattern matching.

This commit is contained in:
2022-11-14 01:49:10 +00:00
parent 8a511d0d44
commit 040b4eab4e
18 changed files with 33 additions and 57 deletions

View File

@@ -90,8 +90,7 @@ public sealed partial class DeviceReport
Features.SeparatedFeatures ftr = Features.Separate(buffer);
if(ftr.Descriptors == null ||
ftr.Descriptors.Length <= 0)
if(ftr.Descriptors is not { Length: > 0 })
return null;
var report = new MmcFeatures

View File

@@ -113,8 +113,7 @@ public sealed partial class DeviceReport
byte[] evpdPages = EVPD.DecodePage00(buffer);
if(evpdPages == null ||
evpdPages.Length <= 0)
if(evpdPages is not { Length: > 0 })
return null;
List<ScsiPage> evpds = new();

View File

@@ -1196,8 +1196,7 @@ public static class Statistics
if(string.IsNullOrWhiteSpace(command))
return;
if(Settings.Current.Stats == null ||
!Settings.Current.Stats.DeviceStats)
if(Settings.Current.Stats is not { DeviceStats: true })
return;
using var ctx = AaruContext.Create(Settings.LocalDbPath);
@@ -1227,8 +1226,7 @@ public static class Statistics
if(string.IsNullOrWhiteSpace(filesystem))
return;
if(Settings.Current.Stats == null ||
!Settings.Current.Stats.FilesystemStats)
if(Settings.Current.Stats is not { FilesystemStats: true })
return;
using var ctx = AaruContext.Create(Settings.LocalDbPath);
@@ -1258,8 +1256,7 @@ public static class Statistics
if(string.IsNullOrWhiteSpace(partition))
return;
if(Settings.Current.Stats == null ||
!Settings.Current.Stats.PartitionStats)
if(Settings.Current.Stats is not { PartitionStats: true })
return;
using var ctx = AaruContext.Create(Settings.LocalDbPath);
@@ -1289,8 +1286,7 @@ public static class Statistics
if(string.IsNullOrWhiteSpace(filter))
return;
if(Settings.Current.Stats == null ||
!Settings.Current.Stats.FilterStats)
if(Settings.Current.Stats is not { FilterStats: true })
return;
using var ctx = AaruContext.Create(Settings.LocalDbPath);
@@ -1320,8 +1316,7 @@ public static class Statistics
if(string.IsNullOrWhiteSpace(format))
return;
if(Settings.Current.Stats == null ||
!Settings.Current.Stats.MediaImageStats)
if(Settings.Current.Stats is not { MediaImageStats: true })
return;
using var ctx = AaruContext.Create(Settings.LocalDbPath);
@@ -1348,8 +1343,7 @@ public static class Statistics
/// <param name="dev">Device</param>
public static void AddDevice(Device dev)
{
if(Settings.Current.Stats == null ||
!Settings.Current.Stats.DeviceStats)
if(Settings.Current.Stats is not { DeviceStats: true })
return;
string deviceBus;
@@ -1392,8 +1386,7 @@ public static class Statistics
/// <param name="real">Set if media was found on a real device, otherwise found on a media image</param>
public static void AddMedia(MediaType type, bool real)
{
if(Settings.Current.Stats == null ||
!Settings.Current.Stats.MediaStats)
if(Settings.Current.Stats is not { MediaStats: true })
return;
using var ctx = AaruContext.Create(Settings.LocalDbPath);
@@ -1421,8 +1414,7 @@ public static class Statistics
public static void AddRemote(string serverApplication, string serverVersion, string serverOperatingSystem,
string serverOperatingSystemVersion, string serverArchitecture)
{
if(Settings.Current.Stats == null ||
!Settings.Current.Stats.MediaStats)
if(Settings.Current.Stats is not { MediaStats: true })
return;
using var ctx = AaruContext.Create(Settings.LocalDbPath);

View File

@@ -77,8 +77,7 @@ public partial class Device
if(dev is null)
return null;
if(dev.Type == DeviceType.SCSI ||
dev.Type == DeviceType.ATAPI)
if(dev.Type is DeviceType.SCSI or DeviceType.ATAPI)
{
dev.ScsiInquiry(out byte[] inqBuf, out _);

View File

@@ -132,7 +132,6 @@ public sealed partial class Device : Devices.Device
dev.Type = DeviceType.Unknown;
dev.ScsiType = PeripheralDeviceTypes.UnknownDevice;
if(dev.Error)
if(dev.Error)
{
errno = (ErrorNumber)dev.LastError;

View File

@@ -285,8 +285,7 @@ public sealed class RBF : IFilesystem
static uint LSNToUInt32(byte[] lsn)
{
if(lsn == null ||
lsn.Length != 3)
if(lsn is not { Length: 3 })
return 0;
return (uint)((lsn[0] << 16) + (lsn[1] << 8) + lsn[2]);

View File

@@ -184,7 +184,7 @@ public sealed class ImageInfoViewModel : ViewModelBase
imageFormat.Info.Heads > 0 &&
imageFormat.Info.SectorsPerTrack > 0 &&
imageFormat.Info.XmlMediaType != XmlMediaType.OpticalDisc &&
(imageFormat is not ITapeImage tapeImage || !tapeImage.IsTape))
imageFormat is not ITapeImage { IsTape: true })
MediaGeometryText =
$"Media geometry: {imageFormat.Info.Cylinders} cylinders, {imageFormat.Info.Heads} heads, {imageFormat.Info.SectorsPerTrack} sectors per track";

View File

@@ -522,9 +522,7 @@ public sealed class MainWindowViewModel : ViewModelBase
try
{
var imageFormat = ImageFormat.Detect(inputFilter) as IMediaImage;
if(imageFormat == null)
if(ImageFormat.Detect(inputFilter) is not IMediaImage imageFormat)
{
MessageBoxManager.GetMessageBoxStandardWindow("Error", "Image format not identified.", ButtonEnum.Ok,
Icon.Error);

View File

@@ -1302,9 +1302,7 @@ public sealed partial class BlindWrite5
AaruConsole.VerboseWriteLine("BlindWrite image describes a disc of type {0}", _imageInfo.MediaType);
if(_header.profile == ProfileNumber.CDR ||
_header.profile == ProfileNumber.CDRW ||
_header.profile == ProfileNumber.CDROM)
if(_header.profile is ProfileNumber.CDR or ProfileNumber.CDRW or ProfileNumber.CDROM)
return ErrorNumber.NoError;
foreach(Track track in Tracks)

View File

@@ -1549,9 +1549,8 @@ public sealed partial class CdrWin
var mediaTypeAsInt = (int)_discImage.MediaType;
_isCd = mediaTypeAsInt is >= 10 and <= 39 || mediaTypeAsInt is 112 or 113 ||
mediaTypeAsInt is >= 150 and <= 152 || mediaTypeAsInt is 154 or 155 ||
mediaTypeAsInt is >= 171 and <= 179 || mediaTypeAsInt is >= 740 and <= 749;
_isCd = mediaTypeAsInt is >= 10 and <= 39 or 112 or 113 or >= 150 and <= 152 or 154 or 155
or >= 171 and <= 179 or >= 740 and <= 749;
if(currentSession > 1 &&
leadouts.Count == 0 &&

View File

@@ -107,9 +107,8 @@ public sealed partial class CdrWin
var mediaTypeAsInt = (int)_discImage.MediaType;
_isCd = mediaTypeAsInt is >= 10 and <= 39 || mediaTypeAsInt is 112 or 113 ||
mediaTypeAsInt is >= 150 and <= 152 || mediaTypeAsInt is 154 or 155 ||
mediaTypeAsInt is >= 171 and <= 179 || mediaTypeAsInt is >= 740 and <= 749;
_isCd = mediaTypeAsInt is >= 10 and <= 39 or 112 or 113 or >= 150 and <= 152 or 154 or 155 or >= 171 and <= 179
or >= 740 and <= 749;
if(_isCd)
{

View File

@@ -159,10 +159,9 @@ public sealed partial class Ndif
}
// TODO: Handle compressed chunks
if(bChnk.type is > CHUNK_TYPE_COPY and < CHUNK_TYPE_KENCODE ||
bChnk.type is > CHUNK_TYPE_ADC and < CHUNK_TYPE_STUFFIT ||
bChnk.type is > CHUNK_TYPE_STUFFIT and < CHUNK_TYPE_END ||
bChnk.type == 1)
if(bChnk.type is > CHUNK_TYPE_COPY and < CHUNK_TYPE_KENCODE or > CHUNK_TYPE_ADC and < CHUNK_TYPE_STUFFIT
or > CHUNK_TYPE_STUFFIT and < CHUNK_TYPE_END
or 1)
{
AaruConsole.ErrorWriteLine($"Unsupported chunk type 0x{bChnk.type:X8} found");

View File

@@ -414,8 +414,7 @@ public sealed partial class Udif
return ErrorNumber.NotImplemented;
}
if(bChnk.type is > CHUNK_TYPE_NOCOPY and < CHUNK_TYPE_COMMNT ||
bChnk.type is > CHUNK_TYPE_LZMA and < CHUNK_TYPE_END)
if(bChnk.type is > CHUNK_TYPE_NOCOPY and < CHUNK_TYPE_COMMNT or > CHUNK_TYPE_LZMA and < CHUNK_TYPE_END)
{
AaruConsole.ErrorWriteLine($"Unsupported chunk type 0x{bChnk.type:X8} found");

View File

@@ -160,9 +160,8 @@ public abstract class ReadOnlyFilesystemTest : FilesystemTest
var filtersList = new FiltersList();
IFilter inputFilter = filtersList.GetFilter(testFile);
var image = ImageFormat.Detect(inputFilter) as IMediaImage;
if(image is null)
if(ImageFormat.Detect(inputFilter) is not IMediaImage image)
continue;
ErrorNumber opened = image.Open(inputFilter);

View File

@@ -216,9 +216,7 @@ public abstract class OpticalMediaImageTest : BaseMediaImageTest
Assert.AreEqual(track.FileSystems[i].VolumeSerial, fs.XmlFsType.VolumeSerial,
$"Volume serial: {testFile}");
var rofs = Activator.CreateInstance(plugin.GetType()) as IReadOnlyFilesystem;
if(rofs == null)
if(Activator.CreateInstance(plugin.GetType()) is not IReadOnlyFilesystem rofs)
{
if(track.FileSystems[i].Contents != null ||
track.FileSystems[i].ContentsJson != null ||

View File

@@ -413,7 +413,7 @@ sealed class ChecksumCommand : Command
break;
case ITapeImage { IsTape: true, Files: { Count: > 0 } } tapeImage:
case ITapeImage { IsTape: true, Files.Count: > 0 } tapeImage:
{
Checksum trackChecksum = null;
@@ -580,7 +580,7 @@ sealed class ChecksumCommand : Command
break;
}
case IByteAddressableImage { Info: { XmlMediaType: XmlMediaType.LinearMedia } } byteAddressableImage:
case IByteAddressableImage { Info.XmlMediaType: XmlMediaType.LinearMedia } byteAddressableImage:
{
mediaChecksum = new Checksum(enabledChecksums);