Run scripts after cmdlet install

pull/33/head
Pat Hartl 2023-11-16 01:44:21 -06:00
parent c71cf9fedd
commit 839e9b4935
2 changed files with 59 additions and 1 deletions

View File

@ -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();
}
}
}

View File

@ -46,6 +46,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Cmdlets\Edit-PatchBinary.cs" />
<Compile Include="Cmdlets\Install-Game.cs" />
<Compile Include="Cmdlets\Write-ReplaceContentInFile.cs" />
<Compile Include="Cmdlets\ConvertTo-StringBytes.cs" />
<Compile Include="Cmdlets\Get-PrimaryDisplay.cs" />