private void CreateFile() { try { if (folderBrowserDialog1.ShowDialog() != DialogResult.Cancel) { filepath = folderBrowserDialog1.SelectedPath + "\\rmorf.bin"; FileStream fileStream = new FileStream(filepath, FileMode.Create); BinaryWriter writer = new BinaryWriter(fileStream); headFs = (uint)BitConverter.ToInt32(fS, 0); headKey = (uint)BitConverter.ToInt32(k, 0); headAgc = (uint)BitConverter.ToInt32(agc, 0); rmorfhead = new RmorfHead(headFs, headKey, headAgc); rmorfgrouplist = new List <RmorfGroup>(); writer.Write(headFs); writer.Write(headKey); writer.Write(headAgc); try { // Writing size of file on its begin and save it writer.Seek(0, SeekOrigin.End); writer.Write(NendofFile); writer.Seek(0, SeekOrigin.Begin); FileInfo file = new FileInfo(filepath); long size = file.Length; byte[] sizeout = BitConverter.GetBytes(size); writer.Write(sizeout, 0, 4); writer.Close(); fileStream.Close(); //MessageBox.Show("DONE BLYAD!"); VisualGroup(); Objects1.Items.Clear(); comboBox1.Text = "Unknown/None"; FilesaveString(false); FilesaveString(true); } catch (FormatException) { MessageBox.Show("Wrong type of data!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch { MessageBox.Show("Wrong path!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ParseFile() { rmorfgrouplist = new List <RmorfGroup>(); filepath = openFileDialog1.FileName; labelFilepath.Text = filepath; try { FileStream fileStream = new FileStream(filepath, FileMode.Open); BinaryReader reader = new BinaryReader(fileStream); headFs = reader.ReadUInt32(); headKey = reader.ReadUInt32(); if (headKey == 1036831949) { try { headAgc = reader.ReadUInt32(); rmorfhead = new RmorfHead(headFs, headKey, headAgc); for (int animgr = 0; animgr < headAgc; animgr++) { nameslist = new List <string>(); grMc = reader.ReadUInt32(); grToa = reader.ReadUInt32(); grFrq = reader.ReadUInt32(); grU3 = reader.ReadUInt32(); grU4 = reader.ReadUInt32(); grU5 = reader.ReadUInt32(); for (uint i = 0; i < grMc; i++) { List <byte> listname = new List <byte>(); byte[] arrname; while (reader.PeekChar() != '\x00') { listname.Add(reader.ReadByte()); } arrname = listname.ToArray(); reader.BaseStream.Seek(+1, SeekOrigin.Current); string name = Encoding.ASCII.GetString(arrname); nameslist.Add(name); } rmorfgrouplist.Add(new RmorfGroup(grMc, grToa, grFrq, grU3, grU4, grU5, nameslist)); } } catch { MessageBox.Show("File is wrong!. Couldn't parse.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("File is wrong!. Wrong constant.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } reader.Close(); fileStream.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }