Kaynağa Gözat

align version

marinofaggiana 5 yıl önce
ebeveyn
işleme
ab8020108a

+ 2 - 22
iOSClient/Main/NCMainCommon.swift

@@ -1310,31 +1310,11 @@ class NCNetworkingMain: NSObject, CCNetworkingDelegate {
                         return
                     }
                     
-                    let source = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
-                    let destination =  URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
-                    
-                    try? FileManager().unzipItem(at: source, to: destination)
-                    
-                    let bundleDirectory = NCUtility.sharedInstance.IMGetBundleDirectory(metadata: metadata)
-                    
-                    if bundleDirectory.error {
-                        appDelegate.messageNotification("_error_", description: "Bundle imagemeter error. 🤷‍♂️", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+                    if !NCUtility.sharedInstance.IMUnzip(metadata: metadata) {
+                        appDelegate.messageNotification("_error_", description: "Bundle imagemeter error. 🤷‍♂️", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
                         return
                     }
                     
-                    if let fileHandle = FileHandle(forReadingAtPath: bundleDirectory.immPath) {
-                        //                        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)
-                        //                            return;
-                        //                        }
-                        let dataZip = fileHandle.readData(ofLength: 4)
-                        if dataZip.starts(with: [0x50, 0x4b, 0x03, 0x04]) {
-                            try? FileManager().unzipItem(at: NSURL(fileURLWithPath: bundleDirectory.immPath) as URL, to: NSURL(fileURLWithPath: bundleDirectory.bundleDirectory) as URL)
-                        }
-                        fileHandle.closeFile()
-                    }
-                    
                     let storyboard = UIStoryboard(name: "IMImagemeter", bundle: nil)
                     let imiVC = storyboard.instantiateInitialViewController() as! IMImagemeterViewer
                     imiVC.metadata = metadata

+ 1 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -112,6 +112,7 @@
 "_wipe_account_"            = "Account wiped from server";
 "_appconfig_view_title_"    = "Account configuration in progress…";
 "_no_permission_add_file_"  = "You don't have permission to add files";
+"_request_upload_new_ver_"  = "The file has been modified, do you want to upload the new version ?";
 
 // App
 

+ 35 - 0
iOSClient/Utility/NCUtility.swift

@@ -452,6 +452,41 @@ class NCUtility: NSObject {
         }
     }
     
+    func IMUnzip(metadata: tableMetadata) -> Bool {
+        
+        // bak
+        let atPathBak = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId) + "/" + metadata.fileNameView
+        let toPathBak = (CCUtility.getDirectoryProviderStorageOcId(metadata.ocId) + "/" + metadata.fileNameView as NSString).deletingPathExtension + ".bak"
+        CCUtility.copyFile(atPath: atPathBak, toPath: toPathBak)
+        
+        let source = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
+        let destination = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
+        let removeAtPath = (CCUtility.getDirectoryProviderStorageOcId(metadata.ocId) + "/" + metadata.fileNameView as NSString).deletingPathExtension
+        
+        try? FileManager.default.removeItem(atPath: removeAtPath)
+        try? FileManager().unzipItem(at: source, to: destination)
+        
+        let bundleDirectory = NCUtility.sharedInstance.IMGetBundleDirectory(metadata: metadata)
+        if bundleDirectory.error {
+            return false
+        }
+        
+        if let fileHandle = FileHandle(forReadingAtPath: bundleDirectory.immPath) {
+            //                        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)
+            //                            return;
+            //                        }
+            let dataZip = fileHandle.readData(ofLength: 4)
+            if dataZip.starts(with: [0x50, 0x4b, 0x03, 0x04]) {
+                try? FileManager().unzipItem(at: NSURL(fileURLWithPath: bundleDirectory.immPath) as URL, to: NSURL(fileURLWithPath: bundleDirectory.bundleDirectory) as URL)
+            }
+            fileHandle.closeFile()
+        }
+        
+        return true
+    }
+    
     func IMGetBundleDirectory(metadata: tableMetadata) -> bundleDirectoryType {
         
         var error = true