From 344c8e40d6e1b3beae8d7a945f407839158b9440 Mon Sep 17 00:00:00 2001 From: Justin Swanson Date: Sun, 22 Dec 2019 00:50:11 -0600 Subject: [PATCH] ProcessExt: WaitForExitAndWarn --- Wabbajack.Common/Extensions/ProcessExt.cs | 22 ++++++++++++++++++++++ Wabbajack.Common/FileExtractor.cs | 13 ++++--------- Wabbajack.Common/Utils.cs | 2 +- Wabbajack.Common/Wabbajack.Common.csproj | 1 + 4 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 Wabbajack.Common/Extensions/ProcessExt.cs diff --git a/Wabbajack.Common/Extensions/ProcessExt.cs b/Wabbajack.Common/Extensions/ProcessExt.cs new file mode 100644 index 00000000..04277531 --- /dev/null +++ b/Wabbajack.Common/Extensions/ProcessExt.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Wabbajack.Common +{ + public static class ProcessExt + { + public static void WaitForExitAndWarn(this Process process, TimeSpan warningTimeout, string processTitle) + { + if (!process.WaitForExit((int)warningTimeout.TotalMilliseconds)) + { + Utils.Status($"{processTitle} - Taking a long time to exit.", alsoLog: true); + process.WaitForExit(); + Utils.Status($"{processTitle} - Exited after a long period.", alsoLog: true); + } + } + } +} diff --git a/Wabbajack.Common/FileExtractor.cs b/Wabbajack.Common/FileExtractor.cs index 904111a4..6a9faaf7 100644 --- a/Wabbajack.Common/FileExtractor.cs +++ b/Wabbajack.Common/FileExtractor.cs @@ -107,7 +107,7 @@ namespace Wabbajack.Common Utils.Error(e, "Error while reading StandardOutput for innounp.exe"); } - p.WaitForExit(); + p.WaitForExitAndWarn(TimeSpan.FromSeconds(30), $"Extracting {name}"); if (p.ExitCode == 0) return; @@ -204,15 +204,10 @@ namespace Wabbajack.Common { } - if (!p.WaitForExit(30000)) - { - Utils.Status($"Extracting {name} - Taking a long time to exit.", alsoLog: true); - p.WaitForExit(); - } + p.WaitForExitAndWarn(TimeSpan.FromSeconds(30), $"Extracting {name}"); if (p.ExitCode == 0) { - Utils.Log(new GenericInfo($"Extracted {Path.GetFileName(source)}")); return; } Utils.Log(new _7zipReturnError(p.ExitCode, source, dest, p.StandardOutput.ReadToEnd())); @@ -260,7 +255,7 @@ namespace Wabbajack.Common Utils.Status($"Testing {name} - {line.Trim()}"); } - p.WaitForExit(); + p.WaitForExitAndWarn(TimeSpan.FromSeconds(30), $"Testing {name}"); return p.ExitCode == 0; } @@ -297,7 +292,7 @@ namespace Wabbajack.Common } } catch (Exception){} - testP.WaitForExit(); + testP.WaitForExitAndWarn(TimeSpan.FromSeconds(30), $"Can Extract Check {v}"); return testP.ExitCode == 0; } } diff --git a/Wabbajack.Common/Utils.cs b/Wabbajack.Common/Utils.cs index c72edef5..fb02fede 100644 --- a/Wabbajack.Common/Utils.cs +++ b/Wabbajack.Common/Utils.cs @@ -1008,7 +1008,7 @@ namespace Wabbajack.Common if (line == null) break; Status(line); } - p.WaitForExit(); + p.WaitForExitAndWarn(TimeSpan.FromSeconds(30), $"Deletion process of {path}"); } /// diff --git a/Wabbajack.Common/Wabbajack.Common.csproj b/Wabbajack.Common/Wabbajack.Common.csproj index b8cfa161..bbe54f78 100644 --- a/Wabbajack.Common/Wabbajack.Common.csproj +++ b/Wabbajack.Common/Wabbajack.Common.csproj @@ -103,6 +103,7 @@ +