Example #1
0
        public void CabinetUtfPaths()
        {
            string[] files = new string[]
            {
                "어그리먼트送信ポート1ßà_Agreement.txt",
                "콘토소ßà_MyProfile.txt",
                "파트너1ßà_PartnerProfile.txt",
            };

            string dirA = "utf8-A";
            if (Directory.Exists(dirA)) Directory.Delete(dirA, true);
            Directory.CreateDirectory(dirA);
            string dirB = "utf8-B";
            if (Directory.Exists(dirB)) Directory.Delete(dirB, true);
            Directory.CreateDirectory(dirB);

            int txtSize = 1024;
            CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[0]), 0, txtSize);
            CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[1]), 1, txtSize);
            CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[2]), 2, txtSize);

            ArchiveFileStreamContext streamContextA = new ArchiveFileStreamContext("utf8.cab", dirA, null);
            using (CabEngine cabEngine = new CabEngine())
            {
                cabEngine.Pack(streamContextA, files);
            }

            ArchiveFileStreamContext streamContextB = new ArchiveFileStreamContext("utf8.cab", dirB, null);
            using (CabEngine cex = new CabEngine())
            {
                cex.Unpack(streamContextB, null);
            }

            bool directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB);
            Assert.IsTrue(directoryMatch,
                "Testing whether cabinet output directory matches input directory.");
        }
Example #2
0
        public void CabEngineNoTempFileTest()
        {
            int txtSize = 10240;
            CompressionTestUtil.GenerateRandomFile("testnotemp.txt", 0, txtSize);

            ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext("testnotemp.cab", null, null);

            using (CabEngine cabEngine = new CabEngine())
            {
                cabEngine.UseTempFiles = false;
                cabEngine.Pack(streamContext, new string[] { "testnotemp.txt" });
            }

            new CabInfo("testnotemp.cab").UnpackFile("testnotemp.txt", "testnotemp2.txt");
            Assert.AreEqual(txtSize, new FileInfo("testnotemp2.txt").Length);
        }
Example #3
0
        public void CabinetOffset()
        {
            int txtSize = 10240;
            CompressionTestUtil.GenerateRandomFile("test.txt", 0, txtSize);
            CompressionTestUtil.GenerateRandomFile("base.txt", 1, 2 * txtSize + 4);

            ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext("base.txt", null, null);
            streamContext.EnableOffsetOpen = true;

            using (CabEngine cabEngine = new CabEngine())
            {
                cabEngine.Pack(streamContext, new string[] { "test.txt" });
            }

            Assert.IsTrue(new FileInfo("base.txt").Length > 2 * txtSize + 4);

            string saveText;
            using (Stream txtStream = File.OpenRead("test.txt"))
            {
                saveText = new StreamReader(txtStream).ReadToEnd();
            }
            File.Delete("test.txt");

            using (CabEngine cex = new CabEngine())
            {
                cex.Unpack(streamContext, null);
            }
            string testText;
            using (Stream txtStream = File.OpenRead("test.txt"))
            {
                testText = new StreamReader(txtStream).ReadToEnd();
            }
            Assert.AreEqual<string>(saveText, testText);
        }
Example #4
0
        private IList<ArchiveFileInfo> RunCabinetPackUnpack(int fileCount, long fileSize,
            long maxFolderSize, long maxArchiveSize, CompressionLevel compLevel)
        {
            Console.WriteLine("Creating cabinet with {0} files of size {1}",
                fileCount, fileSize);
            Console.WriteLine("MaxFolderSize={0}, MaxArchiveSize={1}, CompressionLevel={2}",
                maxFolderSize, maxArchiveSize, compLevel);

            string dirA = String.Format("{0}-{1}-A", fileCount, fileSize);
            if (Directory.Exists(dirA)) Directory.Delete(dirA, true);
            Directory.CreateDirectory(dirA);
            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] = TEST_FILENAME_PREFIX + iFile + ".txt";
                CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[iFile]), iFile, fileSize);
            }

            string[] archiveNames = new string[100];
            for (int i = 0; i < archiveNames.Length; i++)
            {
                archiveNames[i] = String.Format("{0}-{1}{2}{3}.cab", fileCount, fileSize,
                    (i == 0 ? "" : "-"), (i == 0 ? "" : i.ToString()));
            }

            string progressTextFile = String.Format("progress_{0}-{1}.txt", fileCount, fileSize);
            CompressionTestUtil testUtil = new CompressionTestUtil(progressTextFile);

            IList<ArchiveFileInfo> fileInfo;
            using (CabEngine cabEngine = new CabEngine())
            {
                cabEngine.CompressionLevel = compLevel;

                File.AppendAllText(progressTextFile,
                    "\r\n\r\n====================================================\r\nCREATE\r\n\r\n");
                cabEngine.Progress += testUtil.PrintArchiveProgress;

                OptionStreamContext streamContext = new OptionStreamContext(archiveNames, dirA, null);
                if (maxFolderSize == 1)
                {
                    streamContext.OptionHandler =
                        delegate(string optionName, object[] parameters)
                        {
                            if (optionName == "nextFolder") return true;
                            return null;
                        };
                }
                else if (maxFolderSize > 1)
                {
                    streamContext.OptionHandler =
                        delegate(string optionName, object[] parameters)
                        {
                            if (optionName == "maxFolderSize") return maxFolderSize;
                            return null;
                        };
                }
                cabEngine.Pack(streamContext, files, maxArchiveSize);

                IList<string> createdArchiveNames = new List<string>(archiveNames.Length);
                for (int i = 0; i < archiveNames.Length; i++)
                {
                    if (File.Exists(archiveNames[i]))
                    {
                        createdArchiveNames.Add(archiveNames[i]);
                    }
                    else
                    {
                        break;
                    }
                }

                Console.WriteLine("Listing cabinet with {0} files of size {1}",
                    fileCount, fileSize);
                File.AppendAllText(progressTextFile, "\r\n\r\nLIST\r\n\r\n");
                fileInfo = cabEngine.GetFileInfo(
                    new ArchiveFileStreamContext(createdArchiveNames, null, null), null);

                Assert.AreEqual<int>(fileCount, fileInfo.Count);
                if (fileCount > 0)
                {
                    int folders = ((CabFileInfo) fileInfo[fileInfo.Count - 1]).CabinetFolderNumber + 1;
                    if (maxFolderSize == 1)
                    {
                        Assert.AreEqual<int>(fileCount, folders);
                    }
                }

                Console.WriteLine("Extracting cabinet with {0} files of size {1}",
                    fileCount, fileSize);
                File.AppendAllText(progressTextFile, "\r\n\r\nEXTRACT\r\n\r\n");
                cabEngine.Unpack(new ArchiveFileStreamContext(createdArchiveNames, dirB, null), null);
            }

            bool directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB);
            Assert.IsTrue(directoryMatch,
                "Testing whether cabinet output directory matches input directory.");

            return fileInfo;
        }