コード例 #1
0
        public void TestGeneralTwoFiles()
        {
            var archive = BA2Loader.Load(SharedData.GetDataPath("GeneralTwoFiles.ba2"));
            var header  = archive.Header;

            Assert.IsTrue(header.Signature.SequenceEqual(SharedData.ArchiveMagic));
            Assert.AreEqual(1U, header.Version);
            Assert.IsTrue(BA2Loader.GetArchiveType(header.ArchiveType) == BA2Type.General);
            Assert.AreEqual(2U, header.TotalFiles);
            Assert.AreEqual(121UL, header.NameTableOffset);

            var files = archive.FileList;

            Assert.AreEqual(2, files.Count);
            Assert.AreEqual("test.txt", files[0]);
            Assert.AreEqual("wazzup.bin", files[1]);

            var folder = SharedData.CreateTempDirectory();

            archive.Extract("test.txt", folder, false);

            var testPath = Path.Combine(folder, "test.txt");

            Assert.IsTrue(File.Exists(testPath));

            TestUtils.AssertExtractedTextFile(archive, archive.GetIndexFromFilename("test.txt"), "test text");
            TestUtils.AssertExtractedTextFile(archive, archive.GetIndexFromFilename("wazzup.bin"), "wazzup dude bro?");

            // Assert.IsTrue(File.ReadAllLines)
        }
コード例 #2
0
        public void ExtractShouldThrowExceptionWhenDisposed()
        {
            BA2GeneralArchive archive = BA2Loader.Load <BA2GeneralArchive>(SharedData.GeneralOneFileArchive);

            archive.Dispose();

            var dir = SharedData.CreateTempDirectory();

            using (var stream = new MemoryStream())
            {
                Assert.Throws <ObjectDisposedException>(() => archive.Extract(0, dir, false));
                Assert.Throws <ObjectDisposedException>(() => archive.Extract("test.txt", dir, false));
                Assert.Throws <ObjectDisposedException>(() => archive.ExtractToStream(0, stream));
                Assert.Throws <ObjectDisposedException>(() => archive.ExtractAll("", false));
                Assert.Throws <ObjectDisposedException>(() => archive.ExtractAll("", false, CancellationToken.None, null));
                Assert.Throws <ObjectDisposedException>(() => archive.ExtractFiles(new int[] { 0 }, dir, false));
                Assert.Throws <ObjectDisposedException>(() => archive.ExtractFiles(new int[] { 0 }, dir, false,
                                                                                   CancellationToken.None, null));
                Assert.Throws <ObjectDisposedException>(() => archive.ExtractFiles(new string[] { "test.txt" }, dir, false));
                Assert.Throws <ObjectDisposedException>(() => archive.ExtractFiles(new string[] { "test.txt" }, dir, false,
                                                                                   CancellationToken.None, null));

                // These methods should not throw ObjectDisposedException
                Assert.DoesNotThrow(() => {
                    var files = archive.FileList;
                    archive.GetIndexFromFilename("test.txt");
                    archive.GetIndexFromFilename("ajkkfajsdlkfjlkasdf");
                    var total  = archive.TotalFiles;
                    var header = archive.Header;
                });
            }
        }
コード例 #3
0
        public void TestGeneralArchiveExtractionWithProgress()
        {
            BA2Archive archive          = BA2Loader.Load(SharedData.GeneralOneFileArchive);
            string     temp             = SharedData.CreateTempDirectory();
            int        progressValue    = 0;
            bool       progressReceived = false;
            var        progressHandler  = new Progress <int>(x =>
            {
                progressReceived = true;
                progressValue    = x;
            });

            archive.ExtractAll(temp, false, CancellationToken.None, progressHandler);

            // workaround of dumb test execution
            int waits = 0;

            while (!progressReceived)
            {
                if (waits > 10)
                {
                    break;
                }
                Thread.Sleep(25);
                waits++;
            }
            Assert.AreEqual(1, progressValue);
        }
コード例 #4
0
        public void ExtractAllFromTwoFileArchive()
        {
            BA2GeneralArchive archive = BA2Loader.Load <BA2GeneralArchive>(SharedData.GeneralTwoFilesArchive);

            string temp = SharedData.CreateTempDirectory();

            archive.ExtractAll(temp, false);
            Assert.IsTrue(File.Exists(Path.Combine(temp, "test.txt")));
            Assert.IsTrue(File.Exists(Path.Combine(temp, "wazzup.bin")));

            archive.Dispose();
        }
コード例 #5
0
        public void ExtractFilesByIndexesFromTwoFileArchiveMultithreaded()
        {
            BA2GeneralArchive archive =
                BA2Loader.Load <BA2GeneralArchive>(SharedData.GeneralTwoFilesArchive, BA2LoaderFlags.Multithreaded);

            string temp = SharedData.CreateTempDirectory();

            archive.ExtractFiles(new int[] { 0, 1 }, temp, false);
            Assert.IsTrue(File.Exists(Path.Combine(temp, "test.txt")));
            Assert.IsTrue(File.Exists(Path.Combine(temp, "wazzup.bin")));

            archive.Dispose();
        }
コード例 #6
0
        public void TestGeneralOneFile()
        {
            var archive = BA2Loader.Load(SharedData.GetDataPath("GeneralOneFile.ba2"));
            var header  = archive.Header;

            Assert.IsTrue(header.Signature.SequenceEqual(SharedData.ArchiveMagic));
            Assert.AreEqual(1U, header.Version);
            Assert.IsTrue(BA2Loader.GetArchiveType(header.ArchiveType) == BA2Type.General);
            Assert.AreEqual(1U, header.TotalFiles);
            Assert.AreEqual(69UL, header.NameTableOffset);

            var files = archive.FileList;

            Assert.AreEqual(1, files.Count);
            Assert.AreEqual(true, archive.ContainsFile("test.txt"));

            var folder = SharedData.CreateTempDirectory();

            archive.Extract("test.txt", folder, false);
            string path = Path.Combine(folder, "test.txt");

            Assert.IsTrue(File.Exists(path));
            Assert.AreEqual("test text", File.ReadAllText(path));
        }