diff --git a/src/Zip/FastZip.cs b/src/Zip/FastZip.cs index 260e2f420..3fb2373a2 100644 --- a/src/Zip/FastZip.cs +++ b/src/Zip/FastZip.cs @@ -485,6 +485,70 @@ public void ExtractZip(Stream inputStream, string targetDirectory, } } } + + /// + /// Extract the contents of a zip file. + /// + /// The zip file to extract from. + /// The directory to save extracted information in. + /// The style of overwriting to apply. + /// A delegate to invoke when confirming overwriting. + /// A method-filter to apply to files. + /// A method-filter to apply to directories. + public void ExtractZip( + string zipFileName, + string targetDirectory, + Overwrite overwrite, + ConfirmOverwriteDelegate confirmDelegate, + Func fileFilter, + Func directoryFilter) + { + if ((overwrite == Overwrite.Prompt) && (confirmDelegate == null)) + { + throw new ArgumentNullException("confirmDelegate"); + } + + continueRunning_ = true; + overwrite_ = overwrite; + confirmDelegate_ = confirmDelegate; + extractNameTransform_ = new WindowsNameTransform(targetDirectory); + + restoreDateTimeOnExtract_ = true; + + Stream inputStream = File.Open(zipFileName, FileMode.Open, FileAccess.Read, FileShare.Read); + using (zipFile_ = new ZipFile(inputStream)) + { + +#if !NETCF_1_0 + if (password_ != null) + { + zipFile_.Password = password_; + } +#endif + zipFile_.IsStreamOwner = true; + System.Collections.IEnumerator enumerator = zipFile_.GetEnumerator(); + while (continueRunning_ && enumerator.MoveNext()) + { + ZipEntry entry = (ZipEntry)enumerator.Current; + if (entry.IsFile) + { + // TODO Path.GetDirectory can fail here on invalid characters. + if (directoryFilter(Path.GetDirectoryName(entry.Name)) && fileFilter(entry.Name)) + { + ExtractEntry(entry); + } + } + else if (entry.IsDirectory) + { + if (directoryFilter(entry.Name) && CreateEmptyDirectories) + { + ExtractEntry(entry); + } + } + } + } + } + #endregion #region Internal Processing