Skip to content

Commit

Permalink
Add timeout for running cli tools + workaround for setup.exe
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Nov 7, 2024
1 parent 17ff0a0 commit 8dd58d3
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions generator/CSharpReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using NuGet.Common;
using NuGet.Packaging;

Expand Down Expand Up @@ -153,16 +152,20 @@ public static async Task UpdateVpkCliReference(string outputCliReference)

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
Console.WriteLine("Generating Win Setup.exe");
var setupExe = Path.Combine(extractedVpk, "vendor", "setup.exe");
var setupHelp = await RunCaptureStdOut(setupExe, ["-h"]);
File.WriteAllText(
Path.Combine(outputCliReference, "setup-windows.mdx"),
$"""
try {
var setupExe = Path.Combine(extractedVpk, "vendor", "setup.exe");
var setupHelp = await RunCaptureStdOut(setupExe, ["-h"]);
File.WriteAllText(
Path.Combine(outputCliReference, "setup-windows.mdx"),
$"""
# Setup.exe (Windows)
```
{setupHelp}
```
""");
} catch (TaskCanceledException ex) {
Console.WriteLine("Failed to generate setup-windows.mdx: " + ex.Message);
}

Console.WriteLine("Generating Win Update.exe");
var updateExe = Path.Combine(extractedVpk, "vendor", "update.exe");
Expand Down Expand Up @@ -362,7 +365,9 @@ static async Task<string> RunCaptureStdOut(ProcessStartInfo psi)
p.OutputDataReceived += (sender, e) => sw.AppendLine(e?.Data);
p.Start();
p.BeginOutputReadLine();
await p.WaitForExitAsync();

var timeout = new CancellationTokenSource(60 * 1000);
await p.WaitForExitAsync(timeout.Token);
return sw.ToString();
}
}

0 comments on commit 8dd58d3

Please sign in to comment.