Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NefsHeaderPart1"/> class.
        /// </summary>
        /// <param name="items">The list of items in the archive sorted by id.</param>
        /// <param name="part4">Header part 4.</param>
        internal NefsHeaderPart1(NefsItemList items, NefsHeaderPart4 part4)
        {
            this.entriesById = new SortedDictionary <NefsItemId, NefsHeaderPart1Entry>();
            var nextMetadataIndex = 0U;

            // Enumerate this list depth first. This determines the metadata index.
            // The part 1 entries will be sorted by item id.
            foreach (var item in items.EnumerateDepthFirstByName())
            {
                var entry = new NefsHeaderPart1Entry();
                entry.Data0x00_OffsetToData.Value   = item.DataSource.Offset;
                entry.Data0x08_MetadataIndex.Value  = nextMetadataIndex++;
                entry.Data0x10_Id.Value             = item.Id.Value;
                entry.Data0x0c_IndexIntoPart4.Value = part4.GetIndexForItem(item);

                this.entriesById.Add(item.Id, entry);
            }

            // Part 1 is sorted by item id
            this.entriesByIndex = new List <NefsHeaderPart1Entry>(this.entriesById.Values);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NefsHeaderPart1"/> class.
        /// </summary>
        /// <param name="items">The list of items in the archive.</param>
        /// <param name="part4">Header part 4.</param>
        internal NefsHeaderPart1(NefsItemList items, INefsHeaderPart4 part4)
        {
            this.entriesByGuid = new Dictionary <Guid, NefsHeaderPart1Entry>();
            var indexPart2 = 0U;

            // Enumerate this list depth first. This determines the part 2 order. The part 1 entries
            // will be sorted by item id.
            foreach (var item in items.EnumerateDepthFirstByName())
            {
                var entry = new NefsHeaderPart1Entry(item.Guid);
                entry.Data0x00_OffsetToData.Value = item.DataSource.Offset;
                entry.Data0x08_IndexPart2.Value   = indexPart2++;
                entry.Data0x10_Id.Value           = item.Id.Value;
                entry.Data0x0c_IndexPart4.Value   = part4.GetIndexForItem(item);

                this.entriesByGuid.Add(item.Guid, entry);
            }

            // Sort part 1 by item id
            this.entriesByIndex = new List <NefsHeaderPart1Entry>(this.entriesByGuid.Values.OrderBy(e => e.Id));
        }