diff --git a/SSZipArchive.h b/SSZipArchive.h index fb8d055..cb3a168 100644 --- a/SSZipArchive.h +++ b/SSZipArchive.h @@ -42,4 +42,5 @@ - (void)zipArchiveWillUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo; - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo; +- (void)zipArchiveDidUnzipArchiveFile:(NSString *)zipFile entryPath:(NSString *)entryPath destPath:(NSString *)destPath; @end diff --git a/SSZipArchive.m b/SSZipArchive.m index 93693f5..d4e3cc2 100644 --- a/SSZipArchive.m +++ b/SSZipArchive.m @@ -240,7 +240,10 @@ [delegate zipArchiveDidUnzipFileAtIndex:currentFileNumber totalFiles:(NSInteger)globalInfo.number_entry archivePath:path fileInfo:fileInfo]; } - + if ([delegate respondsToSelector:@selector(zipArchiveDidUnzipArchiveFile:entryPath:destPath:)]) { + [delegate zipArchiveDidUnzipArchiveFile:path entryPath:strPath destPath:fullPath]; + } + currentFileNumber++; } while(ret == UNZ_OK && UNZ_OK != UNZ_END_OF_LIST_OF_FILE); diff --git a/Tests/CollectingDelegate.h b/Tests/CollectingDelegate.h new file mode 100644 index 0000000..ce56265 --- /dev/null +++ b/Tests/CollectingDelegate.h @@ -0,0 +1,8 @@ +#import + +/** +* Test delegate by collecting its calls +*/ +@interface CollectingDelegate : NSObject +@property(nonatomic, retain) NSMutableArray *files; +@end \ No newline at end of file diff --git a/Tests/CollectingDelegate.m b/Tests/CollectingDelegate.m new file mode 100644 index 0000000..0d9e5e0 --- /dev/null +++ b/Tests/CollectingDelegate.m @@ -0,0 +1,35 @@ +// +// Created by chris on 8/1/12. +// +// To change the template use AppCode | Preferences | File Templates. +// + + +#import "SSZipArchive.h" +#import "CollectingDelegate.h" + +@implementation CollectingDelegate { + +} +@synthesize files = _files; + + +- (id)init { + self = [super init]; + if (self) { + self.files = [NSMutableArray array]; + } + return self; +} + +- (void)zipArchiveDidUnzipArchiveFile:(NSString *)zipFile entryPath:(NSString *)entryPath destPath:(NSString *)destPath { + [self.files addObject:entryPath]; +} + +- (void)dealloc { + [_files release]; + [super dealloc]; +} + + +@end \ No newline at end of file diff --git a/Tests/SSZipArchive.xcodeproj/project.pbxproj b/Tests/SSZipArchive.xcodeproj/project.pbxproj index 04fbae8..b385f39 100644 --- a/Tests/SSZipArchive.xcodeproj/project.pbxproj +++ b/Tests/SSZipArchive.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 5A416BA09CD6A335F551C015 /* CollectingDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A416109F75BF6E777908B04 /* CollectingDelegate.m */; }; B215FB32143AD3C7003AC546 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B215FB31143AD3C7003AC546 /* SenTestingKit.framework */; }; B215FB63143AD514003AC546 /* SSZipArchiveTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B215FB61143AD514003AC546 /* SSZipArchiveTests.m */; }; B215FB65143AD527003AC546 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B215FB64143AD527003AC546 /* libz.dylib */; }; @@ -24,6 +25,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 5A416109F75BF6E777908B04 /* CollectingDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CollectingDelegate.m; sourceTree = ""; }; + 5A4164B83A2827BFD88C3CA1 /* CollectingDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollectingDelegate.h; sourceTree = ""; }; B215FB18143AD3C7003AC546 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; B215FB30143AD3C7003AC546 /* SSZipArchiveTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SSZipArchiveTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; B215FB31143AD3C7003AC546 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; @@ -120,6 +123,8 @@ B215FB5E143AD505003AC546 /* SSZipArchiveTests */ = { isa = PBXGroup; children = ( + 5A416109F75BF6E777908B04 /* CollectingDelegate.m */, + 5A4164B83A2827BFD88C3CA1 /* CollectingDelegate.h */, B2283D5C155AD80F00F9395A /* Unicode.zip */, B215FB61143AD514003AC546 /* SSZipArchiveTests.m */, B215FB5F143AD514003AC546 /* SSZipArchiveTests-Info.plist */, @@ -220,6 +225,7 @@ B215FB69143AD576003AC546 /* mztools.c in Sources */, B215FB6A143AD576003AC546 /* unzip.c in Sources */, B215FB6B143AD576003AC546 /* zip.c in Sources */, + 5A416BA09CD6A335F551C015 /* CollectingDelegate.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/SSZipArchiveTests.m b/Tests/SSZipArchiveTests.m index bc45c64..d6f1d9d 100644 --- a/Tests/SSZipArchiveTests.m +++ b/Tests/SSZipArchiveTests.m @@ -7,6 +7,7 @@ // #import "SSZipArchive.h" +#import "CollectingDelegate.h" #import #import @@ -131,6 +132,16 @@ // [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath]; //} +-(void)testShouldProvidePathOfUnzippedFileInDelegateCallback { + CollectingDelegate *collector = [[CollectingDelegate new] autorelease]; + NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestArchive" ofType:@"zip"]; + NSString *outputPath = [self _cachesPath:@"Regular"]; + + [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:collector]; + + STAssertEqualObjects([collector.files objectAtIndex:0], @"LICENSE", nil); + STAssertEqualObjects([collector.files objectAtIndex:1], @"Readme.markdown", nil); +} #pragma mark - SSZipArchiveDelegate