-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
105 lines (95 loc) · 3.47 KB
/
Copy pathProgram.cs
File metadata and controls
105 lines (95 loc) · 3.47 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Serilog;
using System;
using System.IO;
namespace GModContentWizard
{
/// <summary>
/// Main entry point for the GModContentWizard application.
/// </summary>
class Program
{
/// <summary>
/// Application entry point with logging and exception handling.
/// </summary>
/// <param name="args">Command line arguments.</param>
[STAThread]
public static void Main(string[] args)
{
var logDir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"GModContentWizard",
"logs");
Directory.CreateDirectory(logDir);
var logPath = Path.Combine(logDir, "app-.log");
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.File(logPath,
rollingInterval: RollingInterval.Day,
retainedFileCountLimit: 2,
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
.CreateLogger();
try
{
Log.Information("Application starting");
var builder = BuildAvaloniaApp();
bool useSoftwareRender = args.Contains("--software-render");
if (!useSoftwareRender && IsNvidiaSystem())
{
Log.Warning("NVIDIA detected, using software rendering to avoid shutdown crash");
useSoftwareRender = true;
}
if (useSoftwareRender)
{
builder.With(new X11PlatformOptions
{
RenderingMode = new[] { X11RenderingMode.Software }
});
}
builder.StartWithClassicDesktopLifetime(args);
}
catch (Exception ex)
{
Log.Fatal(ex, "Application terminated unexpectedly");
}
finally
{
Log.CloseAndFlush();
}
}
/// <summary>
/// Checks if running on an NVIDIA system (heuristic).
/// </summary>
private static bool IsNvidiaSystem()
{
try
{
var nvidiaFiles = new[] {
"/lib/libnvidia-gl.so.1",
"/usr/lib/libnvidia-gl.so.1",
"/lib64/libnvidia-gl.so.1"
};
foreach (var path in nvidiaFiles)
{
if (File.Exists(path))
return true;
}
var procModules = File.ReadAllText("/proc/modules");
if (procModules.Contains("nvidia"))
return true;
}
catch { }
return false;
}
/// <summary>
/// Creates and configures the Avalonia application builder.
/// </summary>
/// <returns>The configured AppBuilder instance.</returns>
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
}
}