forked from ExOK/Celeste64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
73 lines (63 loc) · 1.77 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
using System.Diagnostics;
using System.Globalization;
using System.Text;
namespace Celeste64;
class Program
{
public static void Main(string[] args)
{
Log.Info($"Celeste 64 v.{Game.Version.Major}.{Game.Version.Minor}.{Game.Version.Build}");
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.Version.Major}.{Game.Version.Minor}.{Game.Version.Build}");
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();
}
}
}