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

            FilePath = filePath;

            stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);

            stream.Seek(DAT_HEADER_OFFSET, SeekOrigin.Begin);
            using (var reader = new BinaryReader(stream, System.Text.Encoding.Default, true))
                Header.Unpack(reader);

            RootDirectory = new DatDirectory(Header.BTree, Header.BlockSize);
            RootDirectory.Read(stream);

            if (!keepOpen)
            {
                stream.Close();
                stream.Dispose();
                stream = null;
            }

            RootDirectory.AddFilesToList(AllFiles);
        }
Пример #2
0
        internal DatDatabase(string filePath, DatDatabaseType type)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(filePath);
            }

            this.FilePath = filePath;
            DatType       = type;

            using (FileStream stream = new FileStream(filePath, FileMode.Open))
            {
                byte[] sectorSizeBuffer = new byte[4];
                stream.Seek(0x144u, SeekOrigin.Begin);
                stream.Read(sectorSizeBuffer, 0, sizeof(uint));
                this.SectorSize = BitConverter.ToUInt32(sectorSizeBuffer, 0);

                stream.Seek(0x160u, SeekOrigin.Begin);
                byte[] firstDirBuffer = new byte[4];
                stream.Read(firstDirBuffer, 0, sizeof(uint));
                uint firstDirectoryOffset = BitConverter.ToUInt32(firstDirBuffer, 0);

                RootDirectory = new DatDirectory(firstDirectoryOffset, Convert.ToInt32(this.SectorSize), stream, DatType);
            }

            AllFiles = new Dictionary <uint, DatFile>();
            RootDirectory.AddFilesToList(AllFiles);
        }
Пример #3
0
        public DatDatabase(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(filePath);
            }

            using (FileStream stream = new FileStream(filePath, FileMode.Open))
            {
                byte[] sectorSizeBuffer = new byte[4];
                stream.Seek(0x144u, SeekOrigin.Begin);
                stream.Read(sectorSizeBuffer, 0, sizeof(uint));
                uint sectorSize = BitConverter.ToUInt32(sectorSizeBuffer, 0);

                stream.Seek(0x160u, SeekOrigin.Begin);
                byte[] firstDirBuffer = new byte[4];
                stream.Read(firstDirBuffer, 0, sizeof(uint));
                uint firstDirectoryOffset = BitConverter.ToUInt32(firstDirBuffer, 0);

                RootDirectory = new DatDirectory(firstDirectoryOffset, Convert.ToInt32(sectorSize), stream);
            }

            AllFiles = new List <DatFile>();
            RootDirectory.AddFilesToList(AllFiles);
        }
Пример #4
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);
                }
            }
        }