public bool Load(string fileName) { if (!File.Exists(fileName)) { return(false); } using (FileStream stream = new FileStream(fileName, FileMode.Open)) { XmlSerializer deserializer = new XmlSerializer(typeof(Quest), ManagerArray.GetAllDetailTypes()); try { Quest loadedQuest = (Quest)deserializer.Deserialize(stream); if (loadedQuest.version == null) { System.Windows.Forms.MessageBox.Show("The selected xml file does not contain a version number. \n\nThe save file is likely earlier than SOC 0.7.0.0 and no longer supported.", "SOC", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return(false); } coreDetails = loadedQuest.coreDetails; questObjectDetails = loadedQuest.questObjectDetails; return(true); } catch (InvalidOperationException e) { System.Windows.Forms.MessageBox.Show(string.Format("An Exception has occurred and the selected xml file could not be loaded. \n\nInnerException message: \n{0}", e.InnerException), "SOC", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } return(false); }
public void Save(string fileName) { using (FileStream stream = new FileStream(fileName, FileMode.Create)) { XmlSerializer serializer = new XmlSerializer(typeof(Quest), ManagerArray.GetAllDetailTypes()); serializer.Serialize(stream, this); } }