forked from YSRKEN/HSP-Decompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HspConsole.cs
165 lines (144 loc) · 3.57 KB
/
HspConsole.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace KttK.HspDecompiler
{
internal static class HspConsole
{
private static int startTime = Environment.TickCount;
private static string newLine = null;
private static StreamWriter logStream;
internal static void Initialize()
{
}
internal static void ExceptionHandlingClose(Exception e)
{
WriteLog(e.GetType().ToString() +":" + e.Source + ":" + e.Message );
WriteLog("abort");
if (logStream != null)
{
logStream.Close();
MessageBox.Show("例外を適切にcatchできませんでした。詳細をlog.datに出力し終了します。", "致命的なエラー");
}
logStream = null;
}
internal static void Close()
{
WriteLog("exit");
if (logStream != null)
logStream.Close();
logStream = null;
}
internal static string NewLine
{
get { return HspConsole.newLine; }
}
internal static void DecompStart(string filePath)
{
startTime = Environment.TickCount;
newLine = null;
tabCount = 0;
warnings.Clear();
StringBuilder builder = new StringBuilder();
builder.Append("経過(ms)");
builder.Append(':');
builder.Append("処理内容");
newLine = builder.ToString();
Flush();
WriteLog("decompile " + Path.GetFileName(filePath));
}
private static int tabCount = 0;
internal static void Write(string line)
{
int time = Environment.TickCount - startTime;
StringBuilder builder = new StringBuilder();
builder.Append(time.ToString("D08"));
builder.Append(':');
builder.Append(' ', tabCount*2);
builder.Append(line);
newLine = builder.ToString();
Flush();
}
internal static void StartParagraph()
{
tabCount++;
}
internal static void EndParagraph()
{
tabCount--;
}
internal static void BreakParagraph()
{
tabCount = 0;
}
internal static void Warning(string errMsg, int lineNo)
{
string warning = string.Format("{0:D06}行:{1}", lineNo, errMsg);
warnings.Add(warning);
//newLine = warning;
//Flush();
}
internal static void Warning(string errMsg)
{
warnings.Add(errMsg);
//newLine = warning;
//Flush();
}
private static List<string> warnings = new List<string>();
internal static List<string> Warnings
{
get { return HspConsole.warnings; }
}
internal static void FatalError(string line)
{
int time = Environment.TickCount - startTime;
StringBuilder builder = new StringBuilder();
builder.Append(time.ToString("D08"));
builder.Append(':');
builder.Append(line);
newLine = builder.ToString();
Flush();
}
internal static void FatalError(Exception e)
{
int time = Environment.TickCount - startTime;
StringBuilder builder = new StringBuilder();
StringBuilder logBuilder = new StringBuilder();
builder.Append(time.ToString("D08"));
builder.Append(':');
if (e is SystemException)
{
logBuilder.Append(e.GetType().ToString());
logBuilder.Append(':');
logBuilder.Append(e.Source);
logBuilder.Append(':');
}
else
{
logBuilder.Append("HspDecoderException:");
}
logBuilder.Append(e.Message);
builder.Append(logBuilder);
newLine = builder.ToString();
Flush();
WriteLog(logBuilder.ToString());
}
internal delegate void WriteDown();
internal static event WriteDown Flush;
private static void HspConsole_Flush()
{
WriteLog(newLine);
}
internal static void WriteLog(string line)
{
if (string.IsNullOrEmpty(line))
return;
if (logStream == null)
return;
logStream.WriteLine(DateTime.Now.ToString() + ":" + line);
logStream.Flush();
}
}
}