mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Refactor] Convert to switch expressions.
This commit is contained in:
@@ -570,28 +570,19 @@ public partial class Device
|
||||
public bool ReadPosition(out byte[] buffer, out byte[] senseBuffer, SscPositionForms responseForm, uint timeout,
|
||||
out double duration)
|
||||
{
|
||||
switch(responseForm)
|
||||
{
|
||||
case SscPositionForms.Long:
|
||||
case SscPositionForms.OldLong:
|
||||
case SscPositionForms.OldLongTclpVendor:
|
||||
case SscPositionForms.OldLongVendor:
|
||||
case SscPositionForms.Extended:
|
||||
buffer = new byte[32];
|
||||
|
||||
break;
|
||||
case SscPositionForms.OldTclp:
|
||||
case SscPositionForms.OldTclpVendor:
|
||||
case SscPositionForms.Short:
|
||||
case SscPositionForms.VendorShort:
|
||||
buffer = new byte[20];
|
||||
|
||||
break;
|
||||
default:
|
||||
buffer = new byte[32]; // Invalid
|
||||
|
||||
break;
|
||||
}
|
||||
buffer = responseForm switch
|
||||
{
|
||||
SscPositionForms.Long
|
||||
or SscPositionForms.OldLong
|
||||
or SscPositionForms.OldLongTclpVendor
|
||||
or SscPositionForms.OldLongVendor
|
||||
or SscPositionForms.Extended => new byte[32],
|
||||
SscPositionForms.OldTclp
|
||||
or SscPositionForms.OldTclpVendor
|
||||
or SscPositionForms.Short
|
||||
or SscPositionForms.VendorShort => new byte[20],
|
||||
_ => new byte[32]
|
||||
};
|
||||
|
||||
var cdb = new byte[10];
|
||||
senseBuffer = new byte[64];
|
||||
|
||||
@@ -110,24 +110,18 @@ partial class Device
|
||||
/// <returns>SG_IO direction</returns>
|
||||
static ScsiDirection AtaProtocolToScsiDirection(AtaProtocol protocol)
|
||||
{
|
||||
switch(protocol)
|
||||
{
|
||||
case AtaProtocol.DeviceDiagnostic:
|
||||
case AtaProtocol.DeviceReset:
|
||||
case AtaProtocol.HardReset:
|
||||
case AtaProtocol.NonData:
|
||||
case AtaProtocol.SoftReset:
|
||||
case AtaProtocol.ReturnResponse:
|
||||
return ScsiDirection.None;
|
||||
case AtaProtocol.PioIn:
|
||||
case AtaProtocol.UDmaIn:
|
||||
return ScsiDirection.In;
|
||||
case AtaProtocol.PioOut:
|
||||
case AtaProtocol.UDmaOut:
|
||||
return ScsiDirection.Out;
|
||||
default:
|
||||
return ScsiDirection.Unspecified;
|
||||
}
|
||||
return protocol switch
|
||||
{
|
||||
AtaProtocol.DeviceDiagnostic
|
||||
or AtaProtocol.DeviceReset
|
||||
or AtaProtocol.HardReset
|
||||
or AtaProtocol.NonData
|
||||
or AtaProtocol.SoftReset
|
||||
or AtaProtocol.ReturnResponse => ScsiDirection.None,
|
||||
AtaProtocol.PioIn or AtaProtocol.UDmaIn => ScsiDirection.In,
|
||||
AtaProtocol.PioOut or AtaProtocol.UDmaOut => ScsiDirection.Out,
|
||||
_ => ScsiDirection.Unspecified
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -150,18 +144,11 @@ partial class Device
|
||||
|
||||
if(transferRegister != AtaTransferRegister.NoTransfer && protocol != AtaProtocol.NonData)
|
||||
{
|
||||
switch(protocol)
|
||||
{
|
||||
case AtaProtocol.PioIn:
|
||||
case AtaProtocol.UDmaIn:
|
||||
cdb[2] = 0x08;
|
||||
|
||||
break;
|
||||
default:
|
||||
cdb[2] = 0x00;
|
||||
|
||||
break;
|
||||
}
|
||||
cdb[2] = protocol switch
|
||||
{
|
||||
AtaProtocol.PioIn or AtaProtocol.UDmaIn => 0x08,
|
||||
_ => 0x00
|
||||
};
|
||||
|
||||
if(transferBlocks) cdb[2] |= 0x04;
|
||||
|
||||
@@ -222,18 +209,11 @@ partial class Device
|
||||
|
||||
if(transferRegister != AtaTransferRegister.NoTransfer && protocol != AtaProtocol.NonData)
|
||||
{
|
||||
switch(protocol)
|
||||
{
|
||||
case AtaProtocol.PioIn:
|
||||
case AtaProtocol.UDmaIn:
|
||||
cdb[2] = 0x08;
|
||||
|
||||
break;
|
||||
default:
|
||||
cdb[2] = 0x00;
|
||||
|
||||
break;
|
||||
}
|
||||
cdb[2] = protocol switch
|
||||
{
|
||||
AtaProtocol.PioIn or AtaProtocol.UDmaIn => 0x08,
|
||||
_ => 0x00
|
||||
};
|
||||
|
||||
if(transferBlocks) cdb[2] |= 0x04;
|
||||
|
||||
@@ -295,18 +275,11 @@ partial class Device
|
||||
|
||||
if(transferRegister != AtaTransferRegister.NoTransfer && protocol != AtaProtocol.NonData)
|
||||
{
|
||||
switch(protocol)
|
||||
{
|
||||
case AtaProtocol.PioIn:
|
||||
case AtaProtocol.UDmaIn:
|
||||
cdb[2] = 0x08;
|
||||
|
||||
break;
|
||||
default:
|
||||
cdb[2] = 0x00;
|
||||
|
||||
break;
|
||||
}
|
||||
cdb[2] = protocol switch
|
||||
{
|
||||
AtaProtocol.PioIn or AtaProtocol.UDmaIn => 0x08,
|
||||
_ => 0x00
|
||||
};
|
||||
|
||||
if(transferBlocks) cdb[2] |= 0x04;
|
||||
|
||||
|
||||
@@ -140,19 +140,12 @@ static class ListDevices
|
||||
else
|
||||
devices[i].Bus = devices[i].Bus.ToUpper();
|
||||
|
||||
switch(devices[i].Bus)
|
||||
{
|
||||
case "ATA":
|
||||
case "ATAPI":
|
||||
case "SCSI":
|
||||
case "USB":
|
||||
case "PCMCIA":
|
||||
case "FireWire":
|
||||
case "MMC/SD":
|
||||
devices[i].Supported = true;
|
||||
|
||||
break;
|
||||
}
|
||||
devices[i].Supported = devices[i].Bus switch
|
||||
{
|
||||
"ATA" or "ATAPI" or "SCSI" or "USB" or "PCMCIA" or "FireWire" or "MMC/SD" =>
|
||||
true,
|
||||
_ => devices[i].Supported
|
||||
};
|
||||
}
|
||||
|
||||
return devices;
|
||||
|
||||
@@ -150,20 +150,12 @@ partial class Device
|
||||
}
|
||||
};
|
||||
|
||||
switch(protocol)
|
||||
{
|
||||
case AtaProtocol.PioIn:
|
||||
case AtaProtocol.UDmaIn:
|
||||
case AtaProtocol.Dma:
|
||||
aptd.AtaFlags = AtaFlags.DataIn;
|
||||
|
||||
break;
|
||||
case AtaProtocol.PioOut:
|
||||
case AtaProtocol.UDmaOut:
|
||||
aptd.AtaFlags = AtaFlags.DataOut;
|
||||
|
||||
break;
|
||||
}
|
||||
aptd.AtaFlags = protocol switch
|
||||
{
|
||||
AtaProtocol.PioIn or AtaProtocol.UDmaIn or AtaProtocol.Dma => AtaFlags.DataIn,
|
||||
AtaProtocol.PioOut or AtaProtocol.UDmaOut => AtaFlags.DataOut,
|
||||
_ => aptd.AtaFlags
|
||||
};
|
||||
|
||||
switch(protocol)
|
||||
{
|
||||
@@ -253,20 +245,12 @@ partial class Device
|
||||
}
|
||||
};
|
||||
|
||||
switch(protocol)
|
||||
{
|
||||
case AtaProtocol.PioIn:
|
||||
case AtaProtocol.UDmaIn:
|
||||
case AtaProtocol.Dma:
|
||||
aptd.AtaFlags = AtaFlags.DataIn;
|
||||
|
||||
break;
|
||||
case AtaProtocol.PioOut:
|
||||
case AtaProtocol.UDmaOut:
|
||||
aptd.AtaFlags = AtaFlags.DataOut;
|
||||
|
||||
break;
|
||||
}
|
||||
aptd.AtaFlags = protocol switch
|
||||
{
|
||||
AtaProtocol.PioIn or AtaProtocol.UDmaIn or AtaProtocol.Dma => AtaFlags.DataIn,
|
||||
AtaProtocol.PioOut or AtaProtocol.UDmaOut => AtaFlags.DataOut,
|
||||
_ => aptd.AtaFlags
|
||||
};
|
||||
|
||||
switch(protocol)
|
||||
{
|
||||
@@ -363,20 +347,12 @@ partial class Device
|
||||
}
|
||||
};
|
||||
|
||||
switch(protocol)
|
||||
{
|
||||
case AtaProtocol.PioIn:
|
||||
case AtaProtocol.UDmaIn:
|
||||
case AtaProtocol.Dma:
|
||||
aptd.AtaFlags = AtaFlags.DataIn;
|
||||
|
||||
break;
|
||||
case AtaProtocol.PioOut:
|
||||
case AtaProtocol.UDmaOut:
|
||||
aptd.AtaFlags = AtaFlags.DataOut;
|
||||
|
||||
break;
|
||||
}
|
||||
aptd.AtaFlags = protocol switch
|
||||
{
|
||||
AtaProtocol.PioIn or AtaProtocol.UDmaIn or AtaProtocol.Dma => AtaFlags.DataIn,
|
||||
AtaProtocol.PioOut or AtaProtocol.UDmaOut => AtaFlags.DataOut,
|
||||
_ => aptd.AtaFlags
|
||||
};
|
||||
|
||||
switch(protocol)
|
||||
{
|
||||
|
||||
@@ -197,24 +197,22 @@ static class ListDevices
|
||||
}
|
||||
}
|
||||
|
||||
switch(descriptor.BusType)
|
||||
{
|
||||
case StorageBusType.SCSI:
|
||||
case StorageBusType.ATAPI:
|
||||
case StorageBusType.ATA:
|
||||
case StorageBusType.FireWire:
|
||||
case StorageBusType.SSA:
|
||||
case StorageBusType.Fibre:
|
||||
case StorageBusType.USB:
|
||||
case StorageBusType.iSCSI:
|
||||
case StorageBusType.SAS:
|
||||
case StorageBusType.SATA:
|
||||
case StorageBusType.SecureDigital:
|
||||
case StorageBusType.MultiMediaCard:
|
||||
info.Supported = true;
|
||||
|
||||
break;
|
||||
}
|
||||
info.Supported = descriptor.BusType switch
|
||||
{
|
||||
StorageBusType.SCSI
|
||||
or StorageBusType.ATAPI
|
||||
or StorageBusType.ATA
|
||||
or StorageBusType.FireWire
|
||||
or StorageBusType.SSA
|
||||
or StorageBusType.Fibre
|
||||
or StorageBusType.USB
|
||||
or StorageBusType.iSCSI
|
||||
or StorageBusType.SAS
|
||||
or StorageBusType.SATA
|
||||
or StorageBusType.SecureDigital
|
||||
or StorageBusType.MultiMediaCard => true,
|
||||
_ => info.Supported
|
||||
};
|
||||
|
||||
Marshal.FreeHGlobal(descriptorPtr);
|
||||
devList.Add(info);
|
||||
|
||||
Reference in New Issue
Block a user