Remove all exceptions inside dumpers.

This commit is contained in:
2019-04-20 14:02:25 +01:00
parent b5162fd4be
commit 552bb57514
10 changed files with 115 additions and 61 deletions

View File

@@ -55,7 +55,6 @@ namespace DiscImageChef.Core.Devices.Dumping
/// <summary>
/// Dumps an ATA device
/// </summary>
/// <exception cref="InvalidOperationException">If the resume file is invalid</exception>
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);

View File

@@ -67,9 +67,6 @@ namespace DiscImageChef.Core.Devices.Dumping
/// Dumps a compact disc
/// </summary>
/// <param name="dskType">Disc type as detected in MMC layer</param>
/// <exception cref="NotImplementedException">If trying to dump scrambled sectors</exception>
/// <exception cref="InvalidOperationException">If the resume file is invalid</exception>
/// <exception cref="ArgumentOutOfRangeException">If the track type is unknown (never)</exception>
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);

View File

@@ -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();

View File

@@ -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
/// <param name="dumpLeadIn">Try to read and dump as much Lead-in as possible</param>
/// <param name="outputPath">Path to output file</param>
/// <param name="formatOptions">Formats to pass to output file plugin</param>
/// <exception cref="NotImplementedException">If trying to dump GOD or WOD, or XGDs without a Kreon drive</exception>
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;
}

View File

@@ -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.");
}
}
}

View File

@@ -29,7 +29,6 @@ namespace DiscImageChef.Core.Devices.Dumping
/// <summary>
/// Dumps a CFW PlayStation Portable UMD
/// </summary>
/// <exception cref="ArgumentException">If you asked to dump long sectors from a SCSI Streaming device</exception>
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);

View File

@@ -76,7 +76,6 @@ namespace DiscImageChef.Core.Devices.Dumping
/// <param name="dskType">Disc type as detected in SCSI or MMC layer</param>
/// <param name="outputPath">Path to output file</param>
/// <param name="formatOptions">Formats to pass to output file plugin</param>
/// <exception cref="InvalidOperationException">If the resume file is invalid</exception>
internal void Sbc(Dictionary<MediaTagType, byte[]> 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);

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -77,10 +77,6 @@ namespace DiscImageChef.Core.Devices.Dumping
/// <param name="dskType">Disc type as detected in MMC layer</param>
/// <param name="outputPath">Path to output file</param>
/// <param name="formatOptions">Formats to pass to output file plugin</param>
/// <exception cref="InvalidOperationException">
/// If the provided resume does not correspond with the current in progress
/// dump
/// </exception>
internal void Xgd(Dictionary<MediaTagType, byte[]> 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<Track>
{
@@ -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);