Add support for archives in folders

This commit is contained in:
Lars Immisch
2015-03-27 10:53:38 +01:00
parent 9f93d0c1b7
commit 9426653711
2 changed files with 37 additions and 1 deletions
+29 -1
View File
@@ -320,8 +320,30 @@
return success;
}
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths inFolder:(NSString *)folder {
BOOL success = NO;
SSZipArchive *zipArchive = [[SSZipArchive alloc] initWithPath:path];
if ([zipArchive open]) {
for (NSString *path in paths) {
if (!folder) {
[zipArchive writeFile:path];
}
else {
NSString *destination = [folder stringByAppendingPathComponent:path.lastPathComponent];
[zipArchive writeFileAtPath:path withFileName:destination];
}
}
success = [zipArchive close];
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath {
#if !__has_feature(objc_arc)
[zipArchive release];
#endif
return success;
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath inFolder:(NSString *)folder {
BOOL success = NO;
NSFileManager *fileManager = nil;
@@ -336,6 +358,9 @@
while ((fileName = [dirEnumerator nextObject])) {
BOOL isDir;
NSString *fullFilePath = [directoryPath stringByAppendingPathComponent:fileName];
if (folder) {
fileName = [folder stringByAppendingPathComponent: fileName];
}
[fileManager fileExistsAtPath:fullFilePath isDirectory:&isDir];
if (!isDir) {
[zipArchive writeFileAtPath:fullFilePath withFileName:fileName];
@@ -352,6 +377,9 @@
return success;
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath {
return [SSZipArchive createZipFileAtPath:path withContentsOfDirectory:directoryPath inFolder:nil];
}
- (id)initWithPath:(NSString *)path {
if ((self = [super init])) {