From 433d629232e228f7da74bdb12513dec2aeb44ae5 Mon Sep 17 00:00:00 2001 From: Gianluca Bertani Date: Thu, 27 Aug 2015 16:16:26 +0200 Subject: [PATCH] ARC-ified; removed ARCHelper.h --- ARCHelper/ARCHelper.h | 59 --- Classes/Objective_ZipAppDelegate.h | 4 +- Classes/Objective_ZipAppDelegate.m | 7 - Classes/Objective_ZipViewController.m | 599 +++++++++++------------- Objective-Zip.xcodeproj/project.pbxproj | 26 +- Objective-Zip/FileInZipInfo.h | 2 +- Objective-Zip/FileInZipInfo.m | 10 +- Objective-Zip/ZipException.h | 1 - Objective-Zip/ZipFile.h | 1 - Objective-Zip/ZipFile.m | 85 ++-- Objective-Zip/ZipReadStream.h | 1 - Objective-Zip/ZipReadStream.m | 4 +- Objective-Zip/ZipWriteStream.h | 1 - Objective-Zip/ZipWriteStream.m | 4 +- Objective_ZipViewController.xib | 377 ++++++++------- main.m | 9 +- 16 files changed, 538 insertions(+), 652 deletions(-) delete mode 100644 ARCHelper/ARCHelper.h diff --git a/ARCHelper/ARCHelper.h b/ARCHelper/ARCHelper.h deleted file mode 100644 index 492b012..0000000 --- a/ARCHelper/ARCHelper.h +++ /dev/null @@ -1,59 +0,0 @@ -// -// ARC Helper -// -// Version 2.1 -// -// Created by Nick Lockwood on 05/01/2012. -// Copyright 2012 Charcoal Design -// -// Distributed under the permissive zlib license -// Get the latest version from here: -// -// https://gist.github.com/1563325 -// - -#ifndef ah_retain -#if __has_feature(objc_arc) -#define ah_retain self -#define ah_dealloc self -#define release self -#define autorelease self -#else -#define ah_retain retain -#define ah_dealloc dealloc -#define __bridge -#endif -#endif - -// Weak reference support - -#import -#if (!__has_feature(objc_arc)) || \ -(defined __IPHONE_OS_VERSION_MIN_REQUIRED && \ -__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0) || \ -(defined __MAC_OS_X_VERSION_MIN_REQUIRED && \ -__MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7) -#undef weak -#define weak unsafe_unretained -#undef __weak -#define __weak __unsafe_unretained -#endif - -// Weak delegate support - -#ifndef ah_weak -#import -#if (__has_feature(objc_arc)) && \ -((defined __IPHONE_OS_VERSION_MIN_REQUIRED && \ -__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0) || \ -(defined __MAC_OS_X_VERSION_MIN_REQUIRED && \ -__MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_7)) -#define ah_weak weak -#define __ah_weak __weak -#else -#define ah_weak unsafe_unretained -#define __ah_weak __unsafe_unretained -#endif -#endif - -// ARC Helper ends diff --git a/Classes/Objective_ZipAppDelegate.h b/Classes/Objective_ZipAppDelegate.h index 01dc7e0..f996116 100644 --- a/Classes/Objective_ZipAppDelegate.h +++ b/Classes/Objective_ZipAppDelegate.h @@ -40,8 +40,8 @@ Objective_ZipViewController *viewController; } -@property (nonatomic, retain) IBOutlet UIWindow *window; -@property (nonatomic, retain) IBOutlet Objective_ZipViewController *viewController; +@property (nonatomic, strong) IBOutlet UIWindow *window; +@property (nonatomic, strong) IBOutlet Objective_ZipViewController *viewController; @end diff --git a/Classes/Objective_ZipAppDelegate.m b/Classes/Objective_ZipAppDelegate.m index 12bc5a4..84410f7 100644 --- a/Classes/Objective_ZipAppDelegate.m +++ b/Classes/Objective_ZipAppDelegate.m @@ -46,11 +46,4 @@ } -- (void)dealloc { - [viewController release]; - [window release]; - [super dealloc]; -} - - @end diff --git a/Classes/Objective_ZipViewController.m b/Classes/Objective_ZipViewController.m index 8c596f5..15735cc 100644 --- a/Classes/Objective_ZipViewController.m +++ b/Classes/Objective_ZipViewController.m @@ -72,43 +72,30 @@ _textView.font= [UIFont fontWithName:@"Helvetica" size:11.0]; } -- (void) dealloc { - [_testThread release]; - - [super dealloc]; -} - (void) didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (IBAction) zipUnzip { - if (_testThread) - [_testThread release]; _testThread= [[NSThread alloc] initWithTarget:self selector:@selector(test1) object:nil]; [_testThread start]; } - (IBAction) zipUnzip2 { - if (_testThread) - [_testThread release]; _testThread= [[NSThread alloc] initWithTarget:self selector:@selector(test2) object:nil]; [_testThread start]; } - (IBAction) zipCheck1 { - if (_testThread) - [_testThread release]; _testThread= [[NSThread alloc] initWithTarget:self selector:@selector(test3) object:nil]; [_testThread start]; } - (IBAction) zipCheck2 { - if (_testThread) - [_testThread release]; _testThread= [[NSThread alloc] initWithTarget:self selector:@selector(test4) object:nil]; [_testThread start]; @@ -119,134 +106,131 @@ #pragma mark Test 1: zip & unzip - (void) test1 { - NSAutoreleasePool *pool= [[NSAutoreleasePool alloc] init]; + @autoreleasepool { - NSString *documentsDir= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; - NSString *filePath= [documentsDir stringByAppendingPathComponent:@"test.zip"]; + NSString *documentsDir= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; + NSString *filePath= [documentsDir stringByAppendingPathComponent:@"test.zip"]; - @try { - [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL]; + @try { + [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL]; - [self log:@"Test 1: opening zip file for writing..."]; - - ZipFile *zipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeCreate]; - - [self log:@"Test 1: adding first file..."]; - - ZipWriteStream *stream1= [zipFile writeFileInZipWithName:@"abc.txt" fileDate:[NSDate dateWithTimeIntervalSinceNow:-86400.0] compressionLevel:ZipCompressionLevelBest]; - - [self log:@"Test 1: writing to first file's stream..."]; - - NSString *text= @"abc"; - [stream1 writeData:[text dataUsingEncoding:NSUTF8StringEncoding]]; - - [self log:@"Test 1: closing first file's stream..."]; - - [stream1 finishedWriting]; - - [self log:@"Test 1: adding second file..."]; - - NSString *file2name= @"x/y/z/xyz.txt"; - ZipWriteStream *stream2= [zipFile writeFileInZipWithName:file2name compressionLevel:ZipCompressionLevelNone]; - - [self log:@"Test 1: writing to second file's stream..."]; - - NSString *text2= @"XYZ"; - [stream2 writeData:[text2 dataUsingEncoding:NSUTF8StringEncoding]]; - - [self log:@"Test 1: closing second file's stream..."]; - - [stream2 finishedWriting]; - - [self log:@"Test 1: closing zip file..."]; - - [zipFile close]; - [zipFile release]; - - [self log:@"Test 1: opening zip file for reading..."]; - - ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeUnzip]; - - [self log:@"Test 1: reading file infos..."]; - - NSArray *infos= [unzipFile listFileInZipInfos]; - for (FileInZipInfo *info in infos) - [self log:@"Test 1: - %@ %@ %d (%d)", info.name, info.date, info.size, info.level]; - - [self log:@"Test 1: opening first file..."]; - - [unzipFile goToFirstFileInZip]; - ZipReadStream *read1= [unzipFile readCurrentFileInZip]; - - [self log:@"Test 1: reading from first file's stream..."]; - - NSMutableData *data1= [[[NSMutableData alloc] initWithLength:256] autorelease]; - int bytesRead1= [read1 readDataWithBuffer:data1]; - - BOOL ok= NO; - if (bytesRead1 == 3) { - NSString *fileText1= [[[NSString alloc] initWithBytes:[data1 bytes] length:bytesRead1 encoding:NSUTF8StringEncoding] autorelease]; - if ([fileText1 isEqualToString:@"abc"]) - ok= YES; - } - - if (ok) - [self log:@"Test 1: content of first file is OK"]; - else - [self log:@"Test 1: content of first file is WRONG"]; + [self log:@"Test 1: opening zip file for writing..."]; - [self log:@"Test 1: closing first file's stream..."]; - - [read1 finishedReading]; - - [self log:@"Test 1: opening second file..."]; + ZipFile *zipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeCreate]; - [unzipFile locateFileInZip:file2name]; - ZipReadStream *read2= [unzipFile readCurrentFileInZip]; + [self log:@"Test 1: adding first file..."]; + + ZipWriteStream *stream1= [zipFile writeFileInZipWithName:@"abc.txt" fileDate:[NSDate dateWithTimeIntervalSinceNow:-86400.0] compressionLevel:ZipCompressionLevelBest]; - [self log:@"Test 1: reading from second file's stream..."]; - - NSMutableData *data2= [[[NSMutableData alloc] initWithLength:256] autorelease]; - int bytesRead2= [read2 readDataWithBuffer:data2]; - - ok= NO; - if (bytesRead2 == 3) { - NSString *fileText2= [[[NSString alloc] initWithBytes:[data2 bytes] length:bytesRead2 encoding:NSUTF8StringEncoding] autorelease]; - if ([fileText2 isEqualToString:@"XYZ"]) - ok= YES; + [self log:@"Test 1: writing to first file's stream..."]; + + NSString *text= @"abc"; + [stream1 writeData:[text dataUsingEncoding:NSUTF8StringEncoding]]; + + [self log:@"Test 1: closing first file's stream..."]; + + [stream1 finishedWriting]; + + [self log:@"Test 1: adding second file..."]; + + NSString *file2name= @"x/y/z/xyz.txt"; + ZipWriteStream *stream2= [zipFile writeFileInZipWithName:file2name compressionLevel:ZipCompressionLevelNone]; + + [self log:@"Test 1: writing to second file's stream..."]; + + NSString *text2= @"XYZ"; + [stream2 writeData:[text2 dataUsingEncoding:NSUTF8StringEncoding]]; + + [self log:@"Test 1: closing second file's stream..."]; + + [stream2 finishedWriting]; + + [self log:@"Test 1: closing zip file..."]; + + [zipFile close]; + + [self log:@"Test 1: opening zip file for reading..."]; + + ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeUnzip]; + + [self log:@"Test 1: reading file infos..."]; + + NSArray *infos= [unzipFile listFileInZipInfos]; + for (FileInZipInfo *info in infos) + [self log:@"Test 1: - %@ %@ %d (%d)", info.name, info.date, info.size, info.level]; + + [self log:@"Test 1: opening first file..."]; + + [unzipFile goToFirstFileInZip]; + ZipReadStream *read1= [unzipFile readCurrentFileInZip]; + + [self log:@"Test 1: reading from first file's stream..."]; + + NSMutableData *data1= [[NSMutableData alloc] initWithLength:256]; + int bytesRead1= [read1 readDataWithBuffer:data1]; + + BOOL ok= NO; + if (bytesRead1 == 3) { + NSString *fileText1= [[NSString alloc] initWithBytes:[data1 bytes] length:bytesRead1 encoding:NSUTF8StringEncoding]; + if ([fileText1 isEqualToString:@"abc"]) + ok= YES; + } + + if (ok) + [self log:@"Test 1: content of first file is OK"]; + else + [self log:@"Test 1: content of first file is WRONG"]; + + [self log:@"Test 1: closing first file's stream..."]; + + [read1 finishedReading]; + + [self log:@"Test 1: opening second file..."]; + + [unzipFile locateFileInZip:file2name]; + ZipReadStream *read2= [unzipFile readCurrentFileInZip]; + + [self log:@"Test 1: reading from second file's stream..."]; + + NSMutableData *data2= [[NSMutableData alloc] initWithLength:256]; + int bytesRead2= [read2 readDataWithBuffer:data2]; + + ok= NO; + if (bytesRead2 == 3) { + NSString *fileText2= [[NSString alloc] initWithBytes:[data2 bytes] length:bytesRead2 encoding:NSUTF8StringEncoding]; + if ([fileText2 isEqualToString:@"XYZ"]) + ok= YES; + } + + if (ok) + [self log:@"Test 1: content of second file is OK"]; + else + [self log:@"Test 1: content of second file is WRONG"]; + + [self log:@"Test 1: closing second file's stream..."]; + + [read2 finishedReading]; + + [self log:@"Test 1: closing zip file..."]; + + [unzipFile close]; + + [self log:@"Test 1: test terminated succesfully"]; + + } @catch (ZipException *ze) { + [self log:@"Test 1: caught a ZipException (see logs), terminating..."]; + + NSLog(@"Test 1: ZipException caught: %d - %@", ze.error, [ze reason]); + + } @catch (id e) { + [self log:@"Test 1: caught a generic exception (see logs), terminating..."]; + + NSLog(@"Test 1: Exception caught: %@ - %@", [[e class] description], [e description]); + + } @finally { + [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL]; } - - if (ok) - [self log:@"Test 1: content of second file is OK"]; - else - [self log:@"Test 1: content of second file is WRONG"]; - - [self log:@"Test 1: closing second file's stream..."]; - - [read2 finishedReading]; - - [self log:@"Test 1: closing zip file..."]; - - [unzipFile close]; - [unzipFile release]; - - [self log:@"Test 1: test terminated succesfully"]; - - } @catch (ZipException *ze) { - [self log:@"Test 1: caught a ZipException (see logs), terminating..."]; - - NSLog(@"Test 1: ZipException caught: %d - %@", ze.error, [ze reason]); - - } @catch (id e) { - [self log:@"Test 1: caught a generic exception (see logs), terminating..."]; - - NSLog(@"Test 1: Exception caught: %@ - %@", [[e class] description], [e description]); - - } @finally { - [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL]; } - - [pool drain]; } @@ -254,104 +238,99 @@ #pragma mark Test 2: zip & unzip 5 GB - (void) test2 { - NSAutoreleasePool *pool= [[NSAutoreleasePool alloc] init]; + @autoreleasepool { - NSString *documentsDir= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; - NSString *filePath= [documentsDir stringByAppendingPathComponent:@"huge_test.zip"]; + NSString *documentsDir= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; + NSString *filePath= [documentsDir stringByAppendingPathComponent:@"huge_test.zip"]; - @try { - [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL]; + @try { + [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL]; - [self log:@"Test 2: opening zip file for writing..."]; - - ZipFile *zipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeCreate]; - - [self log:@"Test 2: adding file..."]; - - ZipWriteStream *stream= [zipFile writeFileInZipWithName:@"huge_file.txt" compressionLevel:ZipCompressionLevelBest]; - - [self log:@"Test 2: writing to file's stream..."]; - - NSMutableData *data= [[NSMutableData alloc] initWithLength:HUGE_TEST_BLOCK_LENGTH]; - SecRandomCopyBytes(kSecRandomDefault, [data length], [data mutableBytes]); - - NSData *checkData= [data subdataWithRange:NSMakeRange(0, 100)]; - - NSMutableData *buffer= [[NSMutableData alloc] initWithLength:HUGE_TEST_BLOCK_LENGTH]; // For use later - - for (int i= 0; i < HUGE_TEST_NUMBER_OF_BLOCKS; i++) { - [stream writeData:data]; + [self log:@"Test 2: opening zip file for writing..."]; - if (i % 100 == 0) - [self log:@"Test 2: written %d KB...", ([data length] / 1024) * (i +1)]; - } + ZipFile *zipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeCreate]; + + [self log:@"Test 2: adding file..."]; + + ZipWriteStream *stream= [zipFile writeFileInZipWithName:@"huge_file.txt" compressionLevel:ZipCompressionLevelBest]; + + [self log:@"Test 2: writing to file's stream..."]; + + NSMutableData *data= [[NSMutableData alloc] initWithLength:HUGE_TEST_BLOCK_LENGTH]; + SecRandomCopyBytes(kSecRandomDefault, [data length], [data mutableBytes]); + + NSData *checkData= [data subdataWithRange:NSMakeRange(0, 100)]; + + NSMutableData *buffer= [[NSMutableData alloc] initWithLength:HUGE_TEST_BLOCK_LENGTH]; // For use later + + for (int i= 0; i < HUGE_TEST_NUMBER_OF_BLOCKS; i++) { + [stream writeData:data]; - [self log:@"Test 2: closing file's stream..."]; - - [stream finishedWriting]; - - [self log:@"Test 2: closing zip file..."]; - - [zipFile close]; - [zipFile release]; - - [self log:@"Test 2: opening zip file for reading..."]; - - ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeUnzip]; - - [self log:@"Test 2: opening file..."]; - - [unzipFile goToFirstFileInZip]; - ZipReadStream *read= [unzipFile readCurrentFileInZip]; - - [self log:@"Test 2: reading from file's stream..."]; - - for (int i= 0; i < HUGE_TEST_NUMBER_OF_BLOCKS; i++) { - int bytesRead= [read readDataWithBuffer:buffer]; + if (i % 100 == 0) + [self log:@"Test 2: written %d KB...", ([data length] / 1024) * (i +1)]; + } + + [self log:@"Test 2: closing file's stream..."]; - BOOL ok= NO; - if (bytesRead == [data length]) { - NSRange range= [buffer rangeOfData:checkData options:0 range:NSMakeRange(0, [buffer length])]; - if (range.location == 0) - ok= YES; + [stream finishedWriting]; + + [self log:@"Test 2: closing zip file..."]; + + [zipFile close]; + + [self log:@"Test 2: opening zip file for reading..."]; + + ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeUnzip]; + + [self log:@"Test 2: opening file..."]; + + [unzipFile goToFirstFileInZip]; + ZipReadStream *read= [unzipFile readCurrentFileInZip]; + + [self log:@"Test 2: reading from file's stream..."]; + + for (int i= 0; i < HUGE_TEST_NUMBER_OF_BLOCKS; i++) { + int bytesRead= [read readDataWithBuffer:buffer]; + + BOOL ok= NO; + if (bytesRead == [data length]) { + NSRange range= [buffer rangeOfData:checkData options:0 range:NSMakeRange(0, [buffer length])]; + if (range.location == 0) + ok= YES; + } + + if (!ok) + [self log:@"Test 2: content of file is WRONG at position %d KB", ([buffer length] / 1024) * i]; + + if (i % 100 == 0) + [self log:@"Test 2: read %d KB...", ([buffer length] / 1024) * (i +1)]; } - if (!ok) - [self log:@"Test 2: content of file is WRONG at position %d KB", ([buffer length] / 1024) * i]; + [self log:@"Test 2: closing file's stream..."]; - if (i % 100 == 0) - [self log:@"Test 2: read %d KB...", ([buffer length] / 1024) * (i +1)]; + [read finishedReading]; + + [self log:@"Test 2: closing zip file..."]; + + [unzipFile close]; + + [self log:@"Test 2: test terminated succesfully"]; + + } @catch (ZipException *ze) { + [self log:@"Test 2: caught a ZipException (see logs), terminating..."]; + + NSLog(@"Test 2: ZipException caught: %d - %@", ze.error, [ze reason]); + + } @catch (id e) { + [self log:@"Test 2: caught a generic exception (see logs), terminating..."]; + + NSLog(@"Test 2: Exception caught: %@ - %@", [[e class] description], [e description]); + + } @finally { + [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL]; } - - [self log:@"Test 2: closing file's stream..."]; - - [read finishedReading]; - - [self log:@"Test 2: closing zip file..."]; - - [unzipFile close]; - [unzipFile release]; - - [self log:@"Test 2: test terminated succesfully"]; - - [data release]; - [buffer release]; - - } @catch (ZipException *ze) { - [self log:@"Test 2: caught a ZipException (see logs), terminating..."]; - - NSLog(@"Test 2: ZipException caught: %d - %@", ze.error, [ze reason]); - - } @catch (id e) { - [self log:@"Test 2: caught a generic exception (see logs), terminating..."]; - - NSLog(@"Test 2: Exception caught: %@ - %@", [[e class] description], [e description]); - } @finally { - [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL]; } - - [pool drain]; } @@ -359,58 +338,53 @@ #pragma mark Test 3: unzip & check Mac zip file - (void) test3 { - NSAutoreleasePool *pool= [[NSAutoreleasePool alloc] init]; + @autoreleasepool { - NSString *filePath= [[NSBundle mainBundle] pathForResource:@"mac_test_file" ofType:@"zip"]; - - @try { - [self log:@"Test 3: opening zip file for reading..."]; + NSString *filePath= [[NSBundle mainBundle] pathForResource:@"mac_test_file" ofType:@"zip"]; - ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeUnzip]; - - [self log:@"Test 3: opening file..."]; - - [unzipFile goToFirstFileInZip]; - ZipReadStream *read= [unzipFile readCurrentFileInZip]; - - [self log:@"Test 3: reading from file's stream..."]; - - NSMutableData *buffer= [[NSMutableData alloc] initWithLength:1024]; + @try { + [self log:@"Test 3: opening zip file for reading..."]; + + ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeUnzip]; + + [self log:@"Test 3: opening file..."]; + + [unzipFile goToFirstFileInZip]; + ZipReadStream *read= [unzipFile readCurrentFileInZip]; + + [self log:@"Test 3: reading from file's stream..."]; + + NSMutableData *buffer= [[NSMutableData alloc] initWithLength:1024]; - int bytesRead= [read readDataWithBuffer:buffer]; - - NSString *fileText= [[[NSString alloc] initWithBytes:[buffer bytes] length:bytesRead encoding:NSUTF8StringEncoding] autorelease]; - if ([fileText isEqualToString:@"Objective-Zip Mac test file\n"]) - [self log:@"Test 3: content of Mac file is OK"]; - else - [self log:@"Test 3: content of Mac file is WRONG"]; - - [self log:@"Test 3: closing file's stream..."]; - - [read finishedReading]; - - [self log:@"Test 3: closing zip file..."]; - - [unzipFile close]; - [unzipFile release]; - - [self log:@"Test 3: test terminated succesfully"]; - - [buffer release]; + int bytesRead= [read readDataWithBuffer:buffer]; + + NSString *fileText= [[NSString alloc] initWithBytes:[buffer bytes] length:bytesRead encoding:NSUTF8StringEncoding]; + if ([fileText isEqualToString:@"Objective-Zip Mac test file\n"]) + [self log:@"Test 3: content of Mac file is OK"]; + else + [self log:@"Test 3: content of Mac file is WRONG"]; + + [self log:@"Test 3: closing file's stream..."]; + + [read finishedReading]; + + [self log:@"Test 3: closing zip file..."]; + + [unzipFile close]; + + [self log:@"Test 3: test terminated succesfully"]; - } @catch (ZipException *ze) { - [self log:@"Test 3: caught a ZipException (see logs), terminating..."]; - - NSLog(@"Test 3: ZipException caught: %d - %@", ze.error, [ze reason]); - - } @catch (id e) { - [self log:@"Test 3: caught a generic exception (see logs), terminating..."]; - - NSLog(@"Test 3: Exception caught: %@ - %@", [[e class] description], [e description]); - + } @catch (ZipException *ze) { + [self log:@"Test 3: caught a ZipException (see logs), terminating..."]; + + NSLog(@"Test 3: ZipException caught: %d - %@", ze.error, [ze reason]); + + } @catch (id e) { + [self log:@"Test 3: caught a generic exception (see logs), terminating..."]; + + NSLog(@"Test 3: Exception caught: %@ - %@", [[e class] description], [e description]); + } } - - [pool drain]; } @@ -418,57 +392,53 @@ #pragma mark Test 4: unzip & check Win zip file - (void) test4 { - NSAutoreleasePool *pool= [[NSAutoreleasePool alloc] init]; + @autoreleasepool { - NSString *filePath= [[NSBundle mainBundle] pathForResource:@"win_test_file" ofType:@"zip"]; - - @try { - [self log:@"Test 4: opening zip file for reading..."]; + NSString *filePath= [[NSBundle mainBundle] pathForResource:@"win_test_file" ofType:@"zip"]; - ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeUnzip]; - - [self log:@"Test 4: opening file..."]; - - [unzipFile goToFirstFileInZip]; - ZipReadStream *read= [unzipFile readCurrentFileInZip]; - - [self log:@"Test 4: reading from file's stream..."]; - - NSMutableData *buffer= [[NSMutableData alloc] initWithLength:1024]; - - int bytesRead= [read readDataWithBuffer:buffer]; - - NSString *fileText= [[[NSString alloc] initWithBytes:[buffer bytes] length:bytesRead encoding:NSUTF8StringEncoding] autorelease]; - if ([fileText isEqualToString:@"Objective-Zip Windows test file\r\n"]) - [self log:@"Test 4: content of Win file is OK"]; - else - [self log:@"Test 4: content of Win file is WRONG"]; - - [self log:@"Test 4: closing file's stream..."]; - - [read finishedReading]; - - [self log:@"Test 4: closing zip file..."]; - - [unzipFile close]; - [unzipFile release]; - - [self log:@"Test 4: test terminated succesfully"]; - - [buffer release]; - - } @catch (ZipException *ze) { - [self log:@"Test 4: caught a ZipException (see logs), terminating..."]; - - NSLog(@"Test 4: ZipException caught: %d - %@", ze.error, [ze reason]); - - } @catch (id e) { - [self log:@"Test 4: caught a generic exception (see logs), terminating..."]; - - NSLog(@"Test 4: Exception caught: %@ - %@", [[e class] description], [e description]); + @try { + [self log:@"Test 4: opening zip file for reading..."]; + + ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeUnzip]; + + [self log:@"Test 4: opening file..."]; + + [unzipFile goToFirstFileInZip]; + ZipReadStream *read= [unzipFile readCurrentFileInZip]; + + [self log:@"Test 4: reading from file's stream..."]; + + NSMutableData *buffer= [[NSMutableData alloc] initWithLength:1024]; + + int bytesRead= [read readDataWithBuffer:buffer]; + + NSString *fileText= [[NSString alloc] initWithBytes:[buffer bytes] length:bytesRead encoding:NSUTF8StringEncoding]; + if ([fileText isEqualToString:@"Objective-Zip Windows test file\r\n"]) + [self log:@"Test 4: content of Win file is OK"]; + else + [self log:@"Test 4: content of Win file is WRONG"]; + + [self log:@"Test 4: closing file's stream..."]; + + [read finishedReading]; + + [self log:@"Test 4: closing zip file..."]; + + [unzipFile close]; + + [self log:@"Test 4: test terminated succesfully"]; + + } @catch (ZipException *ze) { + [self log:@"Test 4: caught a ZipException (see logs), terminating..."]; + + NSLog(@"Test 4: ZipException caught: %d - %@", ze.error, [ze reason]); + + } @catch (id e) { + [self log:@"Test 4: caught a generic exception (see logs), terminating..."]; + + NSLog(@"Test 4: Exception caught: %@ - %@", [[e class] description], [e description]); + } } - - [pool drain]; } @@ -485,7 +455,6 @@ [self performSelectorOnMainThread:@selector(printLog:) withObject:logLine waitUntilDone:YES]; - [logLine release]; } - (void) printLog:(NSString *)logLine { diff --git a/Objective-Zip.xcodeproj/project.pbxproj b/Objective-Zip.xcodeproj/project.pbxproj index c6ae679..9914008 100755 --- a/Objective-Zip.xcodeproj/project.pbxproj +++ b/Objective-Zip.xcodeproj/project.pbxproj @@ -80,7 +80,6 @@ 8C83F49410E7CBCB002FB3CB /* FileInZipInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FileInZipInfo.m; path = "Objective-Zip/FileInZipInfo.m"; sourceTree = ""; }; 8C8F2D3910EBC94B00F75833 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = ""; }; 8C8F2D9210EBCE0300F75833 /* ObjectiveZipIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ObjectiveZipIcon.png; sourceTree = ""; }; - 8C9893AF16E5511500E1190A /* ARCHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ARCHelper.h; sourceTree = ""; }; 8CBE431610E95FA300AC9ED3 /* ZipReadStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ZipReadStream.h; path = "Objective-Zip/ZipReadStream.h"; sourceTree = ""; }; 8CBE431710E95FA300AC9ED3 /* ZipReadStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ZipReadStream.m; path = "Objective-Zip/ZipReadStream.m"; sourceTree = ""; }; 8CD8B3E917766067005212EC /* adler32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = adler32.c; path = ZLib/adler32.c; sourceTree = ""; }; @@ -154,7 +153,6 @@ 8C6D353B10E56BA400B63EFA /* Objective-Zip */, 8C6D350110E56A4B00B63EFA /* MiniZip */, 8CD8B3E817766056005212EC /* ZLib */, - 8C9893AE16E550E600E1190A /* ARC Helper */, 080E96DDFE201D6D7F000001 /* Classes */, 29B97315FDCFA39411CA2CEA /* Other Sources */, 29B97317FDCFA39411CA2CEA /* Resources */, @@ -231,15 +229,6 @@ name = "Objective-Zip"; sourceTree = ""; }; - 8C9893AE16E550E600E1190A /* ARC Helper */ = { - isa = PBXGroup; - children = ( - 8C9893AF16E5511500E1190A /* ARCHelper.h */, - ); - name = "ARC Helper"; - path = ARCHelper; - sourceTree = ""; - }; 8CD8B3E817766056005212EC /* ZLib */ = { isa = PBXGroup; children = ( @@ -299,7 +288,7 @@ 29B97313FDCFA39411CA2CEA /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0460; + LastUpgradeCheck = 0640; }; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "Objective-Zip" */; compatibilityVersion = "Xcode 3.2"; @@ -379,6 +368,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_OBJC_ARC = YES; CODE_SIGN_IDENTITY = "iPhone Developer: Gianluca Bertani (42HXKD6D45)"; COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; @@ -388,6 +378,7 @@ GCC_PREPROCESSOR_DEFINITIONS = ""; GCC_THUMB_SUPPORT = NO; INFOPLIST_FILE = "Objective_Zip-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; PRODUCT_NAME = "Objective-Zip"; PROVISIONING_PROFILE = "8D9AD182-36E0-47FE-AB6B-E87632E60994"; }; @@ -397,6 +388,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_OBJC_ARC = YES; CODE_SIGN_IDENTITY = "iPhone Developer: Gianluca Bertani (42HXKD6D45)"; COPY_PHASE_STRIP = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; @@ -404,6 +396,7 @@ GCC_PREPROCESSOR_DEFINITIONS = ""; GCC_THUMB_SUPPORT = NO; INFOPLIST_FILE = "Objective_Zip-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; PRODUCT_NAME = "Objective-Zip"; PROVISIONING_PROFILE = "8D9AD182-36E0-47FE-AB6B-E87632E60994"; }; @@ -412,10 +405,6 @@ C01FCF4F08A954540054247B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = ( - "$(ARCHS_STANDARD_32_BIT)", - armv6, - ); CODE_SIGN_IDENTITY = "iPhone Developer: Gianluca Bertani (42HXKD6D45)"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Gianluca Bertani (42HXKD6D45)"; GCC_C_LANGUAGE_STANDARD = c99; @@ -423,6 +412,7 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 3.1.2; + ONLY_ACTIVE_ARCH = YES; PROVISIONING_PROFILE = "8D9AD182-36E0-47FE-AB6B-E87632E60994"; "PROVISIONING_PROFILE[sdk=iphoneos*]" = "8D920AE2-DF44-48C7-A9B5-0AB3D42590BB"; SDKROOT = iphoneos; @@ -432,10 +422,6 @@ C01FCF5008A954540054247B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = ( - "$(ARCHS_STANDARD_32_BIT)", - armv6, - ); CODE_SIGN_IDENTITY = "iPhone Developer: Gianluca Bertani (42HXKD6D45)"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Gianluca Bertani (42HXKD6D45)"; GCC_C_LANGUAGE_STANDARD = c99; diff --git a/Objective-Zip/FileInZipInfo.h b/Objective-Zip/FileInZipInfo.h index 0be2202..1aec65a 100644 --- a/Objective-Zip/FileInZipInfo.h +++ b/Objective-Zip/FileInZipInfo.h @@ -32,8 +32,8 @@ // #import + #import "ZipFile.h" -#import "ARCHelper.h" @interface FileInZipInfo : NSObject { diff --git a/Objective-Zip/FileInZipInfo.m b/Objective-Zip/FileInZipInfo.m index 2962f99..1062125 100644 --- a/Objective-Zip/FileInZipInfo.m +++ b/Objective-Zip/FileInZipInfo.m @@ -38,24 +38,18 @@ - (id) initWithName:(NSString *)name length:(NSUInteger)length level:(ZipCompressionLevel)level crypted:(BOOL)crypted size:(NSUInteger)size date:(NSDate *)date crc32:(NSUInteger)crc32 { if (self= [super init]) { - _name= [name ah_retain]; + _name= name; _length= length; _level= level; _crypted= crypted; _size= size; - _date= [date ah_retain]; + _date= date; _crc32= crc32; } return self; } -- (void) dealloc { - [_date release]; - [_name release]; - - [super ah_dealloc]; -} @synthesize name= _name; @synthesize length= _length; diff --git a/Objective-Zip/ZipException.h b/Objective-Zip/ZipException.h index 77a0e2b..07d5388 100644 --- a/Objective-Zip/ZipException.h +++ b/Objective-Zip/ZipException.h @@ -32,7 +32,6 @@ // #import -#import "ARCHelper.h" @interface ZipException : NSException { diff --git a/Objective-Zip/ZipFile.h b/Objective-Zip/ZipFile.h index d5582f3..233c376 100644 --- a/Objective-Zip/ZipFile.h +++ b/Objective-Zip/ZipFile.h @@ -32,7 +32,6 @@ // #import -#import "ARCHelper.h" #include "zip.h" #include "unzip.h" diff --git a/Objective-Zip/ZipFile.m b/Objective-Zip/ZipFile.m index 00b09a5..59a5f98 100644 --- a/Objective-Zip/ZipFile.m +++ b/Objective-Zip/ZipFile.m @@ -45,7 +45,7 @@ - (id) initWithFileName:(NSString *)fileName mode:(ZipFileMode)mode { if (self= [super init]) { - _fileName= [fileName ah_retain]; + _fileName= fileName; _mode= mode; switch (mode) { @@ -53,7 +53,7 @@ _unzFile= unzOpen64([_fileName cStringUsingEncoding:NSUTF8StringEncoding]); if (_unzFile == NULL) { NSString *reason= [NSString stringWithFormat:@"Can't open '%@'", _fileName]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } break; @@ -61,7 +61,7 @@ _zipFile= zipOpen64([_fileName cStringUsingEncoding:NSUTF8StringEncoding], APPEND_STATUS_CREATE); if (_zipFile == NULL) { NSString *reason= [NSString stringWithFormat:@"Can't open '%@'", _fileName]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } break; @@ -69,13 +69,13 @@ _zipFile= zipOpen64([_fileName cStringUsingEncoding:NSUTF8StringEncoding], APPEND_STATUS_ADDINZIP); if (_zipFile == NULL) { NSString *reason= [NSString stringWithFormat:@"Can't open '%@'", _fileName]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } break; default: { NSString *reason= [NSString stringWithFormat:@"Unknown mode %d", _mode]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } } } @@ -83,16 +83,11 @@ return self; } -- (void) dealloc { - [_fileName release]; - - [super ah_dealloc]; -} - (ZipWriteStream *) writeFileInZipWithName:(NSString *)fileNameInZip compressionLevel:(ZipCompressionLevel)compressionLevel { if (_mode == ZipFileModeUnzip) { NSString *reason= [NSString stringWithFormat:@"Operation not permitted with Unzip mode"]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } NSDate *now= [NSDate date]; @@ -120,16 +115,16 @@ NULL, 0, 1); if (err != ZIP_OK) { NSString *reason= [NSString stringWithFormat:@"Error opening '%@' in zipfile", fileNameInZip]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } - return [[[ZipWriteStream alloc] initWithZipFileStruct:_zipFile fileNameInZip:fileNameInZip] autorelease]; + return [[ZipWriteStream alloc] initWithZipFileStruct:_zipFile fileNameInZip:fileNameInZip]; } - (ZipWriteStream *) writeFileInZipWithName:(NSString *)fileNameInZip fileDate:(NSDate *)fileDate compressionLevel:(ZipCompressionLevel)compressionLevel { if (_mode == ZipFileModeUnzip) { NSString *reason= [NSString stringWithFormat:@"Operation not permitted with Unzip mode"]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } NSCalendar *calendar= [NSCalendar currentCalendar]; @@ -156,16 +151,16 @@ NULL, 0, 1); if (err != ZIP_OK) { NSString *reason= [NSString stringWithFormat:@"Error opening '%@' in zipfile", fileNameInZip]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } - return [[[ZipWriteStream alloc] initWithZipFileStruct:_zipFile fileNameInZip:fileNameInZip] autorelease]; + return [[ZipWriteStream alloc] initWithZipFileStruct:_zipFile fileNameInZip:fileNameInZip]; } - (ZipWriteStream *) writeFileInZipWithName:(NSString *)fileNameInZip fileDate:(NSDate *)fileDate compressionLevel:(ZipCompressionLevel)compressionLevel password:(NSString *)password crc32:(NSUInteger)crc32 { if (_mode == ZipFileModeUnzip) { NSString *reason= [NSString stringWithFormat:@"Operation not permitted with Unzip mode"]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } NSCalendar *calendar= [NSCalendar currentCalendar]; @@ -192,10 +187,10 @@ [password cStringUsingEncoding:NSUTF8StringEncoding], crc32, 1); if (err != ZIP_OK) { NSString *reason= [NSString stringWithFormat:@"Error opening '%@' in zipfile", fileNameInZip]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } - return [[[ZipWriteStream alloc] initWithZipFileStruct:_zipFile fileNameInZip:fileNameInZip] autorelease]; + return [[ZipWriteStream alloc] initWithZipFileStruct:_zipFile fileNameInZip:fileNameInZip]; } - (NSString*) fileName { @@ -205,14 +200,14 @@ - (NSUInteger) numFilesInZip { if (_mode != ZipFileModeUnzip) { NSString *reason= [NSString stringWithFormat:@"Operation not permitted without Unzip mode"]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } unz_global_info64 gi; int err= unzGetGlobalInfo64(_unzFile, &gi); if (err != UNZ_OK) { NSString *reason= [NSString stringWithFormat:@"Error getting global info in '%@'", _fileName]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } return gi.number_entry; @@ -221,9 +216,9 @@ - (NSArray *) listFileInZipInfos { int num= [self numFilesInZip]; if (num < 1) - return [[[NSArray alloc] init] autorelease]; + return [[NSArray alloc] init]; - NSMutableArray *files= [[[NSMutableArray alloc] initWithCapacity:num] autorelease]; + NSMutableArray *files= [[NSMutableArray alloc] initWithCapacity:num]; [self goToFirstFileInZip]; for (int i= 0; i < num; i++) { @@ -240,20 +235,20 @@ - (void) goToFirstFileInZip { if (_mode != ZipFileModeUnzip) { NSString *reason= [NSString stringWithFormat:@"Operation not permitted without Unzip mode"]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } int err= unzGoToFirstFile(_unzFile); if (err != UNZ_OK) { NSString *reason= [NSString stringWithFormat:@"Error going to first file in zip in '%@'", _fileName]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } } - (BOOL) goToNextFileInZip { if (_mode != ZipFileModeUnzip) { NSString *reason= [NSString stringWithFormat:@"Operation not permitted without Unzip mode"]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } int err= unzGoToNextFile(_unzFile); @@ -262,7 +257,7 @@ if (err != UNZ_OK) { NSString *reason= [NSString stringWithFormat:@"Error going to next file in zip in '%@'", _fileName]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } return YES; @@ -271,7 +266,7 @@ - (BOOL) locateFileInZip:(NSString *)fileNameInZip { if (_mode != ZipFileModeUnzip) { NSString *reason= [NSString stringWithFormat:@"Operation not permitted without Unzip mode"]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } int err= unzLocateFile(_unzFile, [fileNameInZip cStringUsingEncoding:NSUTF8StringEncoding], NULL); @@ -280,7 +275,7 @@ if (err != UNZ_OK) { NSString *reason= [NSString stringWithFormat:@"Error localting file in zip in '%@'", _fileName]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } return YES; @@ -289,7 +284,7 @@ - (FileInZipInfo *) getCurrentFileInZipInfo { if (_mode != ZipFileModeUnzip) { NSString *reason= [NSString stringWithFormat:@"Operation not permitted without Unzip mode"]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } char filename_inzip[FILE_IN_ZIP_MAX_NAME_LENGTH]; @@ -298,7 +293,7 @@ int err= unzGetCurrentFileInfo64(_unzFile, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0); if (err != UNZ_OK) { NSString *reason= [NSString stringWithFormat:@"Error getting current file info in '%@'", _fileName]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } NSString *name= [NSString stringWithCString:filename_inzip encoding:NSUTF8StringEncoding]; @@ -322,7 +317,7 @@ BOOL crypted= ((file_info.flag & 1) != 0); - NSDateComponents *components= [[[NSDateComponents alloc] init] autorelease]; + NSDateComponents *components= [[NSDateComponents alloc] init]; [components setDay:file_info.tmu_date.tm_mday]; [components setMonth:file_info.tmu_date.tm_mon +1]; [components setYear:file_info.tmu_date.tm_year]; @@ -333,13 +328,13 @@ NSDate *date= [calendar dateFromComponents:components]; FileInZipInfo *info= [[FileInZipInfo alloc] initWithName:name length:file_info.uncompressed_size level:level crypted:crypted size:file_info.compressed_size date:date crc32:file_info.crc]; - return [info autorelease]; + return info; } - (ZipReadStream *) readCurrentFileInZip { if (_mode != ZipFileModeUnzip) { NSString *reason= [NSString stringWithFormat:@"Operation not permitted without Unzip mode"]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } char filename_inzip[FILE_IN_ZIP_MAX_NAME_LENGTH]; @@ -348,7 +343,7 @@ int err= unzGetCurrentFileInfo64(_unzFile, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0); if (err != UNZ_OK) { NSString *reason= [NSString stringWithFormat:@"Error getting current file info in '%@'", _fileName]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } NSString *fileNameInZip= [NSString stringWithCString:filename_inzip encoding:NSUTF8StringEncoding]; @@ -356,16 +351,16 @@ err= unzOpenCurrentFilePassword(_unzFile, NULL); if (err != UNZ_OK) { NSString *reason= [NSString stringWithFormat:@"Error opening current file in '%@'", _fileName]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } - return [[[ZipReadStream alloc] initWithUnzFileStruct:_unzFile fileNameInZip:fileNameInZip] autorelease]; + return [[ZipReadStream alloc] initWithUnzFileStruct:_unzFile fileNameInZip:fileNameInZip]; } - (ZipReadStream *) readCurrentFileInZipWithPassword:(NSString *)password { if (_mode != ZipFileModeUnzip) { NSString *reason= [NSString stringWithFormat:@"Operation not permitted without Unzip mode"]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } char filename_inzip[FILE_IN_ZIP_MAX_NAME_LENGTH]; @@ -374,7 +369,7 @@ int err= unzGetCurrentFileInfo64(_unzFile, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0); if (err != UNZ_OK) { NSString *reason= [NSString stringWithFormat:@"Error getting current file info in '%@'", _fileName]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } NSString *fileNameInZip= [NSString stringWithCString:filename_inzip encoding:NSUTF8StringEncoding]; @@ -382,10 +377,10 @@ err= unzOpenCurrentFilePassword(_unzFile, [password cStringUsingEncoding:NSUTF8StringEncoding]); if (err != UNZ_OK) { NSString *reason= [NSString stringWithFormat:@"Error opening current file in '%@'", _fileName]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } - return [[[ZipReadStream alloc] initWithUnzFileStruct:_unzFile fileNameInZip:fileNameInZip] autorelease]; + return [[ZipReadStream alloc] initWithUnzFileStruct:_unzFile fileNameInZip:fileNameInZip]; } - (void) close { @@ -394,7 +389,7 @@ int err= unzClose(_unzFile); if (err != UNZ_OK) { NSString *reason= [NSString stringWithFormat:@"Error closing '%@'", _fileName]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } break; } @@ -403,7 +398,7 @@ int err= zipClose(_zipFile, NULL); if (err != ZIP_OK) { NSString *reason= [NSString stringWithFormat:@"Error closing '%@'", _fileName]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } break; } @@ -412,14 +407,14 @@ int err= zipClose(_zipFile, NULL); if (err != ZIP_OK) { NSString *reason= [NSString stringWithFormat:@"Error closing '%@'", _fileName]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } break; } default: { NSString *reason= [NSString stringWithFormat:@"Unknown mode %d", _mode]; - @throw [[[ZipException alloc] initWithReason:reason] autorelease]; + @throw [[ZipException alloc] initWithReason:reason]; } } } diff --git a/Objective-Zip/ZipReadStream.h b/Objective-Zip/ZipReadStream.h index cc429e3..0afa633 100644 --- a/Objective-Zip/ZipReadStream.h +++ b/Objective-Zip/ZipReadStream.h @@ -32,7 +32,6 @@ // #import -#import "ARCHelper.h" #include "unzip.h" diff --git a/Objective-Zip/ZipReadStream.m b/Objective-Zip/ZipReadStream.m index 2ebea6c..a3850a6 100644 --- a/Objective-Zip/ZipReadStream.m +++ b/Objective-Zip/ZipReadStream.m @@ -53,7 +53,7 @@ int err= unzReadCurrentFile(_unzFile, [buffer mutableBytes], [buffer length]); if (err < 0) { NSString *reason= [NSString stringWithFormat:@"Error reading '%@' in the zipfile", _fileNameInZip]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } return err; @@ -63,7 +63,7 @@ int err= unzCloseCurrentFile(_unzFile); if (err != UNZ_OK) { NSString *reason= [NSString stringWithFormat:@"Error closing '%@' in the zipfile", _fileNameInZip]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } } diff --git a/Objective-Zip/ZipWriteStream.h b/Objective-Zip/ZipWriteStream.h index 90ca29b..ca7c337 100644 --- a/Objective-Zip/ZipWriteStream.h +++ b/Objective-Zip/ZipWriteStream.h @@ -32,7 +32,6 @@ // #import -#import "ARCHelper.h" #include "zip.h" diff --git a/Objective-Zip/ZipWriteStream.m b/Objective-Zip/ZipWriteStream.m index 4ca9156..61f3287 100644 --- a/Objective-Zip/ZipWriteStream.m +++ b/Objective-Zip/ZipWriteStream.m @@ -53,7 +53,7 @@ int err= zipWriteInFileInZip(_zipFile, [data bytes], [data length]); if (err < 0) { NSString *reason= [NSString stringWithFormat:@"Error writing '%@' in the zipfile", _fileNameInZip]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } } @@ -61,7 +61,7 @@ int err= zipCloseFileInZip(_zipFile); if (err != ZIP_OK) { NSString *reason= [NSString stringWithFormat:@"Error closing '%@' in the zipfile", _fileNameInZip]; - @throw [[[ZipException alloc] initWithError:err reason:reason] autorelease]; + @throw [[ZipException alloc] initWithError:err reason:reason]; } } diff --git a/Objective_ZipViewController.xib b/Objective_ZipViewController.xib index fe670ab..f2507fc 100644 --- a/Objective_ZipViewController.xib +++ b/Objective_ZipViewController.xib @@ -1,33 +1,29 @@ - + - 1552 - 12E55 - 3084 - 1187.39 - 626.00 + 1296 + 14F27 + 7706 + 1348.17 + 758.70 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 2083 + 7703 - - YES + IBProxyObject IBUIButton - IBUIImageView IBUITextView IBUIView - - - YES + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin - + PluginDependencyRecalculationVersion - - YES + IBFilesOwner IBCocoaTouchFramework @@ -39,25 +35,7 @@ 274 - - YES - - - 292 - {{0, -20}, {320, 480}} - - - - NO - NO - 4 - NO - IBCocoaTouchFramework - - NSImage - Default.png - - + 292 @@ -71,15 +49,15 @@ 0 0 1 - Zip & Unzip + + 1 + MC4xOTYwNzg0MzE0IDAuMzA5ODAzOTIxNiAwLjUyMTU2ODYyNzUAA + 3 MQA - - 1 - MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA - + Zip & Unzip 3 MC41AA @@ -109,12 +87,9 @@ 0 0 1 - 5 GB Zip & Unzip (use with caution) + - - 1 - MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA - + 5 GB Zip & Unzip (use with caution) @@ -132,12 +107,9 @@ 0 0 1 - Unzip & Check Mac OS X Zip File + - - 1 - MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA - + Unzip & Check Mac OS X Zip File @@ -155,12 +127,9 @@ 0 0 1 - Unzip & Check Windows Zip File + - - 1 - MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA - + Unzip & Check Windows Zip File @@ -202,34 +171,31 @@ 1 + 0 17 - Helvetica + HelveticaNeue 17 16 - + {{0, 20}, {320, 460}} - - - 3 - MC43NQA - - 2 - - + NO + + IBUISimulatedFreeformSizeMetricsSentinel + Freeform + IBCocoaTouchFramework - + - - YES + view @@ -282,15 +248,12 @@ 23 - + - - YES + 0 - - YES - + @@ -308,16 +271,14 @@ 6 - - YES + - - + @@ -328,9 +289,7 @@ 9 - - YES - + @@ -338,11 +297,6 @@ - - 13 - - - 15 @@ -358,107 +312,57 @@ - - - - YES - - YES - -1.CustomClassName - -1.IBPluginDependency - -2.CustomClassName - -2.IBPluginDependency - 10.IBPluginDependency - 13.IBPluginDependency - 15.IBPluginDependency - 18.IBPluginDependency - 19.IBPluginDependency - 6.IBPluginDependency - 8.IBPluginDependency - 9.IBPluginDependency - - - YES - Objective_ZipViewController - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - UIResponder - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - - YES - - + + + Objective_ZipViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + - - YES - - - + 23 - - YES + Objective_ZipViewController UIViewController - - YES - - YES - zipCheck1 - zipCheck2 - zipUnzip - zipUnzip2 + + id + id + id + id + + + + zipCheck1 + id - - YES - id - id - id - id + + zipCheck2 + id - - - YES - - YES - zipCheck1 - zipCheck2 - zipUnzip - zipUnzip2 + + zipUnzip + id - - YES - - zipCheck1 - id - - - zipCheck2 - id - - - zipUnzip - id - - - zipUnzip2 - id - + + zipUnzip2 + id - + _textView UITextView @@ -472,23 +376,132 @@ IBProjectSource - ./Classes/Objective_ZipViewController.h + ../Classes/Objective_ZipViewController.h - + + Objective_ZipViewController + + id + id + id + id + + + + zipCheck1 + id + + + zipCheck2 + id + + + zipUnzip + id + + + zipUnzip2 + id + + + + IBProjectSource + ../Classes/Objective_ZipViewController.m + + + + + + UIButton + UIControl + + IBFrameworkSource + UIKit.framework/Headers/UIButton.h + + + + UIControl + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIControl.h + + + + UIGestureRecognizer + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIGestureRecognizer.h + + + + UIResponder + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIResponder.h + + + + UIScrollView + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIScrollView.h + + + + UISearchBar + UIView + + IBFrameworkSource + UIKit.framework/Headers/UISearchBar.h + + + + UISearchDisplayController + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UISearchDisplayController.h + + + + UITextView + UIScrollView + + IBFrameworkSource + UIKit.framework/Headers/UITextView.h + + + + UIView + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIView.h + + + + UIViewController + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIViewController.h + + + 0 IBCocoaTouchFramework + NO com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 - + YES 3 - - Default.png - {320, 480} - - 2083 diff --git a/main.m b/main.m index e2a1197..a9b6b10 100644 --- a/main.m +++ b/main.m @@ -34,9 +34,8 @@ #import int main(int argc, char *argv[]) { - - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - int retVal = UIApplicationMain(argc, argv, nil, nil); - [pool release]; - return retVal; + @autoreleasepool { + int retVal = UIApplicationMain(argc, argv, nil, nil); + return retVal; + } }