Catch and print exceptions from device constructor.

This commit is contained in:
2019-11-02 01:15:49 +00:00
parent bdc55dd648
commit 438fa1c9a2
11 changed files with 754 additions and 565 deletions

View File

@@ -267,6 +267,7 @@
<e p="DiscImageChef.Core.csproj" t="IncludeRecursive" />
<e p="DiscImageChef.Core.csproj.DotSettings" t="Include" />
<e p="Entropy.cs" t="Include" />
<e p="Error.cs" t="Include" />
<e p="Filesystems.cs" t="Include" />
<e p="GetPluginBase.cs" t="Include" />
<e p="ImageFormat.cs" t="Include" />
@@ -571,6 +572,7 @@
<e p="Commands.cs" t="Include" />
<e p="Constructor.cs" t="Include" />
<e p="Destructor.cs" t="Include" />
<e p="DeviceException.cs" t="Include" />
<e p="List.cs" t="Include" />
<e p="MmcCommands" t="Include">
<e p="MMC.cs" t="Include" />

View File

@@ -65,6 +65,7 @@
<Compile Include="Media\Info\XgdInfo.cs" />
<Compile Include="Options.cs" />
<Compile Include="ImageFormat.cs" />
<Compile Include="Error.cs" />
<Compile Include="PrintScsiModePages.cs" />
<Compile Include="Sidecar\Files.cs" />
<Compile Include="Statistics.cs" />

106
DiscImageChef.Core/Error.cs Normal file
View File

@@ -0,0 +1,106 @@
using System;
using DiscImageChef.CommonTypes.Interop;
using PlatformID = DiscImageChef.CommonTypes.Interop.PlatformID;
namespace DiscImageChef.Core
{
public static class Error
{
public static string Print(int errno)
{
switch (DetectOS.GetRealPlatformID())
{
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.Win32NT:
case PlatformID.WinCE:
case PlatformID.WindowsPhone:
case PlatformID.Xbox:
return PrintWin32Error(errno);
case PlatformID.Unix:
case PlatformID.MacOSX:
case PlatformID.iOS:
case PlatformID.Linux:
case PlatformID.Solaris:
case PlatformID.NetBSD:
case PlatformID.OpenBSD:
case PlatformID.FreeBSD:
case PlatformID.DragonFly:
case PlatformID.Android:
case PlatformID.Tizen:
case PlatformID.Hurd:
case PlatformID.Haiku:
case PlatformID.HPUX:
case PlatformID.AIX:
case PlatformID.OS400:
case PlatformID.IRIX:
case PlatformID.Minix:
case PlatformID.QNX:
case PlatformID.SINIX:
case PlatformID.Tru64:
case PlatformID.Ultrix:
case PlatformID.OpenServer:
case PlatformID.UnixWare:
case PlatformID.zOS:
return PrintUnixError(errno);
case PlatformID.Wii:
return $"Unknown error code {errno}";
case PlatformID.WiiU:
return $"Unknown error code {errno}";
case PlatformID.PlayStation3:
return $"Unknown error code {errno}";
case PlatformID.PlayStation4:
return $"Unknown error code {errno}";
case PlatformID.NonStop:
return $"Unknown error code {errno}";
case PlatformID.Unknown:
return $"Unknown error code {errno}";
default:
return $"Unknown error code {errno}";
}
throw new Exception("Arrived an unexpected place");
}
private static string PrintUnixError(int errno)
{
switch (errno)
{
case 2: // ENOENT
case 19: // ENODEV
return "The specified device cannot be found.";
case 13: // EACCESS
return "Not enough permissions to open the device.";
case 16: // EBUSY
return "The specified device is in use by another process.";
case 30: // EROFS
return "Cannot open the device in writable mode, as needed by some commands.";
default:
return $"Unknown error code {errno}";
}
}
private static string PrintWin32Error(int errno)
{
switch (errno)
{
case 2: // ERROR_FILE_NOT_FOUND
case 3: // ERROR_PATH_NOT_FOUND
return "The specified device cannot be found.";
case 5: // ERROR_ACCESS_DENIED
return "Not enough permissions to open the device.";
case 19: // ERROR_WRITE_PROTECT
return "Cannot open the device in writable mode, as needed by some commands.";
case 32: // ERROR_SHARING_VIOLATION
case 33: // ERROR_LOCK_VIOLATION
case 108: // ERROR_DRIVE_LOCKED
case 170: // ERROR_BUSY
return "The specified device is in use by another process.";
case 130: // ERROR_DIRECT_ACCESS_HANDLE
return "Tried to open a file instead of a device.";
default:
return $"Unknown error code {errno}";
}
}
}
}

View File

@@ -141,16 +141,16 @@ namespace DiscImageChef.Devices
if (StringHandlers.CToString(camDevice.SimName) == "ata")
throw new
InvalidOperationException(
DeviceException(
"Parallel ATA devices are not supported on FreeBSD due to upstream bug #224250.");
break;
}
default: throw new InvalidOperationException($"Platform {PlatformId} not yet supported.");
default: throw new DeviceException($"Platform {PlatformId} not yet supported.");
}
}
if (Error) throw new SystemException($"Error {LastError} opening device.");
if (Error) throw new DeviceException(LastError);
Type = DeviceType.Unknown;
ScsiType = PeripheralDeviceTypes.UnknownDevice;
@@ -158,7 +158,7 @@ namespace DiscImageChef.Devices
byte[] ataBuf;
byte[] inqBuf = null;
if (Error) throw new SystemException($"Error {LastError} trying device.");
if (Error) throw new DeviceException(LastError);
var scsiSense = true;

View File

@@ -0,0 +1,24 @@
using System;
namespace DiscImageChef.Devices
{
/// <summary>
/// Exception to be returned by the device constructor
/// </summary>
public class DeviceException : Exception
{
internal DeviceException(string message) : base(message)
{
}
internal DeviceException(int lastError)
{
LastError = lastError;
}
/// <summary>
/// Last error sent by the operating systen
/// </summary>
public int LastError { get; }
}
}

View File

@@ -48,6 +48,7 @@
<Reference Include="System.Management" />
</ItemGroup>
<ItemGroup>
<Compile Include="Device\DeviceException.cs" />
<Compile Include="FreeBSD\ListDevices.cs" />
<Compile Include="Linux\Extern.cs" />
<Compile Include="Linux\Structs.cs" />

View File

@@ -45,12 +45,12 @@ using DeviceInfo = DiscImageChef.Core.Devices.Info.DeviceInfo;
namespace DiscImageChef.Commands
{
class DeviceInfoCommand : Command
internal class DeviceInfoCommand : Command
{
string devicePath;
string outputPrefix;
private string devicePath;
private string outputPrefix;
bool showHelp;
private bool showHelp;
public DeviceInfoCommand() : base("device-info", "Gets information about a device.")
{
@@ -69,29 +69,29 @@ namespace DiscImageChef.Commands
public override int Invoke(IEnumerable<string> arguments)
{
List<string> extra = Options.Parse(arguments);
var extra = Options.Parse(arguments);
if(showHelp)
if (showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return (int)ErrorNumber.HelpRequested;
return (int) ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
if(MainClass.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if(MainClass.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
if (MainClass.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (MainClass.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Statistics.AddCommand("device-info");
if(extra.Count > 1)
if (extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return (int)ErrorNumber.UnexpectedArgumentCount;
return (int) ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
if (extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing device path.");
return (int)ErrorNumber.MissingArgument;
return (int) ErrorNumber.MissingArgument;
}
devicePath = extra[0];
@@ -101,23 +101,32 @@ namespace DiscImageChef.Commands
DicConsole.DebugWriteLine("Device-Info command", "--output-prefix={0}", outputPrefix);
DicConsole.DebugWriteLine("Device-Info command", "--verbose={0}", MainClass.Verbose);
if(devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
if (devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
Device dev = new Device(devicePath);
if(dev.Error)
Device dev;
try
{
DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
return (int)ErrorNumber.CannotOpenDevice;
dev = new Device(devicePath);
if (dev.Error)
{
DicConsole.ErrorWriteLine(Error.Print(dev.LastError));
return (int) ErrorNumber.CannotOpenDevice;
}
}
catch (DeviceException e)
{
DicConsole.ErrorWriteLine(e.Message ?? Error.Print(e.LastError));
return (int) ErrorNumber.CannotOpenDevice;
}
Statistics.AddDevice(dev);
if(dev.IsUsb)
if (dev.IsUsb)
{
DicConsole.WriteLine("USB device");
if(dev.UsbDescriptors != null)
if (dev.UsbDescriptors != null)
DicConsole.WriteLine("USB descriptor is {0} bytes", dev.UsbDescriptors.Length);
DicConsole.WriteLine("USB Vendor ID: {0:X4}", dev.UsbVendorId);
DicConsole.WriteLine("USB Product ID: {0:X4}", dev.UsbProductId);
@@ -127,7 +136,7 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine();
}
if(dev.IsFireWire)
if (dev.IsFireWire)
{
DicConsole.WriteLine("FireWire device");
DicConsole.WriteLine("FireWire Vendor ID: {0:X6}", dev.FireWireVendor);
@@ -138,14 +147,14 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine();
}
if(dev.IsPcmcia)
if (dev.IsPcmcia)
{
DicConsole.WriteLine("PCMCIA device");
DicConsole.WriteLine("PCMCIA CIS is {0} bytes", dev.Cis.Length);
Tuple[] tuples = CIS.GetTuples(dev.Cis);
if(tuples != null)
foreach(Tuple tuple in tuples)
switch(tuple.Code)
var tuples = CIS.GetTuples(dev.Cis);
if (tuples != null)
foreach (var tuple in tuples)
switch (tuple.Code)
{
case TupleCodes.CISTPL_NULL:
case TupleCodes.CISTPL_END: break;
@@ -198,25 +207,25 @@ namespace DiscImageChef.Commands
break;
default:
DicConsole.DebugWriteLine("Device-Info command", "Found unknown tuple ID 0x{0:X2}",
(byte)tuple.Code);
(byte) tuple.Code);
break;
}
else DicConsole.DebugWriteLine("Device-Info command", "Could not get tuples");
}
DeviceInfo devInfo = new DeviceInfo(dev);
var devInfo = new DeviceInfo(dev);
if(devInfo.AtaIdentify != null)
if (devInfo.AtaIdentify != null)
{
DataFile.WriteTo("Device-Info command", outputPrefix, "_ata_identify.bin", "ATA IDENTIFY",
devInfo.AtaIdentify);
DicConsole.WriteLine(Identify.Prettify(devInfo.AtaIdentify));
if(devInfo.AtaMcptError.HasValue)
if (devInfo.AtaMcptError.HasValue)
{
DicConsole.WriteLine("Device supports the Media Card Pass Through Command Set");
switch(devInfo.AtaMcptError.Value.DeviceHead & 0x7)
switch (devInfo.AtaMcptError.Value.DeviceHead & 0x7)
{
case 0:
DicConsole.WriteLine("Device reports incorrect media card type");
@@ -239,16 +248,16 @@ namespace DiscImageChef.Commands
break;
}
if((devInfo.AtaMcptError.Value.DeviceHead & 0x08) == 0x08)
if ((devInfo.AtaMcptError.Value.DeviceHead & 0x08) == 0x08)
DicConsole.WriteLine("Media card is write protected");
ushort specificData = (ushort)(devInfo.AtaMcptError.Value.CylinderHigh * 0x100 +
var specificData = (ushort) (devInfo.AtaMcptError.Value.CylinderHigh * 0x100 +
devInfo.AtaMcptError.Value.CylinderLow);
if(specificData != 0) DicConsole.WriteLine("Card specific data: 0x{0:X4}", specificData);
if (specificData != 0) DicConsole.WriteLine("Card specific data: 0x{0:X4}", specificData);
}
}
if(devInfo.AtapiIdentify != null)
if (devInfo.AtapiIdentify != null)
{
DataFile.WriteTo("Device-Info command", outputPrefix, "_atapi_identify.bin", "ATAPI IDENTIFY",
devInfo.AtapiIdentify);
@@ -256,106 +265,106 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine(Identify.Prettify(devInfo.AtapiIdentify));
}
if(devInfo.ScsiInquiry != null)
if (devInfo.ScsiInquiry != null)
{
if(dev.Type != DeviceType.ATAPI) DicConsole.WriteLine("SCSI device");
if (dev.Type != DeviceType.ATAPI) DicConsole.WriteLine("SCSI device");
DataFile.WriteTo("Device-Info command", outputPrefix, "_scsi_inquiry.bin", "SCSI INQUIRY",
devInfo.ScsiInquiryData);
DicConsole.WriteLine(Inquiry.Prettify(devInfo.ScsiInquiry));
if(devInfo.ScsiEvpdPages != null)
foreach(KeyValuePair<byte, byte[]> page in devInfo.ScsiEvpdPages)
if(page.Key >= 0x01 && page.Key <= 0x7F)
if (devInfo.ScsiEvpdPages != null)
foreach (var page in devInfo.ScsiEvpdPages)
if (page.Key >= 0x01 && page.Key <= 0x7F)
{
DicConsole.WriteLine("ASCII Page {0:X2}h: {1}", page.Key, EVPD.DecodeASCIIPage(page.Value));
DataFile.WriteTo("Device-Info command", outputPrefix, page.Value);
}
else if(page.Key == 0x80)
else if (page.Key == 0x80)
{
DicConsole.WriteLine("Unit Serial Number: {0}", EVPD.DecodePage80(page.Value));
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0x81)
else if (page.Key == 0x81)
{
DicConsole.WriteLine("{0}", EVPD.PrettifyPage_81(page.Value));
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0x82)
else if (page.Key == 0x82)
{
DicConsole.WriteLine("ASCII implemented operating definitions: {0}",
EVPD.DecodePage82(page.Value));
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0x83)
else if (page.Key == 0x83)
{
DicConsole.WriteLine("{0}", EVPD.PrettifyPage_83(page.Value));
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0x84)
else if (page.Key == 0x84)
{
DicConsole.WriteLine("{0}", EVPD.PrettifyPage_84(page.Value));
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0x85)
else if (page.Key == 0x85)
{
DicConsole.WriteLine("{0}", EVPD.PrettifyPage_85(page.Value));
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0x86)
else if (page.Key == 0x86)
{
DicConsole.WriteLine("{0}", EVPD.PrettifyPage_86(page.Value));
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0x89)
else if (page.Key == 0x89)
{
DicConsole.WriteLine("{0}", EVPD.PrettifyPage_89(page.Value));
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0xB0)
else if (page.Key == 0xB0)
{
DicConsole.WriteLine("{0}", EVPD.PrettifyPage_B0(page.Value));
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0xB1)
else if (page.Key == 0xB1)
{
DicConsole.WriteLine("Manufacturer-assigned Serial Number: {0}",
EVPD.DecodePageB1(page.Value));
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0xB2)
else if (page.Key == 0xB2)
{
DicConsole.WriteLine("TapeAlert Supported Flags Bitmap: 0x{0:X16}",
EVPD.DecodePageB2(page.Value));
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0xB3)
else if (page.Key == 0xB3)
{
DicConsole.WriteLine("Automation Device Serial Number: {0}", EVPD.DecodePageB3(page.Value));
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0xB4)
else if (page.Key == 0xB4)
{
DicConsole.WriteLine("Data Transfer Device Element Address: 0x{0}",
EVPD.DecodePageB4(page.Value));
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0xC0 &&
else if (page.Key == 0xC0 &&
StringHandlers.CToString(devInfo.ScsiInquiry.Value.VendorIdentification)
.ToLowerInvariant().Trim() == "quantum")
{
@@ -363,7 +372,7 @@ namespace DiscImageChef.Commands
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0xC0 &&
else if (page.Key == 0xC0 &&
StringHandlers.CToString(devInfo.ScsiInquiry.Value.VendorIdentification)
.ToLowerInvariant().Trim() == "seagate")
{
@@ -371,7 +380,7 @@ namespace DiscImageChef.Commands
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0xC0 &&
else if (page.Key == 0xC0 &&
StringHandlers.CToString(devInfo.ScsiInquiry.Value.VendorIdentification)
.ToLowerInvariant().Trim() == "ibm")
{
@@ -379,7 +388,7 @@ namespace DiscImageChef.Commands
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0xC1 &&
else if (page.Key == 0xC1 &&
StringHandlers.CToString(devInfo.ScsiInquiry.Value.VendorIdentification)
.ToLowerInvariant().Trim() == "ibm")
{
@@ -387,7 +396,7 @@ namespace DiscImageChef.Commands
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if((page.Key == 0xC0 || page.Key == 0xC1) &&
else if ((page.Key == 0xC0 || page.Key == 0xC1) &&
StringHandlers.CToString(devInfo.ScsiInquiry.Value.VendorIdentification)
.ToLowerInvariant().Trim() == "certance")
{
@@ -395,7 +404,7 @@ namespace DiscImageChef.Commands
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if((page.Key == 0xC2 || page.Key == 0xC3 || page.Key == 0xC4 || page.Key == 0xC5 ||
else if ((page.Key == 0xC2 || page.Key == 0xC3 || page.Key == 0xC4 || page.Key == 0xC5 ||
page.Key == 0xC6) &&
StringHandlers.CToString(devInfo.ScsiInquiry.Value.VendorIdentification)
.ToLowerInvariant().Trim() == "certance")
@@ -404,7 +413,7 @@ namespace DiscImageChef.Commands
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if((page.Key == 0xC0 || page.Key == 0xC1 || page.Key == 0xC2 || page.Key == 0xC3 ||
else if ((page.Key == 0xC0 || page.Key == 0xC1 || page.Key == 0xC2 || page.Key == 0xC3 ||
page.Key == 0xC4 || page.Key == 0xC5) && StringHandlers
.CToString(devInfo.ScsiInquiry.Value
.VendorIdentification)
@@ -414,7 +423,7 @@ namespace DiscImageChef.Commands
DataFile.WriteTo("Device-Info command", outputPrefix, $"_scsi_evpd_{page.Key:X2}h.bin",
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
else if(page.Key == 0xDF &&
else if (page.Key == 0xDF &&
StringHandlers.CToString(devInfo.ScsiInquiry.Value.VendorIdentification)
.ToLowerInvariant().Trim() == "certance")
{
@@ -424,7 +433,7 @@ namespace DiscImageChef.Commands
}
else
{
if(page.Key == 0x00) continue;
if (page.Key == 0x00) continue;
DicConsole.DebugWriteLine("Device-Info command", "Found undecoded SCSI VPD page 0x{0:X2}",
page.Key);
@@ -433,38 +442,38 @@ namespace DiscImageChef.Commands
$"SCSI INQUIRY EVPD {page.Key:X2}h", page.Value);
}
if(devInfo.ScsiModeSense6 != null)
if (devInfo.ScsiModeSense6 != null)
DataFile.WriteTo("Device-Info command", outputPrefix, "_scsi_modesense6.bin", "SCSI MODE SENSE",
devInfo.ScsiModeSense6);
if(devInfo.ScsiModeSense10 != null)
if (devInfo.ScsiModeSense10 != null)
DataFile.WriteTo("Device-Info command", outputPrefix, "_scsi_modesense10.bin", "SCSI MODE SENSE",
devInfo.ScsiModeSense10);
if(devInfo.ScsiMode.HasValue)
if (devInfo.ScsiMode.HasValue)
PrintScsiModePages.Print(devInfo.ScsiMode.Value,
(PeripheralDeviceTypes)devInfo.ScsiInquiry.Value.PeripheralDeviceType,
(PeripheralDeviceTypes) devInfo.ScsiInquiry.Value.PeripheralDeviceType,
devInfo.ScsiInquiry.Value.VendorIdentification);
if(devInfo.MmcConfiguration != null)
if (devInfo.MmcConfiguration != null)
{
DataFile.WriteTo("Device-Info command", outputPrefix, "_mmc_getconfiguration.bin",
"MMC GET CONFIGURATION", devInfo.MmcConfiguration);
Features.SeparatedFeatures ftr = Features.Separate(devInfo.MmcConfiguration);
var ftr = Features.Separate(devInfo.MmcConfiguration);
DicConsole.DebugWriteLine("Device-Info command", "GET CONFIGURATION length is {0} bytes",
ftr.DataLength);
DicConsole.DebugWriteLine("Device-Info command", "GET CONFIGURATION current profile is {0:X4}h",
ftr.CurrentProfile);
if(ftr.Descriptors != null)
if (ftr.Descriptors != null)
{
DicConsole.WriteLine("SCSI MMC GET CONFIGURATION Features:");
foreach(Features.FeatureDescriptor desc in ftr.Descriptors)
foreach (var desc in ftr.Descriptors)
{
DicConsole.DebugWriteLine("Device-Info command", "Feature {0:X4}h", desc.Code);
switch(desc.Code)
switch (desc.Code)
{
case 0x0000:
DicConsole.WriteLine(Features.Prettify_0000(desc.Data));
@@ -647,13 +656,15 @@ namespace DiscImageChef.Commands
}
}
else
{
DicConsole.DebugWriteLine("Device-Info command",
"GET CONFIGURATION returned no feature descriptors");
}
}
if(devInfo.PlextorFeatures != null)
if (devInfo.PlextorFeatures != null)
{
if(devInfo.PlextorFeatures.Eeprom != null)
if (devInfo.PlextorFeatures.Eeprom != null)
{
DataFile.WriteTo("Device-Info command", outputPrefix, "_plextor_eeprom.bin",
"PLEXTOR READ EEPROM", devInfo.PlextorFeatures.Eeprom);
@@ -667,7 +678,7 @@ namespace DiscImageChef.Commands
devInfo.PlextorFeatures.CdWriteTime / 3600,
devInfo.PlextorFeatures.CdWriteTime / 60 % 60,
devInfo.PlextorFeatures.CdWriteTime % 60);
if(devInfo.PlextorFeatures.IsDvd)
if (devInfo.PlextorFeatures.IsDvd)
{
DicConsole.WriteLine("Drive has spent {0} hours, {1} minutes and {2} seconds reading DVDs",
devInfo.PlextorFeatures.DvdReadTime / 3600,
@@ -680,30 +691,32 @@ namespace DiscImageChef.Commands
}
}
if(devInfo.PlextorFeatures.PoweRec)
if (devInfo.PlextorFeatures.PoweRec)
{
DicConsole.Write("Drive supports PoweRec");
if(devInfo.PlextorFeatures.PoweRecEnabled)
if (devInfo.PlextorFeatures.PoweRecEnabled)
{
DicConsole.Write(", has it enabled");
if(devInfo.PlextorFeatures.PoweRecRecommendedSpeed > 0)
if (devInfo.PlextorFeatures.PoweRecRecommendedSpeed > 0)
DicConsole.WriteLine(" and recommends {0} Kb/sec.",
devInfo.PlextorFeatures.PoweRecRecommendedSpeed);
else DicConsole.WriteLine(".");
if(devInfo.PlextorFeatures.PoweRecSelected > 0)
if (devInfo.PlextorFeatures.PoweRecSelected > 0)
DicConsole
.WriteLine("Selected PoweRec speed for currently inserted media is {0} Kb/sec ({1}x)",
.WriteLine(
"Selected PoweRec speed for currently inserted media is {0} Kb/sec ({1}x)",
devInfo.PlextorFeatures.PoweRecSelected,
devInfo.PlextorFeatures.PoweRecSelected / 177);
if(devInfo.PlextorFeatures.PoweRecMax > 0)
if (devInfo.PlextorFeatures.PoweRecMax > 0)
DicConsole
.WriteLine("Maximum PoweRec speed for currently inserted media is {0} Kb/sec ({1}x)",
.WriteLine(
"Maximum PoweRec speed for currently inserted media is {0} Kb/sec ({1}x)",
devInfo.PlextorFeatures.PoweRecMax,
devInfo.PlextorFeatures.PoweRecMax / 177);
if(devInfo.PlextorFeatures.PoweRecLast > 0)
if (devInfo.PlextorFeatures.PoweRecLast > 0)
DicConsole.WriteLine("Last used PoweRec was {0} Kb/sec ({1}x)",
devInfo.PlextorFeatures.PoweRecLast,
devInfo.PlextorFeatures.PoweRecLast / 177);
@@ -715,88 +728,88 @@ namespace DiscImageChef.Commands
}
}
if(devInfo.PlextorFeatures.SilentMode)
if (devInfo.PlextorFeatures.SilentMode)
{
DicConsole.WriteLine("Drive supports Plextor SilentMode");
if(devInfo.PlextorFeatures.SilentModeEnabled)
if (devInfo.PlextorFeatures.SilentModeEnabled)
{
DicConsole.WriteLine("Plextor SilentMode is enabled:");
DicConsole.WriteLine(devInfo.PlextorFeatures.AccessTimeLimit == 2
? "\tAccess time is slow"
: "\tAccess time is fast");
if(devInfo.PlextorFeatures.CdReadSpeedLimit > 0)
if (devInfo.PlextorFeatures.CdReadSpeedLimit > 0)
DicConsole.WriteLine("\tCD read speed limited to {0}x",
devInfo.PlextorFeatures.CdReadSpeedLimit);
if(devInfo.PlextorFeatures.DvdReadSpeedLimit > 0 && devInfo.PlextorFeatures.IsDvd)
if (devInfo.PlextorFeatures.DvdReadSpeedLimit > 0 && devInfo.PlextorFeatures.IsDvd)
DicConsole.WriteLine("\tDVD read speed limited to {0}x",
devInfo.PlextorFeatures.DvdReadSpeedLimit);
if(devInfo.PlextorFeatures.CdWriteSpeedLimit > 0)
if (devInfo.PlextorFeatures.CdWriteSpeedLimit > 0)
DicConsole.WriteLine("\tCD write speed limited to {0}x",
devInfo.PlextorFeatures.CdWriteSpeedLimit);
}
}
if(devInfo.PlextorFeatures.GigaRec) DicConsole.WriteLine("Drive supports Plextor GigaRec");
if(devInfo.PlextorFeatures.SecuRec) DicConsole.WriteLine("Drive supports Plextor SecuRec");
if(devInfo.PlextorFeatures.SpeedRead)
if (devInfo.PlextorFeatures.GigaRec) DicConsole.WriteLine("Drive supports Plextor GigaRec");
if (devInfo.PlextorFeatures.SecuRec) DicConsole.WriteLine("Drive supports Plextor SecuRec");
if (devInfo.PlextorFeatures.SpeedRead)
{
DicConsole.Write("Drive supports Plextor SpeedRead");
if(devInfo.PlextorFeatures.SpeedReadEnabled) DicConsole.WriteLine("and has it enabled");
if (devInfo.PlextorFeatures.SpeedReadEnabled) DicConsole.WriteLine("and has it enabled");
else DicConsole.WriteLine();
}
if(devInfo.PlextorFeatures.Hiding)
if (devInfo.PlextorFeatures.Hiding)
{
DicConsole.WriteLine("Drive supports hiding CD-Rs and forcing single session");
if(devInfo.PlextorFeatures.HidesRecordables)
if (devInfo.PlextorFeatures.HidesRecordables)
DicConsole.WriteLine("Drive currently hides CD-Rs");
if(devInfo.PlextorFeatures.HidesSessions)
if (devInfo.PlextorFeatures.HidesSessions)
DicConsole.WriteLine("Drive currently forces single session");
}
if(devInfo.PlextorFeatures.VariRec) DicConsole.WriteLine("Drive supports Plextor VariRec");
if (devInfo.PlextorFeatures.VariRec) DicConsole.WriteLine("Drive supports Plextor VariRec");
if(devInfo.PlextorFeatures.IsDvd)
if (devInfo.PlextorFeatures.IsDvd)
{
if(devInfo.PlextorFeatures.VariRecDvd)
if (devInfo.PlextorFeatures.VariRecDvd)
DicConsole.WriteLine("Drive supports Plextor VariRec for DVDs");
if(devInfo.PlextorFeatures.BitSetting)
if (devInfo.PlextorFeatures.BitSetting)
DicConsole.WriteLine("Drive supports bitsetting DVD+R book type");
if(devInfo.PlextorFeatures.BitSettingDl)
if (devInfo.PlextorFeatures.BitSettingDl)
DicConsole.WriteLine("Drive supports bitsetting DVD+R DL book type");
if(devInfo.PlextorFeatures.DvdPlusWriteTest)
if (devInfo.PlextorFeatures.DvdPlusWriteTest)
DicConsole.WriteLine("Drive supports test writing DVD+");
}
}
if(devInfo.ScsiInquiry.Value.KreonPresent)
if (devInfo.ScsiInquiry.Value.KreonPresent)
{
DicConsole.WriteLine("Drive has kreon firmware:");
if(devInfo.KreonFeatures.HasFlag(KreonFeatures.ChallengeResponse))
if (devInfo.KreonFeatures.HasFlag(KreonFeatures.ChallengeResponse))
DicConsole.WriteLine("\tCan do challenge/response with Xbox discs");
if(devInfo.KreonFeatures.HasFlag(KreonFeatures.DecryptSs))
if (devInfo.KreonFeatures.HasFlag(KreonFeatures.DecryptSs))
DicConsole.WriteLine("\tCan read and descrypt SS from Xbox discs");
if(devInfo.KreonFeatures.HasFlag(KreonFeatures.XtremeUnlock))
if (devInfo.KreonFeatures.HasFlag(KreonFeatures.XtremeUnlock))
DicConsole.WriteLine("\tCan set xtreme unlock state with Xbox discs");
if(devInfo.KreonFeatures.HasFlag(KreonFeatures.WxripperUnlock))
if (devInfo.KreonFeatures.HasFlag(KreonFeatures.WxripperUnlock))
DicConsole.WriteLine("\tCan set wxripper unlock state with Xbox discs");
if(devInfo.KreonFeatures.HasFlag(KreonFeatures.ChallengeResponse360))
if (devInfo.KreonFeatures.HasFlag(KreonFeatures.ChallengeResponse360))
DicConsole.WriteLine("\tCan do challenge/response with Xbox 360 discs");
if(devInfo.KreonFeatures.HasFlag(KreonFeatures.DecryptSs360))
if (devInfo.KreonFeatures.HasFlag(KreonFeatures.DecryptSs360))
DicConsole.WriteLine("\tCan read and descrypt SS from Xbox 360 discs");
if(devInfo.KreonFeatures.HasFlag(KreonFeatures.XtremeUnlock360))
if (devInfo.KreonFeatures.HasFlag(KreonFeatures.XtremeUnlock360))
DicConsole.WriteLine("\tCan set xtreme unlock state with Xbox 360 discs");
if(devInfo.KreonFeatures.HasFlag(KreonFeatures.WxripperUnlock360))
if (devInfo.KreonFeatures.HasFlag(KreonFeatures.WxripperUnlock360))
DicConsole.WriteLine("\tCan set wxripper unlock state with Xbox 360 discs");
if(devInfo.KreonFeatures.HasFlag(KreonFeatures.Lock))
if (devInfo.KreonFeatures.HasFlag(KreonFeatures.Lock))
DicConsole.WriteLine("\tCan set locked state");
if(devInfo.KreonFeatures.HasFlag(KreonFeatures.ErrorSkipping))
if (devInfo.KreonFeatures.HasFlag(KreonFeatures.ErrorSkipping))
DicConsole.WriteLine("\tCan skip read errors");
}
if(devInfo.BlockLimits != null)
if (devInfo.BlockLimits != null)
{
DataFile.WriteTo("Device-Info command", outputPrefix, "_ssc_readblocklimits.bin",
"SSC READ BLOCK LIMITS", devInfo.BlockLimits);
@@ -804,22 +817,22 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine(BlockLimits.Prettify(devInfo.BlockLimits));
}
if(devInfo.DensitySupport != null)
if (devInfo.DensitySupport != null)
{
DataFile.WriteTo("Device-Info command", outputPrefix, "_ssc_reportdensitysupport.bin",
"SSC REPORT DENSITY SUPPORT", devInfo.DensitySupport);
if(devInfo.DensitySupportHeader.HasValue)
if (devInfo.DensitySupportHeader.HasValue)
{
DicConsole.WriteLine("Densities supported by device:");
DicConsole.WriteLine(DensitySupport.PrettifyDensity(devInfo.DensitySupportHeader));
}
}
if(devInfo.MediumDensitySupport != null)
if (devInfo.MediumDensitySupport != null)
{
DataFile.WriteTo("Device-Info command", outputPrefix, "_ssc_reportdensitysupport_medium.bin",
"SSC REPORT DENSITY SUPPORT (MEDIUM)", devInfo.MediumDensitySupport);
if(devInfo.MediaTypeSupportHeader.HasValue)
if (devInfo.MediaTypeSupportHeader.HasValue)
{
DicConsole.WriteLine("Medium types supported by device:");
DicConsole.WriteLine(DensitySupport.PrettifyMediumType(devInfo.MediaTypeSupportHeader));
@@ -829,34 +842,34 @@ namespace DiscImageChef.Commands
}
}
switch(dev.Type)
switch (dev.Type)
{
case DeviceType.MMC:
{
bool noInfo = true;
var noInfo = true;
if(devInfo.CID != null)
if (devInfo.CID != null)
{
noInfo = false;
DataFile.WriteTo("Device-Info command", outputPrefix, "_mmc_cid.bin", "MMC CID", devInfo.CID);
DicConsole.WriteLine("{0}", Decoders.MMC.Decoders.PrettifyCID(devInfo.CID));
}
if(devInfo.CSD != null)
if (devInfo.CSD != null)
{
noInfo = false;
DataFile.WriteTo("Device-Info command", outputPrefix, "_mmc_csd.bin", "MMC CSD", devInfo.CSD);
DicConsole.WriteLine("{0}", Decoders.MMC.Decoders.PrettifyCSD(devInfo.CSD));
}
if(devInfo.OCR != null)
if (devInfo.OCR != null)
{
noInfo = false;
DataFile.WriteTo("Device-Info command", outputPrefix, "_mmc_ocr.bin", "MMC OCR", devInfo.OCR);
DicConsole.WriteLine("{0}", Decoders.MMC.Decoders.PrettifyOCR(devInfo.OCR));
}
if(devInfo.ExtendedCSD != null)
if (devInfo.ExtendedCSD != null)
{
noInfo = false;
DataFile.WriteTo("Device-Info command", outputPrefix, "_mmc_ecsd.bin", "MMC Extended CSD",
@@ -864,14 +877,14 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine("{0}", Decoders.MMC.Decoders.PrettifyExtendedCSD(devInfo.ExtendedCSD));
}
if(noInfo) DicConsole.WriteLine("Could not get any kind of information from the device !!!");
if (noInfo) DicConsole.WriteLine("Could not get any kind of information from the device !!!");
}
break;
case DeviceType.SecureDigital:
{
bool noInfo = true;
var noInfo = true;
if(devInfo.CID != null)
if (devInfo.CID != null)
{
noInfo = false;
DataFile.WriteTo("Device-Info command", outputPrefix, "_sd_cid.bin", "SecureDigital CID",
@@ -879,7 +892,7 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine("{0}", Decoders.SecureDigital.Decoders.PrettifyCID(devInfo.CID));
}
if(devInfo.CSD != null)
if (devInfo.CSD != null)
{
noInfo = false;
DataFile.WriteTo("Device-Info command", outputPrefix, "_sd_csd.bin", "SecureDigital CSD",
@@ -887,7 +900,7 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine("{0}", Decoders.SecureDigital.Decoders.PrettifyCSD(devInfo.CSD));
}
if(devInfo.OCR != null)
if (devInfo.OCR != null)
{
noInfo = false;
DataFile.WriteTo("Device-Info command", outputPrefix, "_sd_ocr.bin", "SecureDigital OCR",
@@ -895,7 +908,7 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine("{0}", Decoders.SecureDigital.Decoders.PrettifyOCR(devInfo.OCR));
}
if(devInfo.SCR != null)
if (devInfo.SCR != null)
{
noInfo = false;
DataFile.WriteTo("Device-Info command", outputPrefix, "_sd_scr.bin", "SecureDigital SCR",
@@ -903,13 +916,13 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine("{0}", Decoders.SecureDigital.Decoders.PrettifySCR(devInfo.SCR));
}
if(noInfo) DicConsole.WriteLine("Could not get any kind of information from the device !!!");
if (noInfo) DicConsole.WriteLine("Could not get any kind of information from the device !!!");
}
break;
}
dev.Close();
return (int)ErrorNumber.NoError;
return (int) ErrorNumber.NoError;
}
}
}

View File

@@ -43,6 +43,7 @@ using DiscImageChef.Database;
using DiscImageChef.Database.Models;
using DiscImageChef.Decoders.ATA;
using DiscImageChef.Decoders.SCSI;
using DiscImageChef.Devices;
using Mono.Options;
using Newtonsoft.Json;
using Command = Mono.Options.Command;
@@ -108,11 +109,20 @@ namespace DiscImageChef.Commands
if (devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
var dev = new Device(devicePath);
Device dev;
try
{
dev = new Device(devicePath);
if (dev.Error)
{
DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
DicConsole.ErrorWriteLine(Error.Print(dev.LastError));
return (int) ErrorNumber.CannotOpenDevice;
}
}
catch (DeviceException e)
{
DicConsole.ErrorWriteLine(e.Message ?? Error.Print(e.LastError));
return (int) ErrorNumber.CannotOpenDevice;
}

View File

@@ -36,7 +36,6 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.CommonTypes.Interop;
@@ -52,26 +51,28 @@ using PlatformID = DiscImageChef.CommonTypes.Interop.PlatformID;
namespace DiscImageChef.Commands
{
class DumpMediaCommand : Command
internal class DumpMediaCommand : Command
{
string cicmXml;
string devicePath;
bool doResume = true;
string encodingName;
bool firstTrackPregap;
bool force;
bool noMetadata;
bool noTrim;
string outputFile;
string outputOptions;
bool persistent;
private string cicmXml;
private string devicePath;
private bool doResume = true;
private string encodingName;
private bool firstTrackPregap;
private bool force;
private bool noMetadata;
private bool noTrim;
private string outputFile;
private string outputOptions;
private bool persistent;
// TODO: Disabled temporarily
bool raw = false;
ushort retryPasses = 5;
bool showHelp;
int skip = 512;
bool stopOnError;
string wanteOutputFormat;
private bool raw = false;
private ushort retryPasses = 5;
private bool showHelp;
private int skip = 512;
private bool stopOnError;
private string wanteOutputFormat;
public DumpMediaCommand() : base("dump-media", "Dumps the media inserted on a device to a media image.")
{
@@ -87,7 +88,7 @@ namespace DiscImageChef.Commands
{"encoding|e=", "Name of character encoding to use.", s => encodingName = s}
};
if(DetectOS.GetRealPlatformID() != PlatformID.FreeBSD)
if (DetectOS.GetRealPlatformID() != PlatformID.FreeBSD)
Options.Add("first-pregap", "Try to read first track pregap. Only applicable to CD/DDCD/GD.",
b => firstTrackPregap = b != null);
@@ -116,29 +117,29 @@ namespace DiscImageChef.Commands
public override int Invoke(IEnumerable<string> arguments)
{
List<string> extra = Options.Parse(arguments);
var extra = Options.Parse(arguments);
if(showHelp)
if (showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return (int)ErrorNumber.HelpRequested;
return (int) ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
if(MainClass.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if(MainClass.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
if (MainClass.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (MainClass.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Statistics.AddCommand("dump-media");
if(extra.Count > 2)
if (extra.Count > 2)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return (int)ErrorNumber.UnexpectedArgumentCount;
return (int) ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count <= 1)
if (extra.Count <= 1)
{
DicConsole.ErrorWriteLine("Missing paths.");
return (int)ErrorNumber.MissingArgument;
return (int) ErrorNumber.MissingArgument;
}
devicePath = extra[0];
@@ -164,93 +165,105 @@ namespace DiscImageChef.Commands
DicConsole.DebugWriteLine("Dump-Media command", "--stop-on-error={0}", stopOnError);
DicConsole.DebugWriteLine("Dump-Media command", "--verbose={0}", MainClass.Verbose);
Dictionary<string, string> parsedOptions = Core.Options.Parse(outputOptions);
var parsedOptions = Core.Options.Parse(outputOptions);
DicConsole.DebugWriteLine("Dump-Media command", "Parsed options:");
foreach(KeyValuePair<string, string> parsedOption in parsedOptions)
foreach (var parsedOption in parsedOptions)
DicConsole.DebugWriteLine("Dump-Media command", "{0} = {1}", parsedOption.Key, parsedOption.Value);
Encoding encoding = null;
if(encodingName != null)
if (encodingName != null)
try
{
encoding = Claunia.Encoding.Encoding.GetEncoding(encodingName);
if(MainClass.Verbose) DicConsole.VerboseWriteLine("Using encoding for {0}.", encoding.EncodingName);
if (MainClass.Verbose)
DicConsole.VerboseWriteLine("Using encoding for {0}.", encoding.EncodingName);
}
catch(ArgumentException)
catch (ArgumentException)
{
DicConsole.ErrorWriteLine("Specified encoding is not supported.");
return (int)ErrorNumber.EncodingUnknown;
return (int) ErrorNumber.EncodingUnknown;
}
if(devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
if (devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
Device dev = new Device(devicePath);
if(dev.Error)
Device dev;
try
{
DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
return (int)ErrorNumber.CannotOpenDevice;
dev = new Device(devicePath);
if (dev.Error)
{
DicConsole.ErrorWriteLine(Error.Print(dev.LastError));
return (int) ErrorNumber.CannotOpenDevice;
}
}
catch (DeviceException e)
{
DicConsole.ErrorWriteLine(e.Message ?? Error.Print(e.LastError));
return (int) ErrorNumber.CannotOpenDevice;
}
Statistics.AddDevice(dev);
string outputPrefix = Path.Combine(Path.GetDirectoryName(outputFile),
var outputPrefix = Path.Combine(Path.GetDirectoryName(outputFile),
Path.GetFileNameWithoutExtension(outputFile));
Resume resume = null;
XmlSerializer xs = new XmlSerializer(typeof(Resume));
if(File.Exists(outputPrefix + ".resume.xml") && doResume)
var xs = new XmlSerializer(typeof(Resume));
if (File.Exists(outputPrefix + ".resume.xml") && doResume)
try
{
StreamReader sr = new StreamReader(outputPrefix + ".resume.xml");
resume = (Resume)xs.Deserialize(sr);
var sr = new StreamReader(outputPrefix + ".resume.xml");
resume = (Resume) xs.Deserialize(sr);
sr.Close();
}
catch
{
DicConsole.ErrorWriteLine("Incorrect resume file, not continuing...");
return (int)ErrorNumber.InvalidResume;
return (int) ErrorNumber.InvalidResume;
}
if(resume != null && resume.NextBlock > resume.LastBlock && resume.BadBlocks.Count == 0 && !resume.Tape)
if (resume != null && resume.NextBlock > resume.LastBlock && resume.BadBlocks.Count == 0 && !resume.Tape)
{
DicConsole.WriteLine("Media already dumped correctly, not continuing...");
return (int)ErrorNumber.AlreadyDumped;
return (int) ErrorNumber.AlreadyDumped;
}
CICMMetadataType sidecar = null;
XmlSerializer sidecarXs = new XmlSerializer(typeof(CICMMetadataType));
if(cicmXml != null)
if(File.Exists(cicmXml))
var sidecarXs = new XmlSerializer(typeof(CICMMetadataType));
if (cicmXml != null)
if (File.Exists(cicmXml))
{
try
{
StreamReader sr = new StreamReader(cicmXml);
sidecar = (CICMMetadataType)sidecarXs.Deserialize(sr);
var sr = new StreamReader(cicmXml);
sidecar = (CICMMetadataType) sidecarXs.Deserialize(sr);
sr.Close();
}
catch
{
DicConsole.ErrorWriteLine("Incorrect metadata sidecar file, not continuing...");
return (int)ErrorNumber.InvalidSidecar;
return (int) ErrorNumber.InvalidSidecar;
}
}
else
{
DicConsole.ErrorWriteLine("Could not find metadata sidecar, not continuing...");
return (int)ErrorNumber.FileNotFound;
return (int) ErrorNumber.FileNotFound;
}
PluginBase plugins = GetPluginBase.Instance;
List<IWritableImage> candidates = new List<IWritableImage>();
var plugins = GetPluginBase.Instance;
var candidates = new List<IWritableImage>();
// Try extension
if(string.IsNullOrEmpty(wanteOutputFormat))
if (string.IsNullOrEmpty(wanteOutputFormat))
candidates.AddRange(plugins.WritableImages.Values.Where(t =>
t.KnownExtensions
.Contains(Path.GetExtension(outputFile))));
// Try Id
else if(Guid.TryParse(wanteOutputFormat, out Guid outId))
else if (Guid.TryParse(wanteOutputFormat, out var outId))
candidates.AddRange(plugins.WritableImages.Values.Where(t => t.Id.Equals(outId)));
// Try name
else
@@ -258,23 +271,23 @@ namespace DiscImageChef.Commands
StringComparison
.InvariantCultureIgnoreCase)));
if(candidates.Count == 0)
if (candidates.Count == 0)
{
DicConsole.WriteLine("No plugin supports requested extension.");
return (int)ErrorNumber.FormatNotFound;
return (int) ErrorNumber.FormatNotFound;
}
if(candidates.Count > 1)
if (candidates.Count > 1)
{
DicConsole.WriteLine("More than one plugin supports requested extension.");
return (int)ErrorNumber.TooManyFormats;
return (int) ErrorNumber.TooManyFormats;
}
IWritableImage outputFormat = candidates[0];
var outputFormat = candidates[0];
DumpLog dumpLog = new DumpLog(outputPrefix + ".log", dev);
var dumpLog = new DumpLog(outputPrefix + ".log", dev);
if(MainClass.Verbose)
if (MainClass.Verbose)
{
dumpLog.WriteLine("Output image format: {0} ({1}).", outputFormat.Name, outputFormat.Id);
DicConsole.VerboseWriteLine("Output image format: {0} ({1}).", outputFormat.Name, outputFormat.Id);
@@ -285,9 +298,9 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine("Output image format: {0}.", outputFormat.Name);
}
Dump dumper = new Dump(doResume, dev, devicePath, outputFormat, retryPasses, force, false, persistent,
var dumper = new Dump(doResume, dev, devicePath, outputFormat, retryPasses, force, false, persistent,
stopOnError, resume, dumpLog, encoding, outputPrefix, outputFile, parsedOptions,
sidecar, (uint)skip, noMetadata, noTrim, firstTrackPregap);
sidecar, (uint) skip, noMetadata, noTrim, firstTrackPregap);
dumper.UpdateStatus += Progress.UpdateStatus;
dumper.ErrorMessage += Progress.ErrorMessage;
dumper.StoppingErrorMessage += Progress.ErrorMessage;
@@ -307,7 +320,7 @@ namespace DiscImageChef.Commands
dumper.Start();
dev.Close();
return (int)ErrorNumber.NoError;
return (int) ErrorNumber.NoError;
}
}
}

View File

@@ -53,11 +53,11 @@ using Spare = DiscImageChef.Decoders.DVD.Spare;
namespace DiscImageChef.Commands
{
class MediaInfoCommand : Command
internal class MediaInfoCommand : Command
{
string devicePath;
string outputPrefix;
bool showHelp;
private string devicePath;
private string outputPrefix;
private bool showHelp;
public MediaInfoCommand() : base("media-info", "Gets information about the media inserted on a device.")
{
@@ -79,29 +79,29 @@ namespace DiscImageChef.Commands
public override int Invoke(IEnumerable<string> arguments)
{
List<string> extra = Options.Parse(arguments);
var extra = Options.Parse(arguments);
if(showHelp)
if (showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return (int)ErrorNumber.HelpRequested;
return (int) ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
if(MainClass.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if(MainClass.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
if (MainClass.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (MainClass.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Statistics.AddCommand("media-info");
if(extra.Count > 1)
if (extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return (int)ErrorNumber.UnexpectedArgumentCount;
return (int) ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
if (extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing device path.");
return (int)ErrorNumber.MissingArgument;
return (int) ErrorNumber.MissingArgument;
}
devicePath = extra[0];
@@ -111,20 +111,29 @@ namespace DiscImageChef.Commands
DicConsole.DebugWriteLine("Media-Info command", "--output-prefix={0}", outputPrefix);
DicConsole.DebugWriteLine("Media-Info command", "--verbose={0}", MainClass.Verbose);
if(devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
if (devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
Device dev = new Device(devicePath);
if(dev.Error)
Device dev;
try
{
DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
return (int)ErrorNumber.CannotOpenDevice;
dev = new Device(devicePath);
if (dev.Error)
{
DicConsole.ErrorWriteLine(Error.Print(dev.LastError));
return (int) ErrorNumber.CannotOpenDevice;
}
}
catch (DeviceException e)
{
DicConsole.ErrorWriteLine(e.Message ?? Error.Print(e.LastError));
return (int) ErrorNumber.CannotOpenDevice;
}
Statistics.AddDevice(dev);
switch(dev.Type)
switch (dev.Type)
{
case DeviceType.ATA:
DoAtaMediaInfo();
@@ -143,38 +152,38 @@ namespace DiscImageChef.Commands
default: throw new NotSupportedException("Unknown device type.");
}
return (int)ErrorNumber.NoError;
return (int) ErrorNumber.NoError;
}
static void DoAtaMediaInfo()
private static void DoAtaMediaInfo()
{
DicConsole.ErrorWriteLine("Please use device-info command for ATA devices.");
}
static void DoNvmeMediaInfo(string outputPrefix, Device dev)
private static void DoNvmeMediaInfo(string outputPrefix, Device dev)
{
throw new NotImplementedException("NVMe devices not yet supported.");
}
static void DoSdMediaInfo()
private static void DoSdMediaInfo()
{
DicConsole.ErrorWriteLine("Please use device-info command for MMC/SD devices.");
}
static void DoScsiMediaInfo(string outputPrefix, Device dev)
private static void DoScsiMediaInfo(string outputPrefix, Device dev)
{
ScsiInfo scsiInfo = new ScsiInfo(dev);
var scsiInfo = new ScsiInfo(dev);
if(!scsiInfo.MediaInserted) return;
if (!scsiInfo.MediaInserted) return;
if(scsiInfo.DeviceInfo.ScsiModeSense6 != null)
if (scsiInfo.DeviceInfo.ScsiModeSense6 != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_scsi_modesense6.bin", "SCSI MODE SENSE (6)",
scsiInfo.DeviceInfo.ScsiModeSense6);
if(scsiInfo.DeviceInfo.ScsiModeSense10 != null)
if (scsiInfo.DeviceInfo.ScsiModeSense10 != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_scsi_modesense10.bin", "SCSI MODE SENSE (10)",
scsiInfo.DeviceInfo.ScsiModeSense10);
switch(dev.ScsiType)
switch (dev.ScsiType)
{
case PeripheralDeviceTypes.DirectAccess:
case PeripheralDeviceTypes.MultiMediaDevice:
@@ -182,37 +191,37 @@ namespace DiscImageChef.Commands
case PeripheralDeviceTypes.OpticalDevice:
case PeripheralDeviceTypes.SimplifiedDevice:
case PeripheralDeviceTypes.WriteOnceDevice:
if(scsiInfo.ReadCapacity != null)
if (scsiInfo.ReadCapacity != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readcapacity.bin", "SCSI READ CAPACITY",
scsiInfo.ReadCapacity);
if(scsiInfo.ReadCapacity16 != null)
if (scsiInfo.ReadCapacity16 != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readcapacity16.bin",
"SCSI READ CAPACITY(16)", scsiInfo.ReadCapacity16);
if(scsiInfo.Blocks != 0 && scsiInfo.BlockSize != 0)
if (scsiInfo.Blocks != 0 && scsiInfo.BlockSize != 0)
DicConsole.WriteLine("Media has {0} blocks of {1} bytes/each. (for a total of {2} bytes)",
scsiInfo.Blocks, scsiInfo.BlockSize, scsiInfo.Blocks * scsiInfo.BlockSize);
break;
case PeripheralDeviceTypes.SequentialAccess:
if(scsiInfo.DensitySupport != null)
if (scsiInfo.DensitySupport != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_ssc_reportdensitysupport_media.bin",
"SSC REPORT DENSITY SUPPORT (MEDIA)", scsiInfo.DensitySupport);
if(scsiInfo.DensitySupportHeader.HasValue)
if (scsiInfo.DensitySupportHeader.HasValue)
{
DicConsole.WriteLine("Densities supported by currently inserted media:");
DicConsole.WriteLine(DensitySupport.PrettifyDensity(scsiInfo.DensitySupportHeader));
}
}
if(scsiInfo.MediaTypeSupport != null)
if (scsiInfo.MediaTypeSupport != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix,
"_ssc_reportdensitysupport_medium_media.bin",
"SSC REPORT DENSITY SUPPORT (MEDIUM & MEDIA)", scsiInfo.MediaTypeSupport);
if(scsiInfo.MediaTypeSupportHeader.HasValue)
if (scsiInfo.MediaTypeSupportHeader.HasValue)
{
DicConsole.WriteLine("Medium types currently inserted in device:");
DicConsole.WriteLine(DensitySupport.PrettifyMediumType(scsiInfo.MediaTypeSupportHeader));
@@ -224,136 +233,136 @@ namespace DiscImageChef.Commands
break;
}
if(dev.ScsiType == PeripheralDeviceTypes.MultiMediaDevice)
if (dev.ScsiType == PeripheralDeviceTypes.MultiMediaDevice)
{
if(scsiInfo.MmcConfiguration != null)
if (scsiInfo.MmcConfiguration != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_getconfiguration_current.bin",
"SCSI GET CONFIGURATION", scsiInfo.MmcConfiguration);
if(scsiInfo.RecognizedFormatLayers != null)
if (scsiInfo.RecognizedFormatLayers != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_formatlayers.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.RecognizedFormatLayers);
if(scsiInfo.WriteProtectionStatus != null)
if (scsiInfo.WriteProtectionStatus != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_writeprotection.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.WriteProtectionStatus);
if(scsiInfo.DvdPfi != null)
if (scsiInfo.DvdPfi != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_pfi.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdPfi);
if(scsiInfo.DecodedPfi.HasValue)
if (scsiInfo.DecodedPfi.HasValue)
DicConsole.WriteLine("PFI:\n{0}", PFI.Prettify(scsiInfo.DecodedPfi));
}
if(scsiInfo.DvdDmi != null)
if (scsiInfo.DvdDmi != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_dmi.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdDmi);
if(DMI.IsXbox(scsiInfo.DvdDmi))
if (DMI.IsXbox(scsiInfo.DvdDmi))
DicConsole.WriteLine("Xbox DMI:\n{0}", DMI.PrettifyXbox(scsiInfo.DvdDmi));
else if(DMI.IsXbox360(scsiInfo.DvdDmi))
else if (DMI.IsXbox360(scsiInfo.DvdDmi))
DicConsole.WriteLine("Xbox 360 DMI:\n{0}", DMI.PrettifyXbox360(scsiInfo.DvdDmi));
}
if(scsiInfo.DvdCmi != null)
if (scsiInfo.DvdCmi != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_cmi.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdCmi);
DicConsole.WriteLine("Lead-In CMI:\n{0}", CSS_CPRM.PrettifyLeadInCopyright(scsiInfo.DvdCmi));
}
if(scsiInfo.DvdBca != null)
if (scsiInfo.DvdBca != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_bca.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdBca);
if(scsiInfo.DvdAacs != null)
if (scsiInfo.DvdAacs != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_aacs.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdAacs);
if(scsiInfo.DvdRamDds != null)
if (scsiInfo.DvdRamDds != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdram_dds.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdRamDds);
DicConsole.WriteLine("Disc Definition Structure:\n{0}", DDS.Prettify(scsiInfo.DvdRamDds));
}
if(scsiInfo.DvdRamCartridgeStatus != null)
if (scsiInfo.DvdRamCartridgeStatus != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdram_status.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdRamCartridgeStatus);
DicConsole.WriteLine("Medium Status:\n{0}", Cartridge.Prettify(scsiInfo.DvdRamCartridgeStatus));
}
if(scsiInfo.DvdRamSpareArea != null)
if (scsiInfo.DvdRamSpareArea != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdram_spare.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdRamSpareArea);
DicConsole.WriteLine("Spare Area Information:\n{0}", Spare.Prettify(scsiInfo.DvdRamSpareArea));
}
if(scsiInfo.LastBorderOutRmd != null)
if (scsiInfo.LastBorderOutRmd != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_lastrmd.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.LastBorderOutRmd);
if(scsiInfo.DvdPreRecordedInfo != null)
if (scsiInfo.DvdPreRecordedInfo != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_pri.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdPreRecordedInfo);
if(scsiInfo.DvdrMediaIdentifier != null)
if (scsiInfo.DvdrMediaIdentifier != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdr_mediaid.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdrMediaIdentifier);
if(scsiInfo.DvdrPhysicalInformation != null)
if (scsiInfo.DvdrPhysicalInformation != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdr_pfi.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdrPhysicalInformation);
if(scsiInfo.DvdPlusAdip != null)
if (scsiInfo.DvdPlusAdip != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd+_adip.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdPlusAdip);
if(scsiInfo.DvdPlusDcb != null)
if (scsiInfo.DvdPlusDcb != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd+_dcb.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdPlusDcb);
if(scsiInfo.HddvdCopyrightInformation != null)
if (scsiInfo.HddvdCopyrightInformation != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_hddvd_cmi.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.HddvdCopyrightInformation);
if(scsiInfo.HddvdrMediumStatus != null)
if (scsiInfo.HddvdrMediumStatus != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_hddvdr_status.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.HddvdrMediumStatus);
if(scsiInfo.HddvdrLastRmd != null)
if (scsiInfo.HddvdrLastRmd != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_hddvdr_lastrmd.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.HddvdrLastRmd);
if(scsiInfo.DvdrLayerCapacity != null)
if (scsiInfo.DvdrLayerCapacity != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdr_layercap.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdrLayerCapacity);
if(scsiInfo.DvdrDlMiddleZoneStart != null)
if (scsiInfo.DvdrDlMiddleZoneStart != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_mzs.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdrDlMiddleZoneStart);
if(scsiInfo.DvdrDlJumpIntervalSize != null)
if (scsiInfo.DvdrDlJumpIntervalSize != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_jis.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdrDlJumpIntervalSize);
if(scsiInfo.DvdrDlManualLayerJumpStartLba != null)
if (scsiInfo.DvdrDlManualLayerJumpStartLba != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_manuallj.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdrDlManualLayerJumpStartLba);
if(scsiInfo.DvdrDlRemapAnchorPoint != null)
if (scsiInfo.DvdrDlRemapAnchorPoint != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_remapanchor.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.DvdrDlRemapAnchorPoint);
if(scsiInfo.BlurayDiscInformation != null)
if (scsiInfo.BlurayDiscInformation != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_di.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.BlurayDiscInformation);
DicConsole.WriteLine("Blu-ray Disc Information:\n{0}", DI.Prettify(scsiInfo.BlurayDiscInformation));
}
if(scsiInfo.BlurayPac != null)
if (scsiInfo.BlurayPac != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_pac.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.BlurayPac);
if(scsiInfo.BlurayBurstCuttingArea != null)
if (scsiInfo.BlurayBurstCuttingArea != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_bca.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.BlurayBurstCuttingArea);
@@ -361,7 +370,7 @@ namespace DiscImageChef.Commands
BCA.Prettify(scsiInfo.BlurayBurstCuttingArea));
}
if(scsiInfo.BlurayDds != null)
if (scsiInfo.BlurayDds != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_dds.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.BlurayDds);
@@ -369,7 +378,7 @@ namespace DiscImageChef.Commands
Decoders.Bluray.DDS.Prettify(scsiInfo.BlurayDds));
}
if(scsiInfo.BlurayCartridgeStatus != null)
if (scsiInfo.BlurayCartridgeStatus != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_cartstatus.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.BlurayCartridgeStatus);
@@ -377,7 +386,7 @@ namespace DiscImageChef.Commands
Decoders.Bluray.Cartridge.Prettify(scsiInfo.BlurayCartridgeStatus));
}
if(scsiInfo.BluraySpareAreaInformation != null)
if (scsiInfo.BluraySpareAreaInformation != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_spare.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.BluraySpareAreaInformation);
@@ -385,11 +394,11 @@ namespace DiscImageChef.Commands
Decoders.Bluray.Spare.Prettify(scsiInfo.BluraySpareAreaInformation));
}
if(scsiInfo.BlurayRawDfl != null)
if (scsiInfo.BlurayRawDfl != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_dfl.bin",
"SCSI READ DISC STRUCTURE", scsiInfo.BlurayRawDfl);
if(scsiInfo.BlurayTrackResources != null)
if (scsiInfo.BlurayTrackResources != null)
{
DicConsole.WriteLine("Track Resources Information:\n{0}",
DiscInformation.Prettify(scsiInfo.BlurayTrackResources));
@@ -397,7 +406,7 @@ namespace DiscImageChef.Commands
"SCSI READ DISC INFORMATION", scsiInfo.BlurayTrackResources);
}
if(scsiInfo.BlurayPowResources != null)
if (scsiInfo.BlurayPowResources != null)
{
DicConsole.WriteLine("POW Resources Information:\n{0}",
DiscInformation.Prettify(scsiInfo.BlurayPowResources));
@@ -405,77 +414,77 @@ namespace DiscImageChef.Commands
"SCSI READ DISC INFORMATION", scsiInfo.BlurayPowResources);
}
if(scsiInfo.Toc != null)
if (scsiInfo.Toc != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_toc.bin", "SCSI READ TOC/PMA/ATIP",
scsiInfo.Toc);
if(scsiInfo.DecodedToc.HasValue)
if (scsiInfo.DecodedToc.HasValue)
DicConsole.WriteLine("TOC:\n{0}", TOC.Prettify(scsiInfo.DecodedToc));
}
if(scsiInfo.Atip != null)
if (scsiInfo.Atip != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_atip.bin", "SCSI READ TOC/PMA/ATIP",
scsiInfo.Atip);
if(scsiInfo.DecodedAtip.HasValue)
if (scsiInfo.DecodedAtip.HasValue)
DicConsole.WriteLine("ATIP:\n{0}", ATIP.Prettify(scsiInfo.DecodedAtip));
}
if(scsiInfo.CompactDiscInformation != null)
if (scsiInfo.CompactDiscInformation != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscinformation_000b.bin",
"SCSI READ DISC INFORMATION", scsiInfo.CompactDiscInformation);
if(scsiInfo.DecodedCompactDiscInformation.HasValue)
if (scsiInfo.DecodedCompactDiscInformation.HasValue)
DicConsole.WriteLine("Standard Disc Information:\n{0}",
DiscInformation.Prettify000b(scsiInfo.DecodedCompactDiscInformation));
}
if(scsiInfo.Session != null)
if (scsiInfo.Session != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_session.bin", "SCSI READ TOC/PMA/ATIP",
scsiInfo.Session);
if(scsiInfo.DecodedSession.HasValue)
if (scsiInfo.DecodedSession.HasValue)
DicConsole.WriteLine("Session information:\n{0}", Session.Prettify(scsiInfo.DecodedSession));
}
if(scsiInfo.RawToc != null)
if (scsiInfo.RawToc != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_rawtoc.bin", "SCSI READ TOC/PMA/ATIP",
scsiInfo.RawToc);
if(scsiInfo.FullToc.HasValue)
if (scsiInfo.FullToc.HasValue)
DicConsole.WriteLine("Raw TOC:\n{0}", FullTOC.Prettify(scsiInfo.RawToc));
}
if(scsiInfo.Pma != null)
if (scsiInfo.Pma != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_pma.bin", "SCSI READ TOC/PMA/ATIP",
scsiInfo.Pma);
DicConsole.WriteLine("PMA:\n{0}", PMA.Prettify(scsiInfo.Pma));
}
if(scsiInfo.CdTextLeadIn != null)
if (scsiInfo.CdTextLeadIn != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_cdtext.bin", "SCSI READ TOC/PMA/ATIP",
scsiInfo.CdTextLeadIn);
if(scsiInfo.DecodedCdTextLeadIn.HasValue)
if (scsiInfo.DecodedCdTextLeadIn.HasValue)
DicConsole.WriteLine("CD-TEXT on Lead-In:\n{0}",
CDTextOnLeadIn.Prettify(scsiInfo.DecodedCdTextLeadIn));
}
if(!string.IsNullOrEmpty(scsiInfo.Mcn)) DicConsole.WriteLine("MCN: {0}", scsiInfo.Mcn);
if (!string.IsNullOrEmpty(scsiInfo.Mcn)) DicConsole.WriteLine("MCN: {0}", scsiInfo.Mcn);
if(scsiInfo.Isrcs != null)
foreach(KeyValuePair<byte, string> isrc in scsiInfo.Isrcs)
if (scsiInfo.Isrcs != null)
foreach (var isrc in scsiInfo.Isrcs)
DicConsole.WriteLine("Track's {0} ISRC: {1}", isrc.Key, isrc.Value);
if(scsiInfo.XboxSecuritySector != null)
if (scsiInfo.XboxSecuritySector != null)
DataFile.WriteTo("Media-Info command", outputPrefix, "_xbox_ss.bin", "KREON EXTRACT SS",
scsiInfo.XboxSecuritySector);
if(scsiInfo.DecodedXboxSecuritySector.HasValue)
if (scsiInfo.DecodedXboxSecuritySector.HasValue)
DicConsole.WriteLine("Xbox Security Sector:\n{0}", SS.Prettify(scsiInfo.DecodedXboxSecuritySector));
if(scsiInfo.XgdInfo != null)
if (scsiInfo.XgdInfo != null)
{
DicConsole.WriteLine("Video layer 0 size: {0} sectors", scsiInfo.XgdInfo.L0Video);
DicConsole.WriteLine("Video layer 1 size: {0} sectors", scsiInfo.XgdInfo.L1Video);
@@ -487,13 +496,13 @@ namespace DiscImageChef.Commands
}
}
if(scsiInfo.MediaSerialNumber != null)
if (scsiInfo.MediaSerialNumber != null)
{
DataFile.WriteTo("Media-Info command", outputPrefix, "_mediaserialnumber.bin",
"SCSI READ MEDIA SERIAL NUMBER", scsiInfo.MediaSerialNumber);
DicConsole.Write("Media Serial Number: ");
for(int i = 4; i < scsiInfo.MediaSerialNumber.Length; i++)
for (var i = 4; i < scsiInfo.MediaSerialNumber.Length; i++)
DicConsole.Write("{0:X2}", scsiInfo.MediaSerialNumber[i]);
DicConsole.WriteLine();

View File

@@ -40,12 +40,12 @@ using Mono.Options;
namespace DiscImageChef.Commands
{
class MediaScanCommand : Command
internal class MediaScanCommand : Command
{
string devicePath;
string ibgLogPath;
string mhddLogPath;
bool showHelp;
private string devicePath;
private string ibgLogPath;
private string mhddLogPath;
private bool showHelp;
public MediaScanCommand() : base("media-scan", "Scans the media inserted on a device.")
{
@@ -65,29 +65,29 @@ namespace DiscImageChef.Commands
public override int Invoke(IEnumerable<string> arguments)
{
List<string> extra = Options.Parse(arguments);
var extra = Options.Parse(arguments);
if(showHelp)
if (showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return (int)ErrorNumber.HelpRequested;
return (int) ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
if(MainClass.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if(MainClass.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
if (MainClass.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (MainClass.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Statistics.AddCommand("media-scan");
if(extra.Count > 1)
if (extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return (int)ErrorNumber.UnexpectedArgumentCount;
return (int) ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
if (extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing device path.");
return (int)ErrorNumber.MissingArgument;
return (int) ErrorNumber.MissingArgument;
}
devicePath = extra[0];
@@ -98,20 +98,29 @@ namespace DiscImageChef.Commands
DicConsole.DebugWriteLine("Media-Scan command", "--mhdd-log={0}", mhddLogPath);
DicConsole.DebugWriteLine("Media-Scan command", "--verbose={0}", MainClass.Verbose);
if(devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
if (devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
Device dev = new Device(devicePath);
if(dev.Error)
Device dev;
try
{
DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
return (int)ErrorNumber.CannotOpenDevice;
dev = new Device(devicePath);
if (dev.Error)
{
DicConsole.ErrorWriteLine(Error.Print(dev.LastError));
return (int) ErrorNumber.CannotOpenDevice;
}
}
catch (DeviceException e)
{
DicConsole.ErrorWriteLine(e.Message ?? Error.Print(e.LastError));
return (int) ErrorNumber.CannotOpenDevice;
}
Statistics.AddDevice(dev);
MediaScan scanner = new MediaScan(mhddLogPath, ibgLogPath, devicePath, dev);
var scanner = new MediaScan(mhddLogPath, ibgLogPath, devicePath, dev);
scanner.UpdateStatus += Progress.UpdateStatus;
scanner.StoppingErrorMessage += Progress.ErrorMessage;
scanner.UpdateProgress += Progress.UpdateProgress;
@@ -123,7 +132,7 @@ namespace DiscImageChef.Commands
e.Cancel = true;
scanner.Abort();
};
ScanResults results = scanner.Scan();
var results = scanner.Scan();
DicConsole.WriteLine("Took a total of {0} seconds ({1} processing commands).", results.TotalTime,
results.ProcessingTime);
@@ -139,20 +148,21 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine("{0} sectors took more than 500 ms.", results.F);
DicConsole.WriteLine("{0} sectors could not be read.",
results.UnreadableSectors.Count);
if(results.UnreadableSectors.Count > 0)
foreach(ulong bad in results.UnreadableSectors)
if (results.UnreadableSectors.Count > 0)
foreach (var bad in results.UnreadableSectors)
DicConsole.WriteLine("Sector {0} could not be read", bad);
DicConsole.WriteLine();
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
if(results.SeekTotal != 0 || results.SeekMin != double.MaxValue || results.SeekMax != double.MinValue)
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
DicConsole.WriteLine("Testing {0} seeks, longest seek took {1:F3} ms, fastest one took {2:F3} ms. ({3:F3} ms average)",
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
if (results.SeekTotal != 0 || results.SeekMin != double.MaxValue || results.SeekMax != double.MinValue)
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
DicConsole.WriteLine(
"Testing {0} seeks, longest seek took {1:F3} ms, fastest one took {2:F3} ms. ({3:F3} ms average)",
results.SeekTimes, results.SeekMax, results.SeekMin, results.SeekTotal / 1000);
dev.Close();
return (int)ErrorNumber.NoError;
return (int) ErrorNumber.NoError;
}
}
}