Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 31 additions & 36 deletions LANCommander.SDK/Clients/ScriptClient.Games.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<int> Game_RunInstallScriptAsync(string installDirectory, Guid
script.AddVariable(customField.Name, customField.Value);
}
}

script.UseWorkingDirectory(installDirectory);
script.UseFile(path);

Expand Down Expand Up @@ -114,15 +114,15 @@ public async Task<int> Game_RunUninstallScriptAsync(string installDirectory, Gui
script.AddVariable("GameManifest", manifest);
script.AddVariable("DefaultInstallDirectory", settingsProvider.CurrentValue.Games.InstallDirectories.FirstOrDefault());
script.AddVariable("ServerAddress", connectionClient.GetServerAddress());

if (manifest.CustomFields != null && manifest.CustomFields.Any())
{
foreach (var customField in manifest.CustomFields)
{
script.AddVariable(customField.Name, customField.Value);
}
}

script.UseWorkingDirectory(installDirectory);
script.UseFile(path);

Expand Down Expand Up @@ -190,15 +190,15 @@ public async Task<int> Game_RunBeforeStartScriptAsync(string installDirectory, G
script.AddVariable("DefaultInstallDirectory", settingsProvider.CurrentValue.Games.InstallDirectories.FirstOrDefault());
script.AddVariable("ServerAddress", connectionClient.GetServerAddress());
script.AddVariable("PlayerAlias", playerAlias);

if (manifest.CustomFields != null && manifest.CustomFields.Any())
{
foreach (var customField in manifest.CustomFields)
{
script.AddVariable(customField.Name, customField.Value);
}
}

script.UseWorkingDirectory(installDirectory);
script.UseFile(path);

Expand Down Expand Up @@ -266,15 +266,15 @@ public async Task<int> Game_RunAfterStopScriptAsync(string installDirectory, Gui
script.AddVariable("DefaultInstallDirectory", settingsProvider.CurrentValue.Games.InstallDirectories.FirstOrDefault());
script.AddVariable("ServerAddress", connectionClient.GetServerAddress());
script.AddVariable("PlayerAlias", GameClient.GetPlayerAlias(installDirectory, gameId));

if (manifest.CustomFields != null && manifest.CustomFields.Any())
{
foreach (var customField in manifest.CustomFields)
{
script.AddVariable(customField.Name, customField.Value);
}
}

script.UseWorkingDirectory(installDirectory);
script.UseFile(path);

Expand Down Expand Up @@ -353,7 +353,7 @@ public async Task<int> Game_RunNameChangeScriptAsync(string installDirectory, Gu
script.AddVariable("ServerAddress", connectionClient.GetServerAddress());
script.AddVariable("OldPlayerAlias", oldName);
script.AddVariable("NewPlayerAlias", newName);

if (manifest.CustomFields != null && manifest.CustomFields.Any())
{
foreach (var customField in manifest.CustomFields)
Expand Down Expand Up @@ -434,15 +434,15 @@ public async Task<int> Game_RunKeyChangeScriptAsync(string installDirectory, Gui
script.AddVariable("DefaultInstallDirectory", settingsProvider.CurrentValue.Games.InstallDirectories.FirstOrDefault());
script.AddVariable("ServerAddress", connectionClient.GetServerAddress());
script.AddVariable("AllocatedKey", key);

if (manifest.CustomFields != null && manifest.CustomFields.Any())
{
foreach (var customField in manifest.CustomFields)
{
script.AddVariable(customField.Name, customField.Value);
}
}

script.UseWorkingDirectory(installDirectory);
script.UseFile(path);

Expand Down Expand Up @@ -486,43 +486,38 @@ public async Task<int> Game_RunKeyChangeScriptAsync(string installDirectory, Gui
return result;
}

public async Task<Package> Game_RunPackageScriptAsync(Script packageScript, Game game, string latestArchivePath = null)
public async Task<Package?> RunPackageScriptAsync(Script packageScript, Game game, string? latestArchivePath = null)
{
try
{
using (var op = logger.BeginOperation("Executing game package script"))
{
var script = powerShellScriptFactory.Create(Enums.ScriptType.Package);
using var op = logger.BeginOperation("Executing game package script");
var script = powerShellScriptFactory.Create(Enums.ScriptType.Package);

script.AddVariable("Game", game);
script.AddVariable("Game", game);

if (!string.IsNullOrEmpty(latestArchivePath))
script.AddVariable("LatestArchivePath", latestArchivePath);
if (!string.IsNullOrEmpty(latestArchivePath))
script.AddVariable("LatestArchivePath", latestArchivePath);

script.UseInline(packageScript.Contents);

try
{
op
.Enrich("GameId", game.Id)
.Enrich("GameTitle", game.Title)
.Enrich("ScriptId", packageScript.Id)
.Enrich("ScriptName", packageScript.Name);
}
catch (Exception ex)
{
logger?.LogError(ex, "Could not enrich logs");
}

if (Debug)
script.EnableDebug();
script.UseInline(packageScript.Contents);

op
.Enrich("GameId", game.Id)
.Enrich("GameTitle", game.Title)
.Enrich("ScriptId", packageScript.Id)
.Enrich("ScriptName", packageScript.Name);

return await script.ExecuteAsync<Package>();
if (Debug)
{
logger.LogInformation("Debugging is enabled for the package script ({ScriptName}) for game {GameTitle}", packageScript.Name, game.Title);
script.EnableDebug();
}

logger.LogInformation("Running package script ({ScriptName}) for game {GameTitle}", packageScript.Name, game.Title);
return await script.ExecuteAsync<Package>();
}
catch (Exception ex)
{
logger?.LogError(ex, "Could not execute game package script");
logger.LogError(ex, "Failed to run package script ({ScriptName}) for game {GameTitle}", packageScript.Name, game.Title);
}

return null;
Expand Down
1 change: 1 addition & 0 deletions LANCommander.SDK/LANCommander.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<RepositoryType>git</RepositoryType>
<PackageTags>lancommander</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading
Loading