public void ExtractWithPredicate(string directory, Func <PakEntry, bool> function) { using (var fileStream = File.Open(LoadedFilePath, FileMode.Open)) { var reader = new PakBinaryReader(fileStream); var pakEntryCollection = Model.Archive.Directory.Entries.Where(function).ToList(); long currentSize = 0; long totalSize = pakEntryCollection.Sum(_ => _.UncompressedSize); foreach (var pakEntry in pakEntryCollection) { if (pakEntry.Offset == -1) { continue; } if (reader.BaseStream.Position != pakEntry.Offset) { reader.BaseStream.Seek(pakEntry.Offset, SeekOrigin.Begin); } Model.ExtractFile(directory, pakEntry, reader); CurrentProgress = (int)(currentSize * 100.0 / totalSize); CurrentFile = pakEntry.Name; currentSize += pakEntry.UncompressedSize; } } }
public void SavePakFile(string path) { using (var inputFileStream = File.Open(LoadedFilePath, FileMode.Open)) { using (var reader = new PakBinaryReader(inputFileStream)) { using (var outputFileStream = File.Open(path, FileMode.Create)) { using (var writer = new PakBinaryWriter(outputFileStream)) { long currentSize = 0; long totalSize = Model.Archive.Directory.Entries.Sum(_ => _.UncompressedSize); for (var i = 0; i < Model.Archive.Directory.Entries.Count; i++) { var entry = Model.Archive.Directory.Entries[i]; Model.SaveDataEntry(reader, writer, entry, Padding && i + 1 != Model.Archive.Directory.Entries.Count); CurrentProgress = (int)(currentSize * 100.0 / totalSize); CurrentFile = entry.Name; currentSize += entry.UncompressedSize; } Model.SavePakFileStructure(writer); } } } } OnPropertyChanged("Model"); }
public void LoadPakFile() { using (FileStream fileStream = File.Open(LoadedFilePath, FileMode.Open)) { PakBinaryReader reader = new PakBinaryReader(fileStream); Model.LoadPakFileStructure(reader, Version, AesKey); OnPropertyChanged("Model"); } }