FileData.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections.Generic;
  2. using System.IO;
  3. namespace OpenVIII
  4. {
  5. public sealed partial class ArchiveZzz
  6. {
  7. #region Classes
  8. public static class FileData
  9. {
  10. #region Methods
  11. /// <summary>
  12. /// Convert the FileData for ZZZ to a String and FI pair
  13. /// </summary>
  14. /// <param name="br">Binary reader with raw data.</param>
  15. /// <returns>String and FI pair</returns>
  16. public static KeyValuePair<string, FI> Load(BinaryReader br)
  17. {
  18. var filenameLength = br.ReadInt32();
  19. var filenameBytes = br.ReadBytes(filenameLength);
  20. return new KeyValuePair<string, FI>(ConvertFilename(filenameBytes), new FI(checked((int)br.ReadInt64()), checked((int)br.ReadUInt32())));
  21. }
  22. /// <summary>
  23. /// Decode/Encode the filename string as bytes.
  24. /// </summary>
  25. /// <remarks>
  26. /// Could be Ascii or UTF8, I see no special characters and the first like 127 of UTF8 is the
  27. /// same as Ascii.
  28. /// </remarks>
  29. private static string ConvertFilename(byte[] filenameBytes) => System.Text.Encoding.UTF8.GetString(filenameBytes);
  30. #endregion Methods
  31. }
  32. #endregion Classes
  33. }
  34. }