From e94609d945da3de8b689106fa979ce181a6c3bae Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Sun, 6 Feb 2022 13:36:52 -0700 Subject: [PATCH] Fixed #22 - Overriding TimeOut on Shutdown Command doesn't seem to work --- Installer/version.txt | 2 +- src/Commands/CommandInvoker.cs | 8 ++++++++ src/Commands/ShutdownCommand.cs | 12 +++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Installer/version.txt b/Installer/version.txt index b6f574f..a93bc91 100644 --- a/Installer/version.txt +++ b/Installer/version.txt @@ -1 +1 @@ -2.2.9.1 \ No newline at end of file +2.2.9.11 \ No newline at end of file diff --git a/src/Commands/CommandInvoker.cs b/src/Commands/CommandInvoker.cs index 225183a..97a92bd 100644 --- a/src/Commands/CommandInvoker.cs +++ b/src/Commands/CommandInvoker.cs @@ -76,6 +76,14 @@ public static CommandInvoker Create(string userCommandsFile, string currentVersi cmd.UserDefined = true; } + if (cmd.Enabled) { + if (cmd.UserDefined) { + Logger.Instance.Log4.Debug($"{commands.GetType().Name}: User defined command enabled: '****'"); + } + else { + Logger.Instance.Log4.Debug($"{commands.GetType().Name}: Builtin command enabled: '{cmd}'"); + } + } commands.Add(cmd); } else { diff --git a/src/Commands/ShutdownCommand.cs b/src/Commands/ShutdownCommand.cs index f99e63b..b22c549 100644 --- a/src/Commands/ShutdownCommand.cs +++ b/src/Commands/ShutdownCommand.cs @@ -39,11 +39,16 @@ public ShutdownCommand() { // Serialzable, must have constructor } + public ShutdownCommand(String type, int timeout) { + this.type = type; + this.TimeOut = timeout; + } + public override string ToString() { return $"Cmd=\"{Cmd}\" Type=\"{Type}\" TimeOut=\"{TimeOut}\""; } - public override ICommand Clone(Reply reply) => base.Clone(reply, new ShutdownCommand() { Type = this.Type }); + public override ICommand Clone(Reply reply) => base.Clone(reply, new ShutdownCommand(Type, TimeOut)); // ICommand:Execute public override bool Execute() { @@ -107,10 +112,11 @@ public override bool Execute() { public static void Shutdown(string shutdownArgs) { Logger.Instance.Log4.Debug($"ShutdownCommand: Invoking 'shutdown.exe {shutdownArgs}'"); + var proc = System.Diagnostics.Process.Start("shutdown", shutdownArgs); - proc.WaitForExit(1000); + proc.WaitForExit(1000 * 2); if (proc.ExitCode != 0x0) { - Logger.Instance.Log4.Error($"ShutdownCommand: 'shutdown.exe {shutdownArgs}' failed ({proc.ExitCode:X}). Forcing Win32Exception..."); + Logger.Instance.Log4.Error($"ShutdownCommand: 'shutdown.exe {shutdownArgs}' failed ({proc.ExitCode:X})"); throw new System.ComponentModel.Win32Exception(proc.ExitCode); } }