From 839e9b49351fd9d8ffc13e4420561fcd112c579e Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Thu, 16 Nov 2023 01:44:21 -0600 Subject: [PATCH] Run scripts after cmdlet install --- .../Cmdlets/Install-Game.cs | 59 ++++++++++++++++++- .../LANCommander.PowerShell.csproj | 1 + 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/LANCommander.PowerShell/Cmdlets/Install-Game.cs b/LANCommander.PowerShell/Cmdlets/Install-Game.cs index a68037a..ffd4308 100644 --- a/LANCommander.PowerShell/Cmdlets/Install-Game.cs +++ b/LANCommander.PowerShell/Cmdlets/Install-Game.cs @@ -1,4 +1,6 @@ using LANCommander.SDK; +using LANCommander.SDK.Helpers; +using LANCommander.SDK.PowerShell; using System; using System.Diagnostics; using System.Linq; @@ -43,9 +45,64 @@ namespace LANCommander.PowerShell.Cmdlets } }; - gameManager.Install(Id); + var installDirectory = gameManager.Install(Id); stopwatch.Stop(); + + RunInstallScript(installDirectory); + RunNameChangeScript(installDirectory); + RunKeyChangeScript(installDirectory); + } + + private int RunInstallScript(string installDirectory) + { + var manifest = ManifestHelper.Read(installDirectory); + var script = new PowerShellScript(); + + script.AddVariable("InstallDirectory", installDirectory); + script.AddVariable("GameManifest", manifest); + script.AddVariable("DefaultInstallDirectory", InstallDirectory); + script.AddVariable("ServerAddress", Client.BaseUrl); + + script.UseFile(ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.Install)); + + return script.Execute(); + } + + private int RunNameChangeScript(string installDirectory) + { + var user = Client.GetProfile(); + var manifest = ManifestHelper.Read(installDirectory); + var script = new PowerShellScript(); + + script.AddVariable("InstallDirectory", installDirectory); + script.AddVariable("GameManifest", manifest); + script.AddVariable("DefaultInstallDirectory", InstallDirectory); + script.AddVariable("ServerAddress", Client.BaseUrl); + script.AddVariable("OldPlayerAlias", ""); + script.AddVariable("NewPlayerAlias", user.UserName); + + script.UseFile(ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.NameChange)); + + return script.Execute(); + } + + private int RunKeyChangeScript(string installDirectory) + { + var manifest = ManifestHelper.Read(installDirectory); + var script = new PowerShellScript(); + + var key = Client.GetAllocatedKey(manifest.Id); + + script.AddVariable("InstallDirectory", installDirectory); + script.AddVariable("GameManifest", manifest); + script.AddVariable("DefaultInstallDirectory", InstallDirectory); + script.AddVariable("ServerAddress", Client.BaseUrl); + script.AddVariable("AllocatedKey", key); + + script.UseFile(ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.KeyChange)); + + return script.Execute(); } } } diff --git a/LANCommander.PowerShell/LANCommander.PowerShell.csproj b/LANCommander.PowerShell/LANCommander.PowerShell.csproj index 515ee5d..aaa8ee5 100644 --- a/LANCommander.PowerShell/LANCommander.PowerShell.csproj +++ b/LANCommander.PowerShell/LANCommander.PowerShell.csproj @@ -46,6 +46,7 @@ +