public void GetFileTest(string path) { GgpkArchive archive = GgpkArchive.From(new FileInfo(@"pass.ggpk")); IGgpkFile file = archive.GetFile(path); Assert.AreEqual(4UL, file.Length); }
public void TestFullName() { GgpkArchive archive = GgpkArchive.From(@"pass.ggpk"); IGgpkFile file = archive.Root.Directories.Where(d => d.Name == "Dir_1").FirstOrDefault().Files.Where(f => f.Name == "Aa_Bb-Cc.DdEe").FirstOrDefault(); Assert.AreEqual("/Dir_1/Aa_Bb-Cc.DdEe", file.FullName); }
public void FromTest() { GgpkArchive archive = GgpkArchive.From(new FileInfo(@"pass.ggpk")); Assert.AreEqual <int>(1, archive.Root.Directories.Count()); IGgpkDirectory dir1 = archive.Root.Directories.FirstOrDefault(); Assert.AreEqual("Dir_1", dir1.Name); IGgpkFile file1 = dir1.Files.Where(f => f.Name == "test-file-1.bin").FirstOrDefault(); IGgpkFile file2 = dir1.Files.Where(f => f.Name == "Aa_Bb-Cc.DdEe").FirstOrDefault(); Assert.IsNotNull(file1); Assert.IsNotNull(file2); Assert.AreEqual <ulong>(4, file1.Length); Assert.IsNull(archive.Root.Parent); Assert.IsNotNull(dir1.Parent); Assert.IsNotNull(file1.Parent); Assert.IsNotNull(file2.Parent); }
public void TestArchive() { string poePath = Environment.GetEnvironmentVariable("POE_PATH"); if (string.IsNullOrEmpty(poePath)) { Assert.Inconclusive("Environment variable POE_PATH not defined - skipping test"); } string contentFile = Path.Combine(poePath, "content.ggpk"); if (!File.Exists(contentFile)) { Assert.Inconclusive("content.ggpk not found - skipping test"); } GgpkArchive archive = GgpkArchive.From(contentFile); Assert.IsNotNull(archive.Root); IEnumerable <IGgpkFile> files = archive.Root.ToFileList(); foreach (var file in files) { StringAssert.StartsWith(file.FullName, "/"); Assert.AreEqual(false, file.FullName.Contains('\\', StringComparison.InvariantCultureIgnoreCase)); } IGgpkDirectory dialogueDirectory = archive.GetDirectory("/Audio/Dialogue/"); Assert.IsNotNull(dialogueDirectory); IGgpkFile noAudioFoundFile = archive.GetFile("/Audio/NoFileFound.ogg"); Assert.IsNotNull(noAudioFoundFile); }
/// <summary> /// Gets an <see cref="IGgpkFile"/> based on the given path. /// </summary> /// <param name="path">The path of the file to search for.</param> /// <returns>An <see cref="IGgpkFile"/> representing the file.</returns> /// <exception cref="FileNotFoundException"><c>path</c> does not exist.</exception> /// <example> /// The following example demonstrates how to use <see cref="GgpkArchive.GetFile(string)"/> method: /// <code> /// GgpkArchive archive = GgpkArchive.From("/path/to/content.ggpk"); /// IGgpkFile noAudioFoundFile = archive.GetFile("/Audio/NoFileFound.ogg"); /// </code> /// </example> public IGgpkFile GetFile(string path) { string[] pathParts = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); IGgpkDirectory currentDirectory = this.Root; for (int i = 0; i < pathParts.Length - 1; i++) { currentDirectory = currentDirectory.Directories.Where(d => d.Name == pathParts[i]).FirstOrDefault(); if (currentDirectory is null) { throw new FileNotFoundException($"File {path} not found"); } } IGgpkFile file = currentDirectory.Files.Where(f => f.Name == pathParts[pathParts.Length - 1]).FirstOrDefault(); if (file is null) { throw new FileNotFoundException($"File {path} not found"); } return(file); }
public void GetFileNotFoundTest() { GgpkArchive archive = GgpkArchive.From(new FileInfo(@"pass.ggpk")); IGgpkFile file = archive.GetFile("/Dir_1/i_do_not_exist.non"); }
public void GetFileDirectoryNotFoundTest() { GgpkArchive archive = GgpkArchive.From(new FileInfo(@"pass.ggpk")); IGgpkFile file = archive.GetFile("/NonExistingDirectory/test-file-1.bin"); }
/// <summary> /// Initializes a new instance of the <see cref="GgpkStreamTests"/> class. /// </summary> public GgpkStreamTests() { this.archive = GgpkArchive.From(@"pass.ggpk"); this.file = this.archive.Root.Directories.Where(d => d.Name == "Dir_1").FirstOrDefault().Files.Where(f => f.Name == "Aa_Bb-Cc.DdEe").FirstOrDefault(); }