Cmdlet for installing game
This commit is contained in:
parent
86211a7500
commit
c71cf9fedd
1 changed files with 51 additions and 0 deletions
51
LANCommander.PowerShell/Cmdlets/Install-Game.cs
Normal file
51
LANCommander.PowerShell/Cmdlets/Install-Game.cs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
using LANCommander.SDK;
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Management.Automation;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace LANCommander.PowerShell.Cmdlets
|
||||||
|
{
|
||||||
|
[Cmdlet(VerbsLifecycle.Install, "PrimaryDisplay")]
|
||||||
|
[OutputType(typeof(string))]
|
||||||
|
public class InstallGameCmdlet : PSCmdlet
|
||||||
|
{
|
||||||
|
[Parameter(Mandatory = true)]
|
||||||
|
public Client Client { get; set; }
|
||||||
|
|
||||||
|
[Parameter(Mandatory = true)]
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
[Parameter(Mandatory = false)]
|
||||||
|
public string InstallDirectory { get; set; } = "C:\\Games";
|
||||||
|
|
||||||
|
protected override void ProcessRecord()
|
||||||
|
{
|
||||||
|
var gameManager = new GameManager(Client, InstallDirectory);
|
||||||
|
var game = Client.GetGame(Id);
|
||||||
|
|
||||||
|
var progress = new ProgressRecord(1, $"Installing {game.Title}", "Progress:");
|
||||||
|
|
||||||
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
|
stopwatch.Start();
|
||||||
|
|
||||||
|
gameManager.OnArchiveExtractionProgress += (long position, long length) =>
|
||||||
|
{
|
||||||
|
// Only update a max of every 500ms
|
||||||
|
if (stopwatch.ElapsedMilliseconds > 500)
|
||||||
|
{
|
||||||
|
progress.PercentComplete = (int)Math.Ceiling((position / (decimal)length) * 100);
|
||||||
|
|
||||||
|
WriteProgress(progress);
|
||||||
|
|
||||||
|
stopwatch.Restart();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
gameManager.Install(Id);
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue