当前位置: 首页>>代码示例>>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;未经允许,请勿转载。