@using LANCommander.Client.Models @using System.Diagnostics @inject DownloadService DownloadService @inject SDK.Client Client @inject GameService GameService @if (CurrentQueueItem != null) {
@if (ShowIcon) {
}
@CurrentQueueItem.Status: @CurrentQueueItem.Progress.ToString("0%")
@if (CurrentQueueItem.TransferSpeed > 0) {
@TimeSpan.FromSeconds((CurrentQueueItem.TotalBytes - CurrentQueueItem.BytesDownloaded) / CurrentQueueItem.TransferSpeed).ToShortTime()
}
@ByteSizeLib.ByteSize.FromBytes(CurrentQueueItem.BytesDownloaded).ToString() / @ByteSizeLib.ByteSize.FromBytes(CurrentQueueItem.TotalBytes).ToString()
} @code { [Parameter] public bool ShowIcon { get; set; } IDownloadQueueItem CurrentQueueItem = null; Stopwatch Stopwatch = new Stopwatch(); protected override async Task OnInitializedAsync() { Client.Games.OnArchiveExtractionProgress += (long position, long length, SDK.Models.Game game) => { if (!Stopwatch.IsRunning) Stopwatch.Start(); if (Stopwatch.ElapsedMilliseconds > 500) { CurrentQueueItem = DownloadService.Queue.OrderByDescending(qi => qi.QueuedOn).FirstOrDefault(qi => qi.State); var bytesThisInterval = position - CurrentQueueItem.BytesDownloaded; CurrentQueueItem.BytesDownloaded = position; CurrentQueueItem.TotalBytes = length; CurrentQueueItem.TransferSpeed = (double)(bytesThisInterval / (Stopwatch.ElapsedMilliseconds / 1000d)); InvokeAsync(StateHasChanged); Stopwatch.Reset(); } }; Client.Games.OnArchiveEntryExtractionProgress += (object sender, SDK.ArchiveEntryExtractionProgressArgs e) => { // InvokeAsync(StateHasChanged); }; DownloadService.OnInstallComplete += async () => { Stopwatch.Stop(); }; DownloadService.OnQueueChanged += async () => { CurrentQueueItem = DownloadService.Queue.OrderByDescending(qi => qi.QueuedOn).FirstOrDefault(qi => qi.State); await InvokeAsync(StateHasChanged); }; } }