Ejemplo n.º 1
0
        public void GetFileTest(string path)
        {
            GgpkArchive archive = GgpkArchive.From(new FileInfo(@"pass.ggpk"));
            IGgpkFile   file    = archive.GetFile(path);

            Assert.AreEqual(4UL, file.Length);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
 public void GetFileNotFoundTest()
 {
     GgpkArchive archive = GgpkArchive.From(new FileInfo(@"pass.ggpk"));
     IGgpkFile   file    = archive.GetFile("/Dir_1/i_do_not_exist.non");
 }
Ejemplo n.º 7
0
 public void GetFileDirectoryNotFoundTest()
 {
     GgpkArchive archive = GgpkArchive.From(new FileInfo(@"pass.ggpk"));
     IGgpkFile   file    = archive.GetFile("/NonExistingDirectory/test-file-1.bin");
 }
Ejemplo n.º 8
0
 /// <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();
 }