mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-22 09:15:48 +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) {
|
||||
Cef.UIThreadTaskFactory.StartNew(() => {
|
||||
var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
|
||||
|
||||
try {
|
||||
using IFrame frame = browser.GetMainFrame();
|
||||
var request = frame.CreateRequest(false);
|
||||
|
||||
var request = frame.CreateRequest(false);
|
||||
request.Method = "GET";
|
||||
request.Url = url;
|
||||
request.Flags = UrlRequestFlags.AllowStoredCredentials;
|
||||
request.SetReferrer(Url, ReferrerPolicy.Default);
|
||||
|
||||
var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
|
||||
var client = new CefDownloadRequestClient(fileStream, onSuccess, onError);
|
||||
frame.CreateUrlRequest(request, client);
|
||||
frame.CreateUrlRequest(request, new CefDownloadRequestClient(fileStream, onSuccess, onError));
|
||||
} catch (Exception e) {
|
||||
fileStream.Dispose();
|
||||
onError?.Invoke(e);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user