Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void doit()
- {
- String address1 = "";
- String address2 = "";
- int filenumber = 1;
- using (BinaryReader b = new BinaryReader(File.Open("C:\\Users\\Alan\\Desktop\\charo\\data\\PackTbl\\_out_EN.tbl", FileMode.Open)))
- {
- int pos = 0; //position in the table file
- int length = (int)b.BaseStream.Length; //length of the table file
- int v1 = b.ReadByte(); pos += sizeof(int); //read a byte and increase the position counter
- int v2 = b.ReadByte(); pos += sizeof(int);
- int v3 = b.ReadByte(); pos += sizeof(int);
- int v4 = b.ReadByte(); pos += sizeof(int);
- address1 = v4.ToString("X2") + v3.ToString("X2") + v2.ToString("X2") + v1.ToString("X2"); //convert the bytes to hex, reverse the order, and store as a string
- v1 = b.ReadByte(); pos += sizeof(int); //the first 4 are empty, so get 4 more
- v2 = b.ReadByte(); pos += sizeof(int);
- v3 = b.ReadByte(); pos += sizeof(int);
- v4 = b.ReadByte(); pos += sizeof(int);
- address2 = v4.ToString("X2") + v3.ToString("X2") + v2.ToString("X2") + v1.ToString("X2");
- while (pos < length) // while there are still bytes in the table file...
- {
- address1 = address2;
- v1 = b.ReadByte(); pos += sizeof(int);
- v2 = b.ReadByte(); pos += sizeof(int);
- v3 = b.ReadByte(); pos += sizeof(int);
- v4 = b.ReadByte(); pos += sizeof(int);
- address2 = v4.ToString("X2") + v3.ToString("X2") + v2.ToString("X2") + v1.ToString("X2") + "\r\n";
- int value1 = int.Parse(address1, System.Globalization.NumberStyles.HexNumber); // "address1" stored as int. I think this should be the number of bytes that I need to read into the file
- int value2 = int.Parse(address2, System.Globalization.NumberStyles.HexNumber);
- using (BinaryReader b2 = new BinaryReader(File.Open("C:\\Users\\Alan\\Desktop\\charo\\data\\PackData\\_out_EN.pck", FileMode.Open))) // open the file with the actual data
- {
- b2.ReadBytes(value1); //read up to the starting position, and ingnore the data so far
- String outputName = "C:\\Users\\Alan\\Desktop\\charo\\data\\PackData\\" + filenumber + ".txt";
- BinaryWriter w = new BinaryWriter(File.Create(outputName)); //make a new file to copy the data into
- for (int i = value1; i < value2; i++) //read the data stored between 2 addresses, and write it into the new file
- {
- int buffer = b2.ReadByte();
- w.Write(buffer);
- }
- w.Close();
- }
- filenumber++; //increase the filename for the next file to be written
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement