Пример #1
0
        public void GetDirectoryTest(string path)
        {
            GgpkArchive    archive = GgpkArchive.From(new FileInfo(@"pass.ggpk"));
            IGgpkDirectory dir     = archive.GetDirectory(path);

            Assert.AreEqual(2, dir.Files.Count());
        }
Пример #2
0
        public void TestFullName()
        {
            GgpkArchive    archive = GgpkArchive.From(@"pass.ggpk");
            IGgpkDirectory dir     = archive.Root.Directories.Where(d => d.Name == "Dir_1").FirstOrDefault();

            Assert.AreEqual("/Dir_1/", dir.FullName);
        }
Пример #3
0
        static void PrintDirectory(IGgpkDirectory directory)
        {
            foreach (var file in directory.Files)
            {
                Console.WriteLine(file.FullName);
            }

            foreach (var subDirectory in directory.Directories)
            {
                PrintDirectory(subDirectory);
            }
        }
Пример #4
0
        /// <summary>
        /// Returns the files of the given directory and all subdirectories.
        /// </summary>
        /// <param name="directory">The given directory.</param>
        /// <returns>All files inside the given directory and all subdirectories.</returns>
        public static IEnumerable <IGgpkFile> ToFileList(this IGgpkDirectory directory)
        {
            List <IGgpkFile> files = new List <IGgpkFile>();

            files.AddRange(directory.Files);

            foreach (IGgpkDirectory subDirectory in directory.Directories)
            {
                files.AddRange(subDirectory.ToFileList());
            }

            return(files);
        }
Пример #5
0
        /// <summary>
        /// Gets the full name of the element (including the names of the parents).
        /// </summary>
        /// <param name="currentDirectory">The current <see cref="IGgpkDirectory"/>.</param>
        /// <param name="name">The name.</param>
        /// <returns>The new name including the name of the current <see cref="IGgpkDirectory"/>.</returns>
        protected virtual string GetName(IGgpkDirectory currentDirectory, string name)
        {
            IGgpkDirectory element = currentDirectory;
            string         result  = name;

            while (element != null)
            {
                if (!string.IsNullOrEmpty(element.Name))
                {
                    result = $"{element.Name}/{result}";
                }

                element = element.Parent;
            }

            return($"/{result}");
        }
Пример #6
0
        /// <summary>
        /// Gets an <see cref="IGgpkDirectory"/> based on the given path.
        /// </summary>
        /// <param name="path">The path of the directory to search for.</param>
        /// <returns>An <see cref="IGgpkDirectory"/> representing the directory.</returns>
        /// <exception cref="DirectoryNotFoundException"><c>path</c> does not exist.</exception>
        /// <example>
        /// The following example demonstrates how to use <see cref="GgpkArchive.GetDirectory(string)"/> method:
        /// <code>
        /// GgpkArchive archive = GgpkArchive.From("/path/to/content.ggpk");
        /// IGgpkDirectory dialogueDirectory = archive.GetDirectory("/Audio/Dialogue/");
        /// </code>
        /// </example>
        public IGgpkDirectory GetDirectory(string path)
        {
            string[]       pathParts        = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            IGgpkDirectory currentDirectory = this.Root;

            foreach (string pathPart in pathParts)
            {
                currentDirectory = currentDirectory.Directories.Where(d => d.Name == pathPart).FirstOrDefault();

                if (currentDirectory is null)
                {
                    throw new DirectoryNotFoundException($"Path {path} not found");
                }
            }

            return(currentDirectory);
        }
Пример #7
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);
        }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
0
 public void GetDirectoryNotFoundTest()
 {
     GgpkArchive    archive = GgpkArchive.From(new FileInfo(@"pass.ggpk"));
     IGgpkDirectory dir     = archive.GetDirectory("/NonExistingDirectory/");
 }