示例#1
0
        private static RemapSegment[] InitSegments(RemapHeader header, MapEntry[] mapEntries)
        {
            var segments = new RemapSegment[header.MapSegmentCount];
            int entryIdx = 0;

            for (int i = 0; i < header.MapSegmentCount; i++)
            {
                var seg = new RemapSegment();
                seg.Entries.Add(mapEntries[entryIdx]);
                seg.Offset = mapEntries[entryIdx].VirtualOffset;
                mapEntries[entryIdx].Segment = seg;
                entryIdx++;

                while (entryIdx < mapEntries.Length &&
                       mapEntries[entryIdx - 1].VirtualOffsetEnd == mapEntries[entryIdx].VirtualOffset)
                {
                    mapEntries[entryIdx].Segment  = seg;
                    mapEntries[entryIdx - 1].Next = mapEntries[entryIdx];
                    seg.Entries.Add(mapEntries[entryIdx]);
                    entryIdx++;
                }

                seg.Length  = seg.Entries[seg.Entries.Count - 1].VirtualOffsetEnd - seg.Entries[0].VirtualOffset;
                segments[i] = seg;
            }

            return(segments);
        }
示例#2
0
        /// <summary>
        /// Creates a new <see cref="RemapStorage"/>
        /// </summary>
        /// <param name="storage">A <see cref="IStorage"/> of the main data of the RemapStream.
        /// The <see cref="RemapStorage"/> object assumes complete ownership of the Storage.</param>
        /// <param name="header">The header for this RemapStorage.</param>
        /// <param name="mapEntries">The remapping entries for this RemapStorage.</param>
        /// <param name="leaveOpen"><see langword="true"/> to leave the storage open after the <see cref="RemapStorage"/> object is disposed; otherwise, <see langword="false"/>.</param>
        public RemapStorage(IStorage storage, IStorage header, IStorage mapEntries, bool leaveOpen)
        {
            BaseStorage     = storage;
            HeaderStorage   = header;
            MapEntryStorage = mapEntries;

            Header = new RemapHeader(HeaderStorage);

            MapEntries = new MapEntry[Header.MapEntryCount];
            var reader = new BinaryReader(MapEntryStorage.AsStream());

            for (int i = 0; i < Header.MapEntryCount; i++)
            {
                MapEntries[i] = new MapEntry(reader);
            }

            if (!leaveOpen)
            {
                ToDispose.Add(BaseStorage);
            }

            Segments = InitSegments(Header, MapEntries);
        }