use static files to download from service

This commit is contained in:
Stanley Dimant
2022-07-28 18:06:45 +02:00
parent 34ed21472a
commit fc18b19a4b
3 changed files with 17 additions and 9 deletions

View File

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

View File

@@ -33,7 +33,7 @@ namespace MareSynchronos.UI
private float _windowContentWidth = 0;
public CompactUi(WindowSystem windowSystem,
UiShared uiShared, Configuration configuration, ApiController apiController) : base("Mare Synchronos " + Assembly.GetExecutingAssembly().GetName().Version)
UiShared uiShared, Configuration configuration, ApiController apiController) : base("Mare Synchronos " + Assembly.GetExecutingAssembly().GetName().Version + "###MareSynchronosMainUI")
{
Logger.Verbose("Creating " + nameof(CompactUi));

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
@@ -35,14 +36,21 @@ namespace MareSynchronos.WebAPI
private async Task<string> DownloadFile(int downloadId, string hash, CancellationToken ct)
{
var reader = _mareHub!.StreamAsync<byte[]>(Api.StreamFileDownloadFileAsync, hash, ct);
string fileName = Path.GetTempFileName();
await using var fs = File.OpenWrite(fileName);
await foreach (var data in reader.WithCancellation(ct))
using WebClient wc = new();
wc.DownloadProgressChanged += (s, e) =>
{
CurrentDownloads[downloadId].Single(f => f.Hash == hash).Transferred += data.Length;
await fs.WriteAsync(data, ct);
}
CurrentDownloads[downloadId].Single(f => f.Hash == hash).Transferred = e.BytesReceived;
};
string fileName = Path.GetTempFileName();
var baseUri = new Uri(ApiUri.Replace("wss", "https"), UriKind.Absolute);
var relativeUri = new Uri("cache/" + hash, UriKind.Relative);
var fileUri = new Uri(baseUri, relativeUri);
await wc.DownloadFileTaskAsync(fileUri, fileName);
CurrentDownloads[downloadId].Single(f => f.Hash == hash).Transferred = CurrentDownloads[downloadId].Single(f => f.Hash == hash).Total;
return fileName;
}