use static files to download from service
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Authors></Authors>
|
<Authors></Authors>
|
||||||
<Company></Company>
|
<Company></Company>
|
||||||
<Version>0.2.9.0</Version>
|
<Version>0.2.10.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>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace MareSynchronos.UI
|
|||||||
private float _windowContentWidth = 0;
|
private float _windowContentWidth = 0;
|
||||||
|
|
||||||
public CompactUi(WindowSystem windowSystem,
|
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));
|
Logger.Verbose("Creating " + nameof(CompactUi));
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -35,14 +36,21 @@ 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)
|
||||||
{
|
{
|
||||||
var reader = _mareHub!.StreamAsync<byte[]>(Api.StreamFileDownloadFileAsync, hash, ct);
|
using WebClient wc = new();
|
||||||
string fileName = Path.GetTempFileName();
|
wc.DownloadProgressChanged += (s, e) =>
|
||||||
await using var fs = File.OpenWrite(fileName);
|
|
||||||
await foreach (var data in reader.WithCancellation(ct))
|
|
||||||
{
|
{
|
||||||
CurrentDownloads[downloadId].Single(f => f.Hash == hash).Transferred += data.Length;
|
CurrentDownloads[downloadId].Single(f => f.Hash == hash).Transferred = e.BytesReceived;
|
||||||
await fs.WriteAsync(data, ct);
|
};
|
||||||
}
|
|
||||||
|
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;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user