fix for crashes on unloading mare while downloading files
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Authors></Authors>
|
<Authors></Authors>
|
||||||
<Company></Company>
|
<Company></Company>
|
||||||
<Version>0.2.12.0</Version>
|
<Version>0.2.13.0</Version>
|
||||||
<Description></Description>
|
<Description></Description>
|
||||||
<Copyright></Copyright>
|
<Copyright></Copyright>
|
||||||
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>
|
||||||
|
|||||||
@@ -38,10 +38,20 @@ namespace MareSynchronos.WebAPI
|
|||||||
private async Task<string> DownloadFile(int downloadId, string hash, CancellationToken ct)
|
private async Task<string> DownloadFile(int downloadId, string hash, CancellationToken ct)
|
||||||
{
|
{
|
||||||
using WebClient wc = new();
|
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();
|
string fileName = Path.GetTempFileName();
|
||||||
var baseUri = new Uri(ApiUri.Replace("wss", "https"), UriKind.Absolute);
|
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;
|
CurrentDownloads[downloadId].Single(f => f.Hash == hash).Transferred = CurrentDownloads[downloadId].Single(f => f.Hash == hash).Total;
|
||||||
|
|
||||||
|
wc.DownloadProgressChanged -= progChanged;
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user