forked from FujiAPI/Fuji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
88 lines (78 loc) · 2.36 KB
/
Program.cs
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
using Foster.Framework;
using System.Diagnostics;
using System.Globalization;
using System.Text;
namespace Celeste64.Launcher;
public class Program
{
// Copied from Celeste64 project
public static void Main(string[] args)
{
if (args.Contains("--console"))
{
ConsoleHelper.CreateConsole();
}
Version loaderVersion = typeof(Program).Assembly.GetName().Version!;
Game.LoaderVersion = $"Fuji: v.{loaderVersion.Major}.{loaderVersion.Minor}.{loaderVersion.Build}";
Game.IsDynamicRes = args.Contains("--dynamic-res");
if (!string.IsNullOrEmpty(BuildProperties.ModVersion()))
{
Game.LoaderVersion += "-" + BuildProperties.ModVersion();
}
Log.Info($"Celeste 64 v.{Game.GameVersion.Major}.{Game.GameVersion.Minor}.{Game.GameVersion.Build}");
Log.Info(Game.LoaderVersion);
AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) =>
{
HandleError((Exception)e.ExceptionObject);
};
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
try
{
App.Run<Game>(Game.GamePath, 1280, 720);
}
catch (Exception e)
{
HandleError(e);
}
}
private static void HandleError(Exception e)
{
// write error to console in case they can see stdout
Console.WriteLine(e?.ToString() ?? string.Empty);
// construct a log message
const string ErrorFileName = "ErrorLog.txt";
StringBuilder error = new();
error.AppendLine($"Celeste 64 v.{Game.GameVersion.Major}.{Game.GameVersion.Minor}.{Game.GameVersion.Build}");
error.AppendLine(Game.LoaderVersion);
error.AppendLine($"Error Log ({DateTime.Now})");
error.AppendLine($"Call Stack:");
error.AppendLine(e?.ToString() ?? string.Empty);
error.AppendLine($"Game Output:");
lock (Log.Logs)
error.AppendLine(Log.Logs.ToString());
// write to file
string path = ErrorFileName;
{
if (App.Running)
{
try
{
path = Path.Join(App.UserPath, ErrorFileName);
}
catch
{
path = ErrorFileName;
}
}
File.WriteAllText(path, error.ToString());
}
// open the file
if (File.Exists(path))
{
new Process { StartInfo = new ProcessStartInfo(path) { UseShellExecute = true } }.Start();
}
}
}