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."; }
public void Open(string filename = null) { try { if (filename == null) { openDialog.InitialDirectory = GetDefaultFileDialogPath(); DialogResult result = openDialog.ShowDialog(); if (result == DialogResult.OK) { filename = openDialog.FileName; // If the user has no file open; or, if the user has a file open, they actually decided to close it (rather than cancel) if (!TryCloseFile()) { return; } } else { return; } } currentFile = filename; textBoxCurrentFile.Text = Path.GetFileName(currentFile); //load file to mainbuffer string ext = Path.GetExtension(currentFile); if (ext == ".xml") { using (StreamReader SR = new StreamReader(File.Open(currentFile, FileMode.Open))) { MAINBUFFER = SValue.FromXMLFile(SR); } } else if (ext == ".hws") { using (BinaryReader BR = new BinaryReader(File.Open(currentFile, FileMode.Open))) { MAINBUFFER = SValue.LoadStream(BR); } } //load values into form if (MAINBUFFERtoFormData()) { buttonSave.Enabled = true; buttonClose.Enabled = true; saveToolStripMenuItem.Enabled = true; saveAsToolStripMenuItem.Enabled = true; closeToolStripMenuItem.Enabled = true; tabGeneral.Enabled = true; tabModifiers.Enabled = true; tabPlayers.Enabled = true; //tabPageSelector.SelectedIndex = 0; ValidifyModifiersCheckBoxes(); toolStripStatusLabel.Text = "Successfully loaded data."; toolStripStatusLabel.ToolTipText = "Successfully loaded data from: \"" + currentFile + "\""; } } catch (Exception e) { ResetForm(); MessageBox.Show("An error occurred while trying to open the file:\n" + e.Message + "\n" + e.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); toolStripStatusLabel.Text = "Error encountered while loading."; toolStripStatusLabel.ToolTipText = "An error occurred while trying to load the data for the save."; } }