Advertisement
Guest User

Untitled

a guest
May 29th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.28 KB | None | 0 0
  1.         /// <summary>
  2.         /// Loads additional numRows into the storage.
  3.         /// </summary>
  4.         /// <param name="numRows">Number of rows to load</param>
  5.         private void LoadRows(uint numRows)
  6.         {
  7.             // rowsLoaded records are already loaded, so skip those + header (=20)
  8.             binReader.BaseStream.Position = 20 + rowsLoaded * recordSize;
  9.  
  10.             for (int i = 0; i < (int)numRows; ++i)
  11.             {
  12.                 // read the full record as plain bytes
  13.                 byte[] curData = binReader.ReadBytes((int)recordSize);
  14.  
  15.                 // a collection of untyped values
  16.                 List<object> curRecord = new List<object>();
  17.                 for (int j = 0; j < (int)numFields; ++j)
  18.                 {
  19.                     object value = null;
  20.  
  21.                     // Get the guessed format for the current field
  22.                     Type type = formatGuesser.GetFormat((int)j);
  23.  
  24.                     // Float and int are simple. Just convert to single/int32
  25.                     if (type == typeof(float))
  26.                         value = (object)BitConverter.ToSingle(curData, j * 4);
  27.                     else if (type == typeof(int))
  28.                         value = (object)BitConverter.ToInt32(curData, j * 4);
  29.  
  30.                     // string is also not really complex. Should reference into the stringtable
  31.                     else if (type == typeof(string))
  32.                     {
  33.                         // tmp should now be the offset in bytes into the stringtable
  34.                         int tmp = BitConverter.ToInt32(curData, j * 4);
  35.                         // if its not in the stringtable its an invalid string. This may happen
  36.                         if (stringList.ContainsKey((uint)tmp))
  37.                         {
  38.                             // get the hash of the string
  39.                             uint hash = (uint)(stringList[(uint)tmp].GetHashCode());
  40.                             // increase the internal references on that string (which is used when a string is modified)
  41.                             // if the string modified is referenced more than once a new string has to be made
  42.                             ++stringReferences[hash];
  43.                             value = (object)stringList[(uint)tmp];
  44.                         }
  45.                         else
  46.                             value = (object)"";
  47.                     }
  48.  
  49.                     // StringBuilder is the dummytype for empty localized fields
  50.                     else if (type == typeof(StringBuilder))
  51.                     {
  52.                         value = (object)new StringBuilder("");
  53.                     }
  54.  
  55.                     // decimal is the dummytype for the last field in licalized strings (the bitmask)
  56.                     else if (type == typeof(decimal))
  57.                     {
  58.                         uint val = BitConverter.ToUInt32(curData, j * 4);
  59.                         decimal dec = (decimal)val;
  60.                         value = (object)dec;
  61.                     }
  62.                     curRecord.Add(value);
  63.                 }
  64.                 if (RecordLoaded != null)
  65.                     RecordLoaded((uint)i, numRows);
  66.                
  67.                 recordList.Add(curRecord);
  68.             }
  69.  
  70.             rowsLoaded += numRows;
  71.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement