Added Delegation Support

This commit is contained in:
Johannes Ekberg
2012-01-14 20:46:32 +01:00
committed by Sam Soffes
parent c05ee25f7f
commit 13edbb940e
2 changed files with 20 additions and 1 deletions
+4
View File
@@ -7,6 +7,7 @@
//
#import <Foundation/Foundation.h>
#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<SSZipArchiveDelegate>)delegate;
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError **)error delegate:(id<SSZipArchiveDelegate>)delegate;
// Zip
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)filenames;
+16 -1
View File
@@ -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<SSZipArchiveDelegate>)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<SSZipArchiveDelegate>)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