LANCommander/LANCommander.PowerShell/Cmdlets/Uninstall-Game.cs

43 lines
1.2 KiB
C#
Raw Permalink Normal View History

2023-11-16 18:04:55 +00:00
using LANCommander.SDK;
using LANCommander.SDK.Helpers;
using LANCommander.SDK.PowerShell;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Windows.Forms;
namespace LANCommander.PowerShell.Cmdlets
{
[Cmdlet(VerbsLifecycle.Uninstall, "Game")]
[OutputType(typeof(string))]
2023-11-16 21:21:50 +00:00
public class UninstallGameCmdlet : Cmdlet
2023-11-16 18:04:55 +00:00
{
[Parameter(Mandatory = true)]
public string InstallDirectory { get; set; }
2023-11-16 18:04:55 +00:00
protected override void ProcessRecord()
{
var scriptPath = ScriptHelper.GetScriptFilePath(InstallDirectory, SDK.Enums.ScriptType.Uninstall);
if (!String.IsNullOrEmpty(scriptPath) && File.Exists(scriptPath))
{
var manifest = ManifestHelper.Read(InstallDirectory);
var script = new PowerShellScript();
script.AddVariable("InstallDirectory", InstallDirectory);
script.AddVariable("GameManifest", manifest);
script.UseFile(scriptPath);
script.Execute();
}
var gameManager = new GameManager(null, InstallDirectory);
gameManager.Uninstall(InstallDirectory);
}
}
}