diff --git a/Core/Utils/BrowserUtils.cs b/Core/Utils/BrowserUtils.cs index 0bae3141..47864c9a 100644 --- a/Core/Utils/BrowserUtils.cs +++ b/Core/Utils/BrowserUtils.cs @@ -69,20 +69,28 @@ public static string GetErrorName(CefErrorCode code){ return ConvertPascalCaseToScreamingSnakeCase(Enum.GetName(typeof(CefErrorCode), code) ?? string.Empty); } - public static void DownloadFileAsync(string url, string target, Action onSuccess, Action<Exception> onFailure){ + public static WebClient DownloadFileAsync(string url, string target, Action onSuccess, Action<Exception> onFailure){ WebClient client = new WebClient{ Proxy = null }; client.Headers[HttpRequestHeader.UserAgent] = HeaderUserAgent; client.DownloadFileCompleted += (sender, args) => { - if (args.Error == null){ - onSuccess?.Invoke(); + if (args.Cancelled){ + try{ + File.Delete(target); + }catch{ + // didn't want it deleted anyways + } + } + else if (args.Error != null){ + onFailure?.Invoke(args.Error); } else{ - onFailure?.Invoke(args.Error); + onSuccess?.Invoke(); } }; client.DownloadFileAsync(new Uri(url), target); + return client; } public static void SetZoomLevel(IBrowser browser, int percentage){