public static MacroManager Load(string fileName) { Console.WriteLine("Deserializing {0}.", fileName); FileStream fs = new FileStream(fileName, FileMode.Open); XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas()); DataContractSerializer ser = new DataContractSerializer(typeof(MacroManager)); MacroManager macroManager = (MacroManager)ser.ReadObject(reader, true); reader.Close(); fs.Close(); return(macroManager); }
public static void Save(string fileName, MacroManager controls) { Console.WriteLine("Serializing {0}.", fileName); DataContractSerializer ser = new DataContractSerializer(typeof(MacroManager)); var settings = new XmlWriterSettings { Indent = true }; using (var writer = XmlWriter.Create(fileName, settings)) { ser.WriteObject(writer, controls); writer.Flush(); } }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { saveFileDialogMacro.RestoreDirectory = true; saveFileDialogMacro.InitialDirectory = Environment.CurrentDirectory + @"\Saves"; saveFileDialogMacro.Filter = "R20CPCMG Macro (*.macro)|*.macro"; saveFileDialogMacro.DefaultExt = ".macro"; DialogResult result = saveFileDialogMacro.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { Console.WriteLine(saveFileDialogMacro.FileName); MacroManager manager = new MacroManager(); manager.Populate(flowLayoutPanelMacros); MacroManager.Save(saveFileDialogMacro.FileName, manager); } }
private void loadMacroToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialogMacro.RestoreDirectory = true; openFileDialogMacro.InitialDirectory = Environment.CurrentDirectory + @"\Saves"; openFileDialogMacro.Filter = "R20CPCMG Macro (*.macro)|*.macro"; openFileDialogMacro.DefaultExt = ".macro"; openFileDialogMacro.FileName = ""; DialogResult result = openFileDialogMacro.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { Console.WriteLine(openFileDialogMacro.FileName); MacroManager manager = MacroManager.Load(openFileDialogMacro.FileName); manager.ExtractControls(flowLayoutPanelMacros); RefreshMacro(); } }