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 toHWSToolStripMenuItem_Click(object sender, EventArgs e) { // Ask for input file DialogResult result = openXMLConvertDialog.ShowDialog(); if (result == DialogResult.OK) { string inFile = openXMLConvertDialog.FileName; // Ask where to save converted file saveHWSConvertDialog.FileName = Path.GetFileNameWithoutExtension(inFile) + ".hws"; result = saveHWSConvertDialog.ShowDialog(); if (result == DialogResult.OK) { string outFile = saveHWSConvertDialog.FileName; TextReader TR = new StreamReader(inFile); SValue OBJ = SValue.FromXMLFile(TR); BinaryWriter BW = new BinaryWriter(File.Open(outFile, FileMode.Create)); SValue.SaveStream(OBJ, BW); BW.Close(); toolStripStatusLabel.Text = "Successfully converted file."; toolStripStatusLabel.ToolTipText = "Successfully converted \"" + inFile + "\" to \"" + outFile + "\""; return; } } toolStripStatusLabel.Text = "Conversion canceled."; toolStripStatusLabel.ToolTipText = "Conversion canceled."; }