-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
82 lines (67 loc) · 2.52 KB
/
Program.cs
File metadata and controls
82 lines (67 loc) · 2.52 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
using System;
using System.IO;
using System.Threading;
using System.Text.Json;
using System.Windows.Forms;
using System.Collections.Generic;
namespace ResourceExplorer;
public static class Program
{
public static List<ResourcePack> Packs = new();
public static Dictionary<ulong, string> Names = new();
[STAThread]
private static void Main()
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
LoadNameList("NameList32.json", true);
LoadNameList("NameList64.json", false);
ApplicationConfiguration.Initialize();
Application.Run(new Main());
}
private static void LoadNameList(string path, bool crc32)
{
if (!File.Exists(path))
return;
var nameList = JsonSerializer.Deserialize<List<string>>(File.ReadAllText(path));
if (nameList is null)
return;
foreach (var name in nameList)
Names.TryAdd(crc32 ? Util.ComputeCrc32(name) : Util.ComputeCrc64(name), name);
}
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
try
{
var exception = string.Empty;
if (e.Exception is not null)
exception = $"{e.Exception.Message}{e.Exception.StackTrace}";
MessageBox.Show($"""
A critical error has occurred, please raise an issue in GitHub with the below information:
{exception}
""", "Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
finally
{
Application.Exit();
}
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
var exception = string.Empty;
if (e.ExceptionObject is Exception ex)
exception = $"{ex.Message}{ex.StackTrace}";
MessageBox.Show($"""
A critical error has occurred, please raise an issue in GitHub with the below information:
{exception}
""", "Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
finally
{
Application.Exit();
}
}
}