Exemple #1
0
        public void CabInfoCompressExtract()
        {
            int fileCount = 10, fileSize = 1024;
            string dirA = String.Format("{0}-{1}-A", fileCount, fileSize);
            if (Directory.Exists(dirA)) Directory.Delete(dirA, true);
            Directory.CreateDirectory(dirA);
            Directory.CreateDirectory(Path.Combine(dirA, "sub"));
            string dirB = String.Format("{0}-{1}-B", fileCount, fileSize);
            if (Directory.Exists(dirB)) Directory.Delete(dirB, true);
            Directory.CreateDirectory(dirB);

            string[] files = new string[fileCount];
            for (int iFile = 0; iFile < fileCount; iFile++)
            {
                files[iFile] = "€" + iFile + ".txt";
                CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[iFile]), iFile, fileSize);
            }
            CompressionTestUtil.GenerateRandomFile(Path.Combine(Path.Combine(dirA, "sub"), "€-.txt"), fileCount + 1, fileSize);

            CabInfo cabInfo = new CabInfo("test.cab");
            cabInfo.Pack(dirA);
            cabInfo.Unpack(dirB);
            bool directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB);
            Assert.IsFalse(directoryMatch,
                "Testing whether cabinet output directory matches input directory.");
            Directory.Delete(dirB, true);
            Directory.CreateDirectory(dirB);
            cabInfo.Pack(dirA, true, CompressionLevel.Normal, null);
            cabInfo.Unpack(dirB);
            directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB);
            Assert.IsTrue(directoryMatch,
                "Testing whether cabinet output directory matches input directory.");
            Directory.Delete(dirB, true);
            Directory.Delete(Path.Combine(dirA, "sub"), true);
            Directory.CreateDirectory(dirB);
            cabInfo.Delete();

            cabInfo.PackFiles(dirA, files, null);
            cabInfo.UnpackFiles(files, dirB, null);
            directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB);
            Assert.IsTrue(directoryMatch,
                "Testing whether cabinet output directory matches input directory.");
            Directory.Delete(dirB, true);
            Directory.CreateDirectory(dirB);
            cabInfo.Delete();

            IDictionary<string, string> testMap = new Dictionary<string, string>(files.Length);
            for (int iFile = 0; iFile < fileCount; iFile++)
            {
                testMap[files[iFile] + ".key"] = files[iFile];
            }
            cabInfo.PackFileSet(dirA, testMap);
            cabInfo.UnpackFileSet(testMap, dirB);
            directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB);
            Assert.IsTrue(directoryMatch,
                "Testing whether cabinet output directory matches input directory.");
            Directory.Delete(dirB, true);
            Directory.CreateDirectory(dirB);

            testMap.Remove(files[1] + ".key");
            cabInfo.UnpackFileSet(testMap, dirB);
            directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB);
            Assert.IsFalse(directoryMatch,
                "Testing whether cabinet output directory matches input directory.");
            Directory.Delete(dirB, true);
            Directory.CreateDirectory(dirB);
            cabInfo.Delete();

            cabInfo.PackFiles(dirA, files, null);
            cabInfo.UnpackFile("€2.txt", Path.Combine(dirB, "test.txt"));
            Assert.IsTrue(File.Exists(Path.Combine(dirB, "test.txt")));
            Assert.AreEqual<int>(1, Directory.GetFiles(dirB).Length);
        }
Exemple #2
0
        /// <summary>
        /// Packs the input files into a cab that is appended to the
        /// output SfxCA.dll.
        /// </summary>
        private static void PackInputFiles(string outputFile, IDictionary<string, string> fileMap)
        {
            log.WriteLine("Packaging files");

            CabInfo cabInfo = new CabInfo(outputFile);
            cabInfo.PackFileSet(null, fileMap, CompressionLevel.Max, PackProgress);
        }