public static void SaveToXml(string filePath, SaveManager sourceObj) { if (sourceObj.titleId == null || sourceObj.codes.Count == 0) { return; } try { using (StreamWriter writer = new StreamWriter(filePath)) { System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(sourceObj.GetType()); xmlSerializer.Serialize(writer, sourceObj); } } catch (Exception ex) { Logger.Log("Exception saving codes [" + sourceObj + "] to XML file", ex); MessageBox.Show(ex.Message); } }
private void SaveButton_Click(object sender, EventArgs e) { SaveManager sm = new SaveManager(); sm.Init(); // Get a list of all saved addresses foreach (DataGridViewRow row in ValuesGrid.Rows) { if (row.Cells[1].Value is GateSharkCode) { // @TODO This will be different. } else if (row.Cells[1].Value is GateShark) { sm.gscodes.Add((GateShark)row.Cells[1].Value); } else { sm.codes.Add(new SaveCode(DataTypeExactTool.GetValue(row.Cells[3].Value.ToString()), row.Cells[1].Value.ToString())); } } // Set the values String[] parts_ = Processes.Text.Split('|'); if (parts_.Length < 2) return; String game = Config.ConfigFileDirectory + Path.DirectorySeparatorChar + parts_[1] + @".xml"; sm.titleId = parts_[1]; SaveManager.SaveToXml(game, sm); MessageBox.Show(@"Saved selected addresses to '" + game + "'"); }