fix for crashes on unloading mare while downloading files

This commit is contained in:
Stanley Dimant
2022-07-29 12:33:31 +02:00
parent 8716352116
commit 4ca2419f46
2 changed files with 14 additions and 3 deletions

View File

@@ -3,7 +3,7 @@
<PropertyGroup>
<Authors></Authors>
<Company></Company>
<Version>0.2.12.0</Version>
<Version>0.2.13.0</Version>
<Description></Description>
<Copyright></Copyright>
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>

View File

@@ -38,10 +38,20 @@ namespace MareSynchronos.WebAPI
private async Task<string> DownloadFile(int downloadId, string hash, CancellationToken ct)
{
using WebClient wc = new();
wc.DownloadProgressChanged += (s, e) =>
DownloadProgressChangedEventHandler progChanged = (s, e) =>
{
CurrentDownloads[downloadId].Single(f => f.Hash == hash).Transferred = e.BytesReceived;
try
{
CurrentDownloads[downloadId].Single(f => f.Hash == hash).Transferred = e.BytesReceived;
}
catch (Exception ex)
{
Logger.Warn("Could not set download progress for " + hash);
Logger.Warn(ex.Message);
Logger.Warn(ex.StackTrace ?? string.Empty);
}
};
wc.DownloadProgressChanged += progChanged;
string fileName = Path.GetTempFileName();
var baseUri = new Uri(ApiUri.Replace("wss", "https"), UriKind.Absolute);
@@ -52,6 +62,7 @@ namespace MareSynchronos.WebAPI
CurrentDownloads[downloadId].Single(f => f.Hash == hash).Transferred = CurrentDownloads[downloadId].Single(f => f.Hash == hash).Total;
wc.DownloadProgressChanged -= progChanged;
return fileName;
}