/// <summary> /// Return a <see cref="Stream"/> containing the data in this GenericRCOLResource instance. /// </summary> /// <returns>A <see cref="Stream"/> containing the data in this GenericRCOLResource instance.</returns> protected override Stream UnParse() { long rcolIndexPos; MemoryStream ms = new MemoryStream(); BinaryWriter w = new BinaryWriter(ms); w.Write(version); w.Write(publicChunks); w.Write(unused); if (resources == null) { resources = new CountedTGIBlockList(OnResourceChanged, "ITG"); } w.Write(resources.Count); if (blockList == null) { blockList = new ChunkEntryList(OnResourceChanged) { ParentTGIBlocks = resources, } } ; w.Write(blockList.Count); foreach (ChunkEntry ce in blockList) { ce.TGIBlock.UnParse(ms); } resources.UnParse(ms); rcolIndexPos = ms.Position; RCOLIndexEntry[] index = new RCOLIndexEntry[blockList.Count]; for (int i = 0; i < blockList.Count; i++) { w.Write((uint)0); w.Write((uint)0); } // Pad for the index int j = 0; foreach (ChunkEntry ce in blockList) { byte[] data = ce.RCOLBlock.AsBytes; while (w.BaseStream.Position % 4 != 0) { w.Write((byte)0); } index[j].Position = (uint)ms.Position; index[j].Length = data.Length; w.Write(data); j++; } ms.Position = rcolIndexPos; foreach (RCOLIndexEntry entry in index) { w.Write(entry.Position); w.Write(entry.Length); } return(ms); }
protected override Stream UnParse() { if (version == 0 && publicChunks == 0 && unused == 0 && blockList == null && resources == null) { // In that case, assume we're a newly created "stream == null" situation GenericRCOLResource that needs // some help to become a real life GeometryResource. resources = new CountedTGIBlockList(OnResourceChanged, "ITG"); // Unfortunately, a Resource does not know its own ResourceKey. This is the best we can manage. TGIBlock rk = new TGIBlock(0, null, 0x015A1849, 0, 0); GEOM geom = new GEOM(requestedApiVersion, OnResourceChanged); blockList = new ChunkEntryList(OnResourceChanged, new ChunkEntry[] { new ChunkEntry(0, OnResourceChanged, rk, geom), }) { ParentTGIBlocks = Resources, }; } return base.UnParse(); }
protected override Stream UnParse() { if (version == 0 && publicChunks == 0 && unused == 0 && blockList == null && resources == null) { // In that case, assume we're a newly created "stream == null" situation GenericRCOLResource that needs // some help to become a real life GeometryResource. resources = new CountedTGIBlockList(OnResourceChanged, "ITG"); // Unfortunately, a Resource does not know its own ResourceKey. This is the best we can manage. TGIBlock rk = new TGIBlock(null, 0x015A1849, 0, 0); GEOM geom = new GEOM(OnResourceChanged); blockList = new ChunkEntryList(OnResourceChanged, new[] { new ChunkEntry(OnResourceChanged, rk, geom), }) { ParentTGIBlocks = Resources, }; } return(base.UnParse()); }
void Parse(Stream s) { BinaryReader r = new BinaryReader(s); version = r.ReadUInt32(); publicChunks = r.ReadInt32(); unused = r.ReadUInt32(); int countResources = r.ReadInt32(); int countChunks = r.ReadInt32(); TGIBlock[] chunks = new TGIBlock[countChunks]; for (int i = 0; i < countChunks; i++) { chunks[i] = new TGIBlock(0, OnResourceChanged, "ITG", s); } resources = new CountedTGIBlockList(OnResourceChanged, "ITG", countResources, s); RCOLIndexEntry[] index = new RCOLIndexEntry[countChunks]; for (int i = 0; i < countChunks; i++) { index[i].Position = r.ReadUInt32(); index[i].Length = r.ReadInt32(); } if (countChunks == 1) { index[0].Position = 0x2c + (uint)countResources * 16; index[0].Length = (int)(s.Length - index[0].Position); if (chunks[0].ResourceType == 0) { string tag = new string(r.ReadChars(4)); chunks[0].ResourceType = GenericRCOLResourceHandler.RCOLTypesForTag(tag).FirstOrDefault(); } } blockList = new ChunkEntryList(requestedApiVersion, OnResourceChanged, s, chunks, index) { ParentTGIBlocks = resources, }; }