summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Services/Scan
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS/HandBrakeWPF/Services/Scan')
-rw-r--r--win/CS/HandBrakeWPF/Services/Scan/Interfaces/IScan.cs5
-rw-r--r--win/CS/HandBrakeWPF/Services/Scan/LibScan.cs25
2 files changed, 27 insertions, 3 deletions
diff --git a/win/CS/HandBrakeWPF/Services/Scan/Interfaces/IScan.cs b/win/CS/HandBrakeWPF/Services/Scan/Interfaces/IScan.cs
index 1c0d3a851..0af5f30ec 100644
--- a/win/CS/HandBrakeWPF/Services/Scan/Interfaces/IScan.cs
+++ b/win/CS/HandBrakeWPF/Services/Scan/Interfaces/IScan.cs
@@ -89,6 +89,11 @@ namespace HandBrakeWPF.Services.Scan.Interfaces
void Scan(string sourcePath, int title, Action<bool, Source> postAction, HBConfiguration configuration);
/// <summary>
+ /// Cancel the current scan.
+ /// </summary>
+ void Cancel();
+
+ /// <summary>
/// Get a Preview image for the current job and preview number.
/// </summary>
/// <param name="task">
diff --git a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs
index b43ec3ce3..3d9d475a1 100644
--- a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs
+++ b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs
@@ -26,6 +26,7 @@ namespace HandBrakeWPF.Services.Scan
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Utilities;
+ using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Encode.Model;
using HandBrakeWPF.Services.Encode.Model.Models;
using HandBrakeWPF.Services.Scan.EventArgs;
@@ -90,6 +91,11 @@ namespace HandBrakeWPF.Services.Scan
/// </summary>
private Action<bool, Source> postScanOperation;
+ /// <summary>
+ /// Global to handle cancelled scans.
+ /// </summary>
+ private bool isCancelled = false;
+
#endregion
/// <summary>
@@ -243,13 +249,24 @@ namespace HandBrakeWPF.Services.Scan
}
}
}
- catch (Exception)
+ catch (Exception exc)
{
+ this.isCancelled = false;
+ this.ScanCompleted?.Invoke(this, new ScanCompletedEventArgs(false, exc, Resources.ScanService_ScanStopFailed, null));
// Do Nothing.
}
}
/// <summary>
+ /// Cancel the current scan.
+ /// </summary>
+ public void Cancel()
+ {
+ this.isCancelled = true;
+ this.Stop();
+ }
+
+ /// <summary>
/// Get a Preview image for the current job and preview number.
/// </summary>
/// <param name="job">
@@ -365,6 +382,8 @@ namespace HandBrakeWPF.Services.Scan
private void InstanceScanCompleted(object sender, System.EventArgs e)
{
this.ServiceLogMessage("Scan Finished ...");
+ bool cancelled = this.isCancelled;
+ this.isCancelled = false;
// Write the log file out before we start processing incase we crash.
try
@@ -391,7 +410,7 @@ namespace HandBrakeWPF.Services.Scan
// Process into internal structures.
Source sourceData = null;
- if (this.instance != null && this.instance.Titles != null)
+ if (this.instance?.Titles != null)
{
sourceData = new Source { Titles = ConvertTitles(this.instance.Titles), ScanPath = path };
}
@@ -413,7 +432,7 @@ namespace HandBrakeWPF.Services.Scan
}
else
{
- if (this.ScanCompleted != null) this.ScanCompleted(this, new ScanCompletedEventArgs(false, null, string.Empty, sourceData));
+ this.ScanCompleted?.Invoke(this, new ScanCompletedEventArgs(cancelled, null, string.Empty, sourceData));
}
}