Advertisement
Guest User

Untitled

a guest
Feb 18th, 2011
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.10 KB | None | 0 0
  1. private void doit()
  2.         {
  3.             String address1 = "";
  4.             String address2 = "";
  5.             int filenumber = 1;
  6.  
  7.             using (BinaryReader b = new BinaryReader(File.Open("C:\\Users\\Alan\\Desktop\\charo\\data\\PackTbl\\_out_EN.tbl", FileMode.Open)))
  8.             {
  9.                 int pos = 0; //position in the table file
  10.                 int length = (int)b.BaseStream.Length; //length of the table file
  11.                 int v1 = b.ReadByte(); pos += sizeof(int); //read a byte and increase the position counter
  12.                 int v2 = b.ReadByte(); pos += sizeof(int);
  13.                 int v3 = b.ReadByte(); pos += sizeof(int);
  14.                 int v4 = b.ReadByte(); pos += sizeof(int);
  15.                 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
  16.                 v1 = b.ReadByte(); pos += sizeof(int); //the first 4 are empty, so get 4 more
  17.                 v2 = b.ReadByte(); pos += sizeof(int);
  18.                 v3 = b.ReadByte(); pos += sizeof(int);
  19.                 v4 = b.ReadByte(); pos += sizeof(int);
  20.                 address2 = v4.ToString("X2") + v3.ToString("X2") + v2.ToString("X2") + v1.ToString("X2");
  21.                 while (pos < length) // while there are still bytes in the table file...
  22.                 {
  23.                     address1 = address2;
  24.                     v1 = b.ReadByte(); pos += sizeof(int);
  25.                     v2 = b.ReadByte(); pos += sizeof(int);
  26.                     v3 = b.ReadByte(); pos += sizeof(int);
  27.                     v4 = b.ReadByte(); pos += sizeof(int);
  28.                     address2 = v4.ToString("X2") + v3.ToString("X2") + v2.ToString("X2") + v1.ToString("X2") + "\r\n";
  29.  
  30.                     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
  31.                     int value2 = int.Parse(address2, System.Globalization.NumberStyles.HexNumber);
  32.                     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
  33.                     {
  34.                         b2.ReadBytes(value1); //read up to the starting position, and ingnore the data so far
  35.                         String outputName = "C:\\Users\\Alan\\Desktop\\charo\\data\\PackData\\" + filenumber + ".txt";
  36.                         BinaryWriter w = new BinaryWriter(File.Create(outputName)); //make a new file to copy the data into
  37.                         for (int i = value1; i < value2; i++) //read the data stored between 2 addresses, and write it into the new file
  38.                         {
  39.                             int buffer = b2.ReadByte();
  40.                             w.Write(buffer);
  41.                         }
  42.                         w.Close();
  43.                     }
  44.                     filenumber++; //increase the filename for the next file to be written
  45.                 }
  46.                
  47.             }
  48.  
  49.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement