private Pk2.pFolder CheckSubfolders(Pk2.pFolder folder, string p) { Pk2.pFolder tmp = folder.subfolders.Find(t => t.name == p); if (tmp == null) { foreach (Pk2.pFolder fl in folder.subfolders) { tmp = CheckSubfolders(fl, p); } } return(tmp); }
private pk2.Pk2.pFolder FindFolder(Pk2.pFolder mainFolder, string p) { Pk2.pFolder rfolder = new Pk2.pFolder(); foreach (Pk2.pFolder folder in mainFolder.subfolders) { if (folder.name == p) { rfolder = folder; } if (rfolder == null) { rfolder = CheckSubfolders(folder, p); } } return(rfolder); }
public pk2Reader(string silkroadPath) { if (!File.Exists(silkroadPath)) { throw new Exception("pk2 not found. Please set the correct Path to your Silkroad directory"); } fileStream = new FileStream(silkroadPath, FileMode.Open, FileAccess.Read, FileShare.Read); blowfish.Initialize(bKey); BinaryReader reader = new BinaryReader(fileStream); pk2File.header = (Pk2.pk2Header)BufferToStruct(reader.ReadBytes(256), typeof(Pk2.pk2Header)); Console.WriteLine(pk2File.header.Name); currentFolder = new Pk2.pFolder(); currentFolder.name = silkroadPath; currentFolder.files = new List<Pk2.pFile>(); currentFolder.subfolders = new List<Pk2.pFolder>(); mainFolder = currentFolder; Read(reader.BaseStream.Position); Console.WriteLine("Done. Found {0} files.", pk2File.Files.Count); }
public pk2Reader(string silkroadPath) { if (!File.Exists(silkroadPath)) { throw new Exception("pk2 not found. Please set the correct Path to your Silkroad directory"); } fileStream = new FileStream(silkroadPath, FileMode.Open, FileAccess.Read, FileShare.Read); blowfish.Initialize(bKey); BinaryReader reader = new BinaryReader(fileStream); pk2File.header = (Pk2.pk2Header)BufferToStruct(reader.ReadBytes(256), typeof(Pk2.pk2Header)); Console.WriteLine(pk2File.header.Name); currentFolder = new Pk2.pFolder(); currentFolder.name = silkroadPath; currentFolder.files = new List <Pk2.pFile>(); currentFolder.subfolders = new List <Pk2.pFolder>(); mainFolder = currentFolder; Read(reader.BaseStream.Position); Console.WriteLine("Done. Found {0} files.", pk2File.Files.Count); }
void Read(long position) { BinaryReader reader = new BinaryReader(fileStream); reader.BaseStream.Position = position; List <Pk2.pFolder> folders = new List <Pk2.pFolder>(); Pk2.Pk2EntryBlock entryBlock = (Pk2.Pk2EntryBlock)BufferToStruct(blowfish.Decode(reader.ReadBytes(Marshal.SizeOf(typeof(Pk2.Pk2EntryBlock)))), typeof(Pk2.Pk2EntryBlock)); for (int i = 0; i < 20; i++) { Pk2.pk2Entry entry = entryBlock.entries[i]; //..... switch (entry.type) { case 0: //Null Entry break; case 1: //Folder if (entry.name != "." && entry.name != "..") { Pk2.pFolder folder = new Pk2.pFolder(); folder.name = entry.name; folder.position = BitConverter.ToInt64(entry.position, 0); folders.Add(folder); pk2File.Folders.Add(folder); currentFolder.subfolders.Add(folder); } break; case 2: //File Pk2.pFile file = new Pk2.pFile(); file.position = entry.Position; file.name = entry.name; file.size = entry.Size; file.parentFolder = currentFolder; pk2File.Files.Add(file); currentFolder.files.Add(file); break; } } if (entryBlock.entries[19].nChain != 0) { Read(entryBlock.entries[19].nChain); } foreach (Pk2.pFolder folder in folders) { currentFolder = folder; if (folder.files == null) { folder.files = new List <Pk2.pFile>(); } if (folder.subfolders == null) { folder.subfolders = new List <Pk2.pFolder>(); } Console.WriteLine(folder.name); Read(folder.position); } }
void Read(long position) { BinaryReader reader = new BinaryReader(fileStream); reader.BaseStream.Position = position; List<Pk2.pFolder> folders = new List<Pk2.pFolder>(); Pk2.Pk2EntryBlock entryBlock = (Pk2.Pk2EntryBlock)BufferToStruct(blowfish.Decode(reader.ReadBytes(Marshal.SizeOf(typeof(Pk2.Pk2EntryBlock)))), typeof(Pk2.Pk2EntryBlock)); for (int i = 0; i < 20; i++) { Pk2.pk2Entry entry = entryBlock.entries[i]; //..... switch (entry.type) { case 0: //Null Entry break; case 1: //Folder if (entry.name != "." && entry.name != "..") { Pk2.pFolder folder = new Pk2.pFolder(); folder.name = entry.name; folder.position = BitConverter.ToInt64(entry.position, 0); folders.Add(folder); pk2File.Folders.Add(folder); currentFolder.subfolders.Add(folder); } break; case 2: //File Pk2.pFile file = new Pk2.pFile(); file.position = entry.Position; file.name = entry.name; file.size = entry.Size; file.parentFolder = currentFolder; pk2File.Files.Add(file); currentFolder.files.Add(file); break; } } if (entryBlock.entries[19].nChain != 0) { Read(entryBlock.entries[19].nChain); } foreach (Pk2.pFolder folder in folders) { currentFolder = folder; if (folder.files == null) { folder.files = new List<Pk2.pFile>(); } if (folder.subfolders == null) { folder.subfolders = new List<Pk2.pFolder>(); } Console.WriteLine(folder.name); Read(folder.position); } }
private pk2.Pk2.pFolder FindFolder(Pk2.pFolder mainFolder, string p) { Pk2.pFolder rfolder = new Pk2.pFolder(); foreach (Pk2.pFolder folder in mainFolder.subfolders) { if (folder.name == p) { rfolder = folder; } if (rfolder == null) { rfolder = CheckSubfolders(folder, p); } } return rfolder; }