private void extract(SevenZipExtractor extractor, string mask, string toDir, string password) { if (extractor.FilesCount == 0) { return; } if (!extractor.IsSolid) { ExtractFileCallback callBack = (t) => { if (PathFE.MatchFileMask(t.ArchiveFileInfo.FileName, mask)) { if (t.Reason == ExtractFileCallbackReason.Start) { string outputFileName = PathFE.Combine(toDir, t.ArchiveFileInfo.FileName); string outputDir = PathFE.GetDirectoryName(outputFileName); if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } if (t.ArchiveFileInfo.IsDirectory) { if (!Directory.Exists(outputFileName)) { Directory.CreateDirectory(outputFileName); } } else { if (File.Exists(outputFileName)) { File.Delete(outputFileName); } t.ExtractToFile = outputFileName; } } } }; extractor.ExtractFiles(callBack); } else { List <int> indexes = new List <int>(); foreach (var afi in extractor.ArchiveFileData) { if (PathFE.MatchFileMask(afi.FileName, mask)) { indexes.Add(afi.Index); } } extractor.ExtractFiles(toDir, indexes.ToArray()); } }
/// <summary> /// Extracts files from the archive asynchronously, giving a callback the choice what /// to do with each file. The order of the files is given by the archive. /// 7-Zip (and any other solid) archives are NOT supported. /// </summary> /// <param name="extractFileCallback">The callback to call for each file in the archive.</param> public async Task ExtractFilesAsync(ExtractFileCallback extractFileCallback) { try { SaveContext(); await Task.Run(() => new ExtractFiles3Delegate(ExtractFiles).Invoke(extractFileCallback)); } finally { ReleaseContext(); } }
public void ExtractFiles(ExtractFileCallback extractFileCallback) { this.DisposedCheck(); this.InitArchiveFileData(false); if (this.IsSolid) { return; } foreach (ArchiveFileInfo archiveFileInfo in this.ArchiveFileData) { ExtractFileCallbackArgs extractFileCallbackArgs = new ExtractFileCallbackArgs(archiveFileInfo); extractFileCallback(extractFileCallbackArgs); if (extractFileCallbackArgs.CancelExtraction) { break; } if (extractFileCallbackArgs.ExtractToStream != null || extractFileCallbackArgs.ExtractToFile != null) { bool flag = false; try { if (extractFileCallbackArgs.ExtractToStream != null) { this.ExtractFile(archiveFileInfo.Index, extractFileCallbackArgs.ExtractToStream); } else { using (FileStream fileStream = new FileStream(extractFileCallbackArgs.ExtractToFile, FileMode.CreateNew, FileAccess.Write, FileShare.None, 8192, FileOptions.SequentialScan)) this.ExtractFile(archiveFileInfo.Index, (Stream)fileStream); } flag = true; } catch (Exception ex) { extractFileCallbackArgs.Exception = ex; extractFileCallbackArgs.Reason = ExtractFileCallbackReason.Failure; extractFileCallback(extractFileCallbackArgs); if (!this.ThrowException((SevenZipBase)null, ex)) { break; } } if (flag) { extractFileCallbackArgs.Reason = ExtractFileCallbackReason.Done; extractFileCallback(extractFileCallbackArgs); } } } }
/// <summary> /// Extracts files from the archive asynchronously, giving a callback the choice what /// to do with each file. The order of the files is given by the archive. /// 7-Zip (and any other solid) archives are NOT supported. /// </summary> /// <param name="extractFileCallback">The callback to call for each file in the archive.</param> /// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param> #else /// <summary> /// Extracts files from the archive asynchronously, giving a callback the choice what /// to do with each file. The order of the files is given by the archive. /// 7-Zip (and any other solid) archives are NOT supported. /// </summary> /// <param name="extractFileCallback">The callback to call for each file in the archive.</param> #endif public void BeginExtractFiles(ExtractFileCallback extractFileCallback #if !DOTNET20 , DispatcherPriority eventPriority #if CS4 = DispatcherPriority.Normal #endif #endif ) { SaveContext( #if !DOTNET20 eventPriority #endif ); (new ExtractFiles3Delegate(ExtractFiles)).BeginInvoke(extractFileCallback, AsyncCallbackImplementation, this); }
/// <summary> /// Extracts files from the archive asynchronously, giving a callback the choice what /// to do with each file. The order of the files is given by the archive. /// 7-Zip (and any other solid) archives are NOT supported. /// </summary> /// <param name="extractFileCallback">The callback to call for each file in the archive.</param> /// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param> #else /// <summary> /// Extracts files from the archive asynchronously, giving a callback the choice what /// to do with each file. The order of the files is given by the archive. /// 7-Zip (and any other solid) archives are NOT supported. /// </summary> /// <param name="extractFileCallback">The callback to call for each file in the archive.</param> #endif public void BeginExtractFiles(ExtractFileCallback extractFileCallback #if !DOTNET20 , DispatcherPriority eventPriority #if CS4 = DispatcherPriority.Normal #endif #endif ) { SaveContext( #if !DOTNET20 eventPriority #endif ); Task.Run(() => new ExtractFiles3Delegate(ExtractFiles).Invoke(extractFileCallback)) .ContinueWith(_ => ReleaseContext()); }
/// <summary> /// Extracts files from the archive, giving a callback the choice what /// to do with each file. The order of the files is given by the archive. /// 7-Zip (and any other solid) archives are NOT supported. /// </summary> /// <param name="extractFileCallback">The callback to call for each file in the archive.</param> public void ExtractFiles(ExtractFileCallback extractFileCallback) { DisposedCheck(); InitArchiveFileData(false); if (IsSolid) { // solid strategy } else { foreach (ArchiveFileInfo archiveFileInfo in ArchiveFileData) { var extractFileCallbackArgs = new ExtractFileCallbackArgs(archiveFileInfo); extractFileCallback(extractFileCallbackArgs); if (extractFileCallbackArgs.CancelExtraction) { break; } if (extractFileCallbackArgs.ExtractToStream != null || extractFileCallbackArgs.ExtractToFile != null) { bool callDone = false; try { if (extractFileCallbackArgs.ExtractToStream != null) { ExtractFile(archiveFileInfo.Index, extractFileCallbackArgs.ExtractToStream); } else { using (var file = new FileStream(extractFileCallbackArgs.ExtractToFile, FileMode.CreateNew, FileAccess.Write, FileShare.None, 8192)) { ExtractFile(archiveFileInfo.Index, file); } } callDone = true; } catch (Exception ex) { extractFileCallbackArgs.Exception = ex; extractFileCallbackArgs.Reason = ExtractFileCallbackReason.Failure; extractFileCallback(extractFileCallbackArgs); if (!ThrowException(null, ex)) { return; } } if (callDone) { extractFileCallbackArgs.Reason = ExtractFileCallbackReason.Done; extractFileCallback(extractFileCallbackArgs); } } } } }
/// <summary> /// Extracts files from the archive asynchronously, giving a callback the choice what /// to do with each file. The order of the files is given by the archive. /// 7-Zip (and any other solid) archives are NOT supported. /// </summary> /// <param name="extractFileCallback">The callback to call for each file in the archive.</param> public void BeginExtractFiles(ExtractFileCallback extractFileCallback, Func <uint, OutStreamWrapper> getStream = null, Action <FileInfoEventArgs> FileExtractStart = null, Action <FileInfoEventArgs> FileExtractComplete = null, Func <AskMode, AskMode> prepareCheck = null, int?entryIndex = null) { SaveContext(); new ExtractFiles4Delegate(ExtractFiles).BeginInvoke(extractFileCallback, getStream, FileExtractStart, FileExtractComplete, prepareCheck, entryIndex, AsyncCallbackImplementation, this); }
/// <summary> /// Extracts files from the archive asynchronously, giving a callback the choice what /// to do with each file. The order of the files is given by the archive. /// 7-Zip (and any other solid) archives are NOT supported. /// </summary> /// <param name="extractFileCallback">The callback to call for each file in the archive.</param> public Task ExtractFilesAsync(ExtractFileCallback extractFileCallback) { SaveContext(); return(Task.Run(() => new ExtractFiles3Delegate(ExtractFiles).Invoke(extractFileCallback)) .ContinueWith(_ => ReleaseContext())); }
/// <summary> /// Extracts files from the archive asynchronously, giving a callback the choice what /// to do with each file. The order of the files is given by the archive. /// 7-Zip (and any other solid) archives are NOT supported. /// </summary> /// <param name="extractFileCallback">The callback to call for each file in the archive.</param> public void BeginExtractFiles(ExtractFileCallback extractFileCallback) { SaveContext(); Task.Run(() => new ExtractFiles3Delegate(ExtractFiles).Invoke(extractFileCallback)) .ContinueWith(_ => ReleaseContext()); }
public void BeginExtractFiles(ExtractFileCallback extractFileCallback #if !DOTNET20 , DispatcherPriority eventPriority #if CS4 = DispatcherPriority.Normal #endif #endif ) { SaveContext( #if !DOTNET20 eventPriority #endif ); (new ExtractFiles3Delegate(ExtractFiles)).BeginInvoke(extractFileCallback, AsyncCallbackImplementation, this); }
/// <summary> /// Extracts files from the archive, giving a callback the choice what /// to do with each file. The order of the files is given by the archive. /// 7-Zip (and any other solid) archives are NOT supported. /// </summary> /// <param name="extractFileCallback">The callback to call for each file in the archive.</param> /// <exception cref="SevenZipExtractionFailedException">Thrown when trying to extract from solid archives.</exception> public void ExtractFiles(ExtractFileCallback extractFileCallback) { DisposedCheck(); InitArchiveFileData(false); if (IsSolid) { throw new SevenZipExtractionFailedException("Solid archives are not supported."); } foreach (var archiveFileInfo in ArchiveFileData) { var extractFileCallbackArgs = new ExtractFileCallbackArgs(archiveFileInfo); extractFileCallback(extractFileCallbackArgs); if (extractFileCallbackArgs.CancelExtraction) { break; } if (extractFileCallbackArgs.ExtractToStream != null || extractFileCallbackArgs.ExtractToFile != null) { var callDone = false; try { if (extractFileCallbackArgs.ExtractToStream != null) { ExtractFile(archiveFileInfo.Index, extractFileCallbackArgs.ExtractToStream); } else { using (var file = new FileStream(extractFileCallbackArgs.ExtractToFile, FileMode.CreateNew, FileAccess.Write, FileShare.None, 8192)) { ExtractFile(archiveFileInfo.Index, file); } } callDone = true; } catch (Exception ex) { extractFileCallbackArgs.Exception = ex; extractFileCallbackArgs.Reason = ExtractFileCallbackReason.Failure; extractFileCallback(extractFileCallbackArgs); if (!ThrowException(null, ex)) { return; } } if (callDone) { extractFileCallbackArgs.Reason = ExtractFileCallbackReason.Done; extractFileCallback(extractFileCallbackArgs); } } } }
/// <summary> /// Extracts files from the archive asynchronously, giving a callback the choice what /// to do with each file. The order of the files is given by the archive. /// 7-Zip (and any other solid) archives are NOT supported. /// </summary> /// <param name="extractFileCallback">The callback to call for each file in the archive.</param> public void BeginExtractFiles(ExtractFileCallback extractFileCallback) { SaveContext(); new ExtractFiles3Delegate(ExtractFiles).BeginInvoke(extractFileCallback, AsyncCallbackImplementation, this); }