Include download speed in progress dialog
This commit is contained in:
parent
6f7c17493c
commit
7c97a3db57
2 changed files with 27 additions and 4 deletions
|
@ -5,6 +5,7 @@ using Playnite.SDK;
|
||||||
using Playnite.SDK.Models;
|
using Playnite.SDK.Models;
|
||||||
using Playnite.SDK.Plugins;
|
using Playnite.SDK.Plugins;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace LANCommander.PlaynitePlugin
|
namespace LANCommander.PlaynitePlugin
|
||||||
|
@ -40,13 +41,30 @@ namespace LANCommander.PlaynitePlugin
|
||||||
{
|
{
|
||||||
var gameManager = new GameManager(Plugin.LANCommanderClient, Plugin.Settings.InstallDirectory);
|
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) =>
|
gameManager.OnArchiveExtractionProgress += (long pos, long len) =>
|
||||||
|
{
|
||||||
|
if (stopwatch.ElapsedMilliseconds > 500)
|
||||||
{
|
{
|
||||||
var percent = Math.Ceiling((pos / (decimal)len) * 100);
|
var percent = Math.Ceiling((pos / (decimal)len) * 100);
|
||||||
|
|
||||||
progress.ProgressMaxValue = len;
|
progress.ProgressMaxValue = len;
|
||||||
progress.CurrentProgressValue = pos;
|
progress.CurrentProgressValue = pos;
|
||||||
progress.Text = $"Downloading {Game.Name} ({percent}%)";
|
|
||||||
|
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) =>
|
gameManager.OnArchiveEntryExtractionProgress += (object sender, ArchiveEntryExtractionProgressArgs e) =>
|
||||||
|
@ -60,6 +78,8 @@ namespace LANCommander.PlaynitePlugin
|
||||||
};
|
};
|
||||||
|
|
||||||
installDirectory = gameManager.Install(gameId);
|
installDirectory = gameManager.Install(gameId);
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
},
|
},
|
||||||
new GlobalProgressOptions($"Preparing to download {Game.Name}")
|
new GlobalProgressOptions($"Preparing to download {Game.Name}")
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,6 +34,9 @@
|
||||||
<Reference Include="BeaconLib, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="BeaconLib, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\rix0rrr.BeaconLib.1.0.2\lib\net40\BeaconLib.dll</HintPath>
|
<HintPath>..\packages\rix0rrr.BeaconLib.1.0.2\lib\net40\BeaconLib.dll</HintPath>
|
||||||
</Reference>
|
</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">
|
<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>
|
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|
Loading…
Add table
Reference in a new issue