/
HistoryDat.cs
228 lines (185 loc) · 4.62 KB
/
HistoryDat.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Copyright (c) 2015, Ben Baker
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing;
namespace CPWizard
{
class HistoryDat : TextViewer, IDisposable
{
public class BioNode
{
public List<string> Text = null;
public BioNode()
{
Text = new List<string>();
}
}
public class HistoryDatNode
{
public string Name = null;
public BioNode Bio = null;
public HistoryDatNode(string name, BioNode bio)
{
Name = name;
Bio = bio;
}
}
private enum HistoryDatElement
{
Nothing,
Comment,
Info,
Bio
}
public Dictionary<string, HistoryDatNode> HistoryDatHash = null;
private Font m_font = new Font("Lucida Console", 14, FontStyle.Bold);
public HistoryDat()
: base()
{
HistoryDatHash = new Dictionary<string, HistoryDatNode>();
}
public override void GetLineData()
{
try
{
HistoryDatNode HistoryDat = null;
if (Settings.MAME.GameName == null)
return;
if (!HistoryDatHash.TryGetValue(Settings.MAME.GameName, out HistoryDat))
return;
Lines.Clear();
//AddLine(HistoryDat.Name);
foreach (string line in HistoryDat.Bio.Text)
AddLine(line);
base.GetLineData();
}
catch (Exception ex)
{
LogFile.WriteLine("GetLineData", "HistoryDat", ex.Message, ex.StackTrace);
}
}
public void ReadHistoryDat(string path)
{
ReadHistoryDat(Settings.Files.HistoryDat, null);
}
public void ReadHistoryDat(string path, string RomName)
{
try
{
HistoryDatElement CurrentElement = HistoryDatElement.Nothing;
List<string> ROMNames = new List<string>();
HistoryDatNode CurrentHistoryDat = null;
BioNode CurrentBio = null;
int EmptyLineCount = 0;
HistoryDatHash.Clear();
string[] Lines = File.ReadAllLines(path, Encoding.ASCII);
for (int i = 0; i < Lines.Length; i++)
{
string Line = Lines[i].Trim();
if (Line == String.Empty)
{
EmptyLineCount++;
if (EmptyLineCount == 2)
EmptyLineCount = 0;
else
continue;
}
else
EmptyLineCount = 0;
if (Line.StartsWith("#"))
{
CurrentElement = HistoryDatElement.Comment;
continue;
}
if (Line.StartsWith("$info"))
{
CurrentElement = HistoryDatElement.Info;
if (RomName != null && CurrentHistoryDat != null)
return;
CurrentHistoryDat = null;
CurrentBio = new BioNode();
string[] Values = Line.Split('=');
if (Values.Length == 2)
{
if (Values[1].Contains(","))
{
string[] Names = Values[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
for (int j = 0; j < Names.Length; j++)
{
if (!HistoryDatHash.ContainsKey(Names[j]))
{
if (RomName != null)
{
if (RomName == Names[j])
HistoryDatHash.Add(Names[j], CurrentHistoryDat = new HistoryDatNode(Names[j], CurrentBio));
}
else
HistoryDatHash.Add(Names[j], CurrentHistoryDat = new HistoryDatNode(Names[j], CurrentBio));
}
}
}
else
{
if (!HistoryDatHash.ContainsKey(Values[1]))
{
if (RomName != null)
{
if (RomName == Values[1])
HistoryDatHash.Add(Values[1], CurrentHistoryDat = new HistoryDatNode(Values[1], CurrentBio));
}
else
HistoryDatHash.Add(Values[1], CurrentHistoryDat = new HistoryDatNode(Values[1], CurrentBio));
}
}
}
continue;
}
if (Line.StartsWith("$bio"))
{
CurrentElement = HistoryDatElement.Bio;
continue;
}
if (Line.StartsWith("$end"))
{
CurrentElement = HistoryDatElement.Nothing;
continue;
}
switch (CurrentElement)
{
case HistoryDatElement.Bio:
if (CurrentHistoryDat != null)
{
if (CurrentHistoryDat.Bio != null)
CurrentHistoryDat.Bio.Text.Add(Line);
}
break;
}
//System.Windows.Forms.Application.DoEvents();
}
}
catch (Exception ex)
{
LogFile.WriteLine("ReadHistoryDat", "HistoryDat", ex.Message, ex.StackTrace);
}
}
public override bool CheckEnabled()
{
if (Settings.MAME.GameName == null)
return false;
if (!HistoryDatHash.ContainsKey(Settings.MAME.GameName))
return false;
return true;
}
public override void Reset(EmulatorMode mode)
{
base.Reset(mode);
}
}
}