Add a progress event while unzipping.

The progress is determined by the compressed file size and zip entries.
This commit is contained in:
Andreas Dangel
2014-03-14 21:22:20 -04:00
parent d3c40f0e95
commit 281571d99f
2 changed files with 17 additions and 0 deletions
+16
View File
@@ -55,6 +55,10 @@
return NO;
}
NSDictionary * fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
ZPOS64_T fileSize = fileAttributes.fileSize;
ZPOS64_T currentPosition = 0;
unz_global_info globalInfo = {0ul, 0ul};
unzGetGlobalInfo(zip, &globalInfo);
@@ -77,6 +81,9 @@
if ([delegate respondsToSelector:@selector(zipArchiveWillUnzipArchiveAtPath:zipInfo:)]) {
[delegate zipArchiveWillUnzipArchiveAtPath:path zipInfo:globalInfo];
}
if ([delegate respondsToSelector:@selector(zipArchiveProgressEvent:total:)]) {
[delegate zipArchiveProgressEvent:currentPosition total:fileSize];
}
NSInteger currentFileNumber = 0;
do {
@@ -103,11 +110,16 @@
break;
}
currentPosition += fileInfo.compressed_size;
// Message delegate
if ([delegate respondsToSelector:@selector(zipArchiveWillUnzipFileAtIndex:totalFiles:archivePath:fileInfo:)]) {
[delegate zipArchiveWillUnzipFileAtIndex:currentFileNumber totalFiles:(NSInteger)globalInfo.number_entry
archivePath:path fileInfo:fileInfo];
}
if ([delegate respondsToSelector:@selector(zipArchiveProgressEvent:total:)]) {
[delegate zipArchiveProgressEvent:currentPosition total:fileSize];
}
char *filename = (char *)malloc(fileInfo.size_filename + 1);
unzGetCurrentFileInfo(zip, &fileInfo, filename, fileInfo.size_filename + 1, NULL, 0, NULL, 0);
@@ -282,6 +294,10 @@
if (success && [delegate respondsToSelector:@selector(zipArchiveDidUnzipArchiveAtPath:zipInfo:unzippedPath:)]) {
[delegate zipArchiveDidUnzipArchiveAtPath:path zipInfo:globalInfo unzippedPath:destination];
}
// final progress event = 100%
if ([delegate respondsToSelector:@selector(zipArchiveProgressEvent:total:)]) {
[delegate zipArchiveProgressEvent:fileSize total:fileSize];
}
return success;
}