20 Commits

Author SHA1 Message Date
Antoine Cœur
30eff54054 2.0.7 2017-09-18 11:32:01 +08:00
Antoine Cœur
d94e717193 updated copyright 2017-09-18 11:08:13 +08:00
Antoine Cœur
5666c74d61 Merge pull request #379 from ZipArchive/gregorian
fix zipInfo:setDate: when currentCalendar was not gregorian
2017-09-18 10:44:24 +08:00
Antoine Cœur
25fb5cdf58 fix zipInfo:setDate: when currentCalendar was not gregorian 2017-09-17 19:51:47 +08:00
Antoine Cœur
961d471d39 readability and simplifications 2017-09-17 00:55:52 +08:00
Antoine Cœur
ec2cc3f474 Merge pull request #377 from ZipArchive/unicode_passwords
unicode passwords support
2017-09-16 23:47:21 +08:00
Antoine Cœur
8f7d1bb6db add testZippingAndUnzippingWithUnicodePassword
fix testZipping and testZippingAndUnzippingForDate
2017-09-16 22:13:31 +08:00
Antoine Cœur
c8a93311b5 unicode passwords 2017-09-16 18:01:56 +08:00
Antoine Cœur
f9df6800d6 modernizing objectiveC 2017-09-14 00:31:27 +08:00
Antoine Cœur
bad8ca91e2 human readable xcodebuild destination 2017-09-13 20:12:05 +08:00
Antoine Cœur
dd86a28b22 SSZipArchive works on Xcode 7-9 and above, iOS 8-11 and above. 2017-09-13 15:54:43 +08:00
Antoine Cœur
465f6210c4 fix compilation on Xcode 7.x 2017-09-13 00:47:45 +08:00
Antoine Cœur
a004f928cd also printing error for Swift example project 2017-09-12 21:44:47 +08:00
Antoine Cœur
e7116f283f alphabetic order 2017-09-12 21:36:56 +08:00
Antoine Cœur
fa3fe1dfd8 correctly reporting errors for createZipFileAtPath 2017-09-12 21:15:13 +08:00
Antoine Cœur
1c5bf00ec3 travis script on multiple lines for readability 2017-09-10 10:23:56 +08:00
Antoine Cœur
f3030e34ab returning write errors and preventing multiple calls to close by setting _zip to nil 2017-09-10 03:07:15 +08:00
Antoine Cœur
44329ab1a1 avoiding calling the completionHandler twice 2017-09-10 02:49:18 +08:00
Antoine Cœur
bdbe304da3 applying some suggestions from AppCode 2017-09-09 23:05:11 +08:00
Antoine Cœur
5bb31f8d67 .gitignore simplified as we don't need to support Xcode3 (https://github.com/github/gitignore/blob/master/Global/Xcode.gitignore) 2017-09-09 20:22:22 +08:00
34 changed files with 432 additions and 275 deletions

20
.gitignore vendored
View File

@@ -1,21 +1,13 @@
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
xcuserdata/
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
# AppCode
.idea
# macOS
.DS_Store
# CocoaPods

View File

@@ -1,7 +1,41 @@
language: objective-c
osx_image: xcode8.3
podfile: ObjectiveCExample/Podfile
xcode_workspace: ObjectiveCExample/ObjectiveCExample.xcworkspace
xcode_scheme: ObjectiveCExample
script: xcodebuild -workspace ObjectiveCExample/ObjectiveCExample.xcworkspace -scheme ObjectiveCExample -sdk iphonesimulator -destination "id=F60B87EC-8969-41A7-90ED-D0826ECC32DB" -configuration Debug ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES test
matrix:
include:
- osx_image: xcode9
env: DESTINATION="iPhone 7 Plus (11.0)" # oldest/newest for iOS 11.x
- osx_image: xcode9
env: DESTINATION="iPhone 7 Plus (10.3.1)" # latest for iOS 10.x
- osx_image: xcode8.3
env: DESTINATION="iPhone 5 (10.0)" # oldest for iOS 10.x
- osx_image: xcode8.3
env: DESTINATION="iPhone 6s Plus (9.3)" # latest for iOS 9.x
- osx_image: xcode7.3
env: DESTINATION="iPhone 4s (9.0)" # oldest for iOS 9.x
- osx_image: xcode7.3
env: DESTINATION="iPhone 6 Plus (8.4)" # latest for iOS 8.x
- osx_image: xcode7.3
env: DESTINATION="iPhone 4s (8.1)" # oldest for iOS 8.x
before_install:
# Grepping destination device udid
- DESTINATION_UDID=$(instruments -s devices | grep "$DESTINATION \[" | sed -E 's/.*\[([0-9A-F-]+)\].*/\1/g')
# Prelaunching simulator to avoid timeout https://github.com/travis-ci/travis-ci/issues/6422
- open -a "simulator" --args -CurrentDeviceUDID $DESTINATION_UDID
script:
# Testing
- xcodebuild
`` -workspace ObjectiveCExample/ObjectiveCExample.xcworkspace
`` -scheme ObjectiveCExample -sdk iphonesimulator
`` -destination "id=$DESTINATION_UDID"
`` -configuration Debug ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES
`` test

View File

@@ -265,7 +265,7 @@
8DFE19E21BDA9FF300709011 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0820;
LastUpgradeCheck = 0900;
TargetAttributes = {
8DFE19E91BDA9FF300709011 = {
CreatedOnToolsVersion = 7.1;
@@ -506,11 +506,12 @@
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES_AGGRESSIVE;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
@@ -531,7 +532,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@@ -558,11 +559,12 @@
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES_AGGRESSIVE;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
@@ -577,7 +579,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";

View File

@@ -50,6 +50,8 @@
if (success) {
_unzipButton.enabled = YES;
_zipButton.enabled = NO;
} else {
NSLog(@"No success");
}
_resetButton.enabled = YES;
}

View File

@@ -5,5 +5,5 @@
* Test delegate by collecting its calls
*/
@interface CollectingDelegate : NSObject <SSZipArchiveDelegate>
@property(nonatomic, retain) NSMutableArray *files;
@end
@property(nonatomic, retain) NSMutableArray<NSString *> *files;
@end

View File

@@ -61,6 +61,8 @@
- (void)testZipping {
// use extracted files from [-testUnzipping]
[self testUnzipping];
NSString *inputPath = [self _cachesPath:@"Regular"];
NSArray *inputPaths = @[[inputPath stringByAppendingPathComponent:@"Readme.markdown"],
[inputPath stringByAppendingPathComponent:@"LICENSE"]];
@@ -68,8 +70,9 @@
NSString *outputPath = [self _cachesPath:@"Zipped"];
NSString *archivePath = [outputPath stringByAppendingPathComponent:@"CreatedArchive.zip"];
[SSZipArchive createZipFileAtPath:archivePath withFilesAtPaths:inputPaths];
BOOL success = [SSZipArchive createZipFileAtPath:archivePath withFilesAtPaths:inputPaths];
XCTAssertTrue(success);
// TODO: Make sure the files are actually unzipped. They are, but the test should be better.
XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:archivePath], @"Archive created");
}
@@ -82,13 +85,13 @@
NSString *outputPath = [self _cachesPath:@"FolderZipped"];
NSString *archivePath = [outputPath stringByAppendingPathComponent:@"ArchiveWithFolders.zip"];
[SSZipArchive createZipFileAtPath:archivePath withContentsOfDirectory:inputPath];
BOOL success = [SSZipArchive createZipFileAtPath:archivePath withContentsOfDirectory:inputPath];
XCTAssertTrue(success);
XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:archivePath], @"Folder Archive created");
}
- (void)testMultipleZippping{
NSArray *inputPaths = @[[[NSBundle bundleForClass: [self class]]pathForResource:@"0" ofType:@"m4a"],
[[NSBundle bundleForClass: [self class]]pathForResource:@"1" ofType:@"m4a"],
[[NSBundle bundleForClass: [self class]]pathForResource:@"2" ofType:@"m4a"],
[[NSBundle bundleForClass: [self class]]pathForResource:@"3" ofType:@"m4a"],
@@ -106,8 +109,9 @@
// Zipping
NSString *archivePath = [outputPath stringByAppendingPathComponent:[NSString stringWithFormat:@"queue_test_%d.zip",test]];
[SSZipArchive createZipFileAtPath:archivePath withFilesAtPaths:inputPaths];
BOOL success = [SSZipArchive createZipFileAtPath:archivePath withFilesAtPaths:inputPaths];
XCTAssertTrue(success);
long long threshold = 510000; // 510kB:size slightly smaller than a successful zip, but much larger than a failed one
long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:archivePath error:nil][NSFileSize] longLongValue];
XCTAssertTrue(fileSize > threshold, @"zipping failed at %@!",archivePath);
@@ -119,8 +123,9 @@
NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestArchive" ofType:@"zip"];
NSString *outputPath = [self _cachesPath:@"Regular"];
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
XCTAssertTrue(success);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *testPath = [outputPath stringByAppendingPathComponent:@"Readme.markdown"];
XCTAssertTrue([fileManager fileExistsAtPath:testPath], @"Readme unzipped");
@@ -132,8 +137,9 @@
NSString *zipPath = [[NSBundle bundleForClass: [self class]] pathForResource:@"TestArchive" ofType:@"zip"];
NSString *outputPath = [self _cachesPath:@"Regular"];
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
XCTAssertTrue(success);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *testPath = [outputPath stringByAppendingPathComponent:@"Readme.markdown"];
XCTAssertTrue([fileManager fileExistsAtPath:testPath], @"Readme unzipped");
@@ -147,8 +153,9 @@
[progressEvents removeAllObjects];
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
XCTAssertTrue(success);
// 4 events: the first, then for each of the two files one, then the final event
XCTAssertTrue(4 == [progressEvents count], @"Expected 4 progress events");
XCTAssertTrue(0 == [progressEvents[0] intValue]);
@@ -163,8 +170,9 @@
NSString *outputPath = [self _cachesPath:@"Password"];
NSError *error = nil;
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath overwrite:YES password:@"passw0rd" error:&error delegate:self];
BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath overwrite:YES password:@"passw0rd" error:&error delegate:self];
XCTAssertTrue(success);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *testPath = [outputPath stringByAppendingPathComponent:@"Readme.markdown"];
XCTAssertTrue([fileManager fileExistsAtPath:testPath], @"Readme unzipped");
@@ -178,7 +186,8 @@
NSString *outputPath = [self _cachesPath:@"Password"];
NSError *error = nil;
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath overwrite:YES password:@"passw0rd123" error:&error delegate:self];
BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath overwrite:YES password:@"passw0rd123" error:&error delegate:self];
XCTAssertTrue(success);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *testPath = [outputPath stringByAppendingPathComponent:@"Readme.markdown"];
@@ -217,13 +226,49 @@
XCTAssertTrue(protected, @"has password");
}
- (void)testZippingAndUnzippingWithUnicodePassword {
/********** Zipping ********/
// use extracted files from [-testUnzipping]
[self testUnzipping];
NSString *inputPath = [self _cachesPath:@"Regular"];
NSArray *inputPaths = @[[inputPath stringByAppendingPathComponent:@"Readme.markdown"],
[inputPath stringByAppendingPathComponent:@"LICENSE"]];
NSString *outputPath = [self _cachesPath:@"Zipped"];
NSString *archivePath = [outputPath stringByAppendingPathComponent:@"CreatedUnicodePasswordArchive.zip"];
BOOL success = [SSZipArchive createZipFileAtPath:archivePath withFilesAtPaths:inputPaths withPassword:@"ꊐ⌒Ⅳ🤐"];
XCTAssertTrue(success);
XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:archivePath], @"Archive created");
/********** Unzipping ********/
outputPath = [self _cachesPath:@"UnicodePassword"];
NSError *error = nil;
success = [SSZipArchive unzipFileAtPath:archivePath toDestination:outputPath overwrite:YES password:@"ꊐ⌒Ⅳ🤐" error:&error delegate:self];
XCTAssertTrue(success);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *testPath = [outputPath stringByAppendingPathComponent:@"Readme.markdown"];
XCTAssertTrue([fileManager fileExistsAtPath:testPath], @"Readme unzipped");
testPath = [outputPath stringByAppendingPathComponent:@"LICENSE"];
XCTAssertTrue([fileManager fileExistsAtPath:testPath], @"LICENSE unzipped");
}
//Temp Disabled test, fix is not yet in the AES version of the unzip lib
//- (void)testUnzippingTruncatedFileFix {
// NSString* zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"IncorrectHeaders" ofType:@"zip"];
// NSString* outputPath = [self _cachesPath:@"IncorrectHeaders"];
//
// [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
// BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
// XCTAssertTrue(success);
//
// NSString* intendedReadmeTxtMD5 = @"31ac96301302eb388070c827447290b5";
//
@@ -240,8 +285,9 @@
NSString* zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"SymbolicLink" ofType:@"zip"];
NSString* outputPath = [self _cachesPath:@"SymbolicLink"];
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
XCTAssertTrue(success);
NSString *testSymlink = [outputPath stringByAppendingPathComponent:@"SymbolicLink/Xcode.app"];
NSError *error = nil;
@@ -256,8 +302,9 @@
NSString* zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:resourceName ofType:@"zip"];
NSString* outputPath = [self _cachesPath:resourceName];
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
XCTAssertTrue(success);
// Determine where the symlinks are
NSString *subfolderName = @"symlinks";
NSString *testBasePath = [NSString pathWithComponents:@[outputPath]];
@@ -278,8 +325,9 @@
NSString* zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"Unicode" ofType:@"zip"];
NSString* outputPath = [self _cachesPath:@"Unicode"];
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
XCTAssertTrue(success);
bool unicodeFilenameWasExtracted = [[NSFileManager defaultManager] fileExistsAtPath:[outputPath stringByAppendingPathComponent:@"Accént.txt"]];
bool unicodeFolderWasExtracted = [[NSFileManager defaultManager] fileExistsAtPath:[outputPath stringByAppendingPathComponent:@"Fólder/Nothing.txt"]];
@@ -291,6 +339,8 @@
- (void)testZippingAndUnzippingForDate {
// use extracted files from [-testUnzipping]
[self testUnzipping];
NSString *inputPath = [self _cachesPath:@"Regular"];
NSArray *inputPaths = @[[inputPath stringByAppendingPathComponent:@"Readme.markdown"]];
@@ -299,8 +349,10 @@
NSString *outputPath = [self _cachesPath:@"ZippedDate"];
NSString *archivePath = [outputPath stringByAppendingPathComponent:@"CreatedArchive.zip"];
[SSZipArchive createZipFileAtPath:archivePath withFilesAtPaths:inputPaths];
[SSZipArchive unzipFileAtPath:archivePath toDestination:outputPath delegate:self];
BOOL success = [SSZipArchive createZipFileAtPath:archivePath withFilesAtPaths:inputPaths];
XCTAssertTrue(success);
success = [SSZipArchive unzipFileAtPath:archivePath toDestination:outputPath delegate:self];
XCTAssertTrue(success);
NSDictionary *createdFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[outputPath stringByAppendingPathComponent:@"Readme.markdown"] error:nil];
@@ -330,14 +382,15 @@
NSString *archivePath = [outputDir stringByAppendingPathComponent:@"TestAppArchive.zip"];
// Create the zip file using the contents of the .app file as the input
[SSZipArchive createZipFileAtPath:archivePath withContentsOfDirectory:inputFile];
BOOL success = [SSZipArchive createZipFileAtPath:archivePath withContentsOfDirectory:inputFile];
XCTAssertTrue(success);
/********** Un-zipping *******/
// Using this newly created zip file, unzip it
[SSZipArchive unzipFileAtPath:archivePath toDestination:outputDir];
success = [SSZipArchive unzipFileAtPath:archivePath toDestination:outputDir];
XCTAssertTrue(success);
// Get the path to the target file after unzipping
NSString *targetFilePath = [outputDir stringByAppendingPathComponent:@"/Contents/MacOS/TestProject"];
@@ -359,8 +412,8 @@
CancelDelegate *delegate = [[CancelDelegate alloc] init];
delegate.numFilesToUnzip = 1;
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate];
BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate];
XCTAssertFalse(success);
XCTAssertEqual(delegate.numFilesUnzipped, 1);
XCTAssertFalse(delegate.didUnzipArchive);
XCTAssertNotEqual(delegate.loaded, delegate.total);
@@ -370,8 +423,8 @@
delegate = [[CancelDelegate alloc] init];
delegate.numFilesToUnzip = 1000;
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate];
success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate];
XCTAssertTrue(success);
XCTAssertEqual(delegate.numFilesUnzipped, 2);
XCTAssertTrue(delegate.didUnzipArchive);
XCTAssertEqual(delegate.loaded, delegate.total);
@@ -385,16 +438,18 @@
// NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"LargeArchive" ofType:@"zip"];
// NSString *outputPath = [self _cachesPath:@"Large"];
//
// [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath];
// BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath];
// XCTAssertTrue(success);
//}
-(void)testShouldProvidePathOfUnzippedFileInDelegateCallback {
CollectingDelegate *collector = [CollectingDelegate new];
NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestArchive" ofType:@"zip"];
NSString *outputPath = [self _cachesPath:@"Regular"];
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:collector];
NSString *outputPath = [self _cachesPath:@"Regular"];
BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:collector];
XCTAssertTrue(success);
// STAssertEqualObjects([collector.files objectAtIndex:0], @"LICENSE.txt", nil);
// STAssertEqualObjects([collector.files objectAtIndex:1], @"README.md", nil);
}
@@ -434,7 +489,7 @@
#pragma mark - Private
- (NSString *)_cachesPath:(NSString *)directory {
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]
NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject
stringByAppendingPathComponent:@"com.samsoffes.ssziparchive.tests"];
if (directory) {
path = [path stringByAppendingPathComponent:directory];

View File

@@ -1,5 +1,5 @@
PODS:
- SSZipArchive (2.0.5)
- SSZipArchive (2.0.7)
DEPENDENCIES:
- SSZipArchive (from `..`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: ..
SPEC CHECKSUMS:
SSZipArchive: 5d129436b3d37fbe5b2befc51fba3badf925e459
SSZipArchive: 8c197761d66bd33e7f8b5b51ee57dff303971150
PODFILE CHECKSUM: 7f4058a9cbc69b4e63808729577a8bb2098bc527

View File

@@ -16,6 +16,8 @@ ZipArchive is a simple utility class for zipping and unzipping files on iOS and
*The main release branch is configured to support Objective C and Swift 3+. There is a 'swift23' branch which is a tied to a older 1.x release and will not be upgraded. Xcode 8.3+ removes support for Swift 2.3*
SSZipArchive works on Xcode 7-9 and above, iOS 8-11 and above.
### CocoaPods
In your Podfile:
`pod 'SSZipArchive'`

View File

@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SSZipArchive'
s.version = '2.0.5'
s.version = '2.0.7'
s.summary = 'Utility class for zipping and unzipping files on iOS, tvOS, watchOS, and Mac.'
s.description = 'SSZipArchive is a simple utility class for zipping and unzipping files on iOS, tvOS, watchOS, and Mac.'
s.homepage = 'https://github.com/ZipArchive/ZipArchive'

View File

@@ -30,14 +30,24 @@ typedef NS_ENUM(NSInteger, SSZipArchiveErrorCode) {
// Password check
+ (BOOL)isFilePasswordProtectedAtPath:(NSString *)path;
+ (BOOL)isPasswordValidForArchiveAtPath:(NSString *)path password:(NSString *)pw error:(NSError * __nullable * __nullable)error NS_SWIFT_NOTHROW;
+ (BOOL)isPasswordValidForArchiveAtPath:(NSString *)path password:(NSString *)pw error:(NSError * _Nullable * _Nullable)error NS_SWIFT_NOTHROW;
// Unzip
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination;
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination delegate:(nullable id<SSZipArchiveDelegate>)delegate;
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(nullable NSString *)password error:(NSError * *)error;
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(nullable NSString *)password error:(NSError * *)error delegate:(nullable id<SSZipArchiveDelegate>)delegate NS_REFINED_FOR_SWIFT;
+ (BOOL)unzipFileAtPath:(NSString *)path
toDestination:(NSString *)destination
overwrite:(BOOL)overwrite
password:(nullable NSString *)password
error:(NSError * *)error;
+ (BOOL)unzipFileAtPath:(NSString *)path
toDestination:(NSString *)destination
overwrite:(BOOL)overwrite
password:(nullable NSString *)password
error:(NSError * *)error
delegate:(nullable id<SSZipArchiveDelegate>)delegate NS_REFINED_FOR_SWIFT;
+ (BOOL)unzipFileAtPath:(NSString *)path
toDestination:(NSString *)destination
@@ -48,38 +58,43 @@ typedef NS_ENUM(NSInteger, SSZipArchiveErrorCode) {
delegate:(nullable id<SSZipArchiveDelegate>)delegate;
+ (BOOL)unzipFileAtPath:(NSString *)path
toDestination:(NSString *)destination
progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * __nullable error))completionHandler;
toDestination:(NSString *)destination
progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler;
+ (BOOL)unzipFileAtPath:(NSString *)path
toDestination:(NSString *)destination
overwrite:(BOOL)overwrite
password:(nullable NSString *)password
progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * __nullable error))completionHandler;
toDestination:(NSString *)destination
overwrite:(BOOL)overwrite
password:(nullable NSString *)password
progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler;
// Zip
// without password
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths;
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths;
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath;
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory;
// with password, password could be nil
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths withPassword:(nullable NSString *)password;
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths withPassword:(nullable NSString *)password;
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(nullable NSString *)password;
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password;
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password andProgressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler;
+ (BOOL)createZipFileAtPath:(NSString *)path
withContentsOfDirectory:(NSString *)directoryPath
keepParentDirectory:(BOOL)keepParentDirectory
withPassword:(nullable NSString *)password
andProgressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler;
- (instancetype)initWithPath:(NSString *)path;
@property (NS_NONATOMIC_IOSONLY, readonly) BOOL open;
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithPath:(NSString *)path NS_DESIGNATED_INITIALIZER;
- (BOOL)open;
- (BOOL)writeFile:(NSString *)path withPassword:(nullable NSString *)password;
- (BOOL)writeFolderAtPath:(NSString *)path withFolderName:(NSString *)folderName withPassword:(nullable NSString *)password;
- (BOOL)writeFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName withPassword:(nullable NSString *)password;
- (BOOL)writeData:(NSData *)data filename:(nullable NSString *)filename withPassword:(nullable NSString *)password;
@property (NS_NONATOMIC_IOSONLY, readonly) BOOL close;
- (BOOL)close;
@end

View File

@@ -5,12 +5,11 @@
// Created by Sam Soffes on 7/21/10.
// Copyright (c) Sam Soffes 2010-2015. All rights reserved.
//
#import "SSZipArchive.h"
#include "unzip.h"
#include "zip.h"
#include "minishared.h"
#import "zlib.h"
#import "zconf.h"
#include <sys/stat.h>
@@ -19,13 +18,13 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
#define CHUNK 16384
@interface SSZipArchive ()
+ (NSDate *)_dateWithMSDOSFormat:(UInt32)msdosDateTime;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
@end
@implementation SSZipArchive
{
/// path for zip file
NSString *_path;
NSString *_filename;
zipFile _zip;
}
@@ -33,7 +32,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
+ (BOOL)isFilePasswordProtectedAtPath:(NSString *)path {
// Begin opening
zipFile zip = unzOpen((const char*)[path fileSystemRepresentation]);
zipFile zip = unzOpen(path.fileSystemRepresentation);
if (zip == NULL) {
return NO;
}
@@ -66,7 +65,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
*error = nil;
}
zipFile zip = unzOpen((const char*)[path fileSystemRepresentation]);
zipFile zip = unzOpen(path.fileSystemRepresentation);
if (zip == NULL) {
if (error) {
*error = [NSError errorWithDomain:SSZipArchiveErrorDomain
@@ -79,10 +78,10 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
int ret = unzGoToFirstFile(zip);
if (ret == UNZ_OK) {
do {
if ([pw length] == 0) {
if (pw.length == 0) {
ret = unzOpenCurrentFile(zip);
} else {
ret = unzOpenCurrentFilePassword(zip, [pw cStringUsingEncoding:NSASCIIStringEncoding]);
ret = unzOpenCurrentFilePassword(zip, [pw cStringUsingEncoding:NSUTF8StringEncoding]);
}
if (ret != UNZ_OK) {
if (ret != UNZ_BADPASSWORD) {
@@ -146,7 +145,12 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
return [self unzipFileAtPath:path toDestination:destination preserveAttributes:YES overwrite:YES password:nil error:nil delegate:delegate progressHandler:nil completionHandler:nil];
}
+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(nullable NSString *)password error:(NSError **)error delegate:(nullable id<SSZipArchiveDelegate>)delegate
+ (BOOL)unzipFileAtPath:(NSString *)path
toDestination:(NSString *)destination
overwrite:(BOOL)overwrite
password:(nullable NSString *)password
error:(NSError **)error
delegate:(nullable id<SSZipArchiveDelegate>)delegate
{
return [self unzipFileAtPath:path toDestination:destination preserveAttributes:YES overwrite:overwrite password:password error:error delegate:delegate progressHandler:nil completionHandler:nil];
}
@@ -156,7 +160,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
overwrite:(BOOL)overwrite
password:(NSString *)password
progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError *__nullable error))completionHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler
{
return [self unzipFileAtPath:path toDestination:destination preserveAttributes:YES overwrite:overwrite password:password error:nil delegate:nil progressHandler:progressHandler completionHandler:completionHandler];
}
@@ -164,7 +168,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
+ (BOOL)unzipFileAtPath:(NSString *)path
toDestination:(NSString *)destination
progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * __nullable error))completionHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler
{
return [self unzipFileAtPath:path toDestination:destination preserveAttributes:YES overwrite:YES password:nil error:nil delegate:nil progressHandler:progressHandler completionHandler:completionHandler];
}
@@ -188,11 +192,10 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
error:(NSError **)error
delegate:(id<SSZipArchiveDelegate>)delegate
progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * __nullable error))completionHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler
{
// Guard against empty strings
if ([path length] == 0 || [destination length] == 0)
if (path.length == 0 || destination.length == 0)
{
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: @"received invalid argument(s)"};
NSError *err = [NSError errorWithDomain:SSZipArchiveErrorDomain code:SSZipArchiveErrorCodeInvalidArguments userInfo:userInfo];
@@ -204,10 +207,11 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
{
completionHandler(nil, NO, err);
}
return NO;
}
// Begin opening
zipFile zip = unzOpen((const char*)[path fileSystemRepresentation]);
zipFile zip = unzOpen(path.fileSystemRepresentation);
if (zip == NULL)
{
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: @"failed to open zip file"};
@@ -252,7 +256,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
int crc_ret = 0;
unsigned char buffer[4096] = {0};
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableArray *directoriesModificationDates = [[NSMutableArray alloc] init];
NSMutableArray<NSDictionary *> *directoriesModificationDates = [[NSMutableArray alloc] init];
// Message delegate
if ([delegate respondsToSelector:@selector(zipArchiveWillUnzipArchiveAtPath:zipInfo:)]) {
@@ -266,10 +270,10 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
NSError *unzippingError;
do {
@autoreleasepool {
if ([password length] == 0) {
if (password.length == 0) {
ret = unzOpenCurrentFile(zip);
} else {
ret = unzOpenCurrentFilePassword(zip, [password cStringUsingEncoding:NSASCIIStringEncoding]);
ret = unzOpenCurrentFilePassword(zip, [password cStringUsingEncoding:NSUTF8StringEncoding]);
}
if (ret != UNZ_OK) {
@@ -342,7 +346,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
// Check if it contains directory
// NSString * strPath = @(filename);
NSString * strPath = [NSString stringWithCString:filename encoding:NSUTF8StringEncoding];
NSString * strPath = @(filename);
//if filename contains chinese dir transform Encoding
if (!strPath) {
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
@@ -372,7 +376,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
if (isDirectory) {
[fileManager createDirectoryAtPath:fullPath withIntermediateDirectories:YES attributes:directoryAttr error:&err];
} else {
[fileManager createDirectoryAtPath:[fullPath stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:directoryAttr error:&err];
[fileManager createDirectoryAtPath:fullPath.stringByDeletingLastPathComponent withIntermediateDirectories:YES attributes:directoryAttr error:&err];
}
if (nil != err) {
if ([err.domain isEqualToString:NSCocoaErrorDomain] &&
@@ -396,7 +400,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
// ensure we are not creating stale file entries
int readBytes = unzReadCurrentFile(zip, buffer, 4096);
if (readBytes >= 0) {
FILE *fp = fopen((const char*)[fullPath fileSystemRepresentation], "wb");
FILE *fp = fopen(fullPath.fileSystemRepresentation, "wb");
while (fp) {
if (readBytes > 0) {
if (0 == fwrite(buffer, readBytes, 1, fp)) {
@@ -415,9 +419,9 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
}
if (fp) {
if ([[[fullPath pathExtension] lowercaseString] isEqualToString:@"zip"]) {
NSLog(@"Unzipping nested .zip file: %@", [fullPath lastPathComponent]);
if ([self unzipFileAtPath:fullPath toDestination:[fullPath stringByDeletingLastPathComponent] overwrite:overwrite password:password error:nil delegate:nil]) {
if ([fullPath.pathExtension.lowercaseString isEqualToString:@"zip"]) {
NSLog(@"Unzipping nested .zip file: %@", fullPath.lastPathComponent);
if ([self unzipFileAtPath:fullPath toDestination:fullPath.stringByDeletingLastPathComponent overwrite:overwrite password:password error:nil delegate:nil]) {
[[NSFileManager defaultManager] removeItemAtPath:fullPath error:nil];
}
}
@@ -432,7 +436,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
NSDictionary *attr = @{NSFileModificationDate: orgDate};
if (attr) {
if ([fileManager setAttributes:attr ofItemAtPath:fullPath error:nil] == NO) {
if (![fileManager setAttributes:attr ofItemAtPath:fullPath error:nil]) {
// Can't set attributes
NSLog(@"[SSZipArchive] Failed to set attributes - whilst setting modification date");
}
@@ -452,7 +456,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
attrs[NSFilePosixPermissions] = permissionsValue;
// Update attributes
if ([fileManager setAttributes:attrs ofItemAtPath:fullPath error:nil] == NO) {
if (![fileManager setAttributes:attrs ofItemAtPath:fullPath error:nil]) {
// Unable to set the permissions attribute
NSLog(@"[SSZipArchive] Failed to set attributes - whilst setting permissions");
}
@@ -477,12 +481,12 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
else
{
// Assemble the path for the symbolic link
NSMutableString* destinationPath = [NSMutableString string];
NSMutableString *destinationPath = [NSMutableString string];
int bytesRead = 0;
while ((bytesRead = unzReadCurrentFile(zip, buffer, 4096)) > 0)
{
buffer[bytesRead] = (int)0;
[destinationPath appendString:@((const char*)buffer)];
[destinationPath appendString:@((const char *)buffer)];
}
// Check if the symlink exists and delete it if we're overwriting
@@ -539,7 +543,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
progressHandler(strPath, fileInfo, currentFileNumber, globalInfo.number_entry);
}
}
} while (ret == UNZ_OK && YES == success);
} while (ret == UNZ_OK && success);
// Close
unzClose(zip);
@@ -597,37 +601,37 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
}
#pragma mark - Zipping
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths
{
return [SSZipArchive createZipFileAtPath:path withFilesAtPaths:paths withPassword:nil];
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath{
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath {
return [SSZipArchive createZipFileAtPath:path withContentsOfDirectory:directoryPath withPassword:nil];
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory{
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory {
return [SSZipArchive createZipFileAtPath:path withContentsOfDirectory:directoryPath keepParentDirectory:keepParentDirectory withPassword:nil];
}
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths withPassword:(NSString *)password
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths withPassword:(NSString *)password
{
BOOL success = NO;
SSZipArchive *zipArchive = [[SSZipArchive alloc] initWithPath:path];
if ([zipArchive open]) {
BOOL success = [zipArchive open];
if (success) {
for (NSString *filePath in paths) {
[zipArchive writeFile:filePath withPassword:password];
success &= [zipArchive writeFile:filePath withPassword:password];
}
success = [zipArchive close];
success &= [zipArchive close];
}
return success;
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(nullable NSString *)password{
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(nullable NSString *)password {
return [SSZipArchive createZipFileAtPath:path withContentsOfDirectory:directoryPath keepParentDirectory:NO withPassword:password];
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password{
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password {
return [SSZipArchive createZipFileAtPath:path
withContentsOfDirectory:directoryPath
keepParentDirectory:keepParentDirectory
@@ -636,17 +640,19 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
];
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password andProgressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler {
BOOL success = NO;
+ (BOOL)createZipFileAtPath:(NSString *)path
withContentsOfDirectory:(NSString *)directoryPath
keepParentDirectory:(BOOL)keepParentDirectory
withPassword:(nullable NSString *)password
andProgressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler {
NSFileManager *fileManager = nil;
SSZipArchive *zipArchive = [[SSZipArchive alloc] initWithPath:path];
if ([zipArchive open]) {
// use a local filemanager (queue/thread compatibility)
fileManager = [[NSFileManager alloc] init];
BOOL success = [zipArchive open];
if (success) {
// use a local fileManager (queue/thread compatibility)
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSDirectoryEnumerator *dirEnumerator = [fileManager enumeratorAtPath:directoryPath];
NSArray *allObjects = dirEnumerator.allObjects;
NSArray<NSString *> *allObjects = dirEnumerator.allObjects;
NSUInteger total = allObjects.count, complete = 0;
NSString *fileName;
for (fileName in allObjects) {
@@ -656,11 +662,11 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
if (keepParentDirectory)
{
fileName = [[directoryPath lastPathComponent] stringByAppendingPathComponent:fileName];
fileName = [directoryPath.lastPathComponent stringByAppendingPathComponent:fileName];
}
if (!isDir) {
[zipArchive writeFileAtPath:fullFilePath withFileName:fileName withPassword:password];
success &= [zipArchive writeFileAtPath:fullFilePath withFileName:fileName withPassword:password];
}
else
{
@@ -668,7 +674,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
{
NSString *tempFilePath = [self _temporaryPathForDiscardableFile];
NSString *tempFileFilename = [fileName stringByAppendingPathComponent:tempFilePath.lastPathComponent];
[zipArchive writeFileAtPath:tempFilePath withFileName:tempFileFilename withPassword:password];
success &= [zipArchive writeFileAtPath:tempFilePath withFileName:tempFileFilename withPassword:password];
}
}
complete++;
@@ -676,12 +682,15 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
progressHandler(complete, total);
}
}
success = [zipArchive close];
success &= [zipArchive close];
}
return success;
}
// disabling `init` because designated initializer is `initWithPath:`
- (instancetype)init { @throw nil; }
// designated initializer
- (instancetype)initWithPath:(NSString *)path
{
if ((self = [super init])) {
@@ -693,28 +702,26 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
- (BOOL)open
{
NSAssert((_zip == NULL), @"Attempting open an archive which is already open");
_zip = zipOpen([_path fileSystemRepresentation], APPEND_STATUS_CREATE);
NSAssert((_zip == NULL), @"Attempting to open an archive which is already open");
_zip = zipOpen(_path.fileSystemRepresentation, APPEND_STATUS_CREATE);
return (NULL != _zip);
}
- (void)zipInfo:(zip_fileinfo*)zipInfo setDate:(NSDate*)date
- (void)zipInfo:(zip_fileinfo *)zipInfo setDate:(NSDate *)date
{
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
#if defined(__IPHONE_8_0) || defined(__MAC_10_10)
uint flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
#else
uint flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
#endif
NSCalendar *currentCalendar = SSZipArchive._gregorian;
NSCalendarUnit flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
NSDateComponents *components = [currentCalendar components:flags fromDate:date];
struct tm tmz_date;
tmz_date.tm_sec = (unsigned int)components.second;
tmz_date.tm_min = (unsigned int)components.minute;
tmz_date.tm_hour = (unsigned int)components.hour;
tmz_date.tm_mday = (unsigned int)components.day;
// ISO/IEC 9899 struct tm is 0-indexed for January but NSDateComponents for gregorianCalendar is 1-indexed for January
tmz_date.tm_mon = (unsigned int)components.month - 1;
tmz_date.tm_year = (unsigned int)components.year;
// ISO/IEC 9899 struct tm is 0-indexed for AD 1900 but NSDateComponents for gregorianCalendar is 1-indexed for AD 1
tmz_date.tm_year = (unsigned int)components.year - 1900;
zipInfo->dos_date = tm_to_dosdate(&tmz_date);
}
@@ -748,14 +755,14 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
// Store this into the external file attributes once it has been shifted 16 places left to form part of the second from last byte
//Casted back to an unsigned int to match type of external_fa in minizip
// Casted back to an unsigned int to match type of external_fa in minizip
zipInfo.external_fa = (unsigned int)(permissionsLong << 16L);
}
}
unsigned int len = 0;
zipOpenNewFileInZip3(_zip, [[folderName stringByAppendingString:@"/"] fileSystemRepresentation], &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_NO_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY, [password UTF8String], 0);
zipOpenNewFileInZip3(_zip, [folderName stringByAppendingString:@"/"].fileSystemRepresentation, &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_NO_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY, password.UTF8String, 0);
zipWriteInFileInZip(_zip, &len, 0);
zipCloseFileInZip(_zip);
return YES;
@@ -773,17 +780,17 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
{
NSAssert((_zip != NULL), @"Attempting to write to an archive which was never opened");
FILE *input = fopen([path fileSystemRepresentation], "r");
FILE *input = fopen(path.fileSystemRepresentation, "r");
if (NULL == input) {
return NO;
}
const char *afileName;
const char *aFileName;
if (!fileName) {
afileName = [path.lastPathComponent fileSystemRepresentation];
aFileName = path.lastPathComponent.fileSystemRepresentation;
}
else {
afileName = [fileName fileSystemRepresentation];
aFileName = fileName.fileSystemRepresentation;
}
zip_fileinfo zipInfo = {0,0,0};
@@ -812,7 +819,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
// Store this into the external file attributes once it has been shifted 16 places left to form part of the second from last byte
//Casted back to an unsigned int to match type of external_fa in minizip
// Casted back to an unsigned int to match type of external_fa in minizip
zipInfo.external_fa = (unsigned int)(permissionsLong << 16L);
}
}
@@ -822,8 +829,8 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
{
return NO;
}
zipOpenNewFileInZip3(_zip, afileName, &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, [password UTF8String], 0);
zipOpenNewFileInZip3(_zip, aFileName, &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, password.UTF8String, 0);
unsigned int len = 0;
while (!feof(input) && !ferror(input))
@@ -849,7 +856,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
zip_fileinfo zipInfo = {0,0,0};
[self zipInfo:&zipInfo setDate:[NSDate date]];
zipOpenNewFileInZip3(_zip, [filename fileSystemRepresentation], &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, [password UTF8String], 0);
zipOpenNewFileInZip3(_zip, filename.fileSystemRepresentation, &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, password.UTF8String, 0);
zipWriteInFileInZip(_zip, data.bytes, (unsigned int)data.length);
@@ -861,8 +868,9 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
- (BOOL)close
{
NSAssert((_zip != NULL), @"[SSZipArchive] Attempting to close an archive which was never opened");
zipClose(_zip, NULL);
return YES;
int error = zipClose(_zip, NULL);
_zip = nil;
return error == UNZ_OK;
}
#pragma mark - Private
@@ -873,7 +881,7 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
static NSString *discardableFilePath = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *temporaryDirectoryName = [[NSUUID UUID] UUIDString];
NSString *temporaryDirectoryName = [NSUUID UUID].UUIDString;
NSString *temporaryDirectory = [NSTemporaryDirectory() stringByAppendingPathComponent:temporaryDirectoryName];
BOOL directoryCreated = [[NSFileManager defaultManager] createDirectoryAtPath:temporaryDirectory withIntermediateDirectories:YES attributes:nil error:nil];
if (directoryCreated) {
@@ -884,6 +892,17 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
return discardableFilePath;
}
+ (NSCalendar *)_gregorian
{
static NSCalendar *gregorian;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
});
return gregorian;
}
// Format from http://newsgroups.derkeiler.com/Archive/Comp/comp.os.msdos.programmer/2009-04/msg00060.html
// Two consecutive words, or a longword, YYYYYYYMMMMDDDDD hhhhhmmmmmmsssss
// YYYYYYY is years from 1980 = 0
@@ -893,6 +912,11 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
// 7423 = 0111 0100 0010 0011 - 01110 100001 00011 = 14 33 3 = 14:33:06
+ (NSDate *)_dateWithMSDOSFormat:(UInt32)msdosDateTime
{
/*
// the whole `_dateWithMSDOSFormat:` method is equivalent but faster than this one line,
// essentially because `mktime` is slow:
NSDate *date = [NSDate dateWithTimeIntervalSince1970:dosdate_to_time_t(msdosDateTime)];
*/
static const UInt32 kYearMask = 0xFE000000;
static const UInt32 kMonthMask = 0x1E00000;
static const UInt32 kDayMask = 0x1F0000;
@@ -900,28 +924,18 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
static const UInt32 kMinuteMask = 0x7E0;
static const UInt32 kSecondMask = 0x1F;
static NSCalendar *gregorian;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
#if defined(__IPHONE_8_0) || defined(__MAC_10_10)
gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
#else
gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
#endif
});
NSAssert(0xFFFFFFFF == (kYearMask | kMonthMask | kDayMask | kHourMask | kMinuteMask | kSecondMask), @"[SSZipArchive] MSDOS date masks don't add up");
NSDateComponents *components = [[NSDateComponents alloc] init];
NSAssert(0xFFFFFFFF == (kYearMask | kMonthMask | kDayMask | kHourMask | kMinuteMask | kSecondMask), @"[SSZipArchive] MSDOS date masks don't add up");
components.year = 1980 + ((msdosDateTime & kYearMask) >> 25);
components.month = (msdosDateTime & kMonthMask) >> 21;
components.day = (msdosDateTime & kDayMask) >> 16;
components.hour = (msdosDateTime & kHourMask) >> 11;
components.minute = (msdosDateTime & kMinuteMask) >> 5;
components.second = (msdosDateTime & kSecondMask) * 2;
[components setYear:1980 + ((msdosDateTime & kYearMask) >> 25)];
[components setMonth:(msdosDateTime & kMonthMask) >> 21];
[components setDay:(msdosDateTime & kDayMask) >> 16];
[components setHour:(msdosDateTime & kHourMask) >> 11];
[components setMinute:(msdosDateTime & kMinuteMask) >> 5];
[components setSecond:(msdosDateTime & kSecondMask) * 2];
NSDate *date = [NSDate dateWithTimeInterval:0 sinceDate:[gregorian dateFromComponents:components]];
NSDate *date = [self._gregorian dateFromComponents:components];
return date;
}

View File

@@ -14,6 +14,6 @@ FOUNDATION_EXPORT double ZipArchiveVersionNumber;
//! Project version string for ZipArchive.
FOUNDATION_EXPORT const unsigned char ZipArchiveVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <ZipArchive/PublicHeader.h>
// In this header, you should import all the public headers of your framework using statements like #import <ZipArchive/SSZipArchive.h>
#import "SSZipArchive.h"

View File

@@ -30,7 +30,8 @@ Issue Date: 20/12/2007
#elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ )
# include <sys/endian.h>
#elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \
defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ )
defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ ) || \
defined(__pnacl__)
# include <machine/endian.h>
#elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
# if !defined( __MINGW32__ ) && !defined( _AIX )

View File

@@ -36,7 +36,7 @@
*/
#include <memory.h>
#include <string.h>
#include "fileenc.h"

View File

@@ -24,7 +24,7 @@ This is an implementation of HMAC, the FIPS standard keyed hash function
#define _HMAC2_H
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#if defined(__cplusplus)
extern "C"

View File

@@ -38,7 +38,7 @@
its location in memory.
*/
#include <memory.h>
#include <string.h>
#include "prng.h"
#if defined(__cplusplus)

View File

@@ -21,7 +21,7 @@ This is an implementation of RFC2898, which specifies key derivation from
a password and a salt value.
*/
#include <memory.h>
#include <string.h>
#include "hmac.h"
#if defined(__cplusplus)

View File

@@ -1,9 +1,12 @@
/* crypt.c -- base code for traditional PKWARE encryption
Version 1.01e, February 12th, 2005
Version 1.2.0, September 16th, 2017
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 1998-2005 Gilles Vollant
Modifications for Info-ZIP crypting
Copyright (C) 2003 Terry Thorsen
Modifications for Info-ZIP crypting
http://www.winimage.com/zLibDll/minizip.html
Copyright (C) 2003 Terry Thorsen
This code is a modified version of crypting code in Info-ZIP distribution
@@ -129,7 +132,7 @@ int cryptrand(unsigned char *buf, unsigned int len)
return rlen;
}
int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys,
int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys,
const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2)
{
uint8_t n = 0; /* index in random header */

View File

@@ -1,9 +1,12 @@
/* crypt.h -- base code for traditional PKWARE encryption
Version 1.01e, February 12th, 2005
Version 1.2.0, September 16th, 2017
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 1998-2005 Gilles Vollant
Modifications for Info-ZIP crypting
Copyright (C) 2003 Terry Thorsen
Modifications for Info-ZIP crypting
http://www.winimage.com/zLibDll/minizip.html
Copyright (C) 2003 Terry Thorsen
This code is a modified version of crypting code in Info-ZIP distribution
@@ -16,6 +19,10 @@
#ifndef _MINICRYPT_H
#define _MINICRYPT_H
#if ZLIB_VERNUM < 0x1270
typedef unsigned long z_crc_t;
#endif
#ifdef __cplusplus
extern "C" {
#endif
@@ -45,7 +52,7 @@ void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab);
int cryptrand(unsigned char *buf, unsigned int len);
/* Create encryption header */
int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys,
int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys,
const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2);
/***************************************************************************/

View File

@@ -1,11 +1,13 @@
/* ioapi.c -- IO base function header for compress/uncompress .zip
part of the MiniZip project
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@@ -1,11 +1,13 @@
/* ioapi.h -- IO base function header for compress/uncompress .zip
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
@@ -25,7 +27,7 @@
# define ftello64 ftell
# define fseeko64 fseek
#else
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) || defined(__APPLE__)
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__ANDROID__)
# define fopen64 fopen
# define ftello64 ftello
# define fseeko64 fseeko

View File

@@ -23,7 +23,7 @@
#ifndef IOBUF_BUFFERSIZE
# define IOBUF_BUFFERSIZE (UINT16_MAX)
#endif
#endif
#if defined(_WIN32)
# include <conio.h>
@@ -73,7 +73,7 @@ typedef struct ourstream_s {
# define print_buf(o,s,f,...) print_buf_internal(o,s,f,__VA_ARGS__);
#else
# define print_buf(o,s,f,...)
#endif
#endif
void print_buf_internal(voidpf opaque, voidpf stream, char *format, ...)
{
@@ -137,7 +137,7 @@ long fflush_buf(voidpf opaque, voidpf stream)
uint32_t bytes_to_write = streamio->writebuf_len;
uint32_t bytes_left_to_write = streamio->writebuf_len;
long bytes_written = 0;
while (bytes_left_to_write > 0)
{
if (bufio->filefunc64.zwrite_file != NULL)
@@ -264,7 +264,7 @@ uint32_t ZCALLBACK fwrite_buf_func(voidpf opaque, voidpf stream, const void *buf
continue;
}
memcpy(streamio->writebuf + streamio->writebuf_pos, (char *)buf + (bytes_to_write - bytes_left_to_write), bytes_to_copy);
print_buf(opaque, stream, "write copy [remaining %d write %d:%d len %d]\n", bytes_to_copy, bytes_to_write, bytes_left_to_write, streamio->writebuf_len);
@@ -344,7 +344,7 @@ int fseek_buf_internal_func(voidpf opaque, voidpf stream, uint64_t offset, int o
{
streamio->readbuf_pos += (uint32_t)offset;
return 0;
}
}
offset -= (streamio->readbuf_len - streamio->readbuf_pos);
streamio->position += offset;
}
@@ -419,7 +419,7 @@ int ZCALLBACK fclose_buf_func(voidpf opaque, voidpf stream)
print_buf(opaque, stream, "write efficency %.02f%%\n", (streamio->writebuf_hits / ((float)streamio->writebuf_hits + streamio->writebuf_misses)) * 100);
if (bufio->filefunc64.zclose_file != NULL)
ret = bufio->filefunc64.zclose_file(bufio->filefunc64.opaque, streamio->stream);
else
else
ret = bufio->filefunc.zclose_file(bufio->filefunc.opaque, streamio->stream);
free(streamio);
return ret;

View File

@@ -11,8 +11,11 @@
Based on Unzip ioapi.c version 0.22, May 19th, 2003
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2003 Justin Fletcher
Copyright (C) 1998-2003 Gilles Vollant
(C) 2003 Justin Fletcher
http://www.winimage.com/zLibDll/minizip.html
This file is under the same license as the Unzip tool it is distributed
with.
@@ -30,14 +33,14 @@
#ifndef IOMEM_BUFFERSIZE
# define IOMEM_BUFFERSIZE (UINT16_MAX)
#endif
#endif
voidpf ZCALLBACK fopen_mem_func(voidpf opaque, const char *filename, int mode)
{
ourmemory_t *mem = (ourmemory_t *)opaque;
if (mem == NULL)
return NULL; /* Mem structure passed in was null */
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
{
if (mem->grow)
@@ -128,7 +131,7 @@ long ZCALLBACK fseek_mem_func(voidpf opaque, voidpf stream, uint32_t offset, int
case ZLIB_FILEFUNC_SEEK_SET:
new_pos = offset;
break;
default:
default:
return -1;
}

View File

@@ -4,8 +4,9 @@
This version of ioapi is designed to access memory rather than files.
We do use a region of memory to put data in to and take it out of.
Copyright (C) 1998-2003 Gilles Vollant
Copyright (C) 2012-2017 Nathan Moinvaziri (https://github.com/nmoinvaz/minizip)
(C) 2003 Justin Fletcher
(C) 1998-2003 Gilles Vollant
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@@ -90,16 +90,13 @@ void change_file_date(const char *path, uint32_t dos_date)
}
#else
struct utimbuf ut;
struct tm newdate;
dosdate_to_tm(dos_date, &newdate);
ut.actime = ut.modtime = mktime(&newdate);
ut.actime = ut.modtime = dosdate_to_time_t(dos_date);
utime(path, &ut);
#endif
}
int dosdate_to_tm(uint64_t dos_date, struct tm *ptm)
// convertion without validation
void dosdate_to_raw_tm(uint64_t dos_date, struct tm *ptm)
{
uint64_t date = (uint64_t)(dos_date >> 16);
@@ -110,19 +107,28 @@ int dosdate_to_tm(uint64_t dos_date, struct tm *ptm)
ptm->tm_min = (uint16_t)((dos_date & 0x7E0) / 0x20);
ptm->tm_sec = (uint16_t)(2 * (dos_date & 0x1f));
ptm->tm_isdst = -1;
}
int invalid_date(const struct tm *ptm)
{
#define datevalue_in_range(min, max, value) ((min) <= (value) && (value) <= (max))
if (!datevalue_in_range(0, 11, ptm->tm_mon) ||
!datevalue_in_range(1, 31, ptm->tm_mday) ||
!datevalue_in_range(0, 23, ptm->tm_hour) ||
!datevalue_in_range(0, 59, ptm->tm_min) ||
!datevalue_in_range(0, 59, ptm->tm_sec))
{
/* Invalid date stored, so don't return it. */
return (!datevalue_in_range(0, 11, ptm->tm_mon) ||
!datevalue_in_range(1, 31, ptm->tm_mday) ||
!datevalue_in_range(0, 23, ptm->tm_hour) ||
!datevalue_in_range(0, 59, ptm->tm_min) ||
!datevalue_in_range(0, 59, ptm->tm_sec));
#undef datevalue_in_range
}
int dosdate_to_tm(uint64_t dos_date, struct tm *ptm)
{
dosdate_to_raw_tm(dos_date, ptm);
if (invalid_date(ptm)) {
// Invalid date stored, so don't return it.
memset(ptm, 0, sizeof(struct tm));
return -1;
}
#undef datevalue_in_range
return 0;
}
@@ -139,11 +145,7 @@ uint32_t tm_to_dosdate(const struct tm *ptm)
Due to the date format limitations, only years between 1980 and 2107 can be stored.
*/
if (!(datevalue_in_range(1980, 2107, ptm->tm_year) || datevalue_in_range(0, 207, ptm->tm_year)) ||
!datevalue_in_range(0, 11, ptm->tm_mon) ||
!datevalue_in_range(1, 31, ptm->tm_mday) ||
!datevalue_in_range(0, 23, ptm->tm_hour) ||
!datevalue_in_range(0, 59, ptm->tm_min) ||
!datevalue_in_range(0, 59, ptm->tm_sec))
invalid_date(ptm))
{
return 0;
}
@@ -161,6 +163,15 @@ uint32_t tm_to_dosdate(const struct tm *ptm)
((ptm->tm_sec / 2) + (32 * ptm->tm_min) + (2048 * (uint32_t)ptm->tm_hour));
}
time_t dosdate_to_time_t(uint64_t dos_date)
{
struct tm ptm;
dosdate_to_raw_tm(dos_date, &ptm);
// standard is year 1900 indexed struct tm, but dosdate_to_raw_tm returns a year 0 indexed struct tm
ptm.tm_year %= 1900;
return mktime(&ptm);
}
int makedir(const char *newdir)
{
char *buffer = NULL;

View File

@@ -27,6 +27,9 @@ int dosdate_to_tm(uint64_t dos_date, struct tm *ptm);
/* Convert struct tm to dos date/time format */
uint32_t tm_to_dosdate(const struct tm *ptm);
/* Convert dos date/time format to time_t */
time_t dosdate_to_time_t(uint64_t dos_date);
/* Create a directory and all subdirectories */
int makedir(const char *newdir);

View File

@@ -1,16 +1,17 @@
/* unzip.c -- IO for uncompress .zip files using zlib
Version 1.1, February 14h, 2010
Version 1.2.0, September 16th, 2017
part of the MiniZip project
Copyright (C) 2010-2017 Nathan Moinvaziri
Modifications for AES, PKWARE disk spanning
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support on both zip and unzip
http://result42.com
Copyright (C) 2007-2008 Even Rouault
Modifications of Unzip for Zip64
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
Modifications of Unzip for Zip64
Copyright (C) 2007-2008 Even Rouault
Modifications for Zip64 support on both zip and unzip
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
Modifications for AES, PKWARE disk spanning
Copyright (C) 2010-2014 Nathan Moinvaziri
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
@@ -73,8 +74,7 @@
# define TRYFREE(p) {if (p) free(p);}
#endif
const char unz_copyright[] =
" unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
const char unz_copyright[] = " unzip 1.2.0 Copyright 1998-2017 - https://github.com/nmoinvaz/minizip";
/* unz_file_info_internal contain internal info about a file in zipfile*/
typedef struct unz_file_info64_internal_s
@@ -354,9 +354,6 @@ static unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def *pzlib_f
voidpf filestream = NULL;
int err = UNZ_OK;
if (unz_copyright[0] != ' ')
return NULL;
us.filestream = NULL;
us.filestream_with_CD = NULL;
us.z_filefunc.zseek32_file = NULL;

View File

@@ -1,14 +1,16 @@
/* unzip.h -- IO for uncompress .zip files using zlib
Version 1.1, February 14h, 2010
Version 1.2.0, September 16th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support on both zip and unzip
http://result42.com
Copyright (C) 2007-2008 Even Rouault
Modifications of Unzip for Zip64
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
Modifications of Unzip for Zip64
Copyright (C) 2007-2008 Even Rouault
Modifications for Zip64 support on both zip and unzip
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@@ -1,14 +1,15 @@
/* zip.c -- IO on .zip files using zlib
Version 1.1, February 14h, 2010
Version 1.2.0, September 16th, 2017
part of the MiniZip project
Copyright (C) 2010-2017 Nathan Moinvaziri
Modifications for AES, PKWARE disk spanning
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
Modifications for AES, PKWARE disk spanning
Copyright (C) 2010-2014 Nathan Moinvaziri
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
@@ -912,7 +913,7 @@ extern zipFile ZEXPORT zipOpen64(const void *path, int append)
extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
int strategy, const char *password, uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64)
int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64)
{
zip64_internal *zi = NULL;
uint64_t size_available = 0;
@@ -924,7 +925,6 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
int err = ZIP_OK;
#ifdef NOCRYPT
(crc_for_crypting);
if (password != NULL)
return ZIP_PARAMERROR;
#endif
@@ -1237,10 +1237,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
/*
Info-ZIP modification to ZipCrypto format:
If bit 3 of the general purpose bit flag is set, it uses high byte of 16-bit File Time.
verify1 = (uint8_t)((crc_for_crypting >> 16) & 0xff);
verify2 = (uint8_t)((crc_for_crypting >> 24) & 0xff); */
*/
verify1 = (uint8_t)((zi->ci.dos_date >> 16) & 0xff);
verify2 = (uint8_t)((zi->ci.dos_date >> 8) & 0xff);
@@ -1261,7 +1258,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits,
int memLevel, int strategy, const char *password, uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base)
int memLevel, int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base)
{
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel,
@@ -1271,7 +1268,7 @@ extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, cons
extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits,
int memLevel, int strategy, const char *password, uint32_t crc_for_crypting)
int memLevel, int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting)
{
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel,
@@ -1281,7 +1278,7 @@ extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, cons
extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits,
int memLevel, int strategy, const char *password, uint32_t crc_for_crypting, int zip64)
int memLevel, int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, int zip64)
{
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel, strategy,

View File

@@ -1,12 +1,14 @@
/* zip.h -- IO on .zip files using zlib
Version 1.1, February 14h, 2010
Version 1.2.0, September 16th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
@@ -51,6 +53,12 @@ typedef voidp zipFile;
#define ZIP_BADZIPFILE (-103)
#define ZIP_INTERNALERROR (-104)
#ifdef __GNUC__
# define ZIP_UNUSED __attribute__((__unused__))
#else
# define ZIP_UNUSED
#endif
#ifndef DEF_MEM_LEVEL
# if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
@@ -140,28 +148,28 @@ extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char *filename, c
extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
int strategy, const char *password, uint32_t crcForCrypting);
int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting);
/* Same as zipOpenNewFileInZip2, except
windowBits, memLevel, strategy : see parameter strategy in deflateInit2
password : crypting password (NULL for no crypting)
crcForCrypting : crc of file to compress (needed for crypting) */
crc_for_crypting : crc of file to compress (needed for crypting) */
extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
int strategy, const char *password, uint32_t crc_for_crypting, int zip64);
int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, int zip64);
/* Same as zipOpenNewFileInZip3 with zip64 support */
extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
int strategy, const char *password, uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base);
int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base);
/* Same as zipOpenNewFileInZip3 except versionMadeBy & flag fields */
extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
int strategy, const char *password, uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64);
int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64);
/* Same as zipOpenNewFileInZip4 with zip64 support */
extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len);

View File

@@ -1,5 +1,5 @@
PODS:
- SSZipArchive (2.0.5)
- SSZipArchive (2.0.7)
DEPENDENCIES:
- SSZipArchive (from `..`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: ..
SPEC CHECKSUMS:
SSZipArchive: 5d129436b3d37fbe5b2befc51fba3badf925e459
SSZipArchive: 8c197761d66bd33e7f8b5b51ee57dff303971150
PODFILE CHECKSUM: 0dc500eb72745751ccba7677de4da5534fcef36d

View File

@@ -52,6 +52,8 @@ class ViewController: UIViewController {
if success {
unzipButton.isEnabled = true
zipButton.isEnabled = false
} else {
print("No success")
}
resetButton.isEnabled = true
}
@@ -66,7 +68,10 @@ class ViewController: UIViewController {
}
let password = passwordField.text
let success: Void? = try? SSZipArchive.unzipFile(atPath: zipPath, toDestination: unzipPath, overwrite: true, password: password?.isEmpty == false ? password : nil)
let success: Void? = try? SSZipArchive.unzipFile(atPath: zipPath,
toDestination: unzipPath,
overwrite: true,
password: password?.isEmpty == false ? password : nil)
if success == nil {
print("No success")
return
@@ -123,7 +128,6 @@ class ViewController: UIViewController {
return nil
}
return url.path
}

View File

@@ -318,15 +318,15 @@
children = (
373913E61F0009310094DB3B /* aes */,
373913FC1F0009320094DB3B /* crypt.c */,
B423AE3F1C0DF7950004A2F1 /* crypt.h */,
373913E41F0009310094DB3B /* ioapi_buf.c */,
373913E51F0009310094DB3B /* ioapi_buf.h */,
373913FD1F0009320094DB3B /* ioapi_mem.c */,
373913FF1F0009320094DB3B /* ioapi_mem.h */,
373913FB1F0009320094DB3B /* minishared.c */,
373913FE1F0009320094DB3B /* minishared.h */,
B423AE3F1C0DF7950004A2F1 /* crypt.h */,
B423AE401C0DF7950004A2F1 /* ioapi.c */,
B423AE411C0DF7950004A2F1 /* ioapi.h */,
373913FB1F0009320094DB3B /* minishared.c */,
373913FE1F0009320094DB3B /* minishared.h */,
B423AE441C0DF7950004A2F1 /* unzip.c */,
B423AE451C0DF7950004A2F1 /* unzip.h */,
B423AE461C0DF7950004A2F1 /* zip.c */,

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB