Commit 92d6f8eb authored by Roy Marmelstein's avatar Roy Marmelstein

Merge branch 'swift3.0'

# Conflicts:
#	Zip/ZipUtilities.swift
parents 7437d31d bcb5d05d
# MacOS
.DS_Store
# Xcode # Xcode
# #
build/ build/
......
osx_image: xcode7.2 osx_image: xcode8
language: objective-c language: objective-c
env: env:
global: global:
- LC_CTYPE=en_US.UTF-8 - LC_CTYPE=en_US.UTF-8
- LANG=en_US.UTF-8 - LANG=en_US.UTF-8
before_install: before_install:
- brew update || brew update - gem install cocoapods --pre
- brew outdated xctool || brew upgrade xctool
- gem install cocoapods
- xcrun simctl list
install: echo "<3" install: echo "<3"
env: env:
- MODE=framework - MODE=framework
......
![Zip - Zip and unzip files in Swift](https://cloud.githubusercontent.com/assets/889949/12374908/252373d0-bcac-11e5-8ece-6933aeae8222.png) ![Zip - Zip and unzip files in Swift](https://cloud.githubusercontent.com/assets/889949/12374908/252373d0-bcac-11e5-8ece-6933aeae8222.png)
[![Build Status](https://travis-ci.org/marmelroy/Zip.svg?branch=master)](https://travis-ci.org/marmelroy/Zip) [![Version](http://img.shields.io/cocoapods/v/Zip.svg)](http://cocoapods.org/?q=Zip) [![Build Status](https://travis-ci.org/marmelroy/Zip.svg?branch=master)](https://travis-ci.org/marmelroy/Zip) [![Version](http://img.shields.io/cocoapods/v/Zip.svg)](http://cocoapods.org/?q=Zip)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
# Zip # Zip
A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of [minizip](https://github.com/nmoinvaz/minizip). A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of [minizip](https://github.com/nmoinvaz/minizip).
...@@ -58,26 +57,8 @@ Zip supports '.zip' and '.cbz' files out of the box. To support additional zip-d ...@@ -58,26 +57,8 @@ Zip supports '.zip' and '.cbz' files out of the box. To support additional zip-d
Zip.addCustomFileExtension("file-extension-here") Zip.addCustomFileExtension("file-extension-here")
``` ```
### Setting up with Carthage
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.
You can install Carthage with [Homebrew](http://brew.sh/) using the following command:
```bash
$ brew update
$ brew install carthage
```
To integrate Format into your Xcode project using Carthage, specify it in your `Cartfile`:
```ogdl
github "marmelroy/Zip"
```
### Setting up with [CocoaPods](http://cocoapods.org/?q=Zip) ### Setting up with [CocoaPods](http://cocoapods.org/?q=Zip)
```ruby ```ruby
source 'https://github.com/CocoaPods/Specs.git' source 'https://github.com/CocoaPods/Specs.git'
pod 'Zip', '~> 0.4' pod 'Zip', '~> 0.5', :submodules => true
``` ```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.4.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>7</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "Zip" s.name = "Zip"
s.version = "0.4.3" s.version = "0.5"
s.summary = "Zip and unzip files in Swift." s.summary = "Zip and unzip files in Swift."
# This description is used to generate tags and improve search results. # This description is used to generate tags and improve search results.
......
...@@ -133,7 +133,6 @@ ...@@ -133,7 +133,6 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
342545B51CE525B200336074 /* Zip.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Zip.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 342545B51CE525B200336074 /* Zip.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Zip.framework; sourceTree = BUILT_PRODUCTS_DIR; };
342545B61CE525B300336074 /* Zip copy-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Zip copy-Info.plist"; path = "/Users/marmelroy/Documents/Projects/OpenSource/Zip/Zip copy-Info.plist"; sourceTree = "<absolute>"; };
342FC0D21C5044DC0023A3C3 /* aes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes.h; sourceTree = "<group>"; }; 342FC0D21C5044DC0023A3C3 /* aes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes.h; sourceTree = "<group>"; };
342FC0D31C5044DC0023A3C3 /* aes_via_ace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes_via_ace.h; sourceTree = "<group>"; }; 342FC0D31C5044DC0023A3C3 /* aes_via_ace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes_via_ace.h; sourceTree = "<group>"; };
342FC0D41C5044DC0023A3C3 /* aescrypt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aescrypt.c; sourceTree = "<group>"; }; 342FC0D41C5044DC0023A3C3 /* aescrypt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aescrypt.c; sourceTree = "<group>"; };
...@@ -275,7 +274,6 @@ ...@@ -275,7 +274,6 @@
347E3A761C1DFFB500A11FD3 /* Zip */, 347E3A761C1DFFB500A11FD3 /* Zip */,
347E3A821C1DFFB500A11FD3 /* ZipTests */, 347E3A821C1DFFB500A11FD3 /* ZipTests */,
347E3A751C1DFFB500A11FD3 /* Products */, 347E3A751C1DFFB500A11FD3 /* Products */,
342545B61CE525B300336074 /* Zip copy-Info.plist */,
); );
sourceTree = "<group>"; sourceTree = "<group>";
}; };
...@@ -493,7 +491,7 @@ ...@@ -493,7 +491,7 @@
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastSwiftUpdateCheck = 0720; LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720; LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Roy Marmelstein"; ORGANIZATIONNAME = "Roy Marmelstein";
TargetAttributes = { TargetAttributes = {
343F50FE1C8DAEEC0028C434 = { 343F50FE1C8DAEEC0028C434 = {
...@@ -504,9 +502,11 @@ ...@@ -504,9 +502,11 @@
}; };
347E3A731C1DFFB500A11FD3 = { 347E3A731C1DFFB500A11FD3 = {
CreatedOnToolsVersion = 7.2; CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
}; };
347E3A7D1C1DFFB500A11FD3 = { 347E3A7D1C1DFFB500A11FD3 = {
CreatedOnToolsVersion = 7.2; CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
}; };
}; };
}; };
...@@ -677,9 +677,9 @@ ...@@ -677,9 +677,9 @@
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 7; DYLIB_CURRENT_VERSION = 8;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Zip copy-Info.plist"; INFOPLIST_FILE = "Zip/Info-tvOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)"; LIBRARY_SEARCH_PATHS = "$(inherited)";
...@@ -702,9 +702,9 @@ ...@@ -702,9 +702,9 @@
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 7; DYLIB_CURRENT_VERSION = 8;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Zip copy-Info.plist"; INFOPLIST_FILE = "Zip/Info-tvOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)"; LIBRARY_SEARCH_PATHS = "$(inherited)";
...@@ -714,6 +714,7 @@ ...@@ -714,6 +714,7 @@
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "appletvsimulator appletvos"; SUPPORTED_PLATFORMS = "appletvsimulator appletvos";
SWIFT_INCLUDE_PATHS = "${SRCROOT}/Zip/minizip/**"; SWIFT_INCLUDE_PATHS = "${SRCROOT}/Zip/minizip/**";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = 3; TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0; TVOS_DEPLOYMENT_TARGET = 9.0;
}; };
...@@ -724,10 +725,10 @@ ...@@ -724,10 +725,10 @@
buildSettings = { buildSettings = {
CODE_SIGN_IDENTITY = "-"; CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 7; CURRENT_PROJECT_VERSION = 8;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 7; DYLIB_CURRENT_VERSION = 8;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A; FRAMEWORK_VERSION = A;
INFOPLIST_FILE = Zip/Info.plist; INFOPLIST_FILE = Zip/Info.plist;
...@@ -747,10 +748,10 @@ ...@@ -747,10 +748,10 @@
buildSettings = { buildSettings = {
CODE_SIGN_IDENTITY = "-"; CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 7; CURRENT_PROJECT_VERSION = 8;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 7; DYLIB_CURRENT_VERSION = 8;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A; FRAMEWORK_VERSION = A;
INFOPLIST_FILE = Zip/Info.plist; INFOPLIST_FILE = Zip/Info.plist;
...@@ -762,6 +763,7 @@ ...@@ -762,6 +763,7 @@
SDKROOT = macosx; SDKROOT = macosx;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "${SRCROOT}/Zip/minizip/**"; SWIFT_INCLUDE_PATHS = "${SRCROOT}/Zip/minizip/**";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
}; };
name = Release; name = Release;
}; };
...@@ -812,7 +814,7 @@ ...@@ -812,7 +814,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 7; CURRENT_PROJECT_VERSION = 8;
DEBUG_INFORMATION_FORMAT = dwarf; DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES; ENABLE_TESTABILITY = YES;
...@@ -835,6 +837,7 @@ ...@@ -835,6 +837,7 @@
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = ""; VERSION_INFO_PREFIX = "";
...@@ -860,7 +863,7 @@ ...@@ -860,7 +863,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 7; CURRENT_PROJECT_VERSION = 8;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO; ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
...@@ -875,6 +878,7 @@ ...@@ -875,6 +878,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.2; IPHONEOS_DEPLOYMENT_TARGET = 9.2;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES; VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
...@@ -889,7 +893,7 @@ ...@@ -889,7 +893,7 @@
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 7; DYLIB_CURRENT_VERSION = 8;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Zip/Info.plist; INFOPLIST_FILE = Zip/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
...@@ -911,7 +915,7 @@ ...@@ -911,7 +915,7 @@
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 7; DYLIB_CURRENT_VERSION = 8;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Zip/Info.plist; INFOPLIST_FILE = Zip/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
...@@ -922,6 +926,7 @@ ...@@ -922,6 +926,7 @@
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "${SRCROOT}/Zip/minizip/**"; SWIFT_INCLUDE_PATHS = "${SRCROOT}/Zip/minizip/**";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
}; };
name = Release; name = Release;
}; };
...@@ -942,6 +947,7 @@ ...@@ -942,6 +947,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.ZipTests; PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.ZipTests;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
}; };
name = Release; name = Release;
}; };
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0720" LastUpgradeVersion = "0800"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0730" LastUpgradeVersion = "0800"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0720" LastUpgradeVersion = "0800"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0720" LastUpgradeVersion = "0800"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.4.1</string> <string>0.5.0</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>6</string> <string>8</string>
<key>NSPrincipalClass</key> <key>NSPrincipalClass</key>
<string></string> <string></string>
</dict> </dict>
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.4.3</string> <string>0.5.0</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>7</string> <string>8</string>
<key>NSPrincipalClass</key> <key>NSPrincipalClass</key>
<string></string> <string></string>
</dict> </dict>
......
...@@ -21,7 +21,7 @@ extension Zip { ...@@ -21,7 +21,7 @@ extension Zip {
- returns: NSURL of the destination folder. - returns: NSURL of the destination folder.
*/ */
public class func quickUnzipFile(path: NSURL) throws -> NSURL { public class func quickUnzipFile(_ path: URL) throws -> URL {
return try quickUnzipFile(path, progress: nil) return try quickUnzipFile(path, progress: nil)
} }
...@@ -37,16 +37,21 @@ extension Zip { ...@@ -37,16 +37,21 @@ extension Zip {
- returns: NSURL of the destination folder. - returns: NSURL of the destination folder.
*/ */
public class func quickUnzipFile(path: NSURL, progress: ((progress: Double) -> ())?) throws -> NSURL { public class func quickUnzipFile(_ path: URL, progress: ((_ progress: Double) -> ())?) throws -> URL {
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
guard let fileExtension = path.pathExtension, let fileName = path.lastPathComponent else {
throw ZipError.UnzipFail let fileExtension = path.pathExtension
} let fileName = path.lastPathComponent
let directoryName = fileName.stringByReplacingOccurrencesOfString(".\(fileExtension)", withString: "")
let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let directoryName = fileName.replacingOccurrences(of: ".\(fileExtension)", with: "")
let destinationUrl = documentsUrl.URLByAppendingPathComponent(directoryName, isDirectory: true) let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL
do {
let destinationUrl = documentsUrl.appendingPathComponent(directoryName, isDirectory: true)
try self.unzipFile(path, destination: destinationUrl, overwrite: true, password: nil, progress: progress) try self.unzipFile(path, destination: destinationUrl, overwrite: true, password: nil, progress: progress)
return destinationUrl return destinationUrl
}catch{
throw(ZipError.unzipFail)
}
} }
//MARK: Quick Zip //MARK: Quick Zip
...@@ -63,7 +68,7 @@ extension Zip { ...@@ -63,7 +68,7 @@ extension Zip {
- returns: NSURL of the destination folder. - returns: NSURL of the destination folder.
*/ */
public class func quickZipFiles(paths: [NSURL], fileName: String) throws -> NSURL { public class func quickZipFiles(_ paths: [URL], fileName: String) throws -> URL {
return try quickZipFiles(paths, fileName: fileName, progress: nil) return try quickZipFiles(paths, fileName: fileName, progress: nil)
} }
...@@ -80,10 +85,10 @@ extension Zip { ...@@ -80,10 +85,10 @@ extension Zip {
- returns: NSURL of the destination folder. - returns: NSURL of the destination folder.
*/ */
public class func quickZipFiles(paths: [NSURL], fileName: String, progress: ((progress: Double) -> ())?) throws -> NSURL { public class func quickZipFiles(_ paths: [URL], fileName: String, progress: ((_ progress: Double) -> ())?) throws -> URL {
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL
let destinationUrl = documentsUrl.URLByAppendingPathComponent("\(fileName).zip") let destinationUrl = documentsUrl.appendingPathComponent("\(fileName).zip")
try self.zipFiles(paths, zipFilePath: destinationUrl, password: nil, progress: progress) try self.zipFiles(paths, zipFilePath: destinationUrl, password: nil, progress: progress)
return destinationUrl return destinationUrl
} }
......
...@@ -10,20 +10,20 @@ import Foundation ...@@ -10,20 +10,20 @@ import Foundation
import minizip import minizip
/// Zip error type /// Zip error type
public enum ZipError: ErrorType { public enum ZipError: Error {
/// File not found /// File not found
case FileNotFound case fileNotFound
/// Unzip fail /// Unzip fail
case UnzipFail case unzipFail
/// Zip fail /// Zip fail
case ZipFail case zipFail
/// User readable description /// User readable description
public var description: String { public var description: String {
switch self { switch self {
case .FileNotFound: return NSLocalizedString("File not found.", comment: "") case .fileNotFound: return NSLocalizedString("File not found.", comment: "")
case .UnzipFail: return NSLocalizedString("Failed to unzip file.", comment: "") case .unzipFail: return NSLocalizedString("Failed to unzip file.", comment: "")
case .ZipFail: return NSLocalizedString("Failed to zip file.", comment: "") case .zipFail: return NSLocalizedString("Failed to zip file.", comment: "")
} }
} }
} }
...@@ -62,37 +62,36 @@ public class Zip { ...@@ -62,37 +62,36 @@ public class Zip {
- notes: Supports implicit progress composition - notes: Supports implicit progress composition
*/ */
public class func unzipFile(zipFilePath: NSURL, destination: NSURL, overwrite: Bool, password: String?, progress: ((progress: Double) -> ())?) throws { public class func unzipFile(_ zipFilePath: URL, destination: URL, overwrite: Bool, password: String?, progress: ((_ progress: Double) -> ())?) throws {
// File manager // File manager
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
// Check whether a zip file exists at path. // Check whether a zip file exists at path.
guard let path = zipFilePath.path where destination.path != nil else { let path = zipFilePath.path
throw ZipError.FileNotFound
} if fileManager.fileExists(atPath: path) == false || fileExtensionIsInvalid(zipFilePath.pathExtension) {
if fileManager.fileExistsAtPath(path) == false || fileExtensionIsInvalid(zipFilePath.pathExtension) { throw ZipError.fileNotFound
throw ZipError.FileNotFound
} }
// Unzip set up // Unzip set up
var ret: Int32 = 0 var ret: Int32 = 0
var crc_ret: Int32 = 0 var crc_ret: Int32 = 0
let bufferSize: UInt32 = 4096 let bufferSize: UInt32 = 4096
var buffer = Array<CUnsignedChar>(count: Int(bufferSize), repeatedValue: 0) var buffer = Array<CUnsignedChar>(repeating: 0, count: Int(bufferSize))
// Progress handler set up // Progress handler set up
var totalSize: Double = 0.0 var totalSize: Double = 0.0
var currentPosition: Double = 0.0 var currentPosition: Double = 0.0
let fileAttributes = try fileManager.attributesOfItemAtPath(path) let fileAttributes = try fileManager.attributesOfItem(atPath: path)
if let attributeFileSize = fileAttributes[NSFileSize] as? Double { if let attributeFileSize = fileAttributes[FileAttributeKey.size] as? Double {
totalSize += attributeFileSize totalSize += attributeFileSize
} }
let progressTracker = NSProgress(totalUnitCount: Int64(totalSize)) let progressTracker = Progress(totalUnitCount: Int64(totalSize))
progressTracker.cancellable = false progressTracker.isCancellable = false
progressTracker.pausable = false progressTracker.isPausable = false
progressTracker.kind = NSProgressKindFile progressTracker.kind = ProgressKind.file
// Begin unzipping // Begin unzipping
let zip = unzOpen64(path) let zip = unzOpen64(path)
...@@ -100,64 +99,67 @@ public class Zip { ...@@ -100,64 +99,67 @@ public class Zip {
unzClose(zip) unzClose(zip)
} }
if unzGoToFirstFile(zip) != UNZ_OK { if unzGoToFirstFile(zip) != UNZ_OK {
throw ZipError.UnzipFail throw ZipError.unzipFail
} }
repeat { repeat {
if let cPassword = password?.cStringUsingEncoding(NSASCIIStringEncoding) { if let cPassword = password?.cString(using: String.Encoding.ascii) {
ret = unzOpenCurrentFilePassword(zip, cPassword) ret = unzOpenCurrentFilePassword(zip, cPassword)
} }
else { else {
ret = unzOpenCurrentFile(zip); ret = unzOpenCurrentFile(zip);
} }
if ret != UNZ_OK { if ret != UNZ_OK {
throw ZipError.UnzipFail throw ZipError.unzipFail
} }
var fileInfo = unz_file_info64() var fileInfo = unz_file_info64()
memset(&fileInfo, 0, sizeof(unz_file_info)) memset(&fileInfo, 0, MemoryLayout<unz_file_info>.size)
ret = unzGetCurrentFileInfo64(zip, &fileInfo, nil, 0, nil, 0, nil, 0) ret = unzGetCurrentFileInfo64(zip, &fileInfo, nil, 0, nil, 0, nil, 0)
if ret != UNZ_OK { if ret != UNZ_OK {
unzCloseCurrentFile(zip) unzCloseCurrentFile(zip)
throw ZipError.UnzipFail throw ZipError.unzipFail
} }
currentPosition += Double(fileInfo.compressed_size) currentPosition += Double(fileInfo.compressed_size)
let fileNameSize = Int(fileInfo.size_filename) + 1 let fileNameSize = Int(fileInfo.size_filename) + 1
let fileName = UnsafeMutablePointer<CChar>.alloc(fileNameSize) //let fileName = UnsafeMutablePointer<CChar>(allocatingCapacity: fileNameSize)
if fileName == nil { let fileName = UnsafeMutablePointer<CChar>.allocate(capacity: fileNameSize)
throw ZipError.UnzipFail
}
unzGetCurrentFileInfo64(zip, &fileInfo, fileName, UInt(fileNameSize), nil, 0, nil, 0) unzGetCurrentFileInfo64(zip, &fileInfo, fileName, UInt(fileNameSize), nil, 0, nil, 0)
fileName[Int(fileInfo.size_filename)] = 0 fileName[Int(fileInfo.size_filename)] = 0
guard var pathString = String(CString: fileName, encoding: NSUTF8StringEncoding) else { var pathString = String(cString: fileName)
throw ZipError.UnzipFail
guard pathString.characters.count > 0 else {
throw ZipError.unzipFail
} }
var isDirectory = false var isDirectory = false
let fileInfoSizeFileName = Int(fileInfo.size_filename-1) let fileInfoSizeFileName = Int(fileInfo.size_filename-1)
if (fileName[fileInfoSizeFileName] == "/".cStringUsingEncoding(NSUTF8StringEncoding)?.first || fileName[fileInfoSizeFileName] == "\\".cStringUsingEncoding(NSUTF8StringEncoding)?.first) { if (fileName[fileInfoSizeFileName] == "/".cString(using: String.Encoding.utf8)?.first || fileName[fileInfoSizeFileName] == "\\".cString(using: String.Encoding.utf8)?.first) {
isDirectory = true; isDirectory = true;
} }
free(fileName) free(fileName)
if pathString.rangeOfCharacterFromSet(NSCharacterSet(charactersInString: "/\\")) != nil { if pathString.rangeOfCharacter(from: CharacterSet(charactersIn: "/\\")) != nil {
pathString = pathString.stringByReplacingOccurrencesOfString("\\", withString: "/") pathString = pathString.replacingOccurrences(of: "\\", with: "/")
}
guard let fullPath = destination.URLByAppendingPathComponent(pathString).path else {
throw ZipError.UnzipFail
} }
let creationDate = NSDate()
let directoryAttributes = [NSFileCreationDate: creationDate, NSFileModificationDate: creationDate] let fullPath = destination.appendingPathComponent(pathString).path
let creationDate = Date()
let directoryAttributes = [FileAttributeKey.creationDate.rawValue : creationDate,
FileAttributeKey.modificationDate.rawValue : creationDate]
do { do {
if isDirectory { if isDirectory {
try fileManager.createDirectoryAtPath(fullPath, withIntermediateDirectories: true, attributes: directoryAttributes) try fileManager.createDirectory(atPath: fullPath, withIntermediateDirectories: true, attributes: directoryAttributes)
} }
else { else {
let parentDirectory = (fullPath as NSString).stringByDeletingLastPathComponent let parentDirectory = (fullPath as NSString).deletingLastPathComponent
try fileManager.createDirectoryAtPath(parentDirectory, withIntermediateDirectories: true, attributes: directoryAttributes) try fileManager.createDirectory(atPath: parentDirectory, withIntermediateDirectories: true, attributes: directoryAttributes)
} }
} catch {} } catch {}
if fileManager.fileExistsAtPath(fullPath) && !isDirectory && !overwrite { if fileManager.fileExists(atPath: fullPath) && !isDirectory && !overwrite {
unzCloseCurrentFile(zip) unzCloseCurrentFile(zip)
ret = unzGoToNextFile(zip) ret = unzGoToNextFile(zip)
} }
var filePointer: UnsafeMutablePointer<FILE> var filePointer: UnsafeMutablePointer<FILE>?
filePointer = fopen(fullPath, "wb") filePointer = fopen(fullPath, "wb")
while filePointer != nil { while filePointer != nil {
let readBytes = unzReadCurrentFile(zip, &buffer, bufferSize) let readBytes = unzReadCurrentFile(zip, &buffer, bufferSize)
...@@ -171,13 +173,13 @@ public class Zip { ...@@ -171,13 +173,13 @@ public class Zip {
fclose(filePointer) fclose(filePointer)
crc_ret = unzCloseCurrentFile(zip) crc_ret = unzCloseCurrentFile(zip)
if crc_ret == UNZ_CRCERROR { if crc_ret == UNZ_CRCERROR {
throw ZipError.UnzipFail throw ZipError.unzipFail
} }
ret = unzGoToNextFile(zip) ret = unzGoToNextFile(zip)
// Update progress handler // Update progress handler
if let progressHandler = progress{ if let progressHandler = progress{
progressHandler(progress: (currentPosition/totalSize)) progressHandler((currentPosition/totalSize))
} }
progressTracker.completedUnitCount = Int64(currentPosition) progressTracker.completedUnitCount = Int64(currentPosition)
...@@ -186,7 +188,7 @@ public class Zip { ...@@ -186,7 +188,7 @@ public class Zip {
// Completed. Update progress handler. // Completed. Update progress handler.
if let progressHandler = progress{ if let progressHandler = progress{
progressHandler(progress: 1.0) progressHandler(1.0)
} }
progressTracker.completedUnitCount = Int64(totalSize) progressTracker.completedUnitCount = Int64(totalSize)
...@@ -207,15 +209,13 @@ public class Zip { ...@@ -207,15 +209,13 @@ public class Zip {
- notes: Supports implicit progress composition - notes: Supports implicit progress composition
*/ */
public class func zipFiles(paths: [NSURL], zipFilePath: NSURL, password: String?, progress: ((progress: Double) -> ())?) throws { public class func zipFiles(_ paths: [URL], zipFilePath: URL, password: String?, progress: ((_ progress: Double) -> ())?) throws {
// File manager // File manager
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
// Check whether a zip file exists at path. // Check whether a zip file exists at path.
guard let destinationPath = zipFilePath.path else { let destinationPath = zipFilePath.path
throw ZipError.FileNotFound
}
// Process zip paths // Process zip paths
let processedPaths = ZipUtilities().processZipPaths(paths) let processedPaths = ZipUtilities().processZipPaths(paths)
...@@ -230,8 +230,8 @@ public class Zip { ...@@ -230,8 +230,8 @@ public class Zip {
for path in processedPaths { for path in processedPaths {
do { do {
let filePath = path.filePath() let filePath = path.filePath()
let fileAttributes = try fileManager.attributesOfItemAtPath(filePath) let fileAttributes = try fileManager.attributesOfItem(atPath: filePath)
let fileSize = fileAttributes[NSFileSize] as? Double let fileSize = fileAttributes[FileAttributeKey.size] as? Double
if let fileSize = fileSize { if let fileSize = fileSize {
totalSize += fileSize totalSize += fileSize
} }
...@@ -239,36 +239,36 @@ public class Zip { ...@@ -239,36 +239,36 @@ public class Zip {
catch {} catch {}
} }
let progressTracker = NSProgress(totalUnitCount: Int64(totalSize)) let progressTracker = Progress(totalUnitCount: Int64(totalSize))
progressTracker.cancellable = false progressTracker.isCancellable = false
progressTracker.pausable = false progressTracker.isPausable = false
progressTracker.kind = NSProgressKindFile progressTracker.kind = ProgressKind.file
// Begin Zipping // Begin Zipping
let zip = zipOpen(destinationPath, APPEND_STATUS_CREATE) let zip = zipOpen(destinationPath, APPEND_STATUS_CREATE)
for path in processedPaths { for path in processedPaths {
let filePath = path.filePath() let filePath = path.filePath()
var isDirectory: ObjCBool = false var isDirectory: ObjCBool = false
fileManager.fileExistsAtPath(filePath, isDirectory: &isDirectory) fileManager.fileExists(atPath: filePath, isDirectory: &isDirectory)
if !isDirectory { if !isDirectory.boolValue {
let input = fopen(filePath, "r") let input = fopen(filePath, "r")
if input == nil { if input == nil {
throw ZipError.ZipFail throw ZipError.zipFail
} }
let fileName = path.fileName let fileName = path.fileName
var zipInfo: zip_fileinfo = zip_fileinfo(tmz_date: tm_zip(tm_sec: 0, tm_min: 0, tm_hour: 0, tm_mday: 0, tm_mon: 0, tm_year: 0), dosDate: 0, internal_fa: 0, external_fa: 0) var zipInfo: zip_fileinfo = zip_fileinfo(tmz_date: tm_zip(tm_sec: 0, tm_min: 0, tm_hour: 0, tm_mday: 0, tm_mon: 0, tm_year: 0), dosDate: 0, internal_fa: 0, external_fa: 0)
do { do {
let fileAttributes = try fileManager.attributesOfItemAtPath(filePath) let fileAttributes = try fileManager.attributesOfItem(atPath: filePath)
if let fileDate = fileAttributes[NSFileModificationDate] as? NSDate { if let fileDate = fileAttributes[FileAttributeKey.modificationDate] as? Date {
let components = NSCalendar.currentCalendar().components([.Year, .Month, .Day, .Hour, .Minute, .Second], fromDate: fileDate) let components = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second], from: fileDate)
zipInfo.tmz_date.tm_sec = UInt32(components.second) zipInfo.tmz_date.tm_sec = UInt32(components.second!)
zipInfo.tmz_date.tm_min = UInt32(components.minute) zipInfo.tmz_date.tm_min = UInt32(components.minute!)
zipInfo.tmz_date.tm_hour = UInt32(components.hour) zipInfo.tmz_date.tm_hour = UInt32(components.hour!)
zipInfo.tmz_date.tm_mday = UInt32(components.day) zipInfo.tmz_date.tm_mday = UInt32(components.day!)
zipInfo.tmz_date.tm_mon = UInt32(components.month) - 1 zipInfo.tmz_date.tm_mon = UInt32(components.month!) - 1
zipInfo.tmz_date.tm_year = UInt32(components.year) zipInfo.tmz_date.tm_year = UInt32(components.year!)
} }
if let fileSize = fileAttributes[NSFileSize] as? Double { if let fileSize = fileAttributes[FileAttributeKey.size] as? Double {
currentPosition += fileSize currentPosition += fileSize
} }
} }
...@@ -281,7 +281,7 @@ public class Zip { ...@@ -281,7 +281,7 @@ public class Zip {
zipOpenNewFileInZip3(zip, fileName, &zipInfo, nil, 0, nil, 0, nil,Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, nil, 0) zipOpenNewFileInZip3(zip, fileName, &zipInfo, nil, 0, nil, 0, nil,Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, nil, 0)
} }
else { else {
throw ZipError.ZipFail throw ZipError.zipFail
} }
var length: Int = 0 var length: Int = 0
while (feof(input) == 0) { while (feof(input) == 0) {
...@@ -291,7 +291,7 @@ public class Zip { ...@@ -291,7 +291,7 @@ public class Zip {
// Update progress handler // Update progress handler
if let progressHandler = progress{ if let progressHandler = progress{
progressHandler(progress: (currentPosition/totalSize)) progressHandler((currentPosition/totalSize))
} }
progressTracker.completedUnitCount = Int64(currentPosition) progressTracker.completedUnitCount = Int64(currentPosition)
...@@ -305,7 +305,7 @@ public class Zip { ...@@ -305,7 +305,7 @@ public class Zip {
// Completed. Update progress handler. // Completed. Update progress handler.
if let progressHandler = progress{ if let progressHandler = progress{
progressHandler(progress: 1.0) progressHandler(1.0)
} }
progressTracker.completedUnitCount = Int64(totalSize) progressTracker.completedUnitCount = Int64(totalSize)
...@@ -318,7 +318,7 @@ public class Zip { ...@@ -318,7 +318,7 @@ public class Zip {
- returns: false if the extension is a valid file extension, otherwise true. - returns: false if the extension is a valid file extension, otherwise true.
*/ */
internal class func fileExtensionIsInvalid(fileExtension: String?) -> Bool { internal class func fileExtensionIsInvalid(_ fileExtension: String?) -> Bool {
guard let fileExtension = fileExtension else { return true } guard let fileExtension = fileExtension else { return true }
...@@ -330,7 +330,7 @@ public class Zip { ...@@ -330,7 +330,7 @@ public class Zip {
- parameter fileExtension: A file extension. - parameter fileExtension: A file extension.
*/ */
public class func addCustomFileExtension(fileExtension: String) { public class func addCustomFileExtension(_ fileExtension: String) {
customFileExtensions.insert(fileExtension) customFileExtensions.insert(fileExtension)
} }
...@@ -339,7 +339,7 @@ public class Zip { ...@@ -339,7 +339,7 @@ public class Zip {
- parameter fileExtension: A file extension. - parameter fileExtension: A file extension.
*/ */
public class func removeCustomFileExtension(fileExtension: String) { public class func removeCustomFileExtension(_ fileExtension: String) {
customFileExtensions.remove(fileExtension) customFileExtensions.remove(fileExtension)
} }
...@@ -350,7 +350,7 @@ public class Zip { ...@@ -350,7 +350,7 @@ public class Zip {
- returns: true if the extension valid, otherwise false. - returns: true if the extension valid, otherwise false.
*/ */
public class func isValidFileExtension(fileExtension: String) -> Bool { public class func isValidFileExtension(_ fileExtension: String) -> Bool {
let validFileExtensions: Set<String> = customFileExtensions.union(["zip", "cbz"]) let validFileExtensions: Set<String> = customFileExtensions.union(["zip", "cbz"])
......
...@@ -11,22 +11,17 @@ import Foundation ...@@ -11,22 +11,17 @@ import Foundation
internal class ZipUtilities { internal class ZipUtilities {
// File manager // File manager
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
/** /**
* ProcessedFilePath struct * ProcessedFilePath struct
*/ */
internal struct ProcessedFilePath { internal struct ProcessedFilePath {
let filePathURL: NSURL let filePathURL: URL
let fileName: String? let fileName: String?
func filePath() -> String { func filePath() -> String {
if let filePath = filePathURL.path { return filePathURL.path
return filePath
}
else {
return String()
}
} }
} }
...@@ -39,21 +34,19 @@ internal class ZipUtilities { ...@@ -39,21 +34,19 @@ internal class ZipUtilities {
- returns: Array of ProcessedFilePath structs. - returns: Array of ProcessedFilePath structs.
*/ */
internal func processZipPaths(paths: [NSURL]) -> [ProcessedFilePath]{ internal func processZipPaths(_ paths: [URL]) -> [ProcessedFilePath]{
var processedFilePaths = [ProcessedFilePath]() var processedFilePaths = [ProcessedFilePath]()
for path in paths { for path in paths {
guard let filePath = path.path else { let filePath = path.path
continue
}
var isDirectory: ObjCBool = false var isDirectory: ObjCBool = false
fileManager.fileExistsAtPath(filePath, isDirectory: &isDirectory) fileManager.fileExists(atPath: filePath, isDirectory: &isDirectory)
if !isDirectory { if !isDirectory.boolValue {
let processedPath = ProcessedFilePath(filePathURL: path, fileName: path.lastPathComponent) let processedPath = ProcessedFilePath(filePathURL: path, fileName: path.lastPathComponent)
processedFilePaths.append(processedPath) processedFilePaths.append(processedPath)
} }
else { else {
let directoryContents = expandDirectoryFilePath(path) let directoryContents = expandDirectoryFilePath(path)
processedFilePaths.appendContentsOf(directoryContents) processedFilePaths.append(contentsOf: directoryContents)
} }
} }
return processedFilePaths return processedFilePaths
...@@ -67,24 +60,22 @@ internal class ZipUtilities { ...@@ -67,24 +60,22 @@ internal class ZipUtilities {
- returns: Array of ProcessedFilePath structs. - returns: Array of ProcessedFilePath structs.
*/ */
internal func expandDirectoryFilePath(directory: NSURL) -> [ProcessedFilePath] { internal func expandDirectoryFilePath(_ directory: URL) -> [ProcessedFilePath] {
var processedFilePaths = [ProcessedFilePath]() var processedFilePaths = [ProcessedFilePath]()
if let directoryPath = directory.path, let enumerator = fileManager.enumeratorAtPath(directoryPath) { let directoryPath = directory.path
if let enumerator = fileManager.enumerator(atPath: directoryPath) {
while let filePathComponent = enumerator.nextObject() as? String { while let filePathComponent = enumerator.nextObject() as? String {
let path = directory.URLByAppendingPathComponent(filePathComponent) let path = directory.appendingPathComponent(filePathComponent)
guard let filePath = path.path, let directoryName = directory.lastPathComponent else { let filePath = path.path
continue let directoryName = directory.lastPathComponent
}
var isDirectory: ObjCBool = false var isDirectory: ObjCBool = false
fileManager.fileExistsAtPath(filePath, isDirectory: &isDirectory) fileManager.fileExists(atPath: filePath, isDirectory: &isDirectory)
if !isDirectory { if !isDirectory.boolValue {
let fileName = (directoryName as NSString).stringByAppendingPathComponent(filePathComponent) let fileName = (directoryName as NSString).appendingPathComponent(filePathComponent)
let processedPath = ProcessedFilePath(filePathURL: path, fileName: fileName) let processedPath = ProcessedFilePath(filePathURL: path, fileName: fileName)
processedFilePaths.append(processedPath) processedFilePaths.append(processedPath)
} }
else {
let directoryContents = expandDirectoryFilePath(path)
}
} }
} }
return processedFilePaths return processedFilePaths
......
...@@ -15,10 +15,10 @@ ...@@ -15,10 +15,10 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>BNDL</string> <string>BNDL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.4.3</string> <string>0.5.0</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>7</string> <string>8</string>
</dict> </dict>
</plist> </plist>
...@@ -21,10 +21,10 @@ class ZipTests: XCTestCase { ...@@ -21,10 +21,10 @@ class ZipTests: XCTestCase {
func testQuickUnzip() { func testQuickUnzip() {
do { do {
let filePath = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")! let filePath = Bundle(for: ZipTests.self).url(forResource: "bb8", withExtension: "zip")!
let destinationURL = try Zip.quickUnzipFile(filePath) let destinationURL = try Zip.quickUnzipFile(filePath)
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertTrue(fileManager.fileExistsAtPath(destinationURL.path!)) XCTAssertTrue(fileManager.fileExists(atPath: destinationURL.path))
} }
catch { catch {
XCTFail() XCTFail()
...@@ -33,11 +33,11 @@ class ZipTests: XCTestCase { ...@@ -33,11 +33,11 @@ class ZipTests: XCTestCase {
func testQuickUnzipNonExistingPath() { func testQuickUnzipNonExistingPath() {
do { do {
let filePathURL = NSBundle(forClass: ZipTests.self).resourcePath let filePathURL = Bundle(for: ZipTests.self).resourcePath
let filePath = NSURL(string:"\(filePathURL!)/bb9.zip") let filePath = NSURL(string:"\(filePathURL!)/bb9.zip")
let destinationURL = try Zip.quickUnzipFile(filePath!) let destinationURL = try Zip.quickUnzipFile(filePath! as URL)
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertFalse(fileManager.fileExistsAtPath(destinationURL.path!)) XCTAssertFalse(fileManager.fileExists(atPath:destinationURL.path))
} }
catch { catch {
XCTAssert(true) XCTAssert(true)
...@@ -46,10 +46,10 @@ class ZipTests: XCTestCase { ...@@ -46,10 +46,10 @@ class ZipTests: XCTestCase {
func testQuickUnzipNonZipPath() { func testQuickUnzipNonZipPath() {
do { do {
let filePath = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")! let filePath = Bundle(for: ZipTests.self).url(forResource: "3crBXeO", withExtension: "gif")!
let destinationURL = try Zip.quickUnzipFile(filePath) let destinationURL = try Zip.quickUnzipFile(filePath)
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertFalse(fileManager.fileExistsAtPath(destinationURL.path!)) XCTAssertFalse(fileManager.fileExists(atPath:destinationURL.path))
} }
catch { catch {
XCTAssert(true) XCTAssert(true)
...@@ -58,8 +58,8 @@ class ZipTests: XCTestCase { ...@@ -58,8 +58,8 @@ class ZipTests: XCTestCase {
func testQuickUnzipProgress() { func testQuickUnzipProgress() {
do { do {
let filePath = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")! let filePath = Bundle(for: ZipTests.self).url(forResource: "bb8", withExtension: "zip")!
try Zip.quickUnzipFile(filePath, progress: { (progress) -> () in _ = try Zip.quickUnzipFile(filePath, progress: { (progress) -> () in
XCTAssert(true) XCTAssert(true)
}) })
} }
...@@ -71,9 +71,9 @@ class ZipTests: XCTestCase { ...@@ -71,9 +71,9 @@ class ZipTests: XCTestCase {
func testQuickUnzipOnlineURL() { func testQuickUnzipOnlineURL() {
do { do {
let filePath = NSURL(string: "http://www.google.com/google.zip")! let filePath = NSURL(string: "http://www.google.com/google.zip")!
let destinationURL = try Zip.quickUnzipFile(filePath) let destinationURL = try Zip.quickUnzipFile(filePath as URL)
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertFalse(fileManager.fileExistsAtPath(destinationURL.path!)) XCTAssertFalse(fileManager.fileExists(atPath:destinationURL.path))
} }
catch { catch {
XCTAssert(true) XCTAssert(true)
...@@ -82,15 +82,15 @@ class ZipTests: XCTestCase { ...@@ -82,15 +82,15 @@ class ZipTests: XCTestCase {
func testUnzip() { func testUnzip() {
do { do {
let filePath = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")! let filePath = Bundle(for: ZipTests.self).url(forResource: "bb8", withExtension: "zip")!
let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsFolder = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] as NSURL
try Zip.unzipFile(filePath, destination: documentsFolder, overwrite: true, password: "password", progress: { (progress) -> () in try Zip.unzipFile(filePath, destination: documentsFolder as URL, overwrite: true, password: "password", progress: { (progress) -> () in
print(progress) print(progress)
}) })
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertTrue(fileManager.fileExistsAtPath(documentsFolder.path!)) XCTAssertTrue(fileManager.fileExists(atPath:documentsFolder.path!))
} }
catch { catch {
XCTFail() XCTFail()
...@@ -99,14 +99,14 @@ class ZipTests: XCTestCase { ...@@ -99,14 +99,14 @@ class ZipTests: XCTestCase {
func testImplicitProgressUnzip() { func testImplicitProgressUnzip() {
do { do {
let progress = NSProgress() let progress = Progress()
progress.totalUnitCount = 1 progress.totalUnitCount = 1
let filePath = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")! let filePath = Bundle(for: ZipTests.self).url(forResource: "bb8", withExtension: "zip")!
let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsFolder = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] as NSURL
progress.becomeCurrentWithPendingUnitCount(1) progress.becomeCurrent(withPendingUnitCount: 1)
try Zip.unzipFile(filePath, destination: documentsFolder, overwrite: true, password: "password", progress: nil) try Zip.unzipFile(filePath, destination: documentsFolder as URL, overwrite: true, password: "password", progress: nil)
progress.resignCurrent() progress.resignCurrent()
XCTAssertTrue(progress.totalUnitCount == progress.completedUnitCount) XCTAssertTrue(progress.totalUnitCount == progress.completedUnitCount)
...@@ -119,16 +119,16 @@ class ZipTests: XCTestCase { ...@@ -119,16 +119,16 @@ class ZipTests: XCTestCase {
func testImplicitProgressZip() { func testImplicitProgressZip() {
do { do {
let progress = NSProgress() let progress = Progress()
progress.totalUnitCount = 1 progress.totalUnitCount = 1
let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")! let imageURL1 = Bundle(for: ZipTests.self).url(forResource: "3crBXeO", withExtension: "gif")!
let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")! let imageURL2 = Bundle(for: ZipTests.self).url(forResource: "kYkLkPf", withExtension: "gif")!
let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsFolder = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] as NSURL
let zipFilePath = documentsFolder.URLByAppendingPathComponent("archive.zip") let zipFilePath = documentsFolder.appendingPathComponent("archive.zip")
progress.becomeCurrentWithPendingUnitCount(1) progress.becomeCurrent(withPendingUnitCount: 1)
try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath, password: nil, progress: nil) try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath!, password: nil, progress: nil)
progress.resignCurrent() progress.resignCurrent()
XCTAssertTrue(progress.totalUnitCount == progress.completedUnitCount) XCTAssertTrue(progress.totalUnitCount == progress.completedUnitCount)
...@@ -141,11 +141,11 @@ class ZipTests: XCTestCase { ...@@ -141,11 +141,11 @@ class ZipTests: XCTestCase {
func testQuickZip() { func testQuickZip() {
do { do {
let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")! let imageURL1 = Bundle(for: ZipTests.self).url(forResource: "3crBXeO", withExtension: "gif")!
let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")! let imageURL2 = Bundle(for: ZipTests.self).url(forResource: "kYkLkPf", withExtension: "gif")!
let destinationURL = try Zip.quickZipFiles([imageURL1, imageURL2], fileName: "archive") let destinationURL = try Zip.quickZipFiles([imageURL1, imageURL2], fileName: "archive")
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertTrue(fileManager.fileExistsAtPath(destinationURL.path!)) XCTAssertTrue(fileManager.fileExists(atPath:destinationURL.path))
} }
catch { catch {
XCTFail() XCTFail()
...@@ -154,20 +154,20 @@ class ZipTests: XCTestCase { ...@@ -154,20 +154,20 @@ class ZipTests: XCTestCase {
func testQuickZipFolder() { func testQuickZipFolder() {
do { do {
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")! let imageURL1 = Bundle(for: ZipTests.self).url(forResource: "3crBXeO", withExtension: "gif")!
let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")! let imageURL2 = Bundle(for: ZipTests.self).url(forResource: "kYkLkPf", withExtension: "gif")!
let folderURL = NSBundle(forClass: ZipTests.self).bundleURL.URLByAppendingPathComponent("Directory") let folderURL = Bundle(for: ZipTests.self).bundleURL.appendingPathComponent("Directory")
let targetImageURL1 = folderURL.URLByAppendingPathComponent("3crBXeO.gif") let targetImageURL1 = folderURL.appendingPathComponent("3crBXeO.gif")
let targetImageURL2 = folderURL.URLByAppendingPathComponent("kYkLkPf.gif") let targetImageURL2 = folderURL.appendingPathComponent("kYkLkPf.gif")
if fileManager.fileExistsAtPath(folderURL.path!) { if fileManager.fileExists(atPath:folderURL.path) {
try fileManager.removeItemAtURL(folderURL) try fileManager.removeItem(at: folderURL)
} }
try fileManager.createDirectoryAtURL(folderURL, withIntermediateDirectories: false, attributes: nil) try fileManager.createDirectory(at: folderURL, withIntermediateDirectories: false, attributes: nil)
try fileManager.copyItemAtURL(imageURL1, toURL: targetImageURL1) try fileManager.copyItem(at: imageURL1, to: targetImageURL1)
try fileManager.copyItemAtURL(imageURL2, toURL: targetImageURL2) try fileManager.copyItem(at: imageURL2, to: targetImageURL2)
let destinationURL = try Zip.quickZipFiles([folderURL], fileName: "directory") let destinationURL = try Zip.quickZipFiles([folderURL], fileName: "directory")
XCTAssertTrue(fileManager.fileExistsAtPath(destinationURL.path!)) XCTAssertTrue(fileManager.fileExists(atPath:destinationURL.path))
} }
catch { catch {
XCTFail() XCTFail()
...@@ -177,15 +177,15 @@ class ZipTests: XCTestCase { ...@@ -177,15 +177,15 @@ class ZipTests: XCTestCase {
func testZip() { func testZip() {
do { do {
let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")! let imageURL1 = Bundle(for: ZipTests.self).url(forResource: "3crBXeO", withExtension: "gif")!
let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")! let imageURL2 = Bundle(for: ZipTests.self).url(forResource: "kYkLkPf", withExtension: "gif")!
let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsFolder = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] as NSURL
let zipFilePath = documentsFolder.URLByAppendingPathComponent("archive.zip") let zipFilePath = documentsFolder.appendingPathComponent("archive.zip")
try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath, password: nil, progress: { (progress) -> () in try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath!, password: nil, progress: { (progress) -> () in
print(progress) print(progress)
}) })
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertTrue(fileManager.fileExistsAtPath(zipFilePath.path!)) XCTAssertTrue(fileManager.fileExists(atPath:(zipFilePath?.path)!))
} }
catch { catch {
XCTFail() XCTFail()
...@@ -194,23 +194,23 @@ class ZipTests: XCTestCase { ...@@ -194,23 +194,23 @@ class ZipTests: XCTestCase {
func testZipUnzipPassword() { func testZipUnzipPassword() {
do { do {
let imageURL1 = NSBundle(forClass: ZipTests.self).URLForResource("3crBXeO", withExtension: "gif")! let imageURL1 = Bundle(for: ZipTests.self).url(forResource: "3crBXeO", withExtension: "gif")!
let imageURL2 = NSBundle(forClass: ZipTests.self).URLForResource("kYkLkPf", withExtension: "gif")! let imageURL2 = Bundle(for: ZipTests.self).url(forResource: "kYkLkPf", withExtension: "gif")!
let documentsFolder = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsFolder = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] as NSURL
let zipFilePath = documentsFolder.URLByAppendingPathComponent("archive.zip") let zipFilePath = documentsFolder.appendingPathComponent("archive.zip")
try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath, password: "password", progress: { (progress) -> () in try Zip.zipFiles([imageURL1, imageURL2], zipFilePath: zipFilePath!, password: "password", progress: { (progress) -> () in
print(progress) print(progress)
}) })
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
XCTAssertTrue(fileManager.fileExistsAtPath(zipFilePath.path!)) XCTAssertTrue(fileManager.fileExists(atPath:(zipFilePath?.path)!))
guard let fileExtension = zipFilePath.pathExtension, let fileName = zipFilePath.lastPathComponent else { guard let fileExtension = zipFilePath?.pathExtension, let fileName = zipFilePath?.lastPathComponent else {
throw ZipError.UnzipFail throw ZipError.unzipFail
} }
let directoryName = fileName.stringByReplacingOccurrencesOfString(".\(fileExtension)", withString: "") let directoryName = fileName.replacingOccurrences(of: ".\(fileExtension)", with: "")
let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as NSURL
let destinationUrl = documentsUrl.URLByAppendingPathComponent(directoryName, isDirectory: true) let destinationUrl = documentsUrl.appendingPathComponent(directoryName, isDirectory: true)
try Zip.unzipFile(zipFilePath, destination: destinationUrl, overwrite: true, password: "password", progress: nil) try Zip.unzipFile(zipFilePath!, destination: destinationUrl!, overwrite: true, password: "password", progress: nil)
XCTAssertTrue(fileManager.fileExistsAtPath(destinationUrl.path!)) XCTAssertTrue(fileManager.fileExists(atPath:(destinationUrl?.path)!))
} }
catch { catch {
XCTFail() XCTFail()
...@@ -220,16 +220,15 @@ class ZipTests: XCTestCase { ...@@ -220,16 +220,15 @@ class ZipTests: XCTestCase {
func testQuickUnzipSubDir() { func testQuickUnzipSubDir() {
do { do {
let bookURL = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "zip")! let bookURL = Bundle(for: ZipTests.self).url(forResource: "bb8", withExtension: "zip")!
let unzipDestination = try Zip.quickUnzipFile(bookURL) let unzipDestination = try Zip.quickUnzipFile(bookURL)
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
let subDir = unzipDestination.appendingPathComponent("subDir")
let subDir = unzipDestination.URLByAppendingPathComponent("subDir") let imageURL = subDir.appendingPathComponent("r2W9yu9").appendingPathExtension("gif")
let imageURL = subDir.URLByAppendingPathComponent("r2W9yu9").URLByAppendingPathExtension("gif")
XCTAssertTrue(fileManager.fileExistsAtPath(unzipDestination.path!)) XCTAssertTrue(fileManager.fileExists(atPath:unzipDestination.path))
XCTAssertTrue(fileManager.fileExistsAtPath(subDir.path!)) XCTAssertTrue(fileManager.fileExists(atPath:subDir.path))
XCTAssertTrue(fileManager.fileExistsAtPath(imageURL.path!)) XCTAssertTrue(fileManager.fileExists(atPath:imageURL.path))
} catch { } catch {
XCTFail() XCTFail()
} }
......
#!/bin/bash #!/bin/bash
# **** Update me when new Xcode versions are released! **** # **** Update me when new Xcode versions are released! ****
PLATFORM="platform=iOS Simulator,OS=9.2,name=iPhone 6" PLATFORM="platform=iOS Simulator,OS=10.0,name=iPhone 7"
SDK="iphonesimulator9.2" SDK="iphonesimulator10.0"
# It is pitch black. # It is pitch black.
...@@ -19,12 +19,12 @@ MODE="$1" ...@@ -19,12 +19,12 @@ MODE="$1"
if [ "$MODE" = "framework" ]; then if [ "$MODE" = "framework" ]; then
echo "Building and testing Zip." echo "Building and testing Zip."
xctool \ xcodebuild \
-project Zip.xcodeproj \ -project Zip.xcodeproj \
-scheme Zip \ -scheme Zip \
-sdk "$SDK" \ -sdk "$SDK" \
-destination "$PLATFORM" \ -destination "$PLATFORM" \
build test test
trap - EXIT trap - EXIT
exit 0 exit 0
fi fi
...@@ -35,12 +35,11 @@ if [ "$MODE" = "examples" ]; then ...@@ -35,12 +35,11 @@ if [ "$MODE" = "examples" ]; then
for example in examples/*/; do for example in examples/*/; do
echo "Building $example." echo "Building $example."
pod install --project-directory=$example pod install --project-directory=$example
xctool \ xcodebuild \
-workspace "${example}Sample.xcworkspace" \ -workspace "${example}Sample.xcworkspace" \
-scheme Sample \ -scheme Sample \
-sdk "$SDK" \ -sdk "$SDK" \
-destination "$PLATFORM" \ -destination "$PLATFORM"
build
done done
trap - EXIT trap - EXIT
exit 0 exit 0
......
...@@ -167,14 +167,16 @@ ...@@ -167,14 +167,16 @@
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastSwiftUpdateCheck = 0720; LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720; LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Roy Marmelstein"; ORGANIZATIONNAME = "Roy Marmelstein";
TargetAttributes = { TargetAttributes = {
3430F66C1C45C930007473A6 = { 3430F66C1C45C930007473A6 = {
CreatedOnToolsVersion = 7.2; CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
}; };
3430F6801C45C930007473A6 = { 3430F6801C45C930007473A6 = {
CreatedOnToolsVersion = 7.2; CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
TestTargetID = 3430F66C1C45C930007473A6; TestTargetID = 3430F66C1C45C930007473A6;
}; };
}; };
...@@ -283,8 +285,10 @@ ...@@ -283,8 +285,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
...@@ -311,6 +315,7 @@ ...@@ -311,6 +315,7 @@
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
}; };
name = Debug; name = Debug;
}; };
...@@ -327,8 +332,10 @@ ...@@ -327,8 +332,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
...@@ -347,6 +354,8 @@ ...@@ -347,6 +354,8 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.2; IPHONEOS_DEPLOYMENT_TARGET = 9.2;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
VALIDATE_PRODUCT = YES; VALIDATE_PRODUCT = YES;
}; };
name = Release; name = Release;
...@@ -354,6 +363,7 @@ ...@@ -354,6 +363,7 @@
3430F68B1C45C930007473A6 /* Debug */ = { 3430F68B1C45C930007473A6 /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Sample/Info.plist; INFOPLIST_FILE = Sample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
...@@ -365,6 +375,7 @@ ...@@ -365,6 +375,7 @@
3430F68C1C45C930007473A6 /* Release */ = { 3430F68C1C45C930007473A6 /* Release */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Sample/Info.plist; INFOPLIST_FILE = Sample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0720" LastUpgradeVersion = "0800"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
......
...@@ -14,45 +14,44 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -14,45 +14,44 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow? var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func applicationDidFinishLaunching(_ application: UIApplication) {
if NSUserDefaults.standardUserDefaults().boolForKey("firstLaunch") == false { if UserDefaults.standard.bool(forKey: "firstLaunch") == false {
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "firstLaunch") UserDefaults.standard.set(true, forKey: "firstLaunch")
NSUserDefaults.standardUserDefaults().synchronize() UserDefaults.standard.synchronize()
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
let fileNames = ["Image1.jpg", "Image2.jpg", "Image3.jpg", "Images.zip"] let fileNames = ["Image1.jpg", "Image2.jpg", "Image3.jpg", "Images.zip"]
let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL
let bundleUrl = NSBundle.mainBundle().resourceURL let bundleUrl = Bundle.main.resourceURL
for file in fileNames { for file in fileNames {
if let srcPath = bundleUrl?.URLByAppendingPathComponent(file).path, let toPath = documentsUrl.URLByAppendingPathComponent(file).path{ if let srcPath = bundleUrl?.appendingPathComponent(file).path{
let toPath = documentsUrl.appendingPathComponent(file).path
do { do {
try fileManager.copyItemAtPath(srcPath, toPath: toPath) try fileManager.copyItem(atPath: srcPath, toPath: toPath)
} catch {} } catch {}
} }
} }
} }
// Override point for customization after application launch.
return true
} }
func applicationWillResignActive(application: UIApplication) { func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
} }
func applicationDidEnterBackground(application: UIApplication) { func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
} }
func applicationWillEnterForeground(application: UIApplication) { func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
} }
func applicationDidBecomeActive(application: UIApplication) { func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
} }
func applicationWillTerminate(application: UIApplication) { func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
} }
......
...@@ -17,9 +17,9 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate ...@@ -17,9 +17,9 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate
@IBOutlet weak var zipButton: UIBarButtonItem! @IBOutlet weak var zipButton: UIBarButtonItem!
@IBOutlet weak var unzipButton: UIBarButtonItem! @IBOutlet weak var unzipButton: UIBarButtonItem!
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
var path: NSURL? { var path: URL? {
didSet { didSet {
updateFiles() updateFiles()
} }
...@@ -34,7 +34,7 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate ...@@ -34,7 +34,7 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate
override func viewDidLoad() { override func viewDidLoad() {
if self.path == nil { if self.path == nil {
let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL
self.path = documentsUrl self.path = documentsUrl
} }
updateSelection() updateSelection()
...@@ -47,65 +47,65 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate ...@@ -47,65 +47,65 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate
var tempFiles = [String]() var tempFiles = [String]()
do { do {
self.title = filePath.lastPathComponent self.title = filePath.lastPathComponent
tempFiles = try self.fileManager.contentsOfDirectoryAtPath(filePath.path!) tempFiles = try self.fileManager.contentsOfDirectory(atPath: filePath.path)
} catch { } catch {
if path == "/System" { if filePath.path == "/System" {
tempFiles = ["Library"] tempFiles = ["Library"]
} }
if path == "/Library" { if filePath.path == "/Library" {
tempFiles = ["Preferences"] tempFiles = ["Preferences"]
} }
if path == "/var" { if filePath.path == "/var" {
tempFiles = ["mobile"] tempFiles = ["mobile"]
} }
if path == "/usr" { if filePath.path == "/usr" {
tempFiles = ["lib", "libexec", "bin"] tempFiles = ["lib", "libexec", "bin"]
} }
} }
self.files = tempFiles.sort(){$0 < $1} self.files = tempFiles.sorted(){$0 < $1}
tableView.reloadData() tableView.reloadData()
} }
} }
//MARK: UITableView Data Source and Delegate //MARK: UITableView Data Source and Delegate
func numberOfSectionsInTableView(tableView: UITableView) -> Int { func numberOfSections(in tableView: UITableView) -> Int {
return 1 return 1
} }
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return files.count return files.count
} }
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "FileCell" let cellIdentifier = "FileCell"
var cell = UITableViewCell(style: .Subtitle, reuseIdentifier: cellIdentifier) var cell = UITableViewCell(style: .subtitle, reuseIdentifier: cellIdentifier)
if let reuseCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) { if let reuseCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) {
cell = reuseCell cell = reuseCell
} }
guard let path = path else { guard let path = path else {
return cell return cell
} }
cell.selectionStyle = .None cell.selectionStyle = .none
let filePath = files[indexPath.row] let filePath = files[(indexPath as NSIndexPath).row]
let newPath = path.URLByAppendingPathComponent(filePath).path! let newPath = path.appendingPathComponent(filePath).path
var isDirectory: ObjCBool = false var isDirectory: ObjCBool = false
fileManager.fileExistsAtPath(newPath, isDirectory: &isDirectory) fileManager.fileExists(atPath: newPath, isDirectory: &isDirectory)
cell.textLabel?.text = files[indexPath.row] cell.textLabel?.text = files[(indexPath as NSIndexPath).row]
if isDirectory { if isDirectory.boolValue {
cell.imageView?.image = UIImage(named: "Folder") cell.imageView?.image = UIImage(named: "Folder")
} }
else { else {
cell.imageView?.image = UIImage(named: "File") cell.imageView?.image = UIImage(named: "File")
} }
cell.backgroundColor = (selectedFiles.contains(filePath)) ? UIColor(white: 0.9, alpha: 1.0):UIColor.whiteColor() cell.backgroundColor = (selectedFiles.contains(filePath)) ? UIColor(white: 0.9, alpha: 1.0):UIColor.white
return cell return cell
} }
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let filePath = files[indexPath.row] let filePath = files[(indexPath as NSIndexPath).row]
if let index = selectedFiles.indexOf(filePath) where selectedFiles.contains(filePath) { if let index = selectedFiles.index(of: filePath) , selectedFiles.contains(filePath) {
selectedFiles.removeAtIndex(index) selectedFiles.remove(at: index)
} }
else { else {
selectedFiles.append(filePath) selectedFiles.append(filePath)
...@@ -117,29 +117,29 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate ...@@ -117,29 +117,29 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate
tableView.reloadData() tableView.reloadData()
selectionCounter.title = "\(selectedFiles.count) Selected" selectionCounter.title = "\(selectedFiles.count) Selected"
zipButton.enabled = (selectedFiles.count > 0) zipButton.isEnabled = (selectedFiles.count > 0)
if (selectedFiles.count == 1) { if (selectedFiles.count == 1) {
let filePath = selectedFiles.first let filePath = selectedFiles.first
let pathExtension = path!.URLByAppendingPathComponent(filePath!).pathExtension let pathExtension = path!.appendingPathComponent(filePath!).pathExtension
if pathExtension == "zip" { if pathExtension == "zip" {
unzipButton.enabled = true unzipButton.isEnabled = true
} }
else { else {
unzipButton.enabled = false unzipButton.isEnabled = false
} }
} }
else { else {
unzipButton.enabled = false unzipButton.isEnabled = false
} }
} }
//MARK: Actions //MARK: Actions
@IBAction func unzipSelection(sender: AnyObject) { @IBAction func unzipSelection(_ sender: AnyObject) {
let filePath = selectedFiles.first let filePath = selectedFiles.first
let pathURL = path!.URLByAppendingPathComponent(filePath!) let pathURL = path!.appendingPathComponent(filePath!)
do { do {
try Zip.quickUnzipFile(pathURL) let _ = try Zip.quickUnzipFile(pathURL)
self.selectedFiles.removeAll() self.selectedFiles.removeAll()
updateSelection() updateSelection()
updateFiles() updateFiles()
...@@ -148,13 +148,13 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate ...@@ -148,13 +148,13 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate
} }
} }
@IBAction func zipSelection(sender: AnyObject) { @IBAction func zipSelection(_ sender: AnyObject) {
var urlPaths = [NSURL]() var urlPaths = [URL]()
for filePath in selectedFiles { for filePath in selectedFiles {
urlPaths.append(path!.URLByAppendingPathComponent(filePath)) urlPaths.append(path!.appendingPathComponent(filePath))
} }
do { do {
try Zip.quickZipFiles(urlPaths, fileName: "Archive") let _ = try Zip.quickZipFiles(urlPaths, fileName: "Archive")
self.selectedFiles.removeAll() self.selectedFiles.removeAll()
updateSelection() updateSelection()
updateFiles() updateFiles()
......
...@@ -28,7 +28,7 @@ class SampleTests: XCTestCase { ...@@ -28,7 +28,7 @@ class SampleTests: XCTestCase {
func testPerformanceExample() { func testPerformanceExample() {
// This is an example of a performance test case. // This is an example of a performance test case.
self.measureBlock { self.measure {
// Put the code you want to measure the time of here. // Put the code you want to measure the time of here.
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment