Move SecureDigital / MultiMediaCard device reporting to non-static class and its UI to CLI.

This commit is contained in:
2018-11-25 18:51:16 +00:00
parent ac29604264
commit b8d0dce8af
2 changed files with 49 additions and 62 deletions

View File

@@ -39,26 +39,14 @@ namespace DiscImageChef.Core.Devices.Report
/// <summary>
/// Implements creating a device report for a SecureDigital or MultiMediaCard flash card
/// </summary>
public static class SecureDigital
public partial class DeviceReport
{
/// <summary>
/// Creates a device report for a SecureDigital or MultiMediaCard flash card
/// </summary>
/// <param name="dev">Device</param>
/// <param name="report">Device report</param>
public static void Report(Device dev, ref DeviceReportV2 report)
public MmcSd MmcSdReport()
{
if(report == null) return;
switch(dev.Type)
{
case DeviceType.MMC:
report.MultiMediaCard = new MmcSd();
break;
case DeviceType.SecureDigital:
report.SecureDigital = new MmcSd();
break;
}
MmcSd report = new MmcSd();
DicConsole.WriteLine("Trying to get CID...");
bool sense = dev.ReadCid(out byte[] cid, out _, dev.Timeout, out _);
@@ -71,24 +59,24 @@ namespace DiscImageChef.Core.Devices.Report
{
case DeviceType.SecureDigital:
// Clear serial number and manufacturing date
cid[9] = 0;
cid[10] = 0;
cid[11] = 0;
cid[12] = 0;
cid[13] = 0;
cid[14] = 0;
report.SecureDigital.CID = cid;
cid[9] = 0;
cid[10] = 0;
cid[11] = 0;
cid[12] = 0;
cid[13] = 0;
cid[14] = 0;
break;
case DeviceType.MMC:
// Clear serial number and manufacturing date
cid[10] = 0;
cid[11] = 0;
cid[12] = 0;
cid[13] = 0;
cid[14] = 0;
report.MultiMediaCard.CID = cid;
cid[10] = 0;
cid[11] = 0;
cid[12] = 0;
cid[13] = 0;
cid[14] = 0;
break;
}
report.CID = cid;
}
else DicConsole.WriteLine("Could not read CID...");
@@ -98,40 +86,45 @@ namespace DiscImageChef.Core.Devices.Report
if(!sense)
{
DicConsole.WriteLine("CSD obtained correctly...");
switch(dev.Type)
{
case DeviceType.MMC:
report.MultiMediaCard.CSD = csd;
break;
case DeviceType.SecureDigital:
report.SecureDigital.CSD = csd;
break;
}
report.CSD = csd;
}
else DicConsole.WriteLine("Could not read CSD...");
sense = true;
byte[] ocr = null;
DicConsole.WriteLine("Trying to get OCR...");
switch(dev.Type)
{
case DeviceType.MMC:
{
sense = dev.ReadOcr(out ocr, out _, dev.Timeout, out _);
break;
}
case DeviceType.SecureDigital:
{
sense = dev.ReadSdocr(out ocr, out _, dev.Timeout, out _);
break;
}
}
if(!sense)
{
DicConsole.WriteLine("OCR obtained correctly...");
report.OCR = ocr;
}
else DicConsole.WriteLine("Could not read OCR...");
switch(dev.Type)
{
case DeviceType.MMC:
{
DicConsole.WriteLine("Trying to get OCR...");
sense = dev.ReadOcr(out byte[] ocr, out _, dev.Timeout, out _);
if(!sense)
{
DicConsole.WriteLine("OCR obtained correctly...");
report.MultiMediaCard.OCR = ocr;
}
else DicConsole.WriteLine("Could not read OCR...");
DicConsole.WriteLine("Trying to get Extended CSD...");
sense = dev.ReadExtendedCsd(out byte[] ecsd, out _, dev.Timeout, out _);
if(!sense)
{
DicConsole.WriteLine("Extended CSD obtained correctly...");
report.MultiMediaCard.ExtendedCSD = ecsd;
report.ExtendedCSD = ecsd;
}
else DicConsole.WriteLine("Could not read Extended CSD...");
@@ -139,29 +132,21 @@ namespace DiscImageChef.Core.Devices.Report
}
case DeviceType.SecureDigital:
{
DicConsole.WriteLine("Trying to get OCR...");
sense = dev.ReadSdocr(out byte[] ocr, out _, dev.Timeout, out _);
if(!sense)
{
DicConsole.WriteLine("OCR obtained correctly...");
report.SecureDigital.OCR = ocr;
}
else DicConsole.WriteLine("Could not read OCR...");
DicConsole.WriteLine("Trying to get SCR...");
sense = dev.ReadScr(out byte[] scr, out _, dev.Timeout, out _);
if(!sense)
{
DicConsole.WriteLine("SCR obtained correctly...");
report.SecureDigital.SCR = scr;
report.SCR = scr;
}
else DicConsole.WriteLine("Could not read SCR...");
break;
}
}
return report;
}
}
}

View File

@@ -34,7 +34,6 @@ using System;
using System.IO;
using DiscImageChef.CommonTypes.Metadata;
using DiscImageChef.Console;
using DiscImageChef.Core.Devices.Report;
using DiscImageChef.Core.Devices.Report.SCSI;
using DiscImageChef.Devices;
using Newtonsoft.Json;
@@ -141,11 +140,14 @@ namespace DiscImageChef.Commands
Ata.Report(dev, ref report, options.Debug, ref removable);
break;
case DeviceType.MMC:
report.MultiMediaCard = reporter.MmcSdReport();
break;
case DeviceType.SecureDigital:
SecureDigital.Report(dev, ref report);
report.SecureDigital = reporter.MmcSdReport();
break;
case DeviceType.NVMe:
throw new NotImplementedException("NVMe devices not yet supported.");
break;
case DeviceType.ATAPI:
case DeviceType.SCSI: