Пример #1
0
        public int populate(string[] sortedList, int highLimit, int lowLimit, int startoffset, int centrepoint, List <BinaryTree> treeList)
        {
            this.offset       = startoffset;
            this.listposition = centrepoint;
            BinaryTree tree  = new BinaryTree();
            BinaryTree tree2 = new BinaryTree();
            int        num   = this.offset + sortedList[centrepoint].Length;

            num += 14;
            if ((num % 4) != 0)
            {
                num += 4 - (num % 4);
            }
            if (centrepoint > lowLimit)
            {
                int totalsize = (centrepoint - 1) - lowLimit;
                int maxcentre = totalsize / 2;
                if ((maxcentre * 2) != totalsize)
                {
                    maxcentre++;
                }
                if ((maxcentre != 0) && (maxcentre != 0))
                {
                    maxcentre = findTreeCentre(maxcentre, totalsize);
                }
                this.leftNodeId = lowLimit + maxcentre;
            }
            else
            {
                this.leftNodeId = -1;
            }
            if (centrepoint < highLimit)
            {
                int num4 = centrepoint + 1;
                int num5 = highLimit - num4;
                int num6 = num5 / 2;
                if (((num6 * 2) != num5) && (num6 != 0))
                {
                    num6++;
                }
                if (num6 != 0)
                {
                    num6 = findTreeCentre(num6, num5);
                }
                this.rightNodeId = num4 + num6;
            }
            else
            {
                this.rightNodeId = -1;
            }
            treeList.Add(this);
            int num7 = treeList.Count - 1;

            if (this.leftNodeId != -1)
            {
                treeList[num7].leftNodeOffset = num;
                num = tree.populate(sortedList, centrepoint - 1, lowLimit, num, this.leftNodeId, treeList);
            }
            else
            {
                treeList[num7].leftNodeOffset = 0;
            }
            if (this.rightNodeId != -1)
            {
                treeList[num7].rightNodeOffset = num;
                return(tree2.populate(sortedList, highLimit, centrepoint + 1, num, this.rightNodeId, treeList));
            }
            treeList[num7].rightNodeOffset = 0;
            return(num);
        }
Пример #2
0
        public byte[] DirContentsToByteArray(FileSystemFolder fsfolder)
        {
            if (fsfolder.Count == 0)
            {
                return(new byte[0]);
            }
            Dictionary <string, int> fsDictionary = new Dictionary <string, int>();
            List <string>            list         = new List <string>(fsfolder.Count);

            for (int i = 0; i < fsfolder.Count; i++)
            {
                if (fsfolder[i].CopyMethod != OutputMethod.Special)
                {
                    fsDictionary.Add(fsfolder[i].FileName, i);
                    list.Add(fsfolder[i].FileName);
                }
            }
            string[] array = list.ToArray();
            Array.Sort <string>(array, new FSFilenameComparer());
            BinaryTree tree      = new BinaryTree();
            int        maxcentre = (array.Length - 1) / 2;

            if (maxcentre != 0)
            {
                maxcentre = BinaryTree.findTreeCentre(maxcentre, array.Length - 1);
            }
            List <BinaryTree> treeList = new List <BinaryTree>();
            int num3 = tree.populate(array, array.Length - 1, 0, 0, maxcentre, treeList);

            if (num3 > 0x800)
            {
                num3 += this.alignTree(fsfolder, treeList, fsDictionary, array);
            }
            byte[] buffer = new byte[num3];
            for (int j = 0; j < num3; j++)
            {
                buffer[j] = 0xff;
            }
            foreach (BinaryTree tree2 in treeList)
            {
                string str = array[tree2.listposition];
                XDvdFsFileSystemEntry entry = fsfolder[fsDictionary[str]];
                tree2.leftNodeOffset  /= 4;
                tree2.rightNodeOffset /= 4;
                BitConverter.GetBytes((short)tree2.leftNodeOffset).CopyTo(buffer, tree2.offset);
                BitConverter.GetBytes((short)tree2.rightNodeOffset).CopyTo(buffer, (int)(tree2.offset + 2));
                BitConverter.GetBytes(entry.StartSector).CopyTo(buffer, (int)(tree2.offset + 4));
                if (entry.IsFolder)
                {
                    BitConverter.GetBytes((uint)entry.Files.LogicalDirTableSize).CopyTo(buffer, (int)(tree2.offset + 8));
                }
                else
                {
                    BitConverter.GetBytes((uint)entry.LogicalFileSize).CopyTo(buffer, (int)(tree2.offset + 8));
                }
                BitConverter.GetBytes((short)entry.Attributes).CopyTo(buffer, (int)(tree2.offset + 12));
                BitConverter.GetBytes((short)((byte)entry.FileName.Length)).CopyTo(buffer, (int)(tree2.offset + 13));
                ASCIIEncoding encoding = new ASCIIEncoding();
                encoding.GetBytes(entry.FileName).CopyTo(buffer, (int)(tree2.offset + 14));
            }
            return(buffer);
        }