|
@@ -1226,16 +1226,30 @@ class NCNetworkingMain: NSObject, CCNetworkingDelegate {
|
|
|
|
|
|
if metadata.typeFile == k_metadataTypeFile_imagemeter {
|
|
|
|
|
|
+ var pathArchive = ""
|
|
|
+ var pathArchiveImm = ""
|
|
|
+
|
|
|
let source = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageFileID(metadata.fileID, fileNameView: metadata.fileNameView))
|
|
|
let destination = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageFileID(metadata.fileID))
|
|
|
-
|
|
|
+
|
|
|
try? FileManager().unzipItem(at: source, to: destination)
|
|
|
|
|
|
- let nameArchiveImagemeter = (metadata.fileNameView as NSString).deletingPathExtension
|
|
|
- let pathArchiveImagemeter = CCUtility.getDirectoryProviderStorageFileID(metadata.fileID) + "/" + nameArchiveImagemeter
|
|
|
- let annoPath = (pathArchiveImagemeter + "/anno-" + nameArchiveImagemeter + ".imm")
|
|
|
+ if let archive = Archive(url: source, accessMode: .read) {
|
|
|
+ archive.forEach({ (entry) in
|
|
|
+ let pathComponents = (entry.path as NSString).pathComponents
|
|
|
+ if pathComponents.count == 2 && (pathComponents.last! as NSString).pathExtension.lowercased() == "imm" {
|
|
|
+ pathArchive = CCUtility.getDirectoryProviderStorageFileID(metadata.fileID) + "/" + pathComponents.first!
|
|
|
+ pathArchiveImm = CCUtility.getDirectoryProviderStorageFileID(metadata.fileID) + "/" + entry.path
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ if pathArchive == "" {
|
|
|
+ appDelegate.messageNotification("_error_", description: "File format imagemeter error. 🤷♂️", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- if let fileHandle = FileHandle(forReadingAtPath: annoPath) {
|
|
|
+ if let fileHandle = FileHandle(forReadingAtPath: pathArchiveImm) {
|
|
|
let dataFormat = fileHandle.readData(ofLength: 1)
|
|
|
if dataFormat.starts(with: [0x01]) {
|
|
|
appDelegate.messageNotification("_error_", description: "File format binary error, library imagemeter not present. 🤷♂️", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
@@ -1243,7 +1257,7 @@ class NCNetworkingMain: NSObject, CCNetworkingDelegate {
|
|
|
}
|
|
|
let dataZip = fileHandle.readData(ofLength: 4)
|
|
|
if dataZip.starts(with: [0x50, 0x4b, 0x03, 0x04]) {
|
|
|
- try? FileManager().unzipItem(at: NSURL(fileURLWithPath: annoPath) as URL, to: NSURL(fileURLWithPath: pathArchiveImagemeter) as URL)
|
|
|
+ try? FileManager().unzipItem(at: NSURL(fileURLWithPath: pathArchiveImm) as URL, to: NSURL(fileURLWithPath: pathArchive) as URL)
|
|
|
}
|
|
|
fileHandle.closeFile()
|
|
|
}
|