public static bool unzipFile(Stream inputStream, string targetDirectory, bool overwrite, OnUnzipProgress callback)
{
bool ret = false;
callback(0, 0);
using (ZipFile zipFile_ = new ZipFile(inputStream))
{
int totalBytes = (int)zipFile_.unzipSize;
UnzipCach cach = new UnzipCach();
cach.start(totalBytes, callback, overwrite);
INameTransform extractNameTransform_ = new WindowsNameTransform(targetDirectory);
System.Collections.IEnumerator enumerator = zipFile_.GetEnumerator();
while (enumerator.MoveNext())
{
try
{
ZipEntry entry = (ZipEntry)enumerator.Current;
if (entry.IsFile)
{
string fileName = extractNameTransform_.TransformFile(entry.Name);
string dirName = Path.GetDirectoryName(Path.GetFullPath(fileName));
if (!Directory.Exists(dirName))
{
Directory.CreateDirectory(dirName);
}
Stream source = zipFile_.GetInputStream(entry);
cach.addFile(fileName, (int)entry.Size, source);
source.Close();
}
else
{
string dirName = extractNameTransform_.TransformDirectory(entry.Name);
if (!Directory.Exists(dirName))
{
Directory.CreateDirectory(dirName);
}
}
}
catch (Exception e)
{
cach.setState(UnzipCach.State.Error);
//LogManager.GetInstance().LogException(e.Message, e, LogManager.ModuleFilter.RES);
}
if (cach.isError())
{
break;
}
}
cach.setState(UnzipCach.State.Ok);
ret = cach.stop();
callback(1, ret?0:1);
return(ret);
}
}