예제 #1
0
        protected override void LoadInternal(Utility utility, uint chunkSize)
        {
            var numEntries = utility.ReadU32();

            Entries = new List <DICTEntry>((int)numEntries);

            RootEntry = new DICTEntry
            {
                ReferenceBit   = utility.ReadU32(),
                LeftNodeIndex  = utility.ReadU16(),
                RightNodeIndex = utility.ReadU16(),
                Name           = utility.ReadString(), // NOTE: Expected to always be null
                EntryObject    = LoadObject(utility)   // NOTE: Expected to always be null
            };

            for (var i = 0; i < numEntries; i++)
            {
                Entries.Add(new DICTEntry
                {
                    ReferenceBit   = utility.ReadU32(),
                    LeftNodeIndex  = utility.ReadU16(),
                    RightNodeIndex = utility.ReadU16(),
                    Name           = utility.ReadString(),
                    EntryObject    = LoadObject(utility)
                });
            }
        }
예제 #2
0
        private void RebuildTree()
        {
            var Nodes = new List <DICTEntry>();

            // Adapted from SPICA's code

            if (Entries.Count > 0)
            {
                Nodes.Add(new DICTEntry {
                    ReferenceBit = uint.MaxValue
                });
            }
            else
            {
                Nodes.Add(new DICTEntry());
            }

            int MaxLength = 0;

            foreach (var Value in Entries)
            {
                if (MaxLength < Value.Name.Length)
                {
                    MaxLength = Value.Name.Length;
                }
            }

            foreach (var Value in Entries)
            {
                var Node = new DICTEntry
                {
                    Name = Value.Name,
                    //EntryObject = Value
                };

                PatriciaTree.Insert(Nodes, Node, MaxLength);
            }


            // TODO: Bit of a hacky implementation here, but this "should work"
            // and at least I thankfully get this functionality, courtesy of SPICA

            // Nodes index 0 will be the root node, the others should line up with
            // the subsequent entries...
            RootEntry = Nodes[0];
            for (var entryIndex = 0; entryIndex < Entries.Count; entryIndex++)
            {
                var node  = Nodes[entryIndex + 1];  // +1 because index zero is the root
                var entry = Entries[entryIndex];
                if (node.Name != entry.Name)
                {
                    throw new InvalidOperationException("RebuildTree: Name mismatch in node");
                }

                entry.ReferenceBit   = node.ReferenceBit;
                entry.LeftNodeIndex  = node.LeftNodeIndex;
                entry.RightNodeIndex = node.RightNodeIndex;
            }
        }