Move USB device reporting to non-static class and its UI to CLI.

This commit is contained in:
2018-11-25 18:28:57 +00:00
parent 601da83a93
commit dc4be81e35
7 changed files with 52 additions and 32 deletions

View File

@@ -225,6 +225,7 @@
<e p="Report" t="Include"> <e p="Report" t="Include">
<e p="ATA.cs" t="Include" /> <e p="ATA.cs" t="Include" />
<e p="ATAPI.cs" t="Include" /> <e p="ATAPI.cs" t="Include" />
<e p="DeviceReport.cs" t="Include" />
<e p="FireWire.cs" t="Include" /> <e p="FireWire.cs" t="Include" />
<e p="NVMe.cs" t="Include" /> <e p="NVMe.cs" t="Include" />
<e p="PCMCIA.cs" t="Include" /> <e p="PCMCIA.cs" t="Include" />

View File

@@ -58,8 +58,6 @@ namespace DiscImageChef.Core.Devices.Report
const uint TIMEOUT = 5; const uint TIMEOUT = 5;
if(dev.IsUsb) Usb.Report(dev, ref report, debug, ref removable);
if(dev.IsFireWire) FireWire.Report(dev, ref report, ref removable); if(dev.IsFireWire) FireWire.Report(dev, ref report, ref removable);
if(dev.IsPcmcia) Pcmcia.Report(dev, ref report); if(dev.IsPcmcia) Pcmcia.Report(dev, ref report);

View File

@@ -0,0 +1,16 @@
using DiscImageChef.Devices;
namespace DiscImageChef.Core.Devices.Report
{
public partial class DeviceReport
{
Device dev;
bool debug;
public DeviceReport(Device device, bool debug)
{
this.dev = device;
this.debug = debug;
}
}
}

View File

@@ -63,8 +63,6 @@ namespace DiscImageChef.Core.Devices.Report.SCSI
const uint TIMEOUT = 5; const uint TIMEOUT = 5;
ConsoleKeyInfo pressedKey; ConsoleKeyInfo pressedKey;
if(dev.IsUsb) Usb.Report(dev, ref report, debug, ref removable);
if(dev.IsFireWire) FireWire.Report(dev, ref report, ref removable); if(dev.IsFireWire) FireWire.Report(dev, ref report, ref removable);
if(dev.IsPcmcia) Pcmcia.Report(dev, ref report); if(dev.IsPcmcia) Pcmcia.Report(dev, ref report);

View File

@@ -30,17 +30,14 @@
// Copyright © 2011-2018 Natalia Portillo // Copyright © 2011-2018 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
using System;
using DiscImageChef.CommonTypes.Metadata; using DiscImageChef.CommonTypes.Metadata;
using DiscImageChef.Console;
using DiscImageChef.Devices;
namespace DiscImageChef.Core.Devices.Report namespace DiscImageChef.Core.Devices.Report
{ {
/// <summary> /// <summary>
/// Implements creating a report for a USB device /// Implements creating a report for a USB device
/// </summary> /// </summary>
static class Usb public partial class DeviceReport
{ {
/// <summary> /// <summary>
/// Fills a device report with parameters specific to a USB device /// Fills a device report with parameters specific to a USB device
@@ -49,21 +46,9 @@ namespace DiscImageChef.Core.Devices.Report
/// <param name="report">Device report</param> /// <param name="report">Device report</param>
/// <param name="removable">If device is removable</param> /// <param name="removable">If device is removable</param>
/// <param name="debug">If debug is enabled</param> /// <param name="debug">If debug is enabled</param>
internal static void Report(Device dev, ref DeviceReportV2 report, bool debug, ref bool removable) public Usb UsbReport()
{ {
if(report == null) return; Usb usbReport = new Usb
ConsoleKeyInfo pressedKey = new ConsoleKeyInfo();
while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N)
{
DicConsole.Write("Is the device natively USB (in case of doubt, press Y)? (Y/N): ");
pressedKey = System.Console.ReadKey();
DicConsole.WriteLine();
}
if(pressedKey.Key != ConsoleKey.Y) return;
report.USB = new CommonTypes.Metadata.Usb
{ {
Manufacturer = dev.UsbManufacturerString, Manufacturer = dev.UsbManufacturerString,
Product = dev.UsbProductString, Product = dev.UsbProductString,
@@ -71,17 +56,9 @@ namespace DiscImageChef.Core.Devices.Report
VendorID = dev.UsbVendorId VendorID = dev.UsbVendorId
}; };
pressedKey = new ConsoleKeyInfo(); if(debug) usbReport.Descriptors = dev.UsbDescriptors;
while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N)
{
DicConsole.Write("Is the media removable from the reading/writing elements? (Y/N): ");
pressedKey = System.Console.ReadKey();
DicConsole.WriteLine();
}
report.USB.RemovableMedia = pressedKey.Key == ConsoleKey.Y; return usbReport;
removable = report.USB.RemovableMedia;
if(debug) report.USB.Descriptors = dev.UsbDescriptors;
} }
} }
} }

View File

@@ -49,6 +49,7 @@
<Compile Include="Devices\Info\DeviceInfo.cs" /> <Compile Include="Devices\Info\DeviceInfo.cs" />
<Compile Include="Devices\Info\Plextor.cs" /> <Compile Include="Devices\Info\Plextor.cs" />
<Compile Include="Devices\Info\Properties.cs" /> <Compile Include="Devices\Info\Properties.cs" />
<Compile Include="Devices\Report\DeviceReport.cs" />
<Compile Include="Entropy.cs" /> <Compile Include="Entropy.cs" />
<Compile Include="GetPluginBase.cs" /> <Compile Include="GetPluginBase.cs" />
<Compile Include="ImageInfo.cs" /> <Compile Include="ImageInfo.cs" />

View File

@@ -77,6 +77,35 @@ namespace DiscImageChef.Commands
jsonFile = jsonFile.Replace('\\', '_').Replace('/', '_').Replace('?', '_'); jsonFile = jsonFile.Replace('\\', '_').Replace('/', '_').Replace('?', '_');
Core.Devices.Report.DeviceReport reporter = new Core.Devices.Report.DeviceReport(dev, options.Debug);
if(dev.IsUsb)
{
ConsoleKeyInfo pressedKey = new ConsoleKeyInfo();
while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N)
{
DicConsole.Write("Is the device natively USB (in case of doubt, press Y)? (Y/N): ");
pressedKey = System.Console.ReadKey();
DicConsole.WriteLine();
}
if(pressedKey.Key == ConsoleKey.Y)
{
report.USB = reporter.UsbReport();
pressedKey = new ConsoleKeyInfo();
while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N)
{
DicConsole.Write("Is the media removable from the reading/writing elements? (Y/N): ");
pressedKey = System.Console.ReadKey();
DicConsole.WriteLine();
}
report.USB.RemovableMedia = pressedKey.Key == ConsoleKey.Y;
removable = report.USB.RemovableMedia;
}
}
switch(dev.Type) switch(dev.Type)
{ {
case DeviceType.ATA: case DeviceType.ATA: