mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
REFACTOR: Convert 'if' statement to 'switch' statement.
This commit is contained in:
@@ -137,38 +137,36 @@ namespace DiscImageChef.Core.Devices.Scanning
|
||||
|
||||
Reader scsiReader = null;
|
||||
|
||||
if(dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.DirectAccess ||
|
||||
dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice ||
|
||||
dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.OCRWDevice ||
|
||||
dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.OpticalDevice ||
|
||||
dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.SimplifiedDevice ||
|
||||
dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.WriteOnceDevice)
|
||||
{
|
||||
scsiReader = new Reader(dev, dev.Timeout, null, false);
|
||||
results.Blocks = scsiReader.GetDeviceBlocks();
|
||||
if(scsiReader.FindReadCommand())
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Unable to read medium.");
|
||||
return results;
|
||||
}
|
||||
switch(dev.ScsiType) {
|
||||
case Decoders.SCSI.PeripheralDeviceTypes.DirectAccess:
|
||||
case Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice:
|
||||
case Decoders.SCSI.PeripheralDeviceTypes.OCRWDevice:
|
||||
case Decoders.SCSI.PeripheralDeviceTypes.OpticalDevice:
|
||||
case Decoders.SCSI.PeripheralDeviceTypes.SimplifiedDevice:
|
||||
case Decoders.SCSI.PeripheralDeviceTypes.WriteOnceDevice:
|
||||
scsiReader = new Reader(dev, dev.Timeout, null, false);
|
||||
results.Blocks = scsiReader.GetDeviceBlocks();
|
||||
if(scsiReader.FindReadCommand())
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Unable to read medium.");
|
||||
return results;
|
||||
}
|
||||
|
||||
blockSize = scsiReader.LogicalBlockSize;
|
||||
blockSize = scsiReader.LogicalBlockSize;
|
||||
|
||||
if(results.Blocks != 0 && blockSize != 0)
|
||||
{
|
||||
results.Blocks++;
|
||||
if(results.Blocks != 0 && blockSize != 0)
|
||||
{
|
||||
results.Blocks++;
|
||||
#pragma warning disable IDE0004 // Without this specific cast, it gives incorrect values
|
||||
DicConsole.WriteLine("Media has {0} blocks of {1} bytes/each. (for a total of {2} bytes)",
|
||||
results.Blocks, blockSize, results.Blocks * (ulong)blockSize);
|
||||
DicConsole.WriteLine("Media has {0} blocks of {1} bytes/each. (for a total of {2} bytes)",
|
||||
results.Blocks, blockSize, results.Blocks * (ulong)blockSize);
|
||||
#pragma warning restore IDE0004 // Without this specific cast, it gives incorrect values
|
||||
}
|
||||
}
|
||||
|
||||
if(dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess)
|
||||
{
|
||||
DicConsole.WriteLine("Scanning will never be supported on SCSI Streaming Devices.");
|
||||
DicConsole.WriteLine("It has no sense to do it, and it will put too much strain on the tape.");
|
||||
return results;
|
||||
}
|
||||
break;
|
||||
case Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess:
|
||||
DicConsole.WriteLine("Scanning will never be supported on SCSI Streaming Devices.");
|
||||
DicConsole.WriteLine("It has no sense to do it, and it will put too much strain on the tape.");
|
||||
return results;
|
||||
}
|
||||
|
||||
if(results.Blocks == 0)
|
||||
|
||||
@@ -58,47 +58,51 @@ namespace DiscImageChef.Core.Devices.Scanning
|
||||
uint blockSize = 512;
|
||||
bool byteAddressed = true;
|
||||
|
||||
if(dev.Type == DeviceType.MMC)
|
||||
{
|
||||
ExtendedCSD ecsd = new ExtendedCSD();
|
||||
CSD csd = new CSD();
|
||||
|
||||
sense = dev.ReadExtendedCsd(out cmdBuf, out response, timeout, out duration);
|
||||
if(!sense)
|
||||
switch(dev.Type) {
|
||||
case DeviceType.MMC:
|
||||
{
|
||||
ecsd = Decoders.MMC.Decoders.DecodeExtendedCSD(cmdBuf);
|
||||
blocksToRead = ecsd.OptimalReadSize;
|
||||
results.Blocks = ecsd.SectorCount;
|
||||
blockSize = (uint)(ecsd.SectorSize == 1 ? 4096 : 512);
|
||||
// Supposing it's high-capacity MMC if it has Extended CSD...
|
||||
byteAddressed = false;
|
||||
ExtendedCSD ecsd = new ExtendedCSD();
|
||||
CSD csd = new CSD();
|
||||
|
||||
sense = dev.ReadExtendedCsd(out cmdBuf, out response, timeout, out duration);
|
||||
if(!sense)
|
||||
{
|
||||
ecsd = Decoders.MMC.Decoders.DecodeExtendedCSD(cmdBuf);
|
||||
blocksToRead = ecsd.OptimalReadSize;
|
||||
results.Blocks = ecsd.SectorCount;
|
||||
blockSize = (uint)(ecsd.SectorSize == 1 ? 4096 : 512);
|
||||
// Supposing it's high-capacity MMC if it has Extended CSD...
|
||||
byteAddressed = false;
|
||||
}
|
||||
|
||||
if(sense || results.Blocks == 0)
|
||||
{
|
||||
sense = dev.ReadCsd(out cmdBuf, out response, timeout, out duration);
|
||||
if(!sense)
|
||||
{
|
||||
csd = Decoders.MMC.Decoders.DecodeCSD(cmdBuf);
|
||||
results.Blocks = (ulong)((csd.Size + 1) * Math.Pow(2, csd.SizeMultiplier + 2));
|
||||
blockSize = (uint)Math.Pow(2, csd.ReadBlockLength);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(sense || results.Blocks == 0)
|
||||
case DeviceType.SecureDigital:
|
||||
{
|
||||
Decoders.SecureDigital.CSD csd = new Decoders.SecureDigital.CSD();
|
||||
|
||||
sense = dev.ReadCsd(out cmdBuf, out response, timeout, out duration);
|
||||
if(!sense)
|
||||
{
|
||||
csd = Decoders.MMC.Decoders.DecodeCSD(cmdBuf);
|
||||
results.Blocks = (ulong)((csd.Size + 1) * Math.Pow(2, csd.SizeMultiplier + 2));
|
||||
csd = Decoders.SecureDigital.Decoders.DecodeCSD(cmdBuf);
|
||||
results.Blocks = (ulong)(csd.Structure == 0
|
||||
? (csd.Size + 1) * Math.Pow(2, csd.SizeMultiplier + 2)
|
||||
: (csd.Size + 1) * 1024);
|
||||
blockSize = (uint)Math.Pow(2, csd.ReadBlockLength);
|
||||
// Structure >=1 for SDHC/SDXC, so that's block addressed
|
||||
byteAddressed = csd.Structure == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(dev.Type == DeviceType.SecureDigital)
|
||||
{
|
||||
Decoders.SecureDigital.CSD csd = new Decoders.SecureDigital.CSD();
|
||||
|
||||
sense = dev.ReadCsd(out cmdBuf, out response, timeout, out duration);
|
||||
if(!sense)
|
||||
{
|
||||
csd = Decoders.SecureDigital.Decoders.DecodeCSD(cmdBuf);
|
||||
results.Blocks = (ulong)(csd.Structure == 0
|
||||
? (csd.Size + 1) * Math.Pow(2, csd.SizeMultiplier + 2)
|
||||
: (csd.Size + 1) * 1024);
|
||||
blockSize = (uint)Math.Pow(2, csd.ReadBlockLength);
|
||||
// Structure >=1 for SDHC/SDXC, so that's block addressed
|
||||
byteAddressed = csd.Structure == 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user