The ExtractProgressEventArgs.EntriesTotal and ExtractProgressEventArgs.EntriesExtracted is always zero. Is this a known bug? See my code below:
public static void UnZip(string zipFile, string destination)
{
using(ZipFile zip = ZipFile.Read(zipFile))
{
zip.ExtractProgress += new EventHandler<ExtractProgressEventArgs>(zip_ExtractProgress);
foreach (ZipEntry entry in zip)
{
entry.Extract(destination, ExtractExistingFileAction.OverwriteSilently);
}
Console.WriteLine("DONE");
}
}
static void zip_ExtractProgress(object sender, ExtractProgressEventArgs e)
{
if(e.EventType == ZipProgressEventType.Extracting_AfterExtractEntry)
Console.WriteLine(String.Format("{0} : {1} / {2} = {3}%", e.CurrentEntry.FileName, e.EntriesTotal, e.EntriesExtracted, ((double)e.EntriesTotal / (double)e.EntriesExtracted) * 100.00));
}
It’s defined behavior:
from http://cheeso.members.winisp.net/DotNetZipHelp/html/91d797c7-efff-99a3-2b14-6c9a9797b324.htm
The reason for this is simple: If you call Extract() in a loop that you yourself control, there’s no way for the library to know how many times you plan to call it, how many times you’ve called it in a row, whether to count the first 5 times with the next 5 times, and so on. So DotNetZip can’t give you reliable informaiton about how many you’ve done.
You have two easy workarounds available:
use an int counter that you increment for each call to Extract() in your loop.
call ExtractAll(), In that case it will issue ExtractProgressEvents with the
EntriesExtractedvalue set to a meaningful number.option 1:
option 2: