public void TestFileExistsByPathId() { using var archive = new PackfileReader(Path.Combine(GameDataPath, GameRootArchive)); Assert.IsTrue(Packfile.GetHashForPath(Packfile.SanitizePath("prefetch/fullgame.prefetch")) == 0x2FFF5AF65CD64C0A); Assert.IsTrue(archive.ContainsFile(0x2FFF5AF65CD64C0A)); Assert.ThrowsException <FileNotFoundException>(() => archive.ExtractFile(0xDEADC0DEDEADBEEF, new MemoryStream())); }
public void TestFileExists() { using var archive = new PackfileReader(Path.Combine(GameDataPath, GameRootArchive)); Assert.IsTrue(archive.ContainsFile("prefetch/fullgame.prefetch.core")); Assert.IsTrue(archive.ContainsFile(Packfile.SanitizePath("prefetch/fullgame.prefetch"))); Assert.IsTrue(archive.ContainsFile(Packfile.SanitizePath("prefetch\\fullgame.prefetch.core"))); #if false Assert.IsTrue(archive.ContainsFile("models/weapons/heavy_machinegun/model/model.core.stream"));// Need to find files present in Initial.bin Assert.IsTrue(archive.ContainsFile("sounds/effects/world/weather/habitats/fields/weather_fields.soundbank.core.stream")); #endif Assert.IsFalse(archive.ContainsFile("PREFETCH/fullgame.prefetch.core")); Assert.IsFalse(archive.ContainsFile("prefetch\\FULLGAME.prefetch.core")); Assert.IsFalse(archive.ContainsFile("some/made/up/path/here.core")); }
public void TestPackAndUnpackTrivial() { // Generate a couple useless files to pack var tempPath = Path.GetTempPath(); var tempFiles = new List <(string Path, string Text, string CoreName)>(); for (int i = 0; i < 15; i++) { var coreName = $"{nameof(TestPackAndUnpackTrivial)}_input_file{i}.core"; var path = Path.Combine(tempPath, coreName); var text = $"{i} Here's my testing file with some data! {i}\r\n"; File.WriteAllText(path, text); tempFiles.Add((path, text, coreName)); } // Write out compressed bin var packedArchivePath = Path.Combine(tempPath, $"{nameof(TestPackAndUnpackTrivial)}_packed_archive.bin"); using (var writeArchive = new PackfileWriter(packedArchivePath, false, FileMode.Create)) writeArchive.BuildFromFileList(tempPath, tempFiles.Select(x => x.CoreName)); // Open it back up and validate its contents using (var readArchive = new PackfileReader(packedArchivePath)) { readArchive.Validate(); foreach (var file in tempFiles) { Assert.IsTrue(readArchive.ContainsFile(file.CoreName)); readArchive.ExtractFile(file.CoreName, file.Path, FileMode.Create); Assert.IsTrue(File.ReadAllText(file.Path).Equals(file.Text)); File.Delete(file.Path); } } File.Delete(packedArchivePath); }