當前位置: 首頁>>代碼示例>>C#>>正文


C# SevenZipCompressor.CompressFiles方法代碼示例

本文整理匯總了C#中SevenZip.SevenZipCompressor.CompressFiles方法的典型用法代碼示例。如果您正苦於以下問題:C# SevenZipCompressor.CompressFiles方法的具體用法?C# SevenZipCompressor.CompressFiles怎麽用?C# SevenZipCompressor.CompressFiles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SevenZip.SevenZipCompressor的用法示例。


在下文中一共展示了SevenZipCompressor.CompressFiles方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GZipFiles

        /// <summary>
        /// Compresses files using gzip format
        /// </summary>
        /// <param name="files">The files.</param>
        /// <param name="destination">The destination.</param>
        public static void GZipFiles(string[] files, string destination)
        {
            SetupZlib();

            SevenZipCompressor compressor = new SevenZipCompressor();
            compressor.ArchiveFormat = OutArchiveFormat.GZip;
            compressor.CompressFiles(destination, files);
        }
開發者ID:UhuruSoftware,項目名稱:vcap-dotnet,代碼行數:13,代碼來源:ZipUtilities.cs

示例2: ZipFiles

 public static void ZipFiles(string archivePath, params string[] targetFilesPath)
 {
     var compressor = new SevenZipCompressor();
     compressor.ArchiveFormat = OutArchiveFormat.SevenZip;
     compressor.CompressionMode = CompressionMode.Create;
     compressor.TempFolderPath = System.IO.Path.GetTempPath();
     //compressor.CompressDirectory(source, output);
     compressor.CompressFiles(archivePath, targetFilesPath);
 }
開發者ID:MichalGrzegorzak,項目名稱:Ylvis,代碼行數:9,代碼來源:SevenZipSharp.cs

示例3: compress

 static public void compress(string source, string outputFileName) {
     if (source != null && outputFileName != null) {
         SevenZipCompressor.SetLibraryPath("7z.dll");
         SevenZipCompressor cmp = new SevenZipCompressor();
         cmp.Compressing += new EventHandler<ProgressEventArgs>(cmp_Compressing);
         cmp.FileCompressionStarted += new EventHandler<FileNameEventArgs>(cmp_FileCompressionStarted);
         cmp.CompressionFinished += new EventHandler<EventArgs>(cmp_CompressionFinished);
         cmp.ArchiveFormat = (OutArchiveFormat)Enum.Parse(typeof(OutArchiveFormat), "SevenZip");
         cmp.CompressFiles(outputFileName, source);
     }
 }
開發者ID:AdenFlorian,項目名稱:SlickUpdater,代碼行數:11,代碼來源:Zippy.cs

示例4: SevenZIP

        public static void SevenZIP(List<string> files, string output)
        {
            SevenZipExtractor.SetLibraryPath(ConfigurationManager.AppSettings["7ZIPDLL"]);

            SevenZipCompressor.SetLibraryPath(ConfigurationManager.AppSettings["7ZIPDLL"]);

            SevenZipCompressor compressor = new SevenZipCompressor();
            compressor.ArchiveFormat = OutArchiveFormat.SevenZip;
            compressor.CompressionMode = CompressionMode.Create;
            compressor.TempFolderPath = System.IO.Path.GetTempPath();
            //compressor.VolumeSize = 51200000;//50 MB
            compressor.CompressFiles(output, files.ToArray());
        }
開發者ID:mberaz,項目名稱:ex10ntions,代碼行數:13,代碼來源:seven+zip+Compresor.cs

示例5: Build

        public void Build(Package package, string path)
        {
            var archiveName = package.Manifest.Name.ToLowerInvariant().Replace(" ", "-") + "-v" + package.Manifest.Version;
            var archive = Path.Combine(FilePaths.PackageRepository, archiveName) + FileTypes.Package;

            var file = new FileInfo(Assembly.GetExecutingAssembly().Location);

            SevenZipCompressor.SetLibraryPath(Path.Combine(file.DirectoryName, "7z.dll"));

            var sevenZipCompressor = new SevenZipCompressor
                {
                    ArchiveFormat = OutArchiveFormat.SevenZip,
                    CompressionLevel = CompressionLevel.Ultra
                };

            sevenZipCompressor.Compressing += this.Compressing;
            sevenZipCompressor.CompressionFinished += this.CompressingFinished;

            sevenZipCompressor.CompressFiles(archive, package.Manifest.Files.Select(manifestFile => manifestFile.File).ToArray());
        }
開發者ID:jamesbroome,項目名稱:Templify,代碼行數:20,代碼來源:SevenZipBuilder.cs

示例6: Execute

            public override void Execute()
            {
                if (_cmdlet._directoryOrFilesFromPipeline == null) {
                    _cmdlet._directoryOrFilesFromPipeline = new List<string> {
                        _cmdlet.Path
                    };
                }

                var directoryOrFiles = _cmdlet._directoryOrFilesFromPipeline
                    .Select(path => new FileInfo(System.IO.Path.Combine(_cmdlet.SessionState.Path.CurrentFileSystemLocation.Path, path)).FullName).ToArray();
                var archiveFileName = new FileInfo(System.IO.Path.Combine(_cmdlet.SessionState.Path.CurrentFileSystemLocation.Path, _cmdlet.ArchiveFileName)).FullName;

                switch (System.IO.Path.GetExtension(archiveFileName).ToLowerInvariant()) {
                    case ".7z":
                        _cmdlet.Format = OutArchiveFormat.SevenZip;
                        break;
                    case ".zip":
                        _cmdlet.Format = OutArchiveFormat.Zip;
                        break;
                    case ".gz":
                        _cmdlet.Format = OutArchiveFormat.GZip;
                        break;
                    case ".bz2":
                        _cmdlet.Format = OutArchiveFormat.BZip2;
                        break;
                    case ".tar":
                        _cmdlet.Format = OutArchiveFormat.Tar;
                        break;
                    case ".xz":
                        _cmdlet.Format = OutArchiveFormat.XZ;
                        break;
                }

                var compressor = new SevenZipCompressor {
                    ArchiveFormat = _cmdlet.Format,
                    CompressionLevel = _cmdlet.CompressionLevel,
                    CompressionMethod = _cmdlet.CompressionMethod
                };
                _cmdlet.CustomInitialization?.Invoke(compressor);

                var activity = directoryOrFiles.Length > 1
                    ? $"Compressing {directoryOrFiles.Length} Files to {archiveFileName}"
                    : $"Compressing {directoryOrFiles.First()} to {archiveFileName}";

                var currentStatus = "Compressing";
                compressor.FilesFound += (sender, args) =>
                    Write($"{args.Value} files found for compression");
                compressor.Compressing += (sender, args) =>
                    WriteProgress(new ProgressRecord(0, activity, currentStatus) { PercentComplete = args.PercentDone });
                compressor.FileCompressionStarted += (sender, args) => {
                    currentStatus = $"Compressing {args.FileName}";
                    Write($"Compressing {args.FileName}");
                };

                if (directoryOrFiles.Any(path => new FileInfo(path).Exists)) {
                    var notFoundFiles = directoryOrFiles.Where(path => !new FileInfo(path).Exists).ToArray();
                    if (notFoundFiles.Any()) {
                        throw new FileNotFoundException("File(s) not found: " + string.Join(", ", notFoundFiles));
                    }
                    if (HasPassword) {
                        compressor.CompressFiles(archiveFileName, directoryOrFiles);
                    } else {
                        compressor.CompressFilesEncrypted(archiveFileName, _cmdlet.Password, directoryOrFiles);
                    }
                }

                if (directoryOrFiles.Any(path => new DirectoryInfo(path).Exists)) {
                    if (directoryOrFiles.Length > 1) {
                        throw new ArgumentException("Only one directory allowed as input");
                    }

                    if (_cmdlet.Filter != null) {
                        if (HasPassword) {
                            compressor.CompressDirectory(directoryOrFiles[0], archiveFileName, _cmdlet.Password, _cmdlet.Filter, true);
                        } else {
                            compressor.CompressDirectory(directoryOrFiles[0], archiveFileName, _cmdlet.Filter, true);
                        }
                    } else {
                        if (HasPassword) {
                            compressor.CompressDirectory(directoryOrFiles[0], archiveFileName, _cmdlet.Password);
                        } else {
                            compressor.CompressDirectory(directoryOrFiles[0], archiveFileName);
                        }
                    }
                }

                WriteProgress(new ProgressRecord(0, activity, "Finished") { RecordType = ProgressRecordType.Completed });
                Write("Compression finished");
            }
開發者ID:onyxhat,項目名稱:7Zip4Powershell,代碼行數:89,代碼來源:Compress7Zip.cs

示例7: compressFiles

 /// <param name="zip">Compressor.</param>
 /// <param name="name">Archive name.</param>
 /// <param name="input">Input files.</param>
 protected virtual void compressFiles(SevenZipCompressor zip, string name, params string[] input)
 {
     zip.CompressFiles(name, input); // -_-
 }
開發者ID:3F,項目名稱:vsCommandEvent,代碼行數:7,代碼來源:SevenZipComponent.cs

示例8: CompressFilesZipTest

		public void CompressFilesZipTest(){
			var tmp = new SevenZipCompressor();
			tmp.ArchiveFormat = OutArchiveFormat.Zip;
			tmp.CompressFiles(Path.Combine(tempFolder, TestContext.TestName + ".zip"), testFile1, testFile2);
		}
開發者ID:KOLANICH,項目名稱:SevenZipSharp,代碼行數:5,代碼來源:SevenZipTestPack.cs

示例9: CompressionTestLotsOfFeatures

		public void CompressionTestLotsOfFeatures(){
			var tmp = new SevenZipCompressor();
			tmp.ArchiveFormat = OutArchiveFormat.SevenZip;
			tmp.CompressionLevel = CompressionLevel.High;
			tmp.CompressionMethod = CompressionMethod.Ppmd;
			tmp.FileCompressionStarted += (s, e) =>{
				if (e.PercentDone > 50) e.Cancel = true;
				else {
					//TestContext.WriteLine(String.Format("[{0}%] {1}", e.PercentDone, e.FileName));
				}
			};

			tmp.FilesFound += (se, ea) => { TestContext.WriteLine("Number of files: " + ea.Value.ToString()); };

			var arch = Path.Combine(tempFolder, TestContext.TestName + ".ppmd.7z");
			tmp.CompressFiles(arch, testFile1, testFile2);
			tmp.CompressDirectory(testFold1, arch);
		}
開發者ID:KOLANICH,項目名稱:SevenZipSharp,代碼行數:18,代碼來源:SevenZipTestPack.cs

示例10: Run

        /// <summary>
        /// Performs some work based on the settings passed.
        /// </summary>
        /// <param name="settings">The settings.  These specify the settings that the plugin
        /// should use and normally contain key/value pairs of parameters.</param>
        /// <param name="lastPlugin">The last plugin run.  This is often useful as
        /// normally, plugins need to work with the output produced from the last plugin.</param>
        public void Run(IPluginRuntimeSettings settings, IPlugin lastPlugin)
        {
            _runtimeSettings = settings ;

            string lastPath = lastPlugin.WorkingPath ;

            _workingPath = getPathToSaveZippedFileTo( settings, lastPath ) ;

            if(File.Exists( _workingPath ))
            {
                File.Delete( _workingPath );
            }

            var compressor = new SevenZipCompressor();

            SevenZipLibraryManager.LibraryFileName = Settings.PathTo7ZipBinary ;

            string password = getPasswordIfSpecified( settings ) ;

            if( Directory.Exists( lastPath ))
            {
                compressor.CompressDirectory(
                    lastPath,
                    _workingPath,
                    OutArchiveFormat.SevenZip,
                    password );
            }
            else
            {
                compressor.CompressFiles(
                    new[] { lastPath },
                    _workingPath,
                    OutArchiveFormat.SevenZip,
                    password );
            }
        }
開發者ID:nomailme,項目名稱:treetrim,代碼行數:43,代碼來源:Plugin.cs

示例11: GzipFile

        /// <summary>
        /// Compresses a file using the .gz format.
        /// </summary>
        /// <param name="sourceFile">The file to compress.</param>
        /// <param name="fileName">The name of the archive to be created.</param>
        public static void GzipFile(string sourceFile, string fileName)
        {
            SetupZlib();

            SevenZipCompressor compressor = new SevenZipCompressor();
            compressor.ArchiveFormat = OutArchiveFormat.GZip;
            compressor.CompressFiles(fileName, sourceFile);
        }
開發者ID:UhuruSoftware,項目名稱:vcap-dotnet,代碼行數:13,代碼來源:DEAUtilities.cs

示例12: Compress

        private void Compress()
        {
            //setup settings.
            try
            {
                _sevenZipCompressor = new SevenZipCompressor(tempPath);
                _sevenZipCompressor.ArchiveFormat = _format;
                _sevenZipCompressor.CompressionMethod = CompressionMethod.Default;
                _sevenZipCompressor.DirectoryStructure = true;
                _sevenZipCompressor.IncludeEmptyDirectories = true;
                _sevenZipCompressor.FastCompression = _fastcompression;
                _sevenZipCompressor.PreserveDirectoryRoot = false;
                _sevenZipCompressor.CompressionLevel = _compresstionlevel;

                _sevenZipCompressor.Compressing += Compressing;
                _sevenZipCompressor.FileCompressionStarted += FileCompressionStarted;
                _sevenZipCompressor.CompressionFinished += CompressionFinished;
                _sevenZipCompressor.FileCompressionFinished += FileCompressionFinished;

                try
                {
                    if (_password != null)
                    {
                        for (int i = 0; i < _fileAndDirectoryFullPaths.Count; i++)
                        {
                            if (!Directory.Exists(_fileAndDirectoryFullPaths[i]))
                                continue;

                            //Compress directories
                            var strings = _fileAndDirectoryFullPaths[i].Split('/');
                            if (_fileAndDirectoryFullPaths.Count == 1)
                            {
                                _sevenZipCompressor.CompressDirectory(_fileAndDirectoryFullPaths[i],
                                                                      String.Format("{0}/{1}.{2}",
                                                                                    _archivePath,
                                                                                    _archivename,
                                                                                    SelectExtention(_format)));
                            }
                            else
                            {
                                _sevenZipCompressor.CompressDirectory(_fileAndDirectoryFullPaths[i],
                                                                      String.Format("{0}/{1}_{3}.{2}",
                                                                                    _archivePath,
                                                                                    _archivename,
                                                                                    SelectExtention(_format),
                                                                                    _fileAndDirectoryFullPaths[i].Split('\\')
                                                                                            .Last()),
                                                                      _password);
                            }

                            //remove the directorys from the list so they will not be compressed as files as wel
                            _fileAndDirectoryFullPaths.Remove(_fileAndDirectoryFullPaths[i]);
                        }
                        //compress files
                        if (_fileAndDirectoryFullPaths.Count > 0)
                        {
                            _sevenZipCompressor.FileCompressionFinished += FileCompressionFinished;
                            _sevenZipCompressor.CompressFilesEncrypted(
                                                                       String.Format("{0}/{1}.{2}",
                                                                                     _archivePath,
                                                                                     _archivename,
                                                                                     SelectExtention(_format)),
                                                                       _password,
                                                                       _fileAndDirectoryFullPaths.ToArray());
                        }
                    }
                    else
                    {
                        for (int i = 0; i < _fileAndDirectoryFullPaths.Count; i++)
                        //var fullPath in _fileAndDirectoryFullPaths)
                        {
                            FileInfo fi = new FileInfo(_fileAndDirectoryFullPaths[i]);
                            bytesoffiles += fi.Length;

                            if (!Directory.Exists(_fileAndDirectoryFullPaths[i]))
                                continue;

                            //Compress directorys
                            var strings = _fileAndDirectoryFullPaths[i].Split('/');
                            if (_fileAndDirectoryFullPaths.Count == 1)
                            {
                                _sevenZipCompressor.CompressDirectory(_fileAndDirectoryFullPaths[i],
                                                                      String.Format("{0}/{1}.{2}",
                                                                                    _archivePath,
                                                                                    _archivename,
                                                                                    SelectExtention(_format)));
                            }
                            else
                            {
                                _sevenZipCompressor.CompressDirectory(_fileAndDirectoryFullPaths[i],
                                                                      String.Format("{0}/{1}_{3}.{2}",
                                                                                    _archivePath,
                                                                                    _archivename,
                                                                                    SelectExtention(_format),
                                                                                    _fileAndDirectoryFullPaths[i].Split('\\')
                                                                                            .Last()));
                            }

                            //reset compression bar
                            //FileCompressionFinished(null, null);
//.........這裏部分代碼省略.........
開發者ID:Gainedge,項目名稱:BetterExplorer,代碼行數:101,代碼來源:ArchiveProcressScreen.cs

示例13: CreateReadMeArchive

		/// <summary>
		/// Creates the readme files archive for the current mod.
		/// </summary>
		/// <param name="p_strArchiveFile">The archive name.</param>
		/// <param name="p_strFilesToCompress">The list of files to compress.</param>
		protected bool CreateReadMeArchive(string p_strArchiveFile, string[] p_strFilesToCompress)
		{
			try
			{
				SevenZipCompressor szcCompressor = new SevenZipCompressor();
				szcCompressor.ArchiveFormat = OutArchiveFormat.SevenZip;
				szcCompressor.CompressionLevel = CompressionLevel.Normal;
				szcCompressor.CompressFiles(Path.Combine(m_strReadMePath, p_strArchiveFile), p_strFilesToCompress);

				foreach (string File in p_strFilesToCompress)
					FileUtil.ForceDelete(File);

				return true;
			}
			catch
			{
				return false;
			}
		}
開發者ID:NexusMods,項目名稱:NexusModManager-4.5,代碼行數:24,代碼來源:ReadMeManager.cs

示例14: Execute

            public override void Execute()
            {
                var libraryPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(GetType().Assembly.Location), Environment.Is64BitProcess ? "7z64.dll" : "7z.dll");
                SevenZipBase.SetLibraryPath(libraryPath);

                var compressor = new SevenZipCompressor {
                    ArchiveFormat = _cmdlet.Format,
                    CompressionLevel = _cmdlet.CompressionLevel,
                    CompressionMethod = _cmdlet.CompressionMethod
                };

                if (_cmdlet._directoryOrFilesFromPipeline == null) {
                    _cmdlet._directoryOrFilesFromPipeline = new List<string> {
                        _cmdlet.Path
                    };
                }

                var directoryOrFiles = _cmdlet._directoryOrFilesFromPipeline
                    .Select(path => new FileInfo(System.IO.Path.Combine(_cmdlet.SessionState.Path.CurrentFileSystemLocation.Path, path)).FullName).ToArray();
                var archiveFileName = new FileInfo(System.IO.Path.Combine(_cmdlet.SessionState.Path.CurrentFileSystemLocation.Path, _cmdlet.ArchiveFileName)).FullName;

                var activity = directoryOrFiles.Length > 1
                    ? String.Format("Compressing {0} Files to {1}", directoryOrFiles.Length, archiveFileName)
                    : String.Format("Compressing {0} to {1}", directoryOrFiles.First(), archiveFileName);

                var currentStatus = "Compressing";
                compressor.FilesFound += (sender, args) =>
                    Write(String.Format("{0} files found for compression", args.Value));
                compressor.Compressing += (sender, args) =>
                    WriteProgress(new ProgressRecord(0, activity, currentStatus) { PercentComplete = args.PercentDone });
                compressor.FileCompressionStarted += (sender, args) => {
                    currentStatus = String.Format("Compressing {0}", args.FileName);
                    Write(String.Format("Compressing {0}", args.FileName));
                };

                if (directoryOrFiles.Any(path => new FileInfo(path).Exists)) {
                    var notFoundFiles = directoryOrFiles.Where(path => !new FileInfo(path).Exists).ToArray();
                    if (notFoundFiles.Any()) {
                        throw new FileNotFoundException("File(s) not found: " + string.Join(", ", notFoundFiles));
                    }
                    compressor.CompressFiles(archiveFileName, directoryOrFiles);
                }
                if (directoryOrFiles.Any(path => new DirectoryInfo(path).Exists)) {
                    if (directoryOrFiles.Length > 1) {
                        throw new ArgumentException("Only one directory allowed as input");
                    }
                    if (_cmdlet.Filter != null) {
                        compressor.CompressDirectory(directoryOrFiles[0], archiveFileName, _cmdlet.Filter, true);
                    } else {
                        compressor.CompressDirectory(directoryOrFiles[0], archiveFileName);
                    }
                }

                WriteProgress(new ProgressRecord(0, activity, "Finished") { RecordType = ProgressRecordType.Completed });
                Write("Compression finished");
            }
開發者ID:aolszowka,項目名稱:7Zip4Powershell,代碼行數:56,代碼來源:Compress7Zip.cs

示例15: ArcPostProcessor

 private void ArcPostProcessor(string FilePath)
 {
     SevenZipExtractor.SetLibraryPath(@"C:\Program Files (x86)\7-Zip\7z.dll");
     var tmp = new SevenZipCompressor();
     string PostFile = AMTUtil.GetAbsPath(WorkingDir, CurrentResource.Name + AMTConfig.ResourcePostExtension);
     tmp.CompressFiles(PostFile, FilePath);
     File.Delete(FilePath);
 }
開發者ID:r1cebank,項目名稱:AmiMat,代碼行數:8,代碼來源:AMTPackage.cs


注:本文中的SevenZip.SevenZipCompressor.CompressFiles方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。