/// <summary> /// Changes the directory. /// </summary> /// <param name="directory">The directory.</param> public void ChangeDirectory(PK2Directory directory) { if (directory.Parent != null && directory.Path != null) { ReadBlockAt(directory.Position); } else { ReadBlockAt(256); } CurrentDirectory = directory; }
/// <summary> /// Reads the block. /// </summary> /// <param name="position">The position.</param> /// <param name="currentDirectory">The current directory.</param> private void ReadBlockAt(ulong position, PK2Directory currentDirectory = null) { var currentBlockBuffer = FileAdapter.GetInstance().ReadData((long)position, 2560); var currentBlock = new PK2Block(currentBlockBuffer, position); //Check if the chain continues at another position if (currentBlock.Entries[19].NextChain > 0) { ReadBlockAt(currentBlock.Entries[19].NextChain); } //Read the subfolder chain //The folder "." and ".." are required if you which to use "free-browsing" mode, without reading the whole index at once foreach (var pk2Entry in currentBlock.Entries.Where(entry => !entry.Name.StartsWith(".") && entry.Position > 0)) { switch (pk2Entry.Type) { case PK2EntryType.Directory: if (Config.Mode == PK2Mode.Index) { var subDirectory = new PK2Directory(pk2Entry, currentDirectory?.Path); _directories.Add(subDirectory); ReadBlockAt(pk2Entry.Position, subDirectory); } else { ReadBlockAt(pk2Entry.Position); } break; case PK2EntryType.File: if (Config.Mode == PK2Mode.Index) { _files.Add(new PK2File(pk2Entry, currentDirectory?.Path)); } break; } } if (Config.Mode == PK2Mode.IndexBlocks) { Blocks.Add(currentBlock); } }