Example #1
0
        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.";
        }
Example #2
0
        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.";
            }
        }