mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-30 23:34:09 +02:00
Fix potentially not releasing a file lock if an exception is thrown while setting up a download
This commit is contained in:
parent
d5ae698855
commit
0a9c84feec
@ -73,19 +73,20 @@ private void OnFrameLoadEnd(object sender, FrameLoadEndEventArgs e) {
|
|||||||
|
|
||||||
public override void DownloadFile(string url, string path, Action onSuccess, Action<Exception> onError) {
|
public override void DownloadFile(string url, string path, Action onSuccess, Action<Exception> onError) {
|
||||||
Cef.UIThreadTaskFactory.StartNew(() => {
|
Cef.UIThreadTaskFactory.StartNew(() => {
|
||||||
|
var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
using IFrame frame = browser.GetMainFrame();
|
using IFrame frame = browser.GetMainFrame();
|
||||||
var request = frame.CreateRequest(false);
|
|
||||||
|
|
||||||
|
var request = frame.CreateRequest(false);
|
||||||
request.Method = "GET";
|
request.Method = "GET";
|
||||||
request.Url = url;
|
request.Url = url;
|
||||||
request.Flags = UrlRequestFlags.AllowStoredCredentials;
|
request.Flags = UrlRequestFlags.AllowStoredCredentials;
|
||||||
request.SetReferrer(Url, ReferrerPolicy.Default);
|
request.SetReferrer(Url, ReferrerPolicy.Default);
|
||||||
|
|
||||||
var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
|
frame.CreateUrlRequest(request, new CefDownloadRequestClient(fileStream, onSuccess, onError));
|
||||||
var client = new CefDownloadRequestClient(fileStream, onSuccess, onError);
|
|
||||||
frame.CreateUrlRequest(request, client);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
fileStream.Dispose();
|
||||||
onError?.Invoke(e);
|
onError?.Invoke(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user