using System;
using System.IO;
public static class CheckpointCollector
{
public static int Main(string[] args)
{
string root = Environment.GetEnvironmentVariable("CHECKPOINT_TEST_ROOT");
string script = File.ReadAllText(args[Array.IndexOf(args, "-File") + 1]);
if (script.Contains("UIAutomationClient") || script.Contains(".Select()") || script.Contains("SetConsoleTitle"))
throw new InvalidOperationException("save attempted active UI capture");
int selector = Array.IndexOf(args, "-WindowSelector");
File.AppendAllText(Path.Combine(root, "selectors"), (selector >= 0 ? args[selector + 1] : "<auto>") + "\n");
string counter = Path.Combine(root, "attempts");
int attempt = File.Exists(counter) ? int.Parse(File.ReadAllText(counter)) : 0;
File.WriteAllText(counter, (attempt + 1).ToString());
int phase = attempt;
while (phase > 0 && !File.Exists(Path.Combine(root, "reply-" + phase + ".json"))) phase--;
string reply = Path.Combine(root, "reply-" + phase + ".json");
Console.Write(File.ReadAllText(reply));
return 0;
}
}