diff --git a/DiscImageChef.Core/Devices/Scanning/ATA.cs b/DiscImageChef.Core/Devices/Scanning/ATA.cs
index a7b2e82f8..e166db9ad 100644
--- a/DiscImageChef.Core/Devices/Scanning/ATA.cs
+++ b/DiscImageChef.Core/Devices/Scanning/ATA.cs
@@ -49,7 +49,6 @@ namespace DiscImageChef.Core.Devices.Scanning
public ScanResults Ata()
{
ScanResults results = new ScanResults();
- bool aborted;
bool sense;
results.Blocks = 0;
const ushort ATA_PROFILE = 0x0001;
@@ -111,9 +110,6 @@ namespace DiscImageChef.Core.Devices.Scanning
Random rnd = new Random();
- aborted = false;
- System.Console.CancelKeyPress += (sender, e) => e.Cancel = aborted = true;
-
MhddLog mhddLog;
IbgLog ibgLog;
double duration;
diff --git a/DiscImageChef.Core/Devices/Scanning/MediaScan.cs b/DiscImageChef.Core/Devices/Scanning/MediaScan.cs
index b522834e8..aea49ad48 100644
--- a/DiscImageChef.Core/Devices/Scanning/MediaScan.cs
+++ b/DiscImageChef.Core/Devices/Scanning/MediaScan.cs
@@ -10,6 +10,7 @@ namespace DiscImageChef.Core.Devices.Scanning
readonly string devicePath;
readonly string ibgLogPath;
readonly string mhddLogPath;
+ bool aborted;
/// Path to a MHDD log file
/// Path to a IMGBurn log file
@@ -21,6 +22,7 @@ namespace DiscImageChef.Core.Devices.Scanning
this.ibgLogPath = ibgLogPath;
this.devicePath = devicePath;
this.dev = dev;
+ aborted = false;
}
public ScanResults Scan()
@@ -37,6 +39,11 @@ namespace DiscImageChef.Core.Devices.Scanning
}
}
+ public void Abort()
+ {
+ aborted = true;
+ }
+
///
/// Event raised when the progress bar is not longer needed
///
diff --git a/DiscImageChef.Core/Devices/Scanning/SCSI.cs b/DiscImageChef.Core/Devices/Scanning/SCSI.cs
index f80c12c69..9d2c72542 100644
--- a/DiscImageChef.Core/Devices/Scanning/SCSI.cs
+++ b/DiscImageChef.Core/Devices/Scanning/SCSI.cs
@@ -50,7 +50,6 @@ namespace DiscImageChef.Core.Devices.Scanning
public ScanResults Scsi()
{
ScanResults results = new ScanResults();
- bool aborted;
MhddLog mhddLog;
IbgLog ibgLog;
byte[] senseBuf;
@@ -241,9 +240,6 @@ namespace DiscImageChef.Core.Devices.Scanning
results.MinSpeed = double.MaxValue;
results.UnreadableSectors = new List();
- aborted = false;
- System.Console.CancelKeyPress += (sender, e) => e.Cancel = aborted = true;
-
if(compactDisc)
{
if(toc == null)
diff --git a/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs b/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs
index 1357486c0..b993c7dc5 100644
--- a/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs
+++ b/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs
@@ -46,7 +46,6 @@ namespace DiscImageChef.Core.Devices.Scanning
public ScanResults SecureDigital()
{
ScanResults results = new ScanResults();
- bool aborted;
byte[] cmdBuf;
bool sense;
results.Blocks = 0;
@@ -146,9 +145,6 @@ namespace DiscImageChef.Core.Devices.Scanning
Random rnd = new Random();
- aborted = false;
- System.Console.CancelKeyPress += (sender, e) => e.Cancel = aborted = true;
-
UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time.");
MhddLog mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead);
diff --git a/DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs b/DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs
index f8cf63ef0..95be15de1 100644
--- a/DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs
+++ b/DiscImageChef.Gui/Forms/frmMediaScan.xeto.cs
@@ -46,6 +46,8 @@ namespace DiscImageChef.Gui.Forms
{
string devicePath;
+ MediaScan scanner;
+
public frmMediaScan(string devicePath, DeviceInfo deviceInfo, ScsiInfo scsiInfo = null)
{
MediaType mediaType;
@@ -62,7 +64,7 @@ namespace DiscImageChef.Gui.Forms
void OnBtnStopClick(object sender, EventArgs e)
{
- // TODO: Stop
+ scanner.Abort();
}
// TODO: Allow to save MHDD and ImgBurn log files
@@ -89,7 +91,7 @@ namespace DiscImageChef.Gui.Forms
Statistics.AddDevice(dev);
- MediaScan scanner = new MediaScan(null, null, devicePath, dev);
+ scanner = new MediaScan(null, null, devicePath, dev);
ScanResults results = scanner.Scan();
lblTotalTime.Text = lblTotalTime.Text =
diff --git a/DiscImageChef/Commands/MediaScan.cs b/DiscImageChef/Commands/MediaScan.cs
index 5de4131df..1f178ab6b 100644
--- a/DiscImageChef/Commands/MediaScan.cs
+++ b/DiscImageChef/Commands/MediaScan.cs
@@ -119,6 +119,11 @@ namespace DiscImageChef.Commands
scanner.PulseProgress += Progress.PulseProgress;
scanner.InitProgress += Progress.InitProgress;
scanner.EndProgress += Progress.EndProgress;
+ System.Console.CancelKeyPress += (sender, e) =>
+ {
+ e.Cancel = true;
+ scanner.Abort();
+ };
ScanResults results = scanner.Scan();
DicConsole.WriteLine("Took a total of {0} seconds ({1} processing commands).", results.TotalTime,