public void Unpack( string destDirectory, EventHandler <ArchiveProgressEventArgs> progressHandler) { using (CompressionEngine compressionEngine = this.CreateCompressionEngine()) { compressionEngine.Progress += progressHandler; ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext(this.FullName, destDirectory, null); streamContext.EnableOffsetOpen = true; compressionEngine.Unpack(streamContext, null); } }
/// <summary> /// Uses a CompressionEngine to get ArchiveFileInfo objects from this /// archive, and then associates them with this ArchiveInfo instance. /// </summary> /// <param name="fileFilter">Optional predicate that can determine /// which files to process.</param> /// <returns>A list of <see cref="ArchiveFileInfo"/> objects, each /// containing information about a file in the archive.</returns> private IList <ArchiveFileInfo> InternalGetFiles(Predicate <string> fileFilter) { using (CompressionEngine compressionEngine = this.CreateCompressionEngine()) { ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext(this.FullName, null, null); streamContext.EnableOffsetOpen = true; IList <ArchiveFileInfo> files = compressionEngine.GetFileInfo(streamContext, fileFilter); for (int i = 0; i < files.Count; i++) { files[i].Archive = this; } return(files); } }
/// <summary> /// Compresses files into the archive, specifying the names used to /// store the files in the archive. /// </summary> /// <param name="sourceDirectory">This parameter may be null, but if /// specified it is the root directory /// for any relative paths in <paramref name="sourceFileNames"/>.</param> /// <param name="sourceFileNames">The list of files to be included in /// the archive.</param> /// <param name="fileNames">The names of the files as they are stored in /// the archive. Each name includes the internal path of the file, if any. /// This parameter may be null, in which case the files are stored in the /// archive with their source file names and no path information.</param> /// <param name="compLevel">The compression level used when creating the /// archive.</param> /// <param name="progressHandler">Handler for receiving progress information; /// this may be null if progress is not desired.</param> /// <remarks> /// Duplicate items in the <paramref name="fileNames"/> array will cause /// an <see cref="ArchiveException"/>. /// </remarks> public void PackFiles( string sourceDirectory, IList <string> sourceFileNames, IList <string> fileNames, CompressionLevel compLevel, EventHandler <ArchiveProgressEventArgs> progressHandler) { if (sourceFileNames == null) { throw new ArgumentNullException("sourceFileNames"); } if (fileNames == null) { string[] fileNamesArray = new string[sourceFileNames.Count]; for (int i = 0; i < sourceFileNames.Count; i++) { fileNamesArray[i] = Path.GetFileName(sourceFileNames[i]); } fileNames = fileNamesArray; } else if (fileNames.Count != sourceFileNames.Count) { throw new ArgumentOutOfRangeException("fileNames"); } using (CompressionEngine compressionEngine = this.CreateCompressionEngine()) { compressionEngine.Progress += progressHandler; IDictionary <string, string> contextFiles = ArchiveInfo.CreateStringDictionary(fileNames, sourceFileNames); ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext( this.FullName, sourceDirectory, contextFiles); streamContext.EnableOffsetOpen = true; compressionEngine.CompressionLevel = compLevel; compressionEngine.Pack(streamContext, fileNames); } }
/// <summary> /// Compresses files into the archive, specifying the names used to /// store the files in the archive. /// </summary> /// <param name="sourceDirectory">This parameter may be null, but if /// specified it is the root directory /// for any relative paths in <paramref name="fileNames"/>.</param> /// <param name="fileNames">A mapping from internal file paths to /// external file paths.</param> /// <param name="compLevel">The compression level used when creating /// the archive.</param> /// <param name="progressHandler">Handler for receiving progress information; /// this may be null if progress is not desired.</param> public void PackFileSet( string sourceDirectory, IDictionary <string, string> fileNames, CompressionLevel compLevel, EventHandler <ArchiveProgressEventArgs> progressHandler) { if (fileNames == null) { throw new ArgumentNullException("fileNames"); } string[] fileNamesArray = new string[fileNames.Count]; fileNames.Keys.CopyTo(fileNamesArray, 0); using (CompressionEngine compressionEngine = this.CreateCompressionEngine()) { compressionEngine.Progress += progressHandler; ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext( this.FullName, sourceDirectory, fileNames); streamContext.EnableOffsetOpen = true; compressionEngine.CompressionLevel = compLevel; compressionEngine.Pack(streamContext, fileNamesArray); } }
public void UnpackFileSet( IDictionary <string, string> fileNames, string destDirectory, EventHandler <ArchiveProgressEventArgs> progressHandler) { if (fileNames == null) { throw new ArgumentNullException("fileNames"); } using (CompressionEngine compressionEngine = this.CreateCompressionEngine()) { compressionEngine.Progress += progressHandler; ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext(this.FullName, destDirectory, fileNames); streamContext.EnableOffsetOpen = true; compressionEngine.Unpack( streamContext, delegate(string match) { return(fileNames.ContainsKey(match)); }); } }