Centralize abort for dumpers

This commit is contained in:
2019-04-20 16:40:12 +01:00
parent b7b086b644
commit bc8052f0ae
10 changed files with 56 additions and 61 deletions

View File

@@ -57,8 +57,6 @@ namespace DiscImageChef.Core.Devices.Dumping
/// </summary>
public void Ata()
{
bool aborted;
if(dumpRaw)
{
if(force) ErrorMessage?.Invoke("Raw dumping not yet supported in ATA devices, continuing...");
@@ -92,9 +90,6 @@ namespace DiscImageChef.Core.Devices.Dumping
double maxSpeed = double.MinValue;
double minSpeed = double.MaxValue;
aborted = false;
System.Console.CancelKeyPress += (sender, e) => e.Cancel = aborted = true;
// Initializate reader
UpdateStatus?.Invoke("Initializing reader.");
dumpLog.WriteLine("Initializing reader.");

View File

@@ -82,8 +82,6 @@ namespace DiscImageChef.Core.Devices.Dumping
double maxSpeed = double.MinValue;
double minSpeed = double.MaxValue;
uint blocksToRead = 64;
bool aborted = false;
System.Console.CancelKeyPress += (sender, e) => e.Cancel = aborted = true;
Dictionary<MediaTagType, byte[]> mediaTags = new Dictionary<MediaTagType, byte[]>();
if(dumpRaw)

View File

@@ -31,6 +31,7 @@ namespace DiscImageChef.Core.Devices.Dumping
readonly CICMMetadataType preSidecar;
readonly ushort retryPasses;
readonly bool stopOnError;
bool aborted;
bool dumpFirstTrackPregap;
Resume resume;
uint skip;
@@ -87,6 +88,7 @@ namespace DiscImageChef.Core.Devices.Dumping
this.nometadata = nometadata;
this.notrim = notrim;
this.dumpFirstTrackPregap = dumpFirstTrackPregap;
aborted = false;
}
/// <summary>
@@ -136,6 +138,11 @@ namespace DiscImageChef.Core.Devices.Dumping
fs.Close();
}
public void Abort()
{
aborted = true;
}
/// <summary>
/// Event raised when the progress bar is not longer needed
/// </summary>

View File

@@ -180,10 +180,8 @@ namespace DiscImageChef.Core.Devices.Dumping
double currentSpeed = 0;
double maxSpeed = double.MinValue;
double minSpeed = double.MaxValue;
bool aborted = false;
DateTime start;
DateTime end;
System.Console.CancelKeyPress += (sender, e) => e.Cancel = aborted = true;
bool sense = dev.Read12(out byte[] readBuffer, out _, 0, false, true, false, false, 0, 512, 0, 1, false,
dev.Timeout, out _);
@@ -667,9 +665,7 @@ namespace DiscImageChef.Core.Devices.Dumping
double currentSpeed = 0;
double maxSpeed = double.MinValue;
double minSpeed = double.MaxValue;
bool aborted = false;
uint blocksToRead = 64;
System.Console.CancelKeyPress += (sender, e) => e.Cancel = aborted = true;
DateTime start;
DateTime end;
MediaType dskType;

View File

@@ -76,8 +76,6 @@ namespace DiscImageChef.Core.Devices.Dumping
double maxSpeed = double.MinValue;
double minSpeed = double.MaxValue;
byte[] readBuffer;
bool aborted = false;
System.Console.CancelKeyPress += (sender, e) => e.Cancel = aborted = true;
Modes.DecodedMode? decMode = null;
dumpLog.WriteLine("Initializing reader.");

View File

@@ -55,7 +55,6 @@ namespace DiscImageChef.Core.Devices.Dumping
internal void Ssc()
{
FixedSense? fxSense;
bool aborted;
bool sense;
ulong blocks = 0;
uint blockSize;
@@ -403,8 +402,6 @@ namespace DiscImageChef.Core.Devices.Dumping
};
Checksum partitionChk = new Checksum();
aborted = false;
System.Console.CancelKeyPress += (sender, e) => e.Cancel = aborted = true;
DateTime timeSpeedStart = DateTime.UtcNow;
ulong currentSpeedSize = 0;

View File

@@ -57,8 +57,6 @@ namespace DiscImageChef.Core.Devices.Dumping
/// </summary>
public void SecureDigital()
{
bool aborted;
if(dumpRaw)
{
if(force)
@@ -182,9 +180,6 @@ namespace DiscImageChef.Core.Devices.Dumping
double maxSpeed = double.MinValue;
double minSpeed = double.MaxValue;
aborted = false;
System.Console.CancelKeyPress += (sender, e) => e.Cancel = aborted = true;
if(blocks == 0)
{
dumpLog.WriteLine("Unable to get device size.");

View File

@@ -74,8 +74,6 @@ namespace DiscImageChef.Core.Devices.Dumping
double currentSpeed = 0;
double maxSpeed = double.MinValue;
double minSpeed = double.MaxValue;
bool aborted = false;
System.Console.CancelKeyPress += (sender, e) => e.Cancel = aborted = true;
if(mediaTags.ContainsKey(MediaTagType.DVD_PFI)) mediaTags.Remove(MediaTagType.DVD_PFI);
if(mediaTags.ContainsKey(MediaTagType.DVD_DMI)) mediaTags.Remove(MediaTagType.DVD_DMI);

View File

@@ -58,6 +58,8 @@ namespace DiscImageChef.Gui.Forms
public class frmDump : Form
{
readonly string devicePath;
Dump dumper;
string outputPrefix;
Resume resume;
CICMMetadataType sidecar;
@@ -378,6 +380,11 @@ namespace DiscImageChef.Gui.Forms
Close();
}
void OnBtnAbortClick(object sender, EventArgs e)
{
dumper.Abort();
}
void OnBtnDumpClick(object sender, EventArgs e)
{
Device dev;
@@ -446,8 +453,7 @@ namespace DiscImageChef.Gui.Forms
parsedOptions.Add(key, value);
}
Dump dumper = new Dump(chkResume.Checked == true, dev, devicePath, outputFormat,
(ushort)stpRetries.Value,
dumper = new Dump(chkResume.Checked == true, dev, devicePath, outputFormat, (ushort)stpRetries.Value,
chkForce.Checked == true, false, chkPersistent.Checked == true,
chkStopOnError.Checked == true, resume, dumpLog, encoding, outputPrefix,
txtDestination.Text, parsedOptions, sidecar, (uint)stpSkipped.Value,

View File

@@ -304,6 +304,11 @@ namespace DiscImageChef.Commands
dumper.PulseProgress += Progress.PulseProgress;
dumper.InitProgress += Progress.InitProgress;
dumper.EndProgress += Progress.EndProgress;
System.Console.CancelKeyPress += (sender, e) =>
{
e.Cancel = true;
dumper.Abort();
};
dumper.Start();