Example #1
0
        private void savebinToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
            {
                saveFileDialog1.Filter           = "0.bin (*.bin)|*.bin|All files (*.*)|*.*";
                saveFileDialog1.FilterIndex      = 1;
                saveFileDialog1.RestoreDirectory = true;

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    var savePath = saveFileDialog1.FileName;
                    using (EndianBinaryWriter newMsgData = new EndianBinaryWriter(File.Open(savePath, FileMode.Create, FileAccess.Write), Encoding.GetEncoding(65001), true, Endianness.Little))
                    {
                        filePath       = savePath; //now the Save File option writes here too
                        currentmsgData = new msgDataFile();
                        currentmsgData.WritemsgData(newMsgData, msgDataStrings);
                        MessageBox.Show("File saved to: " + savePath, "File saved");
                    }
                }
            }
        }
Example #2
0
        public void ConvertFile(String fileToConvert)
        {
            var fileExtension = Path.GetExtension(fileToConvert);

            if (fileExtension == ".bin" || fileExtension == ".BIN")
            {
                //Read the contents of the file into a stream
                var fileStream = File.Open(fileToConvert, FileMode.Open);
                currentmsgData = new msgDataFile();
                currentmsgData.ReadmsgData(fileStream);

                using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
                {
                    saveFileDialog1.Filter           = "text file (*.txt)|*.txt|All files (*.*)|*.*";
                    saveFileDialog1.FilterIndex      = 1;
                    saveFileDialog1.RestoreDirectory = true;

                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        displayTXTBox.Text += "Converting binary file to .txt:\r\n" + fileToConvert + "\r\n";
                        var savePath = saveFileDialog1.FileName;
                        File.WriteAllLines(savePath, currentmsgData.msgDataMessages, utf8WithoutBom);
                        MessageBox.Show("File saved to: " + savePath, "File saved");
                    }
                }
            }
            else if (fileExtension == ".txt" || fileExtension == ".TXT")
            {
                string[] readText = File.ReadAllLines(fileToConvert, Encoding.UTF8);

                msgDataStrings = new List <String>();

                int k = 0;
                foreach (string s in readText)
                {
                    msgDataStrings.Add(readText[k]);
                    k++;
                }

                using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
                {
                    saveFileDialog1.Filter           = "0.bin (*.bin)|*.bin|All files (*.*)|*.*";
                    saveFileDialog1.FilterIndex      = 1;
                    saveFileDialog1.RestoreDirectory = true;

                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        var savePath = saveFileDialog1.FileName;
                        using (EndianBinaryWriter newMsgData = new EndianBinaryWriter(File.Open(savePath, FileMode.Create, FileAccess.Write), utf8WithoutBom, false, Endianness.Little))
                        {
                            displayTXTBox.Text += "Converting file text file to P5S message binary\r\n:" + fileToConvert + "\r\n";
                            currentmsgData      = new msgDataFile();
                            currentmsgData.WritemsgData(newMsgData, msgDataStrings);
                            MessageBox.Show("File saved to: " + savePath, "File saved");
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("This file is not a valid message binary or text file", "Invalid file");
            }
        }