Beispiel #1
0
        public IndexContainer(string path) : base(path)
        {
            var data = Read();

            data.Seek(0, SeekOrigin.Begin);
            var br = new BinaryReader(data);

            int bundleCount = br.ReadInt32();

            Bundles = new BundleRecord[bundleCount];
            for (int i = 0; i < bundleCount; i++)
            {
                Bundles[i] = new BundleRecord(br)
                {
                    bundleIndex = i
                }
            }
            ;

            int fileCount = br.ReadInt32();

            Files = new FileRecord[fileCount];
            for (int i = 0; i < fileCount; i++)
            {
                var f = new FileRecord(br);
                Files[i]          = f;
                FindFiles[f.Hash] = f;
                f.bundleRecord    = Bundles[f.BundleIndex];
                Bundles[f.BundleIndex].Files.Add(f);
            }

            int directoryCount = br.ReadInt32();

            Directorys = new DirectoryRecord[directoryCount];
            for (int i = 0; i < directoryCount; i++)
            {
                var d = new DirectoryRecord(br);
                Directorys[i] = d;
            }

            var tmp = br.BaseStream.Position;

            directoryBundleData = br.ReadBytes((int)(br.BaseStream.Length - tmp));
            br.BaseStream.Seek(tmp, SeekOrigin.Begin);

            var directoryBundle = new BundleContainer(br);
            var br2             = new BinaryReader(directoryBundle.Read(br));

            br.Close();
            Hashes = new Dictionary <ulong, string>(Files.Length);
            foreach (var d in Directorys)
            {
                var  temp = new List <string>();
                bool Base = false;
                br2.BaseStream.Seek(d.Offset, SeekOrigin.Begin);
                while (br2.BaseStream.Position - d.Offset <= d.Size - 4)
                {
                    int index = br2.ReadInt32();
                    if (index == 0)
                    {
                        Base = !Base;
                        if (Base)
                        {
                            temp = new List <string>();
                        }
                    }
                    else
                    {
                        index -= 1;
                        var  sb = new StringBuilder();
                        char c;
                        while ((c = br2.ReadChar()) != 0)
                        {
                            sb.Append(c);
                        }
                        var str = sb.ToString();
                        if (index < temp.Count && index >= 0)
                        {
                            str = temp[index] + str;
                        }
                        if (Base)
                        {
                            temp.Add(str);
                        }
                        else
                        {
                            d.paths.Add(str);
                            Hashes[FNV1a64Hash(str)] = str;
                        }
                    }
                }
            }
            br2.Close();
        }
        public IndexContainer(BinaryReader br)
        {
            BundleContainer = new BundleContainer(br);
            var data = BundleContainer.Read(br);

            data.Seek(0, SeekOrigin.Begin);
            var databr = new BinaryReader(data);

            var bundleCount = databr.ReadInt32();

            Bundles = new BundleRecord[bundleCount];
            for (int i = 0; i < bundleCount; i++)
            {
                Bundles[i] = new BundleRecord(databr)
                {
                    bundleIndex = i
                }
            }
            ;

            var fileCount = databr.ReadInt32();

            Files = new FileRecord[fileCount];
            for (var i = 0; i < fileCount; i++)
            {
                var f = new FileRecord(databr);
                Files[i] = f;
                FindFiles[f.NameHash] = f;
                var b = Bundles[f.BundleIndex];
                f.bundleRecord = b;
                b.Files.Add(f);
                if (f.Offset >= b.validSize)
                {
                    b.validSize = f.Offset + f.Size;
                }
            }

            var directoryCount = databr.ReadInt32();

            Directorys = new DirectoryRecord[directoryCount];
            for (var i = 0; i < directoryCount; i++)
            {
                Directorys[i] = new DirectoryRecord(databr);
            }

            var tmp = databr.BaseStream.Position;

            directoryBundleData = databr.ReadBytes((int)(databr.BaseStream.Length - tmp));
            databr.BaseStream.Seek(tmp, SeekOrigin.Begin);

            var directoryBundle = new BundleContainer(databr);
            var br2             = new BinaryReader(directoryBundle.Read(databr), Encoding.UTF8);

            // Array.Sort(Directorys, new Comparison<DirectoryRecord>((dr1, dr2) => { return dr1.Offset > dr2.Offset ? 1 : -1; }));
            foreach (var d in Directorys)
            {
                var temp = new List <string>();
                var Base = false;
                br2.BaseStream.Seek(d.Offset, SeekOrigin.Begin);
                while (br2.BaseStream.Position - d.Offset <= d.Size - 4)
                {
                    var index = br2.ReadInt32();
                    if (index == 0)
                    {
                        Base = !Base;
                        if (Base)
                        {
                            temp.Clear();
                        }
                    }
                    else
                    {
                        index -= 1;
                        var  sb = new StringBuilder();
                        char c;
                        while ((c = br2.ReadChar()) != 0)
                        {
                            sb.Append(c);
                        }
                        var str = sb.ToString();
                        if (index < temp.Count)
                        {
                            str = temp[index] + str;
                        }
                        if (Base)
                        {
                            temp.Add(str);
                        }
                        else
                        {
                            Paths.Add(str);
                            var f = FindFiles[FNV1a64Hash(str)];
                            f.path = str;
                            d.children.Add(f);
                            f.parent = d;
                        }
                    }
                }
            }
            br2.Close();
        }