1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-11 02:34:08 +02:00

Delete corrupted downloads after an error

This commit is contained in:
chylex 2019-07-13 18:10:16 +02:00
parent 11d978dad1
commit 5e3bd31862

View File

@ -26,13 +26,10 @@ public static WebClient NewClient(string userAgent){
public static AsyncCompletedEventHandler FileDownloadCallback(string file, Action? onSuccess, Action<Exception>? onFailure){
return (sender, args) => {
if (args.Cancelled){
try{
File.Delete(file);
}catch{
// didn't want it deleted anyways
}
TryDeleteFile(file);
}
else if (args.Error != null){
TryDeleteFile(file);
onFailure?.Invoke(args.Error);
}
else{
@ -40,5 +37,13 @@ public static AsyncCompletedEventHandler FileDownloadCallback(string file, Actio
}
};
}
private static void TryDeleteFile(string file){
try{
File.Delete(file);
}catch{
// didn't want it deleted anyways
}
}
}
}