Revert "support aes,compatible old way for zip"

This commit is contained in:
Joshua Hudson
2015-11-16 10:46:30 -08:00
parent 964eb630e6
commit c466f6bd99
31 changed files with 4066 additions and 8091 deletions
+18 -35
View File
@@ -5,6 +5,7 @@
// 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"
@@ -118,7 +119,6 @@
BOOL success = YES;
BOOL canceled = NO;
int ret = 0;
int crc_ret =0;
unsigned char buffer[4096] = {0};
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableSet *directoriesModificationDates = [[NSMutableSet alloc] init];
@@ -231,7 +231,6 @@
[directoriesModificationDates addObject: @{@"path": fullPath, @"modDate": modDate}];
if ([fileManager fileExistsAtPath:fullPath] && !isDirectory && !overwrite) {
//FIXME: couldBe CRC Check?
unzCloseCurrentFile(zip);
ret = unzGoToNextFile(zip);
continue;
@@ -317,11 +316,7 @@
}
}
crc_ret = unzCloseCurrentFile( zip );
if (crc_ret == UNZ_CRCERROR) {
//CRC ERROR
return NO;
}
unzCloseCurrentFile( zip );
ret = unzGoToNextFile( zip );
// Message delegate
@@ -378,25 +373,14 @@
}
#pragma mark - Zipping
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths
{
return [SSZipArchive createZipFileAtPath:path withFilesAtPaths:paths withPassword:nil];
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath{
return [SSZipArchive createZipFileAtPath:path withContentsOfDirectory:directoryPath withPassword:nil];
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirector{
return [SSZipArchive createZipFileAtPath:path withContentsOfDirectory:directoryPath keepParentDirectory:keepParentDirector withPassword:nil];
}
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths withPassword:(NSString *)password
{
BOOL success = NO;
SSZipArchive *zipArchive = [[SSZipArchive alloc] initWithPath:path];
if ([zipArchive open]) {
for (NSString *filePath in paths) {
[zipArchive writeFile:filePath withPassword:password];
[zipArchive writeFile:filePath];
}
success = [zipArchive close];
}
@@ -408,12 +392,12 @@
return success;
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(NSString *)password{
return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keepParentDirectory:NO withPassword:password];
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath {
return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keepParentDirectory:NO];
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(NSString *)password{
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory {
BOOL success = NO;
NSFileManager *fileManager = nil;
@@ -433,7 +417,7 @@ return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keep
{
fileName = [[directoryPath lastPathComponent] stringByAppendingPathComponent:fileName];
}
[zipArchive writeFileAtPath:fullFilePath withFileName:fileName withPassword:password];
[zipArchive writeFileAtPath:fullFilePath withFileName:fileName];
}
else
{
@@ -441,7 +425,7 @@ return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keep
{
NSString *tempName = [fullFilePath stringByAppendingPathComponent:@".DS_Store"];
[@"" writeToFile:tempName atomically:YES encoding:NSUTF8StringEncoding error:nil];
[zipArchive writeFileAtPath:tempName withFileName:[fileName stringByAppendingPathComponent:@".DS_Store"] withPassword:password];
[zipArchive writeFileAtPath:tempName withFileName:[fileName stringByAppendingPathComponent:@".DS_Store"]];
[[NSFileManager defaultManager] removeItemAtPath:tempName error:nil];
}
}
@@ -501,7 +485,7 @@ return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keep
zipInfo->tmz_date.tm_year = (unsigned int)components.year;
}
- (BOOL)writeFolderAtPath:(NSString *)path withFolderName:(NSString *)folderName withPassword:(NSString *)password
- (BOOL)writeFolderAtPath:(NSString *)path withFolderName:(NSString *)folderName
{
NSAssert((_zip != NULL), @"Attempting to write to an archive which was never opened");
@@ -535,22 +519,21 @@ return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keep
}
unsigned int len = 0;
zipOpenNewFileInZip3(_zip, [[folderName stringByAppendingString:@"/"] UTF8String], &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_NO_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY, [password UTF8String], 0);
zipOpenNewFileInZip(_zip, [[folderName stringByAppendingString:@"/"] UTF8String], &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_NO_COMPRESSION);
zipWriteInFileInZip(_zip, &len, 0);
zipCloseFileInZip(_zip);
return YES;
}
- (BOOL)writeFile:(NSString *)path withPassword:(NSString *)password;
- (BOOL)writeFile:(NSString *)path
{
return [self writeFileAtPath:path withFileName:nil withPassword:password];
return [self writeFileAtPath:path withFileName:nil];
}
// supports writing files with logical folder/directory structure
// *path* is the absolute path of the file that will be compressed
// *fileName* is the relative name of the file how it is stored within the zip e.g. /folder/subfolder/text1.txt
- (BOOL)writeFileAtPath:(NSString *)path withFileName:(NSString *)fileName withPassword:(NSString *)password
- (BOOL)writeFileAtPath:(NSString *)path withFileName:(NSString *)fileName
{
NSAssert((_zip != NULL), @"Attempting to write to an archive which was never opened");
@@ -596,8 +579,8 @@ return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keep
}
}
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);
zipOpenNewFileInZip(_zip, afileName, &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION);
void *buffer = malloc(CHUNK);
unsigned int len = 0;
@@ -613,7 +596,7 @@ return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keep
return YES;
}
- (BOOL)writeData:(NSData *)data filename:(NSString *)filename withPassword:(NSString *)password;
- (BOOL)writeData:(NSData *)data filename:(NSString *)filename
{
if (!_zip) {
return NO;
@@ -624,7 +607,7 @@ return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keep
zip_fileinfo zipInfo = {{0,0,0,0,0,0},0,0,0};
[self zipInfo:&zipInfo setDate:[NSDate date]];
zipOpenNewFileInZip3(_zip, [filename UTF8String], &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, [password UTF8String], 0);
zipOpenNewFileInZip(_zip, [filename UTF8String], &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION);
zipWriteInFileInZip(_zip, data.bytes, (unsigned int)data.length);