Include dates in console messages

This commit is contained in:
Liza 2024-03-16 11:24:26 +01:00
parent b366db9cae
commit f1373fcbfa
Signed by: liza
GPG Key ID: 7199F8D727D55F67

View File

@ -23,18 +23,20 @@ internal sealed class Program
e.Cancel = true; e.Cancel = true;
}; };
try
{
while (!cts.IsCancellationRequested) while (!cts.IsCancellationRequested)
{ {
var launchers = Process.GetProcessesByName("XIVLauncher").Where(x => !x.HasExited).ToArray(); var launchers = Process.GetProcessesByName("XIVLauncher").Where(x => !x.HasExited).ToArray();
if (launchers.Length >= 2) if (launchers.Length >= 2)
{ {
Console.WriteLine("Found multiple launcher instances??"); Console.WriteLine($"[{DateTime.Now}] Found multiple launcher instances??");
KillAll(launchers); KillAll(launchers);
continue; continue;
} }
else if (launchers.Length == 1) else if (launchers.Length == 1)
{ {
Console.WriteLine($"Waiting for launcher {launchers.Single().Id} to finish"); Console.WriteLine($"[{DateTime.Now}] Waiting for launcher {launchers.Single().Id} to finish");
await launchers.Single().WaitForExitAsync(cts.Token).ConfigureAwait(false); await launchers.Single().WaitForExitAsync(cts.Token).ConfigureAwait(false);
await Task.Delay(1000, cts.Token).ConfigureAwait(false); await Task.Delay(1000, cts.Token).ConfigureAwait(false);
continue; continue;
@ -43,35 +45,45 @@ internal sealed class Program
var ffxiv = Process.GetProcessesByName("ffxiv_dx11").Where(x => !x.HasExited).ToArray(); var ffxiv = Process.GetProcessesByName("ffxiv_dx11").Where(x => !x.HasExited).ToArray();
if (ffxiv.Length >= 2) if (ffxiv.Length >= 2)
{ {
Console.WriteLine("Found multiple XIV instances??"); Console.WriteLine($"[{DateTime.Now}] Found multiple XIV instances??");
KillAll(ffxiv); KillAll(ffxiv);
continue; continue;
} }
else if (ffxiv.Length == 1) else if (ffxiv.Length == 1)
{ {
Console.WriteLine($"Waiting for FFXIV {ffxiv.Single().Id} to finish"); Console.WriteLine($"[{DateTime.Now}] Waiting for FFXIV {ffxiv.Single().Id} to finish");
await ffxiv.Single().WaitForExitAsync(cts.Token).ConfigureAwait(false); await ffxiv.Single().WaitForExitAsync(cts.Token).ConfigureAwait(false);
} }
else else
{ {
var process = Process.Start(new ProcessStartInfo var process = Process.Start(new ProcessStartInfo
{ {
FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), FileName = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
@"XIVLauncher\XIVLauncher.exe"), @"XIVLauncher\XIVLauncher.exe"),
UseShellExecute = false, UseShellExecute = false,
}); });
if (process != null) if (process != null)
{ {
await process.WaitForExitAsync(cts.Token).ConfigureAwait(false); await process.WaitForExitAsync(cts.Token).ConfigureAwait(false);
Console.WriteLine("Started launcher..."); Console.WriteLine($"[{DateTime.Now}] Started launcher...");
} }
else else
Console.WriteLine("No process started?"); Console.WriteLine($"[{DateTime.Now}] No process started?");
} }
await Task.Delay(1000, cts.Token).ConfigureAwait(false); await Task.Delay(1000, cts.Token).ConfigureAwait(false);
} }
} }
catch (TaskCanceledException)
{
// expected if we press ctrl-c
}
catch (Exception e)
{
Console.WriteLine($"[{DateTime.Now}] Unexpected exception: {e}");
}
}
private static void KillAll(Process[] processes) private static void KillAll(Process[] processes)
{ {