Files
GSS2Rework/GSS2.Test/Program.cs
T

67 lines
1.9 KiB
C#

using Avalonia;
using Avalonia.OpenGL.Egl;
using System.CommandLine;
namespace GSS2.Test;
public partial class Program
{
private enum RenderingMode
{
X11,
DRM
}
private static string[]? _args = null;
private static readonly RootCommand _rootCommand = new("GranuSight Software 2");
private static readonly Command _cameraTuningCommand = new("camera-tuning")
{
Description = "Tune camera parameters"
};
private static readonly Option<RenderingMode> _renderingModeArgument = new("--rendering-mode")
{
Description = "Rendering mode to use",
DefaultValueFactory = (_) => RenderingMode.X11
};
private static readonly Option<bool> _hideConsoleArgument = new("--hide-console")
{
Description = "Suppress console output",
DefaultValueFactory = (result) => result.GetRequiredValue(_renderingModeArgument) == RenderingMode.DRM
};
public static event ConsoleCancelEventHandler? ShutdownRequested;
[STAThread]
public static int Main(string[] args)
{
_args = args;
_rootCommand.Add(_cameraTuningCommand);
_rootCommand.Add(_renderingModeArgument);
_rootCommand.Add(_hideConsoleArgument);
_rootCommand.SetAction(Ui);
_cameraTuningCommand.SetAction(CameraTuning);
Console.CancelKeyPress += new ConsoleCancelEventHandler(OnProgramShutdown);
Console.WriteLine("Press Ctrl+C to shut down.");
var parseResult = _rootCommand.Parse(_args);
if (parseResult.Errors.Count() != 0)
{
foreach (var parseError in parseResult.Errors)
Console.Error.WriteLine(parseError.Message);
return 1;
}
return parseResult.Invoke();
}
private static void OnProgramShutdown(object? sender, ConsoleCancelEventArgs ea)
{
ShutdownRequested?.Invoke(sender, ea);
ea.Cancel = true;
}
}