コード例 #1
0
        public async Task EditThenSaveArcAsTwice(string filename, string entryPath, string replacementFile, string expectedFile)
        {
            using (ArcFile arcFile = new ArcFile(filename))
            {
                ContainerEntry arcEntry = arcFile.GetEntry(entryPath);
                if (arcEntry == null)
                {
                    Assert.Fail("Entry not found.");
                }
                using (FileStream fileStream = new FileStream(replacementFile, FileMode.Open, FileAccess.Read))
                {
                    await arcEntry.SetData(fileStream);
                }
                await arcFile.SaveAs("temp1.arc", progress);

                await arcFile.SaveAs("temp2.arc", progress);
            }
            bool eq1 = Compare.CompareFiles(expectedFile, "temp1.arc");
            bool eq2 = Compare.CompareFiles(ArcFile.GetBinName(expectedFile), "temp1.bin");
            bool eq3 = Compare.CompareFiles(expectedFile, "temp2.arc");
            bool eq4 = Compare.CompareFiles(ArcFile.GetBinName(expectedFile), "temp2.bin");

            File.Delete("temp1.arc");
            File.Delete("temp1.bin");
            File.Delete("temp2.arc");
            File.Delete("temp2.bin");
            Assert.IsTrue(eq1);
            Assert.IsTrue(eq2);
            Assert.IsTrue(eq3);
            Assert.IsTrue(eq4);
        }
コード例 #2
0
        public async Task EditEntryReextractTest(string filename, string entryFilepath, string replacementFile, string expectedDir)
        {
            using (ArcFile arcFile = new ArcFile(filename))
            {
                ContainerEntry arcEntry = arcFile.GetEntry(entryFilepath);
                if (arcEntry == null)
                {
                    Assert.Fail("Entry not found.");
                }
                using (FileStream fileStream = new FileStream(replacementFile, FileMode.Open, FileAccess.Read))
                {
                    await arcEntry.SetData(fileStream);
                }
                await arcFile.SaveAs("temp.arc", progress);
            }
            using (ArcFile arcFile = new ArcFile("temp.arc"))
            {
                await arcFile.ExtractAllAsync("tempdir", false, progress);
            }
            File.Move(expectedDir + "/" + entryFilepath, "backup");
            File.Copy(replacementFile, expectedDir + "/" + entryFilepath);
            bool eq = Compare.CompareDirectories(expectedDir, "tempdir");

            File.Delete(expectedDir + "/" + entryFilepath);
            File.Move("backup", expectedDir + "/" + entryFilepath);

            DirectoryInfo directoryInfo = new DirectoryInfo("tempdir");

            directoryInfo.Delete(true);
            File.Delete("temp.arc");
            File.Delete("temp.bin");
            Assert.IsTrue(eq);
        }
コード例 #3
0
        public async Task PatchFont()
        {
            try
            {
                ClearStatus();
                ContainerEntry fontEntry = ArcFile.GetEntry("im2nx_font.par");
                if (fontEntry == null)
                {
                    throw new FileNotFoundException("File im2nx_font.par not found. Make sure you are opening disc.arc");
                }
                using (Stream parStream = await fontEntry.GetData())
                {
                    ReportMessage("Reading im2nx_font.par...");
                    Font font = await Task.Run(() => Font.CreateFromPar(parStream));

                    ReportMessage("Patching font...");
                    await Task.Run(() => font.AddDigraphs());

                    ReportMessage("Writing font as par...");
                    using MemoryStream memStream = new MemoryStream();
                    await font.WriteFontPar(memStream, false);

                    memStream.Position = 0;
                    await fontEntry.SetData(memStream);
                }
                ReportMessage("Done.");
            }
            catch (Exception ex)
            {
                ReportException(ex);
            }
        }
コード例 #4
0
        public async Task GetEntryAndWriteToFile(string filename, string entryFilepath, string expectedFile)
        {
            using ArcFile arcFile = new ArcFile(filename);
            ContainerEntry arcEntry = arcFile.GetEntry(entryFilepath);

            if (arcEntry == null)
            {
                Assert.Fail("Entry not found.");
            }
            using (Stream stream = await arcEntry.GetData())
            {
                using FileStream fileStream = new FileStream("temp.dat", FileMode.Create, FileAccess.Write);
                stream.CopyTo(fileStream);
            }
            bool eq = Compare.CompareFiles(expectedFile, "temp.dat");

            File.Delete("temp.dat");
            Assert.IsTrue(eq);
        }