-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameVersion.cs
More file actions
227 lines (195 loc) · 8.08 KB
/
GameVersion.cs
File metadata and controls
227 lines (195 loc) · 8.08 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
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
using System;
using System.Collections.Generic;
using System.Xml;
using XmlData;
namespace GameSaveInfo {
public class GameVersion : AXmlDataSubEntry {
public GameIdentifier ID { get; protected set; }
public Game Game {
get {
return this.Parent as Game;
}
}
public List<string> Contributors = new List<string>();
public string Comment { get; protected set; }
public string RestoreComment { get; protected set; }
public bool IgnoreVirtualStore { get; protected set; }
private bool _deprecated = false;
public bool IsDeprecated {
get {
if (Game.IsDeprecated)
return true;
else
return _deprecated;
}
protected set {
_deprecated = value;
}
}
public bool DetectionRequired { get; protected set; }
public List<Link> Links = new List<Link>();
public List<Identifier> Identifiers = new List<Identifier>();
public Dictionary<string, FileType> FileTypes = new Dictionary<string, FileType>();
public override string ElementName {
get { return "version"; }
}
protected string _title = null;
public string Title {
get {
if (String.IsNullOrEmpty(_title))
return Game.Title;
return _title;
}
}
public List<ALocation> AllLocations {
get {
if (Locations != null)
return Locations.AllLocations;
else
return new List<ALocation>();
}
}
private Locations _locations;
public Locations Locations {
get {
if (_locations == null)
_locations = new Locations(this);
return _locations;
}
protected set {
_locations = value;
}
}
public List<APlayStationID> PlayStationIDs = new List<APlayStationID>();
public List<ScummVM> ScummVMs = new List<ScummVM>();
public GameVersion(Game parent, string os, string platform, string release)
: base(parent) {
DetectionRequired = false;
this.ID = new GameIdentifier(parent.Name, os, platform, null, null, release, null,0);
}
public GameVersion(Game parent, XmlElement ele)
: base(parent, ele) {
DetectionRequired = false;
}
protected override void LoadData(XmlElement element) {
this.ID = new GameIdentifier(Game.Name, element);
foreach (XmlAttribute attrib in element.Attributes) {
if (GameIdentifier.attributes.Contains(attrib.Name))
continue;
switch (attrib.Name) {
case "virtualstore":
IgnoreVirtualStore = attrib.Value == "ignore";
break;
case "detect":
DetectionRequired = attrib.Value == "required";
break;
case "deprecated":
IsDeprecated = Boolean.Parse(attrib.Value);
break;
default:
throw new NotSupportedException(attrib.Name);
}
}
Links.Clear();
foreach (XmlElement sub in element.ChildNodes) {
switch (sub.Name) {
case "title":
_title = sub.InnerText;
break;
case "locations":
this.Locations = new GameSaveInfo.Locations(this, sub);
break;
case "files":
FileType type = new FileType(this, sub);
FileTypes.Add(type.Type, type);
break;
case "ps_code":
PlayStationIDs.Add(APlayStationID.Create(this, sub));
break;
case "contributor":
Contributors.Add(sub.InnerText);
break;
case "comment":
Comment = sub.InnerText;
break;
case "restore_comment":
RestoreComment = sub.InnerText;
break;
case "identifier":
Identifiers.Add(new Identifier(this, sub));
break;
case "scummvm":
ScummVMs.Add(new ScummVM(this, sub));
break;
case "linkable":
Links.Add(new Link(this, sub));
break;
case "registry":
RegistryType rtype = new RegistryType(this, sub);
RegistryTypes.Add(rtype.Type, rtype);
break;
default:
throw new NotSupportedException(sub.Name);
}
}
}
protected override XmlElement WriteData(XmlElement element) {
// This outputs little more than what's necessary to create a custom game entry
// Once in the file, the xml wil not need to be re-generated, so it won't need to be outputted again
// This way manual updates to the xml file won't be lost ;)
ID.AddAttributes(element);
if (element.HasAttribute("name"))
element.RemoveAttribute("name");
element.AppendChild(Locations.XML);
foreach (FileType type in FileTypes.Values) {
element.AppendChild(type.XML);
}
foreach (string con in Contributors) {
element.AppendChild(Game.createElement("contributor", con));
}
if (!String.IsNullOrEmpty(Comment))
element.AppendChild(Game.createElement("comment", Comment));
if (!String.IsNullOrEmpty(RestoreComment))
element.AppendChild(Game.createElement("restore_comment", RestoreComment));
return element;
}
public void addLocation(ALocation loc) {
Locations.addLocation(loc);
}
public void addContributor(string name) {
if (!Contributors.Contains(name)) {
XmlElement cont = createElement("contributor");
cont.InnerText = name;
this.XML.AppendChild(cont);
Contributors.Add(name);
}
}
public FileType addFileType(string name) {
if (String.IsNullOrEmpty(name))
name = "";
if (!this.FileTypes.ContainsKey(name)) {
FileType type = new FileType(this, name);
this.FileTypes.Add(name, type);
this.XML.AppendChild(type.XML);
}
return this.FileTypes[name];
}
public Dictionary<string, RegistryType> RegistryTypes = new Dictionary<string, RegistryType>();
public RegistryEntry addRegEntry(RegRoot root, string key, string value, string type) {
if (!RegistryTypes.ContainsKey(type)) {
RegistryType reg = new RegistryType(this, type);
this.XML.AppendChild(reg.XML);
RegistryTypes.Add(type, reg);
}
RegistryType registry = RegistryTypes[type];
RegistryEntry entry = registry.addEntry(root, key, type);
return entry;
}
public Link addLink(string path) {
Link link = new Link(this, path);
this.XML.AppendChild(link.XML);
Links.Add(link);
return link;
}
}
}