Include download speed in progress dialog

pull/32/head
Pat Hartl 2023-11-12 01:50:34 -06:00
parent 6f7c17493c
commit 7c97a3db57
2 changed files with 27 additions and 4 deletions

View File

@ -5,6 +5,7 @@ using Playnite.SDK;
using Playnite.SDK.Models;
using Playnite.SDK.Plugins;
using System;
using System.Diagnostics;
using System.Linq;
namespace LANCommander.PlaynitePlugin
@ -40,13 +41,30 @@ namespace LANCommander.PlaynitePlugin
{
var gameManager = new GameManager(Plugin.LANCommanderClient, Plugin.Settings.InstallDirectory);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var lastTotalSize = 0d;
var speed = 0d;
gameManager.OnArchiveExtractionProgress += (long pos, long len) =>
{
var percent = Math.Ceiling((pos / (decimal)len) * 100);
if (stopwatch.ElapsedMilliseconds > 500)
{
var percent = Math.Ceiling((pos / (decimal)len) * 100);
progress.ProgressMaxValue = len;
progress.CurrentProgressValue = pos;
progress.Text = $"Downloading {Game.Name} ({percent}%)";
progress.ProgressMaxValue = len;
progress.CurrentProgressValue = pos;
speed = (double)(progress.CurrentProgressValue - lastTotalSize) / (stopwatch.ElapsedMilliseconds / 1000d);
progress.Text = $"Downloading {Game.Name} ({percent}%) | {ByteSizeLib.ByteSize.FromBytes(speed).ToString("#.#")}/s";
lastTotalSize = pos;
stopwatch.Restart();
}
};
gameManager.OnArchiveEntryExtractionProgress += (object sender, ArchiveEntryExtractionProgressArgs e) =>
@ -60,6 +78,8 @@ namespace LANCommander.PlaynitePlugin
};
installDirectory = gameManager.Install(gameId);
stopwatch.Stop();
},
new GlobalProgressOptions($"Preparing to download {Game.Name}")
{

View File

@ -34,6 +34,9 @@
<Reference Include="BeaconLib, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\rix0rrr.BeaconLib.1.0.2\lib\net40\BeaconLib.dll</HintPath>
</Reference>
<Reference Include="ByteSize, Version=2.1.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ByteSize.2.1.1\lib\net45\ByteSize.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>