Пример #1
0
        public DatDatabase(string filePath, bool keepOpen = false)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(filePath);
            }

            FilePath = filePath;
            uint btree = 0;

            stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            using (var reader = new BinaryReader(stream, System.Text.Encoding.Default, true)) {
                if (DatManager.DatVersion == DatVersionType.ACTOD)
                {
                    stream.Seek(DAT_HEADER_OFFSET_TOD, SeekOrigin.Begin);
                    Header.Unpack(reader);
                    if (Header.Success)
                    {
                        btree     = Header.BTree;
                        Blocksize = Header.BlockSize;
                    }
                }
                else if (DatManager.DatVersion == DatVersionType.ACDM)
                {
                    reader.BaseStream.Seek(DAT_HEADER_OFFSET_ACDM, SeekOrigin.Begin);
                    Header_ACDM.Unpack(reader);
                    if (Header_ACDM.Success)
                    {
                        btree     = Header_ACDM.BTree;
                        Blocksize = Header_ACDM.BlockSize;
                    }
                }
            }

            if (Blocksize > 0)
            {
                RootDirectory = new DatDirectory(btree, Blocksize);
                RootDirectory.Read(stream);
                RootDirectory.AddFilesToList(AllFiles);
            }

            if (!keepOpen)
            {
                stream.Close();
                stream.Dispose();
                stream = null;
            }
        }
Пример #2
0
        public void Read(FileStream stream)
        {
            var headerReader = new DatReader(stream, rootSectorOffset, DatDirectoryHeader.ObjectSize, blockSize);

            using (var memoryStream = new MemoryStream(headerReader.Buffer))
                using (var reader = new BinaryReader(memoryStream))
                    DatDirectoryHeader.Unpack(reader);

            // directory is allowed to have files + 1 subdirectories
            if (DatDirectoryHeader.Branches[0] != 0)
            {
                for (int i = 0; i < DatDirectoryHeader.EntryCount + 1; i++)
                {
                    var directory = new DatDirectory(DatDirectoryHeader.Branches[i], blockSize);
                    directory.Read(stream);
                    Directories.Add(directory);
                }
            }
        }