private void btnOK_Click(object sender, EventArgs e) { DataLocation data = null; if (editDataIndex == null) { data = new DataLocation(); game.DataLocations.Add(data); } else { data = game.DataLocations[Convert.ToInt32(editDataIndex)]; } if (cbCategory.Text != string.Empty) { if (!game.Categories.Contains(cbCategory.Text)) { game.Categories.Add(cbCategory.Text); } } data.Description = txtDescription.Text; if (chkOneByte.Checked) { data.EndOffset = Convert.ToInt32(txtStartOffset.Text, 16); } else { if (!string.IsNullOrEmpty(txtEndOffset.Text)) { data.EndOffset = Convert.ToInt32(txtEndOffset.Text, 16); } } data.StartOffset = Convert.ToInt32(txtStartOffset.Text, 16); data.Name = txtName.Text; data.Category = cbCategory.Text; }
/// <summary> /// Loads the ROM data from an XML file. /// </summary> /// <param name="filename">The filename of the XML file.</param> /// <returns>A Game object that represents the data in the XML file.</returns> public Game LoadROMData(string filename) { Game game = new Game(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(filename); foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) { // Retrieve the name of the game. if (node.Name == "name") { game.Name = node.InnerText; } if (node.Name == "size") { game.Size = Convert.ToInt32(node.InnerText, 16); } if (node.Name == "categories") { foreach (XmlNode category in node.ChildNodes) { game.Categories.Add(category.InnerText); } } if (node.Name == "dataformats") { foreach (XmlNode dataformat in node.ChildNodes) { string name = string.Empty; // Attempt to search for the name attribute. foreach (XmlAttribute att in dataformat.Attributes) { if (att.Name == "name") { name = att.InnerText; } } game.DataFormats.Add(name, dataformat.InnerText); } } if (node.Name == "datalocations") { foreach (XmlNode datalocs in node.ChildNodes) { DataLocation loc = new DataLocation(); foreach (XmlAttribute att in datalocs.Attributes) { if (att.Name == "name") { loc.Name = att.InnerText; } else if (att.Name == "startOffset") { loc.StartOffset = Convert.ToInt32("0x" + att.InnerText, 16); } else if (att.Name == "endOffset") { loc.EndOffset = Convert.ToInt32("0x" + att.InnerText, 16); } else if (att.Name == "category") { loc.Category = att.InnerText; } } foreach (XmlNode descnode in datalocs.ChildNodes) { if (descnode.Name == "description") { loc.Description = descnode.InnerText; } } game.DataLocations.Add(loc); } } } game.SortDataLocations(); return game; }