2022-01-11 03:00:54 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Reactive.Disposables;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2022-01-11 15:05:48 +00:00
|
|
|
|
using Fluxor;
|
2022-01-11 03:00:54 +00:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.CodeAnalysis;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2022-01-11 15:05:48 +00:00
|
|
|
|
using Wabbajack.App.Blazor.Store;
|
2022-01-11 03:00:54 +00:00
|
|
|
|
using Wabbajack.DTOs;
|
|
|
|
|
using Wabbajack.Networking.WabbajackClientApi;
|
|
|
|
|
using Wabbajack.RateLimiter;
|
|
|
|
|
using Wabbajack.Services.OSIntegrated.Services;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.App.Blazor.Components
|
|
|
|
|
{
|
|
|
|
|
public partial class ModlistItem
|
|
|
|
|
{
|
2022-01-11 15:05:48 +00:00
|
|
|
|
[Inject] private ModListDownloadMaintainer _maintainer { get; set; }
|
|
|
|
|
[Inject] private IState<DownloadState> _downloadState { get; set; }
|
|
|
|
|
[Inject] private IDispatcher _dispatcher { get; set; }
|
2022-01-11 03:00:54 +00:00
|
|
|
|
|
|
|
|
|
[Parameter] public ModlistMetadata Metadata { get; set; }
|
2022-01-11 15:05:48 +00:00
|
|
|
|
|
|
|
|
|
public double PercentDownloaded { get; set; }
|
2022-01-11 03:00:54 +00:00
|
|
|
|
|
|
|
|
|
private async Task Download()
|
|
|
|
|
{
|
|
|
|
|
await using Timer timer = new(_ => InvokeAsync(StateHasChanged));
|
2022-01-11 15:05:48 +00:00
|
|
|
|
timer.Change(TimeSpan.FromMilliseconds(250), TimeSpan.FromMilliseconds(250));
|
2022-01-11 03:00:54 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2022-01-11 15:05:48 +00:00
|
|
|
|
UpdateInstallState(InstallState.InstallStateEnum.Downloading, Metadata);
|
2022-01-11 03:00:54 +00:00
|
|
|
|
|
|
|
|
|
(IObservable<Percent> progress, Task task) = _maintainer.DownloadModlist(Metadata);
|
2022-01-11 15:05:48 +00:00
|
|
|
|
IDisposable dispose = progress.Subscribe(p => { PercentDownloaded = p.Value * 100; });
|
2022-01-11 03:00:54 +00:00
|
|
|
|
|
|
|
|
|
await task;
|
|
|
|
|
//await _wjClient.SendMetric("downloading", Metadata.Title);
|
|
|
|
|
Debug.Print("##### WE DOWNLOADED THE THING!");
|
2022-01-11 15:05:48 +00:00
|
|
|
|
UpdateInstallState(InstallState.InstallStateEnum.Configuration);
|
2022-01-11 03:00:54 +00:00
|
|
|
|
dispose.Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Debug.Print(e.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await timer.DisposeAsync();
|
|
|
|
|
}
|
2022-01-11 15:05:48 +00:00
|
|
|
|
|
|
|
|
|
private void UpdateInstallState(InstallState.InstallStateEnum state, ModlistMetadata? metadata = null) => _dispatcher.Dispatch(new UpdateInstallState(state, metadata));
|
2022-01-11 03:00:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|