-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathProgram.cs
More file actions
67 lines (57 loc) · 1.85 KB
/
Program.cs
File metadata and controls
67 lines (57 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Avalonia;
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace N64RecompLauncher
{
class Program
{
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool AttachConsole(int dwProcessId);
[DllImport("kernel32.dll")]
private static extern bool FreeConsole();
private const int ATTACH_PARENT_PROCESS = -1;
[STAThread]
public static int Main(string[] args)
{
if (args.Length > 0 && args[0].StartsWith("-"))
{
if (OperatingSystem.IsWindows())
{
if (AttachConsole(ATTACH_PARENT_PROCESS))
{
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
Console.SetError(new StreamWriter(Console.OpenStandardError()) { AutoFlush = true });
}
}
int exitCode = RunCLI(args);
if (OperatingSystem.IsWindows())
{
FreeConsole();
}
return exitCode;
}
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
return 0;
}
private static int RunCLI(string[] args)
{
try
{
var cliHandler = new CLIHandler();
return cliHandler.Execute(args).GetAwaiter().GetResult();
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error: {ex.Message}");
return 1;
}
}
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}
}