/
HallOfFame.cs
153 lines (134 loc) · 3.76 KB
/
HallOfFame.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
// 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.Xml;
namespace CPWizard
{
public class HallOfFameNode
{
public string ROMName = null;
//public string Description = null;
//public string Manufacturer = null;
public float WeightedAverage = 0f;
public int Votes = 0;
//public string Category = null;
//public string Genre = null;
public HallOfFameNode(string romName, float weightedAverage, int votes)
{
ROMName = romName;
WeightedAverage = weightedAverage;
Votes = votes;
}
/* public HallOfFameNode(string romName, string description, string manufacturer, float weightedAverage, int votes, string category, string genre)
{
ROMName = romName;
Description = description;
Manufacturer = manufacturer;
WeightedAverage = weightedAverage;
Votes = votes;
Category = category;
Genre = genre;
} */
}
public class HallOfFame : IDisposable
{
public enum XmlElement
{
Nothing,
Game
}
//private List<HallOfFameNode> m_gameArray = null;
private Dictionary<string, HallOfFameNode> m_gameDictionary = null;
public HallOfFame()
{
//m_gameArray = new List<HallOfFameNode>();
m_gameDictionary = new Dictionary<string, HallOfFameNode>();
}
public void ReadHallOfFameXml(string fileName)
{
XmlElement currentElement = XmlElement.Nothing;
Hashtable attribHash = new Hashtable();
HallOfFameNode currentGame = null;
XmlReader xmlReader = null;
try
{
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.ProhibitDtd = false;
xmlReader = XmlReader.Create(fileName, xmlReaderSettings);
while (xmlReader.Read())
{
switch (xmlReader.NodeType)
{
case XmlNodeType.Element:
switch (xmlReader.LocalName.ToLower())
{
case "game":
currentElement = XmlElement.Game;
break;
default:
currentElement = XmlElement.Nothing;
break;
}
if (xmlReader.HasAttributes)
{
attribHash.Clear();
while (xmlReader.MoveToNextAttribute())
attribHash.Add(xmlReader.Name.ToLower(), xmlReader.Value);
}
switch (currentElement)
{
case XmlElement.Game:
string romName = (string)attribHash["name"];
//currentGame = new HallOfFameNode(ROMName, (string)AttribHash["description"], (string)AttribHash["manufacturer"], StringTools.FromString<float>((string)AttribHash["weightedaverage"]), StringTools.FromString<int>((string)AttribHash["votes"]), (string)AttribHash["category"], (string)AttribHash["genre"]);
currentGame = new HallOfFameNode(romName, StringTools.FromString<float>((string)attribHash["weightedaverage"]), StringTools.FromString<int>((string)attribHash["votes"]));
m_gameDictionary.Add(romName, currentGame);
break;
default:
break;
}
xmlReader.MoveToElement();
break;
case XmlNodeType.EndElement:
switch (currentElement)
{
case XmlElement.Game:
currentGame = null;
break;
default:
break;
}
break;
}
}
}
catch (Exception ex)
{
LogFile.WriteLine("ReadHallOfFameXml", "HallOfFameXml", ex.Message, ex.StackTrace);
}
finally
{
if (xmlReader != null)
{
xmlReader.Close();
xmlReader = null;
}
}
}
public Dictionary<string, HallOfFameNode> GameDictionary
{
get { return m_gameDictionary; }
}
#region IDisposable Members
public void Dispose()
{
m_gameDictionary.Clear();
}
#endregion
}
}