Skip to content

Commit 13edbb9

Browse files
Johannes Ekbergsoffes
Johannes Ekberg
authored andcommitted
Added Delegation Support
1 parent c05ee25 commit 13edbb9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

SSZipArchive.h

+4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
//
88

99
#import <Foundation/Foundation.h>
10+
#import "SSZipArchiveDelegate.h"
1011

1112
@interface SSZipArchive : NSObject
1213

1314
// Unzip
1415
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination;
1516
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError **)error;
1617

18+
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination delegate:(id<SSZipArchiveDelegate>)delegate;
19+
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError **)error delegate:(id<SSZipArchiveDelegate>)delegate;
20+
1721
// Zip
1822
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)filenames;
1923

SSZipArchive.m

+16-1
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,21 @@ @implementation SSZipArchive {
2929
#pragma mark - Unzipping
3030

3131
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination {
32-
return [self unzipFileAtPath:path toDestination:destination overwrite:YES password:nil error:nil];
32+
return [self unzipFileAtPath:path toDestination:destination delegate:nil];
3333
}
3434

3535

3636
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError **)error {
37+
return [self unzipFileAtPath:path toDestination:destination overwrite:overwrite password:password error:error delegate:nil];
38+
}
39+
40+
41+
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination delegate:(id<SSZipArchiveDelegate>)delegate {
42+
return [self unzipFileAtPath:path toDestination:destination overwrite:YES password:nil error:nil delegate:delegate];
43+
}
44+
45+
46+
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError **)error delegate:(id<SSZipArchiveDelegate>)delegate {
3747
// Begin opening
3848
zipFile zip = unzOpen((const char*)[path UTF8String]);
3949
if (zip == NULL) {
@@ -62,6 +72,7 @@ + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination o
6272
NSFileManager *fileManager = [NSFileManager defaultManager];
6373
NSMutableSet *directoriesModificationDates = [[NSMutableSet alloc] init];
6474

75+
NSInteger currentFileNumber = 0;
6576
do {
6677
if ([password length] == 0) {
6778
ret = unzOpenCurrentFile(zip);
@@ -85,6 +96,8 @@ + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination o
8596
break;
8697
}
8798

99+
[delegate zipArchiveWillUnzipFileNumber:currentFileNumber fromFile:path fileInfo:fileInfo];
100+
88101
char *filename = (char *)malloc(fileInfo.size_filename + 1);
89102
unzGetCurrentFileInfo(zip, &fileInfo, filename, fileInfo.size_filename + 1, NULL, 0, NULL, 0);
90103
filename[fileInfo.size_filename] = '\0';
@@ -155,6 +168,8 @@ + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination o
155168

156169
unzCloseCurrentFile( zip );
157170
ret = unzGoToNextFile( zip );
171+
172+
currentFileNumber++;
158173
} while(ret == UNZ_OK && UNZ_OK != UNZ_END_OF_LIST_OF_FILE);
159174

160175
// Close

0 commit comments

Comments
 (0)