Fix some exceptions being swallowed by SaveImagesOperation

This commit is contained in:
Ben Olden-Cooligan 2016-07-02 02:57:33 -04:00
parent ab4802f69d
commit 96e9c8cbd3
2 changed files with 11 additions and 5 deletions

View File

@ -36,7 +36,6 @@ namespace NAPS2.ImportExport.Images
{
public class SaveImagesOperation : OperationBase
{
private readonly IErrorOutput errorOutput;
private readonly FileNamePlaceholders fileNamePlaceholders;
private readonly ImageSettingsContainer imageSettingsContainer;
private readonly IOverwritePrompt overwritePrompt;
@ -45,9 +44,8 @@ namespace NAPS2.ImportExport.Images
private bool cancel;
private Thread thread;
public SaveImagesOperation(IErrorOutput errorOutput, FileNamePlaceholders fileNamePlaceholders, ImageSettingsContainer imageSettingsContainer, IOverwritePrompt overwritePrompt, ThreadFactory threadFactory)
public SaveImagesOperation(FileNamePlaceholders fileNamePlaceholders, ImageSettingsContainer imageSettingsContainer, IOverwritePrompt overwritePrompt, ThreadFactory threadFactory)
{
this.errorOutput = errorOutput;
this.fileNamePlaceholders = fileNamePlaceholders;
this.imageSettingsContainer = imageSettingsContainer;
this.overwritePrompt = overwritePrompt;
@ -194,9 +192,13 @@ namespace NAPS2.ImportExport.Images
cancel = true;
}
public void WaitUntilFinished()
public void WaitUntilFinished(bool throwOnError = true)
{
thread.Join();
if (throwOnError && LastError != null)
{
throw new Exception(LastError.ErrorMessage, LastError.Exception);
}
}
private static ImageFormat GetImageFormat(string fileName)

View File

@ -20,6 +20,8 @@ namespace NAPS2.Operation
public event EventHandler<OperationErrorEventArgs> Error;
protected OperationErrorEventArgs LastError { get; private set; }
protected void InvokeFinished()
{
if (Finished != null)
@ -38,9 +40,11 @@ namespace NAPS2.Operation
protected void InvokeError(string message, Exception exception)
{
var args = new OperationErrorEventArgs(message, exception);
LastError = args;
if (Error != null)
{
Error.Invoke(this, new OperationErrorEventArgs(message, exception));
Error.Invoke(this, args);
}
}
}