Added ability to retrieve zip creation progress.

Fixed a issue that was caused in the previous PR regarding this feature.
This commit is contained in:
David Evans
2017-01-23 19:45:35 +00:00
parent a363be72d7
commit 84a96fc298
2 changed files with 19 additions and 3 deletions
+18 -3
View File
@@ -586,11 +586,20 @@
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(nullable NSString *)password{
return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keepParentDirectory:NO withPassword:password];
return [SSZipArchive createZipFileAtPath:path withContentsOfDirectory:directoryPath keepParentDirectory:NO withPassword:password];
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password{
return [SSZipArchive createZipFileAtPath:path
withContentsOfDirectory:directoryPath
keepParentDirectory:keepParentDirectory
withPassword:password
andProgressHandler:nil
];
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password andProgressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler {
BOOL success = NO;
NSFileManager *fileManager = nil;
@@ -600,8 +609,10 @@
// use a local filemanager (queue/thread compatibility)
fileManager = [[NSFileManager alloc] init];
NSDirectoryEnumerator *dirEnumerator = [fileManager enumeratorAtPath:directoryPath];
NSArray *allObjects = dirEnumerator.allObjects;
NSUInteger total = allObjects.count, complete = 0;
NSString *fileName;
while ((fileName = [dirEnumerator nextObject])) {
for (fileName in allObjects) {
BOOL isDir;
NSString *fullFilePath = [directoryPath stringByAppendingPathComponent:fileName];
[fileManager fileExistsAtPath:fullFilePath isDirectory:&isDir];
@@ -623,6 +634,10 @@
[zipArchive writeFileAtPath:tempFilePath withFileName:tempFileFilename withPassword:password];
}
}
complete++;
if (progressHandler) {
progressHandler(complete, total);
}
}
success = [zipArchive close];
}
@@ -885,4 +900,4 @@
return date;
}
@end
@end