示例#1
0
        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);
        }
示例#2
0
        public void TestPackAndUnpack()
        {
            // Gather 500 random files to throw into a bin
            var archivePath = Path.Combine(Path.GetTempPath(), $"{nameof(TestPackAndUnpack)}_packed_archive.bin");
            var targetDir   = GameDataPathExtracted;

            if (!targetDir.EndsWith('\\'))
            {
                targetDir += "\\";
            }

            var filesToCombine = Directory
                                 .EnumerateFiles(targetDir, "*.core", SearchOption.AllDirectories)
                                 .Take(500)
                                 .Select(f => f.Substring(targetDir.Length))
                                 .ToArray();

            using (var writeArchive = new PackfileWriter(archivePath, false, FileMode.Create))
                writeArchive.BuildFromFileList(targetDir, filesToCombine);

            // Re-extract all of the contained files into memory
            using (var readArchive = new PackfileReader(archivePath))
            {
                readArchive.Validate();

                using var tempMS = new MemoryStream();

                foreach (string file in filesToCombine)
                {
                    tempMS.Position = 0;
                    tempMS.SetLength(0);
                    readArchive.ExtractFile(file, tempMS);

                    var tempFilePath = Path.Combine(targetDir, file);
                    Assert.IsTrue(tempMS.Length == new FileInfo(tempFilePath).Length);
                }
            }

            File.Delete(archivePath);
        }
示例#3
0
        public static void PackArchivesQuickTest()
        {
            string archivePath = Path.Combine(GameDataPath, "test_packed_archive.tmp");

            var testArchive = new PackfileWriter(archivePath, false, true);

            testArchive.BuildFromFileList(GameDataPathExtracted, QuickTestFiles);

            var testArchive2 = new PackfileReader(archivePath);

            testArchive2.Validate();

            // Re-extract all of the contained files
            foreach (string file in QuickTestFiles)
            {
                string tempFilePath = Path.Combine(GameDataPathExtracted, $"{file}.tmp");

                testArchive2.ExtractFile(file, tempFilePath, true);
                File.Delete(tempFilePath);
            }

            File.Delete(archivePath);
        }
示例#4
0
        public static void PackArchivesTest()
        {
            string archivePath = Path.Combine(GameDataPath, "test_packed_archive.tmp");
            string targetDir   = GameDataPathExtracted;

            if (!targetDir.EndsWith('\\'))
            {
                targetDir += "\\";
            }

            var filesToCombine = Directory
                                 .EnumerateFiles(targetDir, "*.core", SearchOption.AllDirectories)
                                 .Take(500)
                                 .Select(f => f.Substring(targetDir.Length))
                                 .ToArray();

            var testArchive = new PackfileWriter(archivePath, false, true);

            testArchive.BuildFromFileList(targetDir, filesToCombine);

            var testArchive2 = new PackfileReader(archivePath);

            testArchive2.Validate();

            // Re-extract all of the contained files
            foreach (string file in filesToCombine)
            {
                string tempFilePath = Path.Combine(targetDir, $"{file}.tmp");

                testArchive2.ExtractFile(file, tempFilePath, true);
                File.Delete(tempFilePath);
            }


            File.Delete(archivePath);
        }