private bool GetEntry(string ext, string dir, string fileName, out VPKDirectoryEntry entry) { CheckHeader(); string extFixed = ext.ToLower(); string dirFixed = dir.ToLower(); string fileNameFixed = fileName.ToLower(); if (tree != null && tree.ContainsKey(extFixed) && tree[extFixed].ContainsKey(dirFixed) && tree[extFixed][dirFixed].ContainsKey(fileNameFixed)) { entry = tree[extFixed][dirFixed][fileNameFixed]; return(true); } else { entry = new VPKDirectoryEntry(); return(false); } }
private void ParseTree(Stream currentStream) { while (currentStream.Position < header.TreeSize) { string extension = DataParser.ReadNullTerminatedString(currentStream).ToLower(); if (extension.Length <= 0) { extension = tree.Keys.ElementAt(tree.Count - 1); } else { if (!tree.ContainsKey(extension)) { tree.Add(extension, new Dictionary <string, Dictionary <string, VPKDirectoryEntry> >()); } } while (true) { string directory = DataParser.ReadNullTerminatedString(currentStream).ToLower(); if (directory.Length <= 0) { break; } if (!tree[extension].ContainsKey(directory)) { tree[extension].Add(directory, new Dictionary <string, VPKDirectoryEntry>()); } string fileName; do { fileName = DataParser.ReadNullTerminatedString(currentStream).ToLower(); if (!string.IsNullOrEmpty(fileName)) { VPKDirectoryEntry dirEntry = new VPKDirectoryEntry(); dirEntry.CRC = DataParser.ReadUInt(currentStream); dirEntry.PreloadBytes = DataParser.ReadUShort(currentStream); dirEntry.ArchiveIndex = DataParser.ReadUShort(currentStream); dirEntry.EntryOffset = DataParser.ReadUInt(currentStream); dirEntry.EntryLength = DataParser.ReadUInt(currentStream); ushort terminator = DataParser.ReadUShort(currentStream); if (dirEntry.EntryOffset == 0 && dirEntry.ArchiveIndex == DIR_PAK) { dirEntry.EntryOffset = Convert.ToUInt32(currentStream.Position); } if (dirEntry.EntryLength == 0) { dirEntry.EntryLength = dirEntry.PreloadBytes; } currentStream.Position += dirEntry.PreloadBytes; if (!tree[extension][directory].ContainsKey(fileName)) { tree[extension][directory].Add(fileName, dirEntry); } } }while (!string.IsNullOrEmpty(fileName)); } } }