Commit c8d9230b authored by Pavel Hlavnicka's avatar Pavel Hlavnicka

fixes for XC8 beta 4

parent 9d44d606
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "F3707899-72AE-49DA-9BDD-5CB0B64CF03A", "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "F3707899-72AE-49DA-9BDD-5CB0B64CF03A",
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
"8DA5B175D3FDB92A3B3CCBD4109A734F1316A3DD" : "Zip\/Zip\/minizip\/", "8DA5B175D3FDB92A3B3CCBD4109A734F1316A3DD" : "Zip\/Zip\/minizip\/",
"3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4" : "Zip\/" "3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4" : "Zip-swift3\/"
}, },
"DVTSourceControlWorkspaceBlueprintNameKey" : "Zip", "DVTSourceControlWorkspaceBlueprintNameKey" : "Zip",
"DVTSourceControlWorkspaceBlueprintVersion" : 204, "DVTSourceControlWorkspaceBlueprintVersion" : 204,
......
...@@ -39,13 +39,14 @@ extension Zip { ...@@ -39,13 +39,14 @@ extension Zip {
*/ */
public class func quickUnzipFile(_ path: URL, progress: ((progress: Double) -> ())?) throws -> URL { public class func quickUnzipFile(_ path: URL, progress: ((progress: Double) -> ())?) throws -> URL {
let fileManager = FileManager.default 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.replacingOccurrences(of: ".\(fileExtension)", with: "") let directoryName = fileName.replacingOccurrences(of: ".\(fileExtension)", with: "")
let documentsUrl = fileManager.urlsForDirectory(.documentDirectory, inDomains: .userDomainMask)[0] as URL let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL
do { do {
let destinationUrl = try documentsUrl.appendingPathComponent(directoryName, isDirectory: true) 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{ }catch{
...@@ -86,7 +87,7 @@ extension Zip { ...@@ -86,7 +87,7 @@ extension Zip {
*/ */
public class func quickZipFiles(_ paths: [URL], fileName: String, progress: ((progress: Double) -> ())?) throws -> URL { public class func quickZipFiles(_ paths: [URL], fileName: String, progress: ((progress: Double) -> ())?) throws -> URL {
let fileManager = FileManager.default let fileManager = FileManager.default
let documentsUrl = fileManager.urlsForDirectory(.documentDirectory, inDomains: .userDomainMask)[0] as URL let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL
let destinationUrl = try! documentsUrl.appendingPathComponent("\(fileName).zip") let destinationUrl = try! 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,7 +10,7 @@ import Foundation ...@@ -10,7 +10,7 @@ import Foundation
import minizip import minizip
/// Zip error type /// Zip error type
public enum ZipError: ErrorProtocol { public enum ZipError: Error {
/// File not found /// File not found
case fileNotFound case fileNotFound
/// Unzip fail /// Unzip fail
...@@ -68,9 +68,8 @@ public class Zip { ...@@ -68,9 +68,8 @@ public class Zip {
let fileManager = FileManager.default 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, destination.path != nil else { let path = zipFilePath.path
throw ZipError.fileNotFound
}
if fileManager.fileExists(atPath: path) == false || fileExtensionIsInvalid(zipFilePath.pathExtension) { if fileManager.fileExists(atPath: path) == false || fileExtensionIsInvalid(zipFilePath.pathExtension) {
throw ZipError.fileNotFound throw ZipError.fileNotFound
} }
...@@ -121,7 +120,8 @@ public class Zip { ...@@ -121,7 +120,8 @@ public class Zip {
} }
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>(allocatingCapacity: fileNameSize) //let fileName = UnsafeMutablePointer<CChar>(allocatingCapacity: fileNameSize)
let fileName = UnsafeMutablePointer<CChar>.allocate(capacity: fileNameSize)
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
...@@ -140,9 +140,9 @@ public class Zip { ...@@ -140,9 +140,9 @@ public class Zip {
if pathString.rangeOfCharacter(from: CharacterSet(charactersIn: "/\\")) != nil { if pathString.rangeOfCharacter(from: CharacterSet(charactersIn: "/\\")) != nil {
pathString = pathString.replacingOccurrences(of: "\\", with: "/") pathString = pathString.replacingOccurrences(of: "\\", with: "/")
} }
guard let fullPath = try! destination.appendingPathComponent(pathString).path else {
throw ZipError.unzipFail let fullPath = destination.appendingPathComponent(pathString).path
}
let creationDate = Date() let creationDate = Date()
let directoryAttributes = [FileAttributeKey.creationDate.rawValue : creationDate, let directoryAttributes = [FileAttributeKey.creationDate.rawValue : creationDate,
FileAttributeKey.modificationDate.rawValue : creationDate] FileAttributeKey.modificationDate.rawValue : creationDate]
...@@ -215,9 +215,7 @@ public class Zip { ...@@ -215,9 +215,7 @@ public class Zip {
let fileManager = FileManager.default 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)
...@@ -252,7 +250,7 @@ public class Zip { ...@@ -252,7 +250,7 @@ public class Zip {
let filePath = path.filePath() let filePath = path.filePath()
var isDirectory: ObjCBool = false var isDirectory: ObjCBool = false
fileManager.fileExists(atPath: 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
...@@ -262,7 +260,7 @@ public class Zip { ...@@ -262,7 +260,7 @@ public class Zip {
do { do {
let fileAttributes = try fileManager.attributesOfItem(atPath: filePath) let fileAttributes = try fileManager.attributesOfItem(atPath: filePath)
if let fileDate = fileAttributes[FileAttributeKey.modificationDate] as? Date { if let fileDate = fileAttributes[FileAttributeKey.modificationDate] as? Date {
let components = Calendar.current.components([.year, .month, .day, .hour, .minute, .second], from: 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!)
......
...@@ -21,12 +21,7 @@ internal class ZipUtilities { ...@@ -21,12 +21,7 @@ internal class ZipUtilities {
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()
}
} }
} }
...@@ -42,12 +37,10 @@ internal class ZipUtilities { ...@@ -42,12 +37,10 @@ internal class ZipUtilities {
internal func processZipPaths(_ paths: [URL]) -> [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.fileExists(atPath: 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)
} }
...@@ -69,15 +62,16 @@ internal class ZipUtilities { ...@@ -69,15 +62,16 @@ internal class ZipUtilities {
*/ */
internal func expandDirectoryFilePath(_ directory: URL) -> [ProcessedFilePath] { internal func expandDirectoryFilePath(_ directory: URL) -> [ProcessedFilePath] {
var processedFilePaths = [ProcessedFilePath]() var processedFilePaths = [ProcessedFilePath]()
if let directoryPath = directory.path, let enumerator = fileManager.enumerator(atPath: 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 = try! directory.appendingPathComponent(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.fileExists(atPath: filePath, isDirectory: &isDirectory) fileManager.fileExists(atPath: filePath, isDirectory: &isDirectory)
if !isDirectory { if !isDirectory.boolValue {
let fileName = (directoryName as NSString).appendingPathComponent(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)
......
This diff is collapsed.
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