-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
144 lines (121 loc) · 5.28 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Tao.Platform.Windows;
using System.IO;
namespace MinecraftTextureStudio
{
public class Program
{
public static Thread mainThread;
public static Thread openGLThread;
public static bool done;
static void Main()
{
Application.ThreadException += new ThreadExceptionEventHandler(UIThreadException);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
try
{
Application.EnableVisualStyles();
mainThread = new Thread(runMainForm);
mainThread.SetApartmentState(ApartmentState.STA);
mainThread.Start();
openGLThread = new Thread(runOpenGL);
openGLThread.SetApartmentState(ApartmentState.STA);
openGLThread.Start();
}
catch (Exception exception)
{
MessageBox.Show("Exception occured in main: " + exception.Message + "\n" +
exception.StackTrace);
}
}
public static void UIThreadException(object sender, ThreadExceptionEventArgs e)
{
DateTime date = DateTime.Now;
string strDate = date.ToString("yyyyMMMMddmmHHss");
Exception exception = (Exception)e.Exception;
StreamWriter writer = new StreamWriter(new FileStream("error-log-" + strDate + ".log", FileMode.Create, FileAccess.Write));
writer.WriteLine("Exception message: " + exception.Message);
if (exception.InnerException != null)
{
writer.WriteLine("Inner exception: " + exception.InnerException.Message);
writer.WriteLine("Inner exception stack trace");
writer.WriteLine(exception.InnerException.StackTrace);
}
writer.WriteLine("Stack Trace");
writer.WriteLine(exception.StackTrace);
writer.Close();
}
public static void CurrentDomain_UnhandledException(Object sender, UnhandledExceptionEventArgs e)
{
DateTime date = DateTime.Now;
string strDate = date.ToString("yyyyMMddmmHHss");
Exception exception = (Exception)e.ExceptionObject;
StreamWriter writer = new StreamWriter(new FileStream("error-log-" + strDate + ".log", FileMode.Create, FileAccess.Write));
writer.WriteLine("Exception message: " + exception.Message);
if (exception.InnerException != null)
{
writer.WriteLine("Inner exception: " + exception.InnerException.Message);
writer.WriteLine("Inner exception stack trace");
writer.WriteLine(exception.InnerException.StackTrace);
}
writer.WriteLine("Stack Trace");
writer.WriteLine(exception.StackTrace);
writer.Close();
MessageBox.Show("An exception occurred in Minecraft Texture Studio. " +
"Please email the file error-log-" + strDate + ".log in your Minecraft Texture Studio directory " +
"to tertrihfertray@gmail.com as it contains invaluable diagnostic information " +
"that will help fix bugs in the program. Thank you, and sorry for the inconvenience", "Unhandled exception");
}
public static void runMainForm()
{
try
{
Application.Run(new FrmMain());
}
catch (Exception exception)
{
MessageBox.Show("Exception occured running main form: " + exception.Message);
Program.done = true;
}
}
public static void runOpenGL()
{
while (!FrmMain.done)
{
Program.done = false;
try
{
FrmTexturePreview form = new FrmTexturePreview();
if (!FrmTexturePreview.createWindow("Texture preview Click and hold to rotate the block, right click to paint", 640, 480, 16))
{
return;
}
while (!Program.done)
{
Application.DoEvents();
if (FrmTexturePreview.active && (form != null) && !FrmTexturePreview.render())
{
Program.done = true;
}
else
{
Gdi.SwapBuffers(FrmTexturePreview.hDC);
}
}
FrmTexturePreview.closeOpenGLwindow();
}
catch (Exception exception)
{
MessageBox.Show("Exception occured running opengl program loop: " + exception.Message);
}
}
}
}
}