public void ExtractCategorizedPortalContents(string path) { foreach (KeyValuePair <uint, DatFile> entry in AllFiles) { string thisFolder; if (entry.Value.GetFileType(DatDatabaseType.Portal) != null) { thisFolder = Path.Combine(path, entry.Value.GetFileType(DatDatabaseType.Portal).ToString()); } else { thisFolder = Path.Combine(path, "UnknownType"); } if (!Directory.Exists(thisFolder)) { Directory.CreateDirectory(thisFolder); } string hex = entry.Value.ObjectId.ToString("X8"); string thisFile = Path.Combine(thisFolder, hex + ".bin"); // Use the DatReader to get the file data DatReader dr = GetReaderForFile(entry.Value.ObjectId); File.WriteAllBytes(thisFile, dr.Buffer); } }
public void ExtractLandblockContents(string path) { foreach (KeyValuePair <uint, DatFile> entry in AllFiles) { string thisFolder = Path.Combine(path, (entry.Value.ObjectId >> 16).ToString("X4")); if (!Directory.Exists(thisFolder)) { Directory.CreateDirectory(thisFolder); } // Use the DatReader to get the file data - file blocks can extend over block size. DatReader dr = GetReaderForFile(entry.Value.ObjectId); string hex = entry.Value.ObjectId.ToString("X8"); string thisFile = Path.Combine(thisFolder, hex + ".bin"); File.WriteAllBytes(thisFile, dr.Buffer); } }
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); } } }
public DatReader GetReaderForFile(uint fileId) { if (AllFiles.TryGetValue(fileId, out var file)) { DatReader dr; if (stream != null) { lock (streamMutex) dr = new DatReader(stream, file.FileOffset, file.FileSize, Blocksize); } else { dr = new DatReader(FilePath, file.FileOffset, file.FileSize, Blocksize); } return(dr); } return(null); }