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); }
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); } } }