diff --git a/.idea/.idea.DiscImageChef/.idea/contentModel.xml b/.idea/.idea.DiscImageChef/.idea/contentModel.xml index 3ac368934..29e916aa9 100644 --- a/.idea/.idea.DiscImageChef/.idea/contentModel.xml +++ b/.idea/.idea.DiscImageChef/.idea/contentModel.xml @@ -240,6 +240,7 @@ + diff --git a/DiscImageChef.Core/Devices/Scanning/ATA.cs b/DiscImageChef.Core/Devices/Scanning/ATA.cs index 6eb243ba1..625e64dde 100644 --- a/DiscImageChef.Core/Devices/Scanning/ATA.cs +++ b/DiscImageChef.Core/Devices/Scanning/ATA.cs @@ -35,24 +35,19 @@ using System.Collections.Generic; using DiscImageChef.Console; using DiscImageChef.Core.Logging; using DiscImageChef.Decoders.ATA; -using DiscImageChef.Devices; namespace DiscImageChef.Core.Devices.Scanning { /// /// Implements scanning the media from an ATA device /// - public static class Ata + public partial class MediaScan { /// /// Scans the media from an ATA device /// - /// Path to a MHDD log file - /// Path to a IMGBurn log file - /// Device path - /// Device /// Scanning results - public static ScanResults Scan(string mhddLogPath, string ibgLogPath, string devicePath, Device dev) + public ScanResults Ata() { ScanResults results = new ScanResults(); bool aborted; diff --git a/DiscImageChef.Core/Devices/Scanning/MediaScan.cs b/DiscImageChef.Core/Devices/Scanning/MediaScan.cs new file mode 100644 index 000000000..fca7b5b00 --- /dev/null +++ b/DiscImageChef.Core/Devices/Scanning/MediaScan.cs @@ -0,0 +1,40 @@ +using System; +using DiscImageChef.CommonTypes.Enums; +using DiscImageChef.Devices; + +namespace DiscImageChef.Core.Devices.Scanning +{ + public partial class MediaScan + { + readonly Device dev; + readonly string devicePath; + readonly string ibgLogPath; + readonly string mhddLogPath; + + /// Path to a MHDD log file + /// Path to a IMGBurn log file + /// Device path + /// Device + public MediaScan(string mhddLogPath, string ibgLogPath, string devicePath, Device dev) + { + this.mhddLogPath = mhddLogPath; + this.ibgLogPath = ibgLogPath; + this.devicePath = devicePath; + this.dev = dev; + } + + public ScanResults Scan() + { + switch(dev.Type) + { + case DeviceType.ATA: return Ata(); + case DeviceType.MMC: + case DeviceType.SecureDigital: return SecureDigital(); + case DeviceType.NVMe: return Nvme(); + case DeviceType.ATAPI: + case DeviceType.SCSI: return Scsi(); + default: throw new NotSupportedException("Unknown device type."); + } + } + } +} \ No newline at end of file diff --git a/DiscImageChef.Core/Devices/Scanning/NVMe.cs b/DiscImageChef.Core/Devices/Scanning/NVMe.cs index 3f97d537f..992512d7b 100644 --- a/DiscImageChef.Core/Devices/Scanning/NVMe.cs +++ b/DiscImageChef.Core/Devices/Scanning/NVMe.cs @@ -31,13 +31,11 @@ // ****************************************************************************/ using System; -using DiscImageChef.Devices; namespace DiscImageChef.Core.Devices.Scanning { - public static class Nvme + public partial class MediaScan { - public static ScanResults Scan(string mhddLogPath, string ibgLogPath, string devicePath, Device dev) => - throw new NotImplementedException("NVMe devices not yet supported."); + public ScanResults Nvme() => throw new NotImplementedException("NVMe devices not yet supported."); } } \ No newline at end of file diff --git a/DiscImageChef.Core/Devices/Scanning/SCSI.cs b/DiscImageChef.Core/Devices/Scanning/SCSI.cs index f5ea8407f..c41a5d6b1 100644 --- a/DiscImageChef.Core/Devices/Scanning/SCSI.cs +++ b/DiscImageChef.Core/Devices/Scanning/SCSI.cs @@ -45,9 +45,9 @@ namespace DiscImageChef.Core.Devices.Scanning /// /// Implements scanning the media from an SCSI device /// - public static class Scsi + public partial class MediaScan { - public static ScanResults Scan(string mhddLogPath, string ibgLogPath, string devicePath, Device dev) + public ScanResults Scsi() { ScanResults results = new ScanResults(); bool aborted; diff --git a/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs b/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs index 0f2223a99..addb64423 100644 --- a/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs +++ b/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs @@ -36,16 +36,15 @@ using DiscImageChef.CommonTypes.Enums; using DiscImageChef.Console; using DiscImageChef.Core.Logging; using DiscImageChef.Decoders.MMC; -using DiscImageChef.Devices; namespace DiscImageChef.Core.Devices.Scanning { /// /// Implements scanning a SecureDigital or MultiMediaCard flash card /// - public static class SecureDigital + public partial class MediaScan { - public static ScanResults Scan(string mhddLogPath, string ibgLogPath, string devicePath, Device dev) + public ScanResults SecureDigital() { ScanResults results = new ScanResults(); bool aborted; @@ -87,6 +86,7 @@ namespace DiscImageChef.Core.Devices.Scanning break; } + case DeviceType.SecureDigital: { sense = dev.ReadCsd(out cmdBuf, out _, TIMEOUT, out _); diff --git a/DiscImageChef.Core/DiscImageChef.Core.csproj b/DiscImageChef.Core/DiscImageChef.Core.csproj index 3b0fdb0d9..3ffa6e69d 100644 --- a/DiscImageChef.Core/DiscImageChef.Core.csproj +++ b/DiscImageChef.Core/DiscImageChef.Core.csproj @@ -55,6 +55,7 @@ + diff --git a/DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs b/DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs index 34dc5e88a..f8cf63ef0 100644 --- a/DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs +++ b/DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs @@ -32,7 +32,6 @@ using System; using DiscImageChef.CommonTypes; -using DiscImageChef.CommonTypes.Enums; using DiscImageChef.Core; using DiscImageChef.Core.Devices.Scanning; using DiscImageChef.Core.Media.Info; @@ -90,26 +89,8 @@ namespace DiscImageChef.Gui.Forms Statistics.AddDevice(dev); - ScanResults results; - - switch(dev.Type) - { - case DeviceType.ATA: - results = Ata.Scan(null, null, devicePath, dev); - break; - case DeviceType.MMC: - case DeviceType.SecureDigital: - results = SecureDigital.Scan(null, null, devicePath, dev); - break; - case DeviceType.NVMe: - results = Nvme.Scan(null, null, devicePath, dev); - break; - case DeviceType.ATAPI: - case DeviceType.SCSI: - results = Scsi.Scan(null, null, devicePath, dev); - break; - default: throw new NotSupportedException("Unknown device type."); - } + MediaScan scanner = new MediaScan(null, null, devicePath, dev); + ScanResults results = scanner.Scan(); lblTotalTime.Text = lblTotalTime.Text = $"Took a total of {results.TotalTime} seconds ({results.ProcessingTime} processing commands)."; diff --git a/DiscImageChef/Commands/MediaScan.cs b/DiscImageChef/Commands/MediaScan.cs index f95a507bd..f7e517ef6 100644 --- a/DiscImageChef/Commands/MediaScan.cs +++ b/DiscImageChef/Commands/MediaScan.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System; using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.Console; @@ -112,26 +111,8 @@ namespace DiscImageChef.Commands Statistics.AddDevice(dev); - ScanResults results; - - switch(dev.Type) - { - case DeviceType.ATA: - results = Ata.Scan(mhddLogPath, ibgLogPath, devicePath, dev); - break; - case DeviceType.MMC: - case DeviceType.SecureDigital: - results = SecureDigital.Scan(mhddLogPath, ibgLogPath, devicePath, dev); - break; - case DeviceType.NVMe: - results = Nvme.Scan(mhddLogPath, ibgLogPath, devicePath, dev); - break; - case DeviceType.ATAPI: - case DeviceType.SCSI: - results = Scsi.Scan(mhddLogPath, ibgLogPath, devicePath, dev); - break; - default: throw new NotSupportedException("Unknown device type."); - } + MediaScan scanner = new MediaScan(mhddLogPath, ibgLogPath, devicePath, dev); + ScanResults results = scanner.Scan(); DicConsole.WriteLine("Took a total of {0} seconds ({1} processing commands).", results.TotalTime, results.ProcessingTime);