From 552bb575143a1fd1a03c9b13208638bac9112b17 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 20 Apr 2019 14:02:25 +0100 Subject: [PATCH] Remove all exceptions inside dumpers. --- DiscImageChef.Core/Devices/Dumping/ATA.cs | 12 +++-- .../Devices/Dumping/CompactDisc.cs | 17 ++++--- DiscImageChef.Core/Devices/Dumping/Dump.cs | 3 +- DiscImageChef.Core/Devices/Dumping/MMC.cs | 16 +++---- DiscImageChef.Core/Devices/Dumping/NVMe.cs | 4 +- .../Devices/Dumping/PlayStationPortable.cs | 23 +++++++--- DiscImageChef.Core/Devices/Dumping/SBC.cs | 45 ++++++++++++------- DiscImageChef.Core/Devices/Dumping/SCSI.cs | 6 ++- .../Devices/Dumping/SecureDigital.cs | 33 +++++++++----- DiscImageChef.Core/Devices/Dumping/XGD.cs | 17 +++---- 10 files changed, 115 insertions(+), 61 deletions(-) diff --git a/DiscImageChef.Core/Devices/Dumping/ATA.cs b/DiscImageChef.Core/Devices/Dumping/ATA.cs index c82910124..a129a28cc 100644 --- a/DiscImageChef.Core/Devices/Dumping/ATA.cs +++ b/DiscImageChef.Core/Devices/Dumping/ATA.cs @@ -55,7 +55,6 @@ namespace DiscImageChef.Core.Devices.Dumping /// /// Dumps an ATA device /// - /// If the resume file is invalid public void Ata() { bool aborted; @@ -152,7 +151,10 @@ namespace DiscImageChef.Core.Devices.Dumping ResumeSupport.Process(ataReader.IsLba, removable, blocks, dev.Manufacturer, dev.Model, dev.Serial, dev.PlatformId, ref resume, ref currentTry, ref extents); if(currentTry == null || extents == null) - throw new InvalidOperationException("Could not process resume file, not continuing..."); + { + StoppingErrorMessage?.Invoke("Could not process resume file, not continuing..."); + return; + } MhddLog mhddLog; IbgLog ibgLog; @@ -520,7 +522,11 @@ namespace DiscImageChef.Core.Devices.Dumping FiltersList filters = new FiltersList(); IFilter filter = filters.GetFilter(outputPath); IMediaImage inputPlugin = ImageFormat.Detect(filter); - if(!inputPlugin.Open(filter)) throw new ArgumentException("Could not open created image."); + if(!inputPlugin.Open(filter)) + { + StoppingErrorMessage?.Invoke("Could not open created image."); + return; + } DateTime chkStart = DateTime.UtcNow; CICMMetadataType sidecar = Sidecar.Create(inputPlugin, outputPath, filter.Id, encoding); diff --git a/DiscImageChef.Core/Devices/Dumping/CompactDisc.cs b/DiscImageChef.Core/Devices/Dumping/CompactDisc.cs index 803821a27..afdd95df4 100644 --- a/DiscImageChef.Core/Devices/Dumping/CompactDisc.cs +++ b/DiscImageChef.Core/Devices/Dumping/CompactDisc.cs @@ -67,9 +67,6 @@ namespace DiscImageChef.Core.Devices.Dumping /// Dumps a compact disc /// /// Disc type as detected in MMC layer - /// If trying to dump scrambled sectors - /// If the resume file is invalid - /// If the track type is unknown (never) internal void CompactDisc(ref MediaType dskType, bool dumpFirstTrackPregap) { uint subSize; @@ -835,7 +832,10 @@ namespace DiscImageChef.Core.Devices.Dumping ResumeSupport.Process(true, true, blocks, dev.Manufacturer, dev.Model, dev.Serial, dev.PlatformId, ref resume, ref currentTry, ref extents); if(currentTry == null || extents == null) - throw new InvalidOperationException("Could not process resume file, not continuing..."); + { + StoppingErrorMessage?.Invoke("Could not process resume file, not continuing..."); + return; + } DateTime timeSpeedStart = DateTime.UtcNow; ulong sectorSpeedStart = 0; @@ -1809,7 +1809,8 @@ namespace DiscImageChef.Core.Devices.Dumping // Cannot write tag to image dumpLog.WriteLine($"Cannot write tag {tag.Key}."); - throw new ArgumentException(outputPlugin.ErrorMessage); + StoppingErrorMessage?.Invoke(outputPlugin.ErrorMessage); + return; } resume.BadBlocks.Sort(); @@ -1838,7 +1839,11 @@ namespace DiscImageChef.Core.Devices.Dumping FiltersList filters = new FiltersList(); IFilter filter = filters.GetFilter(outputPath); IMediaImage inputPlugin = ImageFormat.Detect(filter); - if(!inputPlugin.Open(filter)) throw new ArgumentException("Could not open created image."); + if(!inputPlugin.Open(filter)) + { + StoppingErrorMessage?.Invoke("Could not open created image."); + return; + } DateTime chkStart = DateTime.UtcNow; CICMMetadataType sidecar = Sidecar.Create(inputPlugin, outputPath, filter.Id, encoding); diff --git a/DiscImageChef.Core/Devices/Dumping/Dump.cs b/DiscImageChef.Core/Devices/Dumping/Dump.cs index 520ee123e..d73c4600c 100644 --- a/DiscImageChef.Core/Devices/Dumping/Dump.cs +++ b/DiscImageChef.Core/Devices/Dumping/Dump.cs @@ -109,7 +109,8 @@ namespace DiscImageChef.Core.Devices.Dumping default: dumpLog.WriteLine("Unknown device type."); dumpLog.Close(); - throw new NotSupportedException("Unknown device type."); + StoppingErrorMessage?.Invoke("Unknown device type."); + return; } dumpLog.Close(); diff --git a/DiscImageChef.Core/Devices/Dumping/MMC.cs b/DiscImageChef.Core/Devices/Dumping/MMC.cs index 080305228..55bd56037 100644 --- a/DiscImageChef.Core/Devices/Dumping/MMC.cs +++ b/DiscImageChef.Core/Devices/Dumping/MMC.cs @@ -34,7 +34,6 @@ using System; using System.Collections.Generic; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; -using DiscImageChef.Console; using DiscImageChef.Decoders.Bluray; using DiscImageChef.Decoders.DVD; using DiscImageChef.Decoders.SCSI; @@ -71,7 +70,6 @@ namespace DiscImageChef.Core.Devices.Dumping /// Try to read and dump as much Lead-in as possible /// Path to output file /// Formats to pass to output file plugin - /// If trying to dump GOD or WOD, or XGDs without a Kreon drive internal void Mmc(ref MediaType dskType, bool dumpLeadIn) { bool sense; @@ -208,8 +206,9 @@ namespace DiscImageChef.Core.Devices.Dumping nintendoPfi.Value.PartVersion == 15) { dumpLog.WriteLine("Dumping Nintendo GameCube or Wii discs is not yet implemented."); - throw new - NotImplementedException("Dumping Nintendo GameCube or Wii discs is not yet implemented."); + StoppingErrorMessage + ?.Invoke("Dumping Nintendo GameCube or Wii discs is not yet implemented."); + return; } } @@ -319,14 +318,15 @@ namespace DiscImageChef.Core.Devices.Dumping !Inquiry.Decode(inqBuf).Value.KreonPresent) { dumpLog.WriteLine("Dumping Xbox Game Discs requires a drive with Kreon firmware."); - throw new - NotImplementedException("Dumping Xbox Game Discs requires a drive with Kreon firmware."); + StoppingErrorMessage + ?.Invoke("Dumping Xbox Game Discs requires a drive with Kreon firmware."); + return; } if(dumpRaw && !force) { - DicConsole - .ErrorWriteLine("Not continuing. If you want to continue reading cooked data when raw is not available use the force option."); + StoppingErrorMessage + ?.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; } diff --git a/DiscImageChef.Core/Devices/Dumping/NVMe.cs b/DiscImageChef.Core/Devices/Dumping/NVMe.cs index 5ff8383a6..d9cdfb9b7 100644 --- a/DiscImageChef.Core/Devices/Dumping/NVMe.cs +++ b/DiscImageChef.Core/Devices/Dumping/NVMe.cs @@ -30,7 +30,7 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System; + // ReSharper disable InconsistentNaming @@ -40,7 +40,7 @@ namespace DiscImageChef.Core.Devices.Dumping { public void NVMe() { - throw new NotImplementedException("NVMe devices not yet supported."); + StoppingErrorMessage?.Invoke("NVMe devices not yet supported."); } } } \ No newline at end of file diff --git a/DiscImageChef.Core/Devices/Dumping/PlayStationPortable.cs b/DiscImageChef.Core/Devices/Dumping/PlayStationPortable.cs index ca99dd56a..107417c0a 100644 --- a/DiscImageChef.Core/Devices/Dumping/PlayStationPortable.cs +++ b/DiscImageChef.Core/Devices/Dumping/PlayStationPortable.cs @@ -29,7 +29,6 @@ namespace DiscImageChef.Core.Devices.Dumping /// /// Dumps a CFW PlayStation Portable UMD /// - /// If you asked to dump long sectors from a SCSI Streaming device void PlayStationPortable() { if(!outputPlugin.SupportedMediaTypes.Contains(MediaType.MemoryStickDuo) && @@ -276,7 +275,10 @@ namespace DiscImageChef.Core.Devices.Dumping ResumeSupport.Process(true, dev.IsRemovable, blocks, dev.Manufacturer, dev.Model, dev.Serial, dev.PlatformId, ref resume, ref currentTry, ref extents); if(currentTry == null || extents == null) - throw new InvalidOperationException("Could not process resume file, not continuing..."); + { + StoppingErrorMessage?.Invoke("Could not process resume file, not continuing..."); + return; + } if(resume.NextBlock > 0) dumpLog.WriteLine("Resuming from block {0}.", resume.NextBlock); bool newTrim = false; @@ -587,7 +589,11 @@ namespace DiscImageChef.Core.Devices.Dumping FiltersList filters = new FiltersList(); IFilter filter = filters.GetFilter(outputPath); IMediaImage inputPlugin = ImageFormat.Detect(filter); - if(!inputPlugin.Open(filter)) throw new ArgumentException("Could not open created image."); + if(!inputPlugin.Open(filter)) + { + StoppingErrorMessage?.Invoke("Could not open created image."); + return; + } DateTime chkStart = DateTime.UtcNow; CICMMetadataType sidecar = Sidecar.Create(inputPlugin, outputPath, filter.Id, encoding); @@ -733,7 +739,10 @@ namespace DiscImageChef.Core.Devices.Dumping ResumeSupport.Process(true, dev.IsRemovable, blocks, dev.Manufacturer, dev.Model, dev.Serial, dev.PlatformId, ref resume, ref currentTry, ref extents); if(currentTry == null || extents == null) - throw new InvalidOperationException("Could not process resume file, not continuing..."); + { + StoppingErrorMessage?.Invoke("Could not process resume file, not continuing..."); + return; + } if(resume.NextBlock > 0) dumpLog.WriteLine("Resuming from block {0}.", resume.NextBlock); bool newTrim = false; @@ -1050,7 +1059,11 @@ namespace DiscImageChef.Core.Devices.Dumping FiltersList filters = new FiltersList(); IFilter filter = filters.GetFilter(outputPath); IMediaImage inputPlugin = ImageFormat.Detect(filter); - if(!inputPlugin.Open(filter)) throw new ArgumentException("Could not open created image."); + if(!inputPlugin.Open(filter)) + { + StoppingErrorMessage?.Invoke("Could not open created image."); + return; + } DateTime chkStart = DateTime.UtcNow; CICMMetadataType sidecar = Sidecar.Create(inputPlugin, outputPath, filter.Id, encoding); diff --git a/DiscImageChef.Core/Devices/Dumping/SBC.cs b/DiscImageChef.Core/Devices/Dumping/SBC.cs index 2bff29e26..3106b0bfa 100644 --- a/DiscImageChef.Core/Devices/Dumping/SBC.cs +++ b/DiscImageChef.Core/Devices/Dumping/SBC.cs @@ -76,7 +76,6 @@ namespace DiscImageChef.Core.Devices.Dumping /// Disc type as detected in SCSI or MMC layer /// Path to output file /// Formats to pass to output file plugin - /// If the resume file is invalid internal void Sbc(Dictionary mediaTags, ref MediaType dskType, bool opticalDisc) { bool sense; @@ -354,7 +353,10 @@ namespace DiscImageChef.Core.Devices.Dumping ResumeSupport.Process(true, dev.IsRemovable, blocks, dev.Manufacturer, dev.Model, dev.Serial, dev.PlatformId, ref resume, ref currentTry, ref extents); if(currentTry == null || extents == null) - throw new InvalidOperationException("Could not process resume file, not continuing..."); + { + StoppingErrorMessage?.Invoke("Could not process resume file, not continuing..."); + return; + } if(resume.NextBlock > 0) { @@ -694,8 +696,9 @@ namespace DiscImageChef.Core.Devices.Dumping // Cannot write tag to image StoppingErrorMessage?.Invoke($"Cannot write tag {tag.Key}."); - dumpLog.WriteLine($"Cannot write tag {tag.Key}."); - throw new ArgumentException(outputPlugin.ErrorMessage); + dumpLog.WriteLine($"Cannot write tag {tag.Key}." + Environment.NewLine + + outputPlugin.ErrorMessage); + return; } else { @@ -710,8 +713,9 @@ namespace DiscImageChef.Core.Devices.Dumping if(!ret && !force) { dumpLog.WriteLine("Cannot write USB descriptors."); - StoppingErrorMessage?.Invoke("Cannot write USB descriptors."); - throw new ArgumentException(outputPlugin.ErrorMessage); + StoppingErrorMessage?.Invoke("Cannot write USB descriptors." + Environment.NewLine + + outputPlugin.ErrorMessage); + return; } } @@ -728,8 +732,10 @@ namespace DiscImageChef.Core.Devices.Dumping if(!ret && !force) { dumpLog.WriteLine("Cannot write ATAPI IDENTIFY PACKET DEVICE."); - StoppingErrorMessage?.Invoke("Cannot write ATAPI IDENTIFY PACKET DEVICE."); - throw new ArgumentException(outputPlugin.ErrorMessage); + StoppingErrorMessage?.Invoke("Cannot write ATAPI IDENTIFY PACKET DEVICE." + + Environment.NewLine + + outputPlugin.ErrorMessage); + return; } } } @@ -744,8 +750,9 @@ namespace DiscImageChef.Core.Devices.Dumping if(!ret && !force) { StoppingErrorMessage?.Invoke("Cannot write SCSI INQUIRY."); - dumpLog.WriteLine("Cannot write SCSI INQUIRY."); - throw new ArgumentException(outputPlugin.ErrorMessage); + dumpLog.WriteLine("Cannot write SCSI INQUIRY." + Environment.NewLine + + outputPlugin.ErrorMessage); + return; } UpdateStatus?.Invoke("Requesting MODE SENSE (10)."); @@ -767,8 +774,10 @@ namespace DiscImageChef.Core.Devices.Dumping if(!ret && !force) { dumpLog.WriteLine("Cannot write SCSI MODE SENSE (10)."); - StoppingErrorMessage?.Invoke("Cannot write SCSI MODE SENSE (10)."); - throw new ArgumentException(outputPlugin.ErrorMessage); + StoppingErrorMessage?.Invoke("Cannot write SCSI MODE SENSE (10)." + + Environment.NewLine + + outputPlugin.ErrorMessage); + return; } } @@ -790,8 +799,10 @@ namespace DiscImageChef.Core.Devices.Dumping if(!ret && !force) { dumpLog.WriteLine("Cannot write SCSI MODE SENSE (6)."); - StoppingErrorMessage?.Invoke("Cannot write SCSI MODE SENSE (6)."); - throw new ArgumentException(outputPlugin.ErrorMessage); + StoppingErrorMessage?.Invoke("Cannot write SCSI MODE SENSE (6)." + + Environment.NewLine + + outputPlugin.ErrorMessage); + return; } } } @@ -827,7 +838,11 @@ namespace DiscImageChef.Core.Devices.Dumping FiltersList filters = new FiltersList(); IFilter filter = filters.GetFilter(outputPath); IMediaImage inputPlugin = ImageFormat.Detect(filter); - if(!inputPlugin.Open(filter)) throw new ArgumentException("Could not open created image."); + if(!inputPlugin.Open(filter)) + { + StoppingErrorMessage?.Invoke("Could not open created image."); + return; + } DateTime chkStart = DateTime.UtcNow; CICMMetadataType sidecar = Sidecar.Create(inputPlugin, outputPath, filter.Id, encoding); diff --git a/DiscImageChef.Core/Devices/Dumping/SCSI.cs b/DiscImageChef.Core/Devices/Dumping/SCSI.cs index 64bb418c9..acfcfeab1 100644 --- a/DiscImageChef.Core/Devices/Dumping/SCSI.cs +++ b/DiscImageChef.Core/Devices/Dumping/SCSI.cs @@ -210,7 +210,11 @@ namespace DiscImageChef.Core.Devices.Dumping switch(dev.ScsiType) { case PeripheralDeviceTypes.SequentialAccess: - if(dumpRaw) throw new ArgumentException("Tapes cannot be dumped raw."); + if(dumpRaw) + { + StoppingErrorMessage?.Invoke("Tapes cannot be dumped raw."); + return; + } Ssc(); return; diff --git a/DiscImageChef.Core/Devices/Dumping/SecureDigital.cs b/DiscImageChef.Core/Devices/Dumping/SecureDigital.cs index aba29ea33..881ad8d0b 100644 --- a/DiscImageChef.Core/Devices/Dumping/SecureDigital.cs +++ b/DiscImageChef.Core/Devices/Dumping/SecureDigital.cs @@ -239,7 +239,10 @@ namespace DiscImageChef.Core.Devices.Dumping ResumeSupport.Process(true, false, blocks, dev.Manufacturer, dev.Model, dev.Serial, dev.PlatformId, ref resume, ref currentTry, ref extents); if(currentTry == null || extents == null) - throw new InvalidOperationException("Could not process resume file, not continuing..."); + { + StoppingErrorMessage?.Invoke("Could not process resume file, not continuing..."); + return; + } bool ret = true; @@ -493,7 +496,7 @@ namespace DiscImageChef.Core.Devices.Dumping FiltersList filters = new FiltersList(); IFilter filter = filters.GetFilter(outputPath); IMediaImage inputPlugin = ImageFormat.Detect(filter); - if(!inputPlugin.Open(filter)) throw new ArgumentException("Could not open created image."); + if(!inputPlugin.Open(filter)) StoppingErrorMessage?.Invoke("Could not open created image."); DateTime chkStart = DateTime.UtcNow; CICMMetadataType sidecar = Sidecar.Create(inputPlugin, outputPath, filter.Id, encoding); @@ -535,8 +538,9 @@ namespace DiscImageChef.Core.Devices.Dumping if(!ret && !force) { dumpLog.WriteLine("Cannot write CID to output image."); - StoppingErrorMessage?.Invoke("Cannot write CID to output image."); - throw new ArgumentException(outputPlugin.ErrorMessage); + StoppingErrorMessage?.Invoke("Cannot write CID to output image." + Environment.NewLine + + outputPlugin.ErrorMessage); + return; } } @@ -557,8 +561,9 @@ namespace DiscImageChef.Core.Devices.Dumping if(!ret && !force) { dumpLog.WriteLine("Cannot write CSD to output image."); - StoppingErrorMessage?.Invoke("Cannot write CSD to output image."); - throw new ArgumentException(outputPlugin.ErrorMessage); + StoppingErrorMessage?.Invoke("Cannot write CSD to output image." + Environment.NewLine + + outputPlugin.ErrorMessage); + return; } } @@ -575,8 +580,10 @@ namespace DiscImageChef.Core.Devices.Dumping if(!ret && !force) { dumpLog.WriteLine("Cannot write Extended CSD to output image."); - StoppingErrorMessage?.Invoke("Cannot write Extended CSD to output image."); - throw new ArgumentException(outputPlugin.ErrorMessage); + StoppingErrorMessage?.Invoke("Cannot write Extended CSD to output image." + + Environment.NewLine + + outputPlugin.ErrorMessage); + return; } } @@ -597,8 +604,9 @@ namespace DiscImageChef.Core.Devices.Dumping if(!ret && !force) { dumpLog.WriteLine("Cannot write OCR to output image."); - StoppingErrorMessage?.Invoke("Cannot write OCR to output image."); - throw new ArgumentException(outputPlugin.ErrorMessage); + StoppingErrorMessage?.Invoke("Cannot write OCR to output image." + Environment.NewLine + + outputPlugin.ErrorMessage); + return; } } @@ -615,8 +623,9 @@ namespace DiscImageChef.Core.Devices.Dumping if(!ret && !force) { dumpLog.WriteLine("Cannot write SCR to output image."); - StoppingErrorMessage?.Invoke("Cannot write SCR to output image."); - throw new ArgumentException(outputPlugin.ErrorMessage); + StoppingErrorMessage?.Invoke("Cannot write SCR to output image." + Environment.NewLine + + outputPlugin.ErrorMessage); + return; } } diff --git a/DiscImageChef.Core/Devices/Dumping/XGD.cs b/DiscImageChef.Core/Devices/Dumping/XGD.cs index 71fbb7ac2..fab86837e 100644 --- a/DiscImageChef.Core/Devices/Dumping/XGD.cs +++ b/DiscImageChef.Core/Devices/Dumping/XGD.cs @@ -77,10 +77,6 @@ namespace DiscImageChef.Core.Devices.Dumping /// Disc type as detected in MMC layer /// Path to output file /// Formats to pass to output file plugin - /// - /// If the provided resume does not correspond with the current in progress - /// dump - /// internal void Xgd(Dictionary mediaTags, ref MediaType dskType) { bool sense; @@ -369,7 +365,7 @@ namespace DiscImageChef.Core.Devices.Dumping ResumeSupport.Process(true, true, totalSize, dev.Manufacturer, dev.Model, dev.Serial, dev.PlatformId, ref resume, ref currentTry, ref extents); if(currentTry == null || extents == null) - throw new NotImplementedException("Could not process resume file, not continuing..."); + StoppingErrorMessage?.Invoke("Could not process resume file, not continuing..."); (outputPlugin as IWritableOpticalImage).SetTracks(new List { @@ -907,9 +903,10 @@ namespace DiscImageChef.Core.Devices.Dumping if(ret || force) continue; // Cannot write tag to image - StoppingErrorMessage?.Invoke($"Cannot write tag {tag.Key}."); dumpLog.WriteLine($"Cannot write tag {tag.Key}."); - throw new ArgumentException(outputPlugin.ErrorMessage); + StoppingErrorMessage?.Invoke($"Cannot write tag {tag.Key}." + Environment.NewLine + + outputPlugin.ErrorMessage); + return; } resume.BadBlocks.Sort(); @@ -941,7 +938,11 @@ namespace DiscImageChef.Core.Devices.Dumping FiltersList filters = new FiltersList(); IFilter filter = filters.GetFilter(outputPath); IMediaImage inputPlugin = ImageFormat.Detect(filter); - if(!inputPlugin.Open(filter)) throw new ArgumentException("Could not open created image."); + if(!inputPlugin.Open(filter)) + { + StoppingErrorMessage?.Invoke("Could not open created image."); + return; + } DateTime chkStart = DateTime.UtcNow; CICMMetadataType sidecar = Sidecar.Create(inputPlugin, outputPath, filter.Id, encoding);