diff --git a/LANCommander.Playnite.Extension/InstallController.cs b/LANCommander.Playnite.Extension/InstallController.cs index bd27e7b..c762c86 100644 --- a/LANCommander.Playnite.Extension/InstallController.cs +++ b/LANCommander.Playnite.Extension/InstallController.cs @@ -7,6 +7,7 @@ using Playnite.SDK.Models; using Playnite.SDK.Plugins; using System; using System.Diagnostics; +using System.IO; using System.Linq; namespace LANCommander.PlaynitePlugin @@ -139,51 +140,72 @@ namespace LANCommander.PlaynitePlugin private int RunInstallScript(string installDirectory) { var manifest = ManifestHelper.Read(installDirectory); - var script = new PowerShellScript(); + var path = ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.Install); - script.AddVariable("InstallDirectory", installDirectory); - script.AddVariable("GameManifest", manifest); - script.AddVariable("DefaultInstallDirectory", Plugin.Settings.InstallDirectory); - script.AddVariable("ServerAddress", Plugin.Settings.ServerAddress); + if (File.Exists(path)) + { + var script = new PowerShellScript(); - script.UseFile(ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.Install)); + script.AddVariable("InstallDirectory", installDirectory); + script.AddVariable("GameManifest", manifest); + script.AddVariable("DefaultInstallDirectory", Plugin.Settings.InstallDirectory); + script.AddVariable("ServerAddress", Plugin.Settings.ServerAddress); - return script.Execute(); + script.UseFile(ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.Install)); + + return script.Execute(); + } + + return 0; } private int RunNameChangeScript(string installDirectory) { var manifest = ManifestHelper.Read(installDirectory); - var script = new PowerShellScript(); + var path = ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.NameChange); - script.AddVariable("InstallDirectory", installDirectory); - script.AddVariable("GameManifest", manifest); - script.AddVariable("DefaultInstallDirectory", Plugin.Settings.InstallDirectory); - script.AddVariable("ServerAddress", Plugin.Settings.ServerAddress); - script.AddVariable("OldPlayerAlias", ""); - script.AddVariable("NewPlayerAlias", Plugin.Settings.PlayerName); + if (File.Exists(path)) + { + var script = new PowerShellScript(); - script.UseFile(ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.NameChange)); + script.AddVariable("InstallDirectory", installDirectory); + script.AddVariable("GameManifest", manifest); + script.AddVariable("DefaultInstallDirectory", Plugin.Settings.InstallDirectory); + script.AddVariable("ServerAddress", Plugin.Settings.ServerAddress); + script.AddVariable("OldPlayerAlias", ""); + script.AddVariable("NewPlayerAlias", Plugin.Settings.PlayerName); - return script.Execute(); + script.UseFile(path); + + return script.Execute(); + } + + return 0; } private int RunKeyChangeScript(string installDirectory) { var manifest = ManifestHelper.Read(installDirectory); - var script = new PowerShellScript(); + var path = ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.KeyChange); - var key = Plugin.LANCommanderClient.GetAllocatedKey(manifest.Id); + if (File.Exists(path)) + { + var script = new PowerShellScript(); - script.AddVariable("InstallDirectory", installDirectory); - script.AddVariable("GameManifest", manifest); - script.AddVariable("DefaultInstallDirectory", Plugin.Settings.InstallDirectory); - script.AddVariable("ServerAddress", Plugin.Settings.ServerAddress); - script.AddVariable("AllocatedKey", key); + var key = Plugin.LANCommanderClient.GetAllocatedKey(manifest.Id); - script.UseFile(ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.KeyChange)); + script.AddVariable("InstallDirectory", installDirectory); + script.AddVariable("GameManifest", manifest); + script.AddVariable("DefaultInstallDirectory", Plugin.Settings.InstallDirectory); + script.AddVariable("ServerAddress", Plugin.Settings.ServerAddress); + script.AddVariable("AllocatedKey", key); - return script.Execute(); + script.UseFile(path); + + return script.Execute(); + } + + return 0; } } } diff --git a/LANCommander.Playnite.Extension/LANCommanderLibraryPlugin.cs b/LANCommander.Playnite.Extension/LANCommanderLibraryPlugin.cs index 491de78..21926a0 100644 --- a/LANCommander.Playnite.Extension/LANCommanderLibraryPlugin.cs +++ b/LANCommander.Playnite.Extension/LANCommanderLibraryPlugin.cs @@ -538,52 +538,73 @@ namespace LANCommander.PlaynitePlugin private int RunInstallScript(string installDirectory) { var manifest = ManifestHelper.Read(installDirectory); - var script = new PowerShellScript(); + var path = ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.Install); - script.AddVariable("InstallDirectory", installDirectory); - script.AddVariable("GameManifest", manifest); - script.AddVariable("DefaultInstallDirectory", Settings.InstallDirectory); - script.AddVariable("ServerAddress", Settings.ServerAddress); + if (File.Exists(path)) + { + var script = new PowerShellScript(); - script.UseFile(ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.Install)); + script.AddVariable("InstallDirectory", installDirectory); + script.AddVariable("GameManifest", manifest); + script.AddVariable("DefaultInstallDirectory", Settings.InstallDirectory); + script.AddVariable("ServerAddress", Settings.ServerAddress); - return script.Execute(); + script.UseFile(path); + + return script.Execute(); + } + + return 0; } private int RunNameChangeScript(string installDirectory, string oldPlayerAlias, string newPlayerAlias) { var manifest = ManifestHelper.Read(installDirectory); - var script = new PowerShellScript(); + var path = ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.NameChange); - script.AddVariable("InstallDirectory", installDirectory); - script.AddVariable("GameManifest", manifest); - script.AddVariable("DefaultInstallDirectory", Settings.InstallDirectory); - script.AddVariable("ServerAddress", Settings.ServerAddress); - script.AddVariable("OldPlayerAlias", oldPlayerAlias); - script.AddVariable("NewPlayerAlias", newPlayerAlias); + if (File.Exists(path)) + { + var script = new PowerShellScript(); - script.UseFile(ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.NameChange)); + script.AddVariable("InstallDirectory", installDirectory); + script.AddVariable("GameManifest", manifest); + script.AddVariable("DefaultInstallDirectory", Settings.InstallDirectory); + script.AddVariable("ServerAddress", Settings.ServerAddress); + script.AddVariable("OldPlayerAlias", oldPlayerAlias); + script.AddVariable("NewPlayerAlias", newPlayerAlias); - return script.Execute(); + script.UseFile(path); + + return script.Execute(); + } + + return 0; } private int RunKeyChangeScript(string installDirectory, string key = "") { var manifest = ManifestHelper.Read(installDirectory); - var script = new PowerShellScript(); + var path = ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.KeyChange); - if (String.IsNullOrEmpty(key)) - key = LANCommanderClient.GetAllocatedKey(manifest.Id); + if (File.Exists(path)) + { + var script = new PowerShellScript(); - script.AddVariable("InstallDirectory", installDirectory); - script.AddVariable("GameManifest", manifest); - script.AddVariable("DefaultInstallDirectory", Settings.InstallDirectory); - script.AddVariable("ServerAddress", Settings.ServerAddress); - script.AddVariable("AllocatedKey", key); + if (String.IsNullOrEmpty(key)) + key = LANCommanderClient.GetAllocatedKey(manifest.Id); - script.UseFile(ScriptHelper.GetScriptFilePath(installDirectory, SDK.Enums.ScriptType.KeyChange)); + script.AddVariable("InstallDirectory", installDirectory); + script.AddVariable("GameManifest", manifest); + script.AddVariable("DefaultInstallDirectory", Settings.InstallDirectory); + script.AddVariable("ServerAddress", Settings.ServerAddress); + script.AddVariable("AllocatedKey", key); - return script.Execute(); + script.UseFile(path); + + return script.Execute(); + } + + return 0; } } } diff --git a/LANCommander.Playnite.Extension/UninstallController.cs b/LANCommander.Playnite.Extension/UninstallController.cs index 8185bc4..df9788f 100644 --- a/LANCommander.Playnite.Extension/UninstallController.cs +++ b/LANCommander.Playnite.Extension/UninstallController.cs @@ -31,7 +31,7 @@ namespace LANCommander.PlaynitePlugin { var scriptPath = ScriptHelper.GetScriptFilePath(Game.InstallDirectory, SDK.Enums.ScriptType.Uninstall); - if (!String.IsNullOrEmpty(scriptPath)) + if (!String.IsNullOrEmpty(scriptPath) && File.Exists(scriptPath)) { var manifest = ManifestHelper.Read(Game.InstallDirectory); var script = new PowerShellScript();