public void Save(string file) { //get data and update the MAINBUFFER ValidifyModifiersCheckBoxes(); if (FormDatatoMAINBUFFER()) { string ext = Path.GetExtension(file); if (ext == ".xml") { using (TextWriter TW = new StreamWriter(File.Open(file, FileMode.Create))) { SValue.SaveXML(MAINBUFFER, TW); } } else if (ext == ".hws") { using (BinaryWriter BW = new BinaryWriter(File.Open(file, FileMode.Create))) { SValue.SaveStream(MAINBUFFER, BW); } } else { MessageBox.Show("Invalid save file type. You must save with either an XML or HWS extension so we know how to save the file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); toolStripStatusLabel.Text = "Error encountered while saving."; toolStripStatusLabel.ToolTipText = "Invalid save file type. You must save with either an XML or HWS extension so we know how to save the file."; return; } toolStripStatusLabel.Text = "Successfully saved data."; toolStripStatusLabel.ToolTipText = "Successfully saved data to: \"" + file + "\""; } }
private void toXMLToolStripMenuItem_Click(object sender, EventArgs e) { // Ask for input file DialogResult result = openHWSConvertDialog.ShowDialog(); if (result == DialogResult.OK) { string inFile = openHWSConvertDialog.FileName; // Ask where to save converted file saveXMLConvertDialog.FileName = Path.GetFileNameWithoutExtension(inFile) + ".xml"; result = saveXMLConvertDialog.ShowDialog(); if (result == DialogResult.OK) { string outFile = saveXMLConvertDialog.FileName; BinaryReader BR = new BinaryReader(File.Open(inFile, FileMode.Open)); SValue OBJ = SValue.LoadStream(BR); TextWriter TW = new StreamWriter(outFile); SValue.SaveXML(OBJ, TW); TW.Close(); toolStripStatusLabel.Text = "Successfully converted file."; toolStripStatusLabel.ToolTipText = "Successfully converted \"" + inFile + "\" to \"" + outFile + "\""; return; } } toolStripStatusLabel.Text = "Conversion canceled."; toolStripStatusLabel.ToolTipText = "Conversion canceled."; }