// PROTECTED READERS / WRITERS // See description of this method in the abstract base class SRZoneProperty. protected override void ReadData(SRBinaryReader binaryReader, int size) { value = binaryReader.ReadString(); SRTrace.WriteLine(" Value: \"" + value + "\""); if (value.Length + 1 != size) throw new SRZoneFileException("String length is wrong."); }
// READERS / WRITERS /// <summary> /// Reads a data block from a file binary stream. /// </summary> /// <param name="binaryReader">Binary reader to read the block from. Must point to the beginning of the block.</param> /// <param name="size">Maximum number of bytes to read.</param> public void Read(SRBinaryReader binaryReader) { SRTrace.WriteLine(""); SRTrace.WriteLine("V-FILE HEADER:"); signature = binaryReader.ReadUInt16(); SRTrace.WriteLine(" V-File Signature: 0x{0:X4}", signature); if (signature != 0x3854) throw new Exception("Incorrect V-file signature. Not a valid zone header file."); version = binaryReader.ReadUInt16(); SRTrace.WriteLine(" V-File Version: {0}", version); if (version != 4) throw new Exception("Incorrect V-file version."); int refDataSize = binaryReader.ReadInt32(); SRTrace.WriteLine(" Reference Data Size: {0}", refDataSize); refDataStart = binaryReader.ReadUInt32(); SRTrace.WriteLine(" Reference Data Start: 0x{0:X8}", refDataStart); // if (refDataStart != 0) // throw new SRZoneFileException("Expected reference data start to be zero."); int refCount = binaryReader.ReadInt32(); SRTrace.WriteLine(" Reference Count: {0}", refCount); unknown = binaryReader.ReadUInt32(); SRTrace.WriteLine(" Unknown: 0x{0:X8}", unknown); binaryReader.BaseStream.Seek(12, SeekOrigin.Current); long refDataOffset = binaryReader.BaseStream.Position; SRTrace.WriteLine(""); SRTrace.WriteLine(" REFERENCE DATA:"); referenceData = new List<string>(refCount); referenceNamesByReadOffset = new Dictionary<long, string>(refCount); var positionDataStart = binaryReader.BaseStream.Position; for (int i = 1; i <= refCount; i++) { long offset = binaryReader.BaseStream.Position - positionDataStart; string name = binaryReader.ReadString(); SRTrace.WriteLine(" {0,3}. {1}", i, name); referenceData.Add(name); referenceNamesByReadOffset.Add(offset, OptionNameReferenceIdentifier ? name : i.ToString()); } var finalNull = binaryReader.ReadByte(); if (finalNull != 0) throw new Exception("Expected trailing null byte."); }