private void doRoundTrip(string examplesZip, string baseTestPath)
        {
            var examplePath = Path.Combine(baseTestPath, "input");

            Directory.CreateDirectory(examplePath);
            // Unzip files into this path
            Debug.WriteLine("Unzipping example files from {0} to {1}", examplesZip, examplePath);

            ArchiveFactory.WriteToDirectory(examplesZip, examplePath);

            //using (var zipfile = ZipFile.Read(examplesZip))
            //{
            //    zipfile.ExtractAll(examplePath, ExtractExistingFileAction.OverwriteSilently);
            //}

            var intermediate1Path = Path.Combine(baseTestPath, "intermediate1");

            Debug.WriteLine("Converting files in {0} to {1}", baseTestPath, intermediate1Path);
            convertFiles(examplePath, intermediate1Path);
            var intermediate2Path = Path.Combine(baseTestPath, "intermediate2");

            Debug.WriteLine("Re-converting files in {0} back to original format in {1}", intermediate1Path, intermediate2Path);
            convertFiles(intermediate1Path, intermediate2Path);
            Debug.WriteLine("Comparing files in {0} to files in {1}", baseTestPath, intermediate2Path);
            compareFiles(examplePath, intermediate2Path);
        }
Beispiel #2
0
        private static void unzip(string zipPath, string outputPath)
        {
            ArchiveFactory.WriteToDirectory(zipPath, outputPath);

            //using (var zipfile = ZipFile.Read(zipPath))
            //{
            //    zipfile.ExtractAll(outputPath);
            //}
        }
Beispiel #3
0
        /// <summary>
        /// 解压文件,自动检测压缩包类型
        /// </summary>
        /// <param name="compressedFile">rar文件</param>
        /// <param name="dir">解压到...</param>
        /// <param name="ignoreEmptyDir">忽略空文件夹</param>
        public void Decompress(string compressedFile, string dir, bool ignoreEmptyDir = true)
        {
            if (string.IsNullOrEmpty(dir))
            {
                dir = Path.GetDirectoryName(compressedFile);
            }

            ArchiveFactory.WriteToDirectory(compressedFile, Directory.CreateDirectory(dir).FullName, new ExtractionOptions()
            {
                ExtractFullPath = true,
                Overwrite       = true
            });
        }
Beispiel #4
0
        public static void ExtractAllFilesInDirectory(string folder)
        {
            //TODO OPTIMIZE
            var filesExtracted = false;

            do
            {
                filesExtracted = false;
                foreach (var file in Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories))
                {
                    if (file.EndsWith(".zip") || file.EndsWith(".rar") || file.EndsWith(".7z") || file.EndsWith(".gz") || file.EndsWith(".tar") || file.EndsWith(".bz2"))
                    {
                        filesExtracted = true;
                        var outputPath = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file));
                        Directory.CreateDirectory(outputPath);
                        ArchiveFactory.WriteToDirectory(file, outputPath, SharpCompress.Common.ExtractOptions.ExtractFullPath);
                        File.Delete(file);
                    }
                }
            } while (filesExtracted);
        }
Beispiel #5
0
        private void ProcessArchive(FileInfo fileInfo)
        {
            WriteDebug("ProcessArchive: " + fileInfo);

            //EnsureArchiveFormat(fileInfo);

            string plaintext         = null;
            bool   passwordSpecified = false;

            if (Password != null)
            {
                passwordSpecified = true;
                IntPtr bstr = Marshal.SecureStringToBSTR(Password);
                plaintext = Marshal.PtrToStringBSTR(bstr);
                Marshal.FreeBSTR(bstr);
            }

            // we don't need to cache extractor here as we only expect one archive per
            // call to this method.

            /*
             * using (var extractor = passwordSpecified ?
             * new SevenZipExtractor(fileInfo.FullName, password: plaintext) :
             * new SevenZipExtractor(fileInfo.FullName))
             * {
             */
            //extractor.PreserveDirectoryStructure = !FlattenPaths;

            if (Index == null && EntryPath == null)
            {
                WriteVerbose("Expanding all.");

                if (ShouldProcess("Entire Archive", "Expand"))
                {
                    ArchiveFactory.WriteToDirectory(fileInfo.FullName, OutputPath.ProviderPath, SharpCompress.Common.ExtractOptions.ExtractFullPath);
                    //extractor.ExtractArchive(OutputPath.ProviderPath);
                }
            }
            else
            {
                // we allow mix of -Index and -EntryPath entries
                if (this.Index != null)
                {
                    WriteVerbose("Extracting index referenced file(s).");
                    if (ShouldProcess("Index list", "Expand"))
                    {
                        ArchiveFactory.WriteToDirectory(fileInfo.FullName, OutputPath.ProviderPath, this.Index, SharpCompress.Common.ExtractOptions.ExtractFullPath);
                        //extractor.ExtractFiles(OutputPath.ProviderPath, this.Index);
                    }
                }
                if (this.EntryPath != null)
                {
                    WriteVerbose("Extracting path referenced file(s).");
                    if (ShouldProcess("EntryPath list", "Expand"))
                    {
                        ArchiveFactory.WriteToDirectory(fileInfo.FullName, OutputPath.ProviderPath, SharpCompress.Common.ExtractOptions.ExtractFullPath);
                        //extractor.ExtractFiles(OutputPath.ProviderPath, this.EntryPath);
                    }
                }
            }
            //}
        }
Beispiel #6
0
 public static void ExtractToDirectory(string pathToZipFile, string extractToDir)
 {
     ArchiveFactory.WriteToDirectory(pathToZipFile, extractToDir, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite | ExtractOptions.PreserveFileTime);
 }
Beispiel #7
0
 public static void ExtractSevenZip(string zipFileName, string targetDirectory)
 {
     ArchiveFactory.WriteToDirectory(zipFileName, targetDirectory);
 }