ProcessExt: WaitForExitAndWarn

This commit is contained in:
Justin Swanson 2019-12-22 00:50:11 -06:00
parent a7aaac425a
commit 344c8e40d6
4 changed files with 28 additions and 10 deletions

View File

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

View File

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

View File

@ -1008,7 +1008,7 @@ namespace Wabbajack.Common
if (line == null) break;
Status(line);
}
p.WaitForExit();
p.WaitForExitAndWarn(TimeSpan.FromSeconds(30), $"Deletion process of {path}");
}
/// <summary>

View File

@ -103,6 +103,7 @@
<Compile Include="Extensions\EnumerableExt.cs" />
<Compile Include="Extensions\EnumExt.cs" />
<Compile Include="Extensions\HashHelper.cs" />
<Compile Include="Extensions\ProcessExt.cs" />
<Compile Include="Extensions\RxExt.cs" />
<Compile Include="Extensions\TaskExt.cs" />
<Compile Include="FileExtractor.cs" />