diff --git a/SSZipArchive.h b/SSZipArchive.h index 7dab1e7..f1a2303 100644 --- a/SSZipArchive.h +++ b/SSZipArchive.h @@ -7,6 +7,7 @@ // #import +#import "SSZipArchiveDelegate.h" @interface SSZipArchive : NSObject @@ -14,6 +15,9 @@ + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination; + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError **)error; ++ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination delegate:(id)delegate; ++ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError **)error delegate:(id)delegate; + // Zip + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)filenames; diff --git a/SSZipArchive.m b/SSZipArchive.m index 8149924..4493db1 100644 --- a/SSZipArchive.m +++ b/SSZipArchive.m @@ -29,11 +29,21 @@ #pragma mark - Unzipping + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination { - return [self unzipFileAtPath:path toDestination:destination overwrite:YES password:nil error:nil]; + return [self unzipFileAtPath:path toDestination:destination delegate:nil]; } + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError **)error { + return [self unzipFileAtPath:path toDestination:destination overwrite:overwrite password:password error:error delegate:nil]; +} + + ++ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination delegate:(id)delegate { + return [self unzipFileAtPath:path toDestination:destination overwrite:YES password:nil error:nil delegate:delegate]; +} + + ++ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError **)error delegate:(id)delegate { // Begin opening zipFile zip = unzOpen((const char*)[path UTF8String]); if (zip == NULL) { @@ -62,6 +72,7 @@ NSFileManager *fileManager = [NSFileManager defaultManager]; NSMutableSet *directoriesModificationDates = [[NSMutableSet alloc] init]; + NSInteger currentFileNumber = 0; do { if ([password length] == 0) { ret = unzOpenCurrentFile(zip); @@ -85,6 +96,8 @@ break; } + [delegate zipArchiveWillUnzipFileNumber:currentFileNumber fromFile:path fileInfo:fileInfo]; + char *filename = (char *)malloc(fileInfo.size_filename + 1); unzGetCurrentFileInfo(zip, &fileInfo, filename, fileInfo.size_filename + 1, NULL, 0, NULL, 0); filename[fileInfo.size_filename] = '\0'; @@ -155,6 +168,8 @@ unzCloseCurrentFile( zip ); ret = unzGoToNextFile( zip ); + + currentFileNumber++; } while(ret == UNZ_OK && UNZ_OK != UNZ_END_OF_LIST_OF_FILE); // Close