diff --git a/DiscImageChef.Core/Devices/Dumping/SBC.cs b/DiscImageChef.Core/Devices/Dumping/SBC.cs
index 2f86bae22..095fb6814 100644
--- a/DiscImageChef.Core/Devices/Dumping/SBC.cs
+++ b/DiscImageChef.Core/Devices/Dumping/SBC.cs
@@ -64,22 +64,22 @@ namespace DiscImageChef.Core.Devices.Dumping
/// Disc type as detected in SCSI or MMC layer
internal void Sbc(Dictionary mediaTags, ref MediaType dskType, bool opticalDisc)
{
- bool sense;
- byte scsiMediumType = 0;
- byte scsiDensityCode = 0;
- bool containsFloppyPage = false;
- const ushort SBC_PROFILE = 0x0001;
- DateTime start;
- DateTime end;
- double totalDuration = 0;
- double currentSpeed = 0;
- double maxSpeed = double.MinValue;
- double minSpeed = double.MaxValue;
- byte[] readBuffer;
+ bool sense;
+ byte scsiMediumType = 0;
+ byte scsiDensityCode = 0;
+ var containsFloppyPage = false;
+ const ushort SBC_PROFILE = 0x0001;
+ DateTime start;
+ DateTime end;
+ double totalDuration = 0;
+ double currentSpeed = 0;
+ var maxSpeed = double.MinValue;
+ var minSpeed = double.MaxValue;
+ byte[] readBuffer;
Modes.DecodedMode? decMode = null;
- if(opticalDisc)
- switch(dskType)
+ if (opticalDisc)
+ switch (dskType)
{
case MediaType.REV35:
case MediaType.REV70:
@@ -89,64 +89,65 @@ namespace DiscImageChef.Core.Devices.Dumping
}
dumpLog.WriteLine("Initializing reader.");
- Reader scsiReader = new Reader(dev, dev.Timeout, null, dumpRaw);
- ulong blocks = scsiReader.GetDeviceBlocks();
- uint blockSize = scsiReader.LogicalBlockSize;
- if(scsiReader.FindReadCommand())
+ var scsiReader = new Reader(dev, dev.Timeout, null, dumpRaw);
+ var blocks = scsiReader.GetDeviceBlocks();
+ var blockSize = scsiReader.LogicalBlockSize;
+ if (scsiReader.FindReadCommand())
{
dumpLog.WriteLine("ERROR: Cannot find correct read command: {0}.", scsiReader.ErrorMessage);
StoppingErrorMessage?.Invoke("Unable to read medium.");
return;
}
- if(blocks != 0 && blockSize != 0)
+ if (blocks != 0 && blockSize != 0)
{
blocks++;
UpdateStatus
- ?.Invoke($"Media has {blocks} blocks of {blockSize} bytes/each. (for a total of {blocks * (ulong)blockSize} bytes)");
+ ?.Invoke(
+ $"Media has {blocks} blocks of {blockSize} bytes/each. (for a total of {blocks * (ulong) blockSize} bytes)");
}
// Check how many blocks to read, if error show and return
- if(scsiReader.GetBlocksToRead())
+ if (scsiReader.GetBlocksToRead())
{
dumpLog.WriteLine("ERROR: Cannot get blocks to read: {0}.", scsiReader.ErrorMessage);
StoppingErrorMessage?.Invoke(scsiReader.ErrorMessage);
return;
}
- uint blocksToRead = scsiReader.BlocksToRead;
- uint logicalBlockSize = blockSize;
- uint physicalBlockSize = scsiReader.PhysicalBlockSize;
+ var blocksToRead = scsiReader.BlocksToRead;
+ var logicalBlockSize = blockSize;
+ var physicalBlockSize = scsiReader.PhysicalBlockSize;
- if(blocks == 0)
+ if (blocks == 0)
{
dumpLog.WriteLine("ERROR: Unable to read medium or empty medium present...");
StoppingErrorMessage?.Invoke("Unable to read medium or empty medium present...");
return;
}
- if(!opticalDisc)
+ if (!opticalDisc)
{
mediaTags = new Dictionary();
- if(dev.IsUsb && dev.UsbDescriptors != null) mediaTags.Add(MediaTagType.USB_Descriptors, null);
- if(dev.Type == DeviceType.ATAPI) mediaTags.Add(MediaTagType.ATAPI_IDENTIFY, null);
- if(dev.IsPcmcia && dev.Cis != null) mediaTags.Add(MediaTagType.PCMCIA_CIS, null);
+ if (dev.IsUsb && dev.UsbDescriptors != null) mediaTags.Add(MediaTagType.USB_Descriptors, null);
+ if (dev.Type == DeviceType.ATAPI) mediaTags.Add(MediaTagType.ATAPI_IDENTIFY, null);
+ if (dev.IsPcmcia && dev.Cis != null) mediaTags.Add(MediaTagType.PCMCIA_CIS, null);
- sense = dev.ScsiInquiry(out byte[] cmdBuf, out _);
+ sense = dev.ScsiInquiry(out var cmdBuf, out _);
mediaTags.Add(MediaTagType.SCSI_INQUIRY, cmdBuf);
- if(!sense)
+ if (!sense)
{
dumpLog.WriteLine("Requesting MODE SENSE (10).");
UpdateStatus?.Invoke("Requesting MODE SENSE (10).");
sense = dev.ModeSense10(out cmdBuf, out _, false, true, ScsiModeSensePageControl.Current, 0x3F,
- 0xFF, 5, out _);
- if(!sense || dev.Error)
+ 0xFF, 5, out _);
+ if (!sense || dev.Error)
sense = dev.ModeSense10(out cmdBuf, out _, false, true, ScsiModeSensePageControl.Current, 0x3F,
- 0x00, 5, out _);
+ 0x00, 5, out _);
- if(!sense && !dev.Error)
- if(Modes.DecodeMode10(cmdBuf, dev.ScsiType).HasValue)
+ if (!sense && !dev.Error)
+ if (Modes.DecodeMode10(cmdBuf, dev.ScsiType).HasValue)
{
mediaTags.Add(MediaTagType.SCSI_MODESENSE_10, cmdBuf);
decMode = Modes.DecodeMode10(cmdBuf, dev.ScsiType);
@@ -155,38 +156,38 @@ namespace DiscImageChef.Core.Devices.Dumping
dumpLog.WriteLine("Requesting MODE SENSE (6).");
UpdateStatus?.Invoke("Requesting MODE SENSE (6).");
sense = dev.ModeSense6(out cmdBuf, out _, false, ScsiModeSensePageControl.Current, 0x3F, 0x00, 5,
- out _);
- if(sense || dev.Error)
+ out _);
+ if (sense || dev.Error)
sense = dev.ModeSense6(out cmdBuf, out _, false, ScsiModeSensePageControl.Current, 0x3F, 0x00,
- 5, out _);
- if(sense || dev.Error) sense = dev.ModeSense(out cmdBuf, out _, 5, out _);
+ 5, out _);
+ if (sense || dev.Error) sense = dev.ModeSense(out cmdBuf, out _, 5, out _);
- if(!sense && !dev.Error)
- if(Modes.DecodeMode6(cmdBuf, dev.ScsiType).HasValue)
+ if (!sense && !dev.Error)
+ if (Modes.DecodeMode6(cmdBuf, dev.ScsiType).HasValue)
{
mediaTags.Add(MediaTagType.SCSI_MODESENSE_6, cmdBuf);
decMode = Modes.DecodeMode6(cmdBuf, dev.ScsiType);
}
- if(decMode.HasValue)
+ if (decMode.HasValue)
{
- scsiMediumType = (byte)decMode.Value.Header.MediumType;
- if(decMode.Value.Header.BlockDescriptors != null &&
- decMode.Value.Header.BlockDescriptors.Length >= 1)
- scsiDensityCode = (byte)decMode.Value.Header.BlockDescriptors[0].Density;
+ scsiMediumType = (byte) decMode.Value.Header.MediumType;
+ if (decMode.Value.Header.BlockDescriptors != null &&
+ decMode.Value.Header.BlockDescriptors.Length >= 1)
+ scsiDensityCode = (byte) decMode.Value.Header.BlockDescriptors[0].Density;
- containsFloppyPage =
- decMode.Value.Pages.Aggregate(containsFloppyPage,
- (current, modePage) => current | (modePage.Page == 0x05));
+ containsFloppyPage = decMode.Value.Pages != null &&
+ decMode.Value.Pages.Aggregate(containsFloppyPage,
+ (current, modePage) => current | (modePage.Page == 0x05));
}
}
}
- if(dskType == MediaType.Unknown)
- dskType = MediaTypeFromScsi.Get((byte)dev.ScsiType, dev.Manufacturer, dev.Model, scsiMediumType,
- scsiDensityCode, blocks, blockSize);
+ if (dskType == MediaType.Unknown)
+ dskType = MediaTypeFromScsi.Get((byte) dev.ScsiType, dev.Manufacturer, dev.Model, scsiMediumType,
+ scsiDensityCode, blocks, blockSize);
- if(dskType == MediaType.Unknown && dev.IsUsb && containsFloppyPage) dskType = MediaType.FlashDrive;
+ if (dskType == MediaType.Unknown && dev.IsUsb && containsFloppyPage) dskType = MediaType.FlashDrive;
UpdateStatus?.Invoke($"Device reports {blocks} blocks ({blocks * blockSize} bytes).");
UpdateStatus?.Invoke($"Device can read {blocksToRead} blocks at a time.");
@@ -198,29 +199,30 @@ namespace DiscImageChef.Core.Devices.Dumping
UpdateStatus?.Invoke($"SCSI floppy mode page present: {containsFloppyPage}.");
UpdateStatus?.Invoke($"Media identified as {dskType}");
- dumpLog.WriteLine("Device reports {0} blocks ({1} bytes).", blocks, blocks * blockSize);
- dumpLog.WriteLine("Device can read {0} blocks at a time.", blocksToRead);
- dumpLog.WriteLine("Device reports {0} bytes per logical block.", blockSize);
+ dumpLog.WriteLine("Device reports {0} blocks ({1} bytes).", blocks, blocks * blockSize);
+ dumpLog.WriteLine("Device can read {0} blocks at a time.", blocksToRead);
+ dumpLog.WriteLine("Device reports {0} bytes per logical block.", blockSize);
dumpLog.WriteLine("Device reports {0} bytes per physical block.", scsiReader.LongBlockSize);
- dumpLog.WriteLine("SCSI device type: {0}.", dev.ScsiType);
- dumpLog.WriteLine("SCSI medium type: {0}.", scsiMediumType);
- dumpLog.WriteLine("SCSI density type: {0}.", scsiDensityCode);
- dumpLog.WriteLine("SCSI floppy mode page present: {0}.", containsFloppyPage);
- dumpLog.WriteLine("Media identified as {0}.", dskType);
+ dumpLog.WriteLine("SCSI device type: {0}.", dev.ScsiType);
+ dumpLog.WriteLine("SCSI medium type: {0}.", scsiMediumType);
+ dumpLog.WriteLine("SCSI density type: {0}.", scsiDensityCode);
+ dumpLog.WriteLine("SCSI floppy mode page present: {0}.", containsFloppyPage);
+ dumpLog.WriteLine("Media identified as {0}.", dskType);
- uint longBlockSize = scsiReader.LongBlockSize;
+ var longBlockSize = scsiReader.LongBlockSize;
- if(dumpRaw)
- if(blockSize == longBlockSize)
+ if (dumpRaw)
+ if (blockSize == longBlockSize)
{
ErrorMessage?.Invoke(!scsiReader.CanReadRaw
- ? "Device doesn't seem capable of reading raw data from media."
- : "Device is capable of reading raw data but I've been unable to guess correct sector size.");
+ ? "Device doesn't seem capable of reading raw data from media."
+ : "Device is capable of reading raw data but I've been unable to guess correct sector size.");
- if(!force)
+ if (!force)
{
StoppingErrorMessage
- ?.Invoke("Not continuing. If you want to continue reading cooked data when raw is not available use the force option.");
+ ?.Invoke(
+ "Not continuing. If you want to continue reading cooked data when raw is not available use the force option.");
// TODO: Exit more gracefully
return;
}
@@ -230,27 +232,28 @@ namespace DiscImageChef.Core.Devices.Dumping
else
{
// Only a block will be read, but it contains 16 sectors and command expect sector number not block number
- blocksToRead = (uint)(longBlockSize == 37856 ? 16 : 1);
+ blocksToRead = (uint) (longBlockSize == 37856 ? 16 : 1);
UpdateStatus
- ?.Invoke($"Reading {longBlockSize} raw bytes ({blockSize * blocksToRead} cooked bytes) per sector.");
+ ?.Invoke(
+ $"Reading {longBlockSize} raw bytes ({blockSize * blocksToRead} cooked bytes) per sector.");
physicalBlockSize = longBlockSize;
- blockSize = longBlockSize;
+ blockSize = longBlockSize;
}
- bool ret = true;
+ var ret = true;
- foreach(MediaTagType tag in mediaTags.Keys)
+ foreach (var tag in mediaTags.Keys)
{
- if(outputPlugin.SupportedMediaTags.Contains(tag)) continue;
+ if (outputPlugin.SupportedMediaTags.Contains(tag)) continue;
ret = false;
dumpLog.WriteLine($"Output format does not support {tag}.");
ErrorMessage?.Invoke($"Output format does not support {tag}.");
}
- if(!ret)
+ if (!ret)
{
- if(force)
+ if (force)
{
dumpLog.WriteLine("Several media tags not supported, continuing...");
ErrorMessage?.Invoke("Several media tags not supported, continuing...");
@@ -266,12 +269,12 @@ namespace DiscImageChef.Core.Devices.Dumping
UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time.");
dumpLog.WriteLine("Reading {0} sectors at a time.", blocksToRead);
- MhddLog mhddLog = new MhddLog(outputPrefix + ".mhddlog.bin", dev, blocks, blockSize, blocksToRead);
- IbgLog ibgLog = new IbgLog(outputPrefix + ".ibg", SBC_PROFILE);
+ var mhddLog = new MhddLog(outputPrefix + ".mhddlog.bin", dev, blocks, blockSize, blocksToRead);
+ var ibgLog = new IbgLog(outputPrefix + ".ibg", SBC_PROFILE);
ret = outputPlugin.Create(outputPath, dskType, formatOptions, blocks, blockSize);
// Cannot create image
- if(!ret)
+ if (!ret)
{
dumpLog.WriteLine("Error creating output image, not continuing.");
dumpLog.WriteLine(outputPlugin.ErrorMessage);
@@ -283,22 +286,24 @@ namespace DiscImageChef.Core.Devices.Dumping
start = DateTime.UtcNow;
double imageWriteDuration = 0;
- if(opticalDisc)
+ if (opticalDisc)
{
- if(outputPlugin is IWritableOpticalImage opticalPlugin)
+ if (outputPlugin is IWritableOpticalImage opticalPlugin)
+ {
opticalPlugin.SetTracks(new List