marinofaggiana 4 years ago
parent
commit
00692641de

+ 3 - 1
File Provider Extension/FileProviderExtension.swift

@@ -221,7 +221,7 @@ class FileProviderExtension: NSFileProviderExtension {
         let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
         let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileName)!
         
-        let task = NCCommunication.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, progressHandler: { (progress) in }) { (account, etag, date, length, errorCode, errorDescription) in
+        NCCommunication.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, progressHandler: { (progress) in }) { (account, etag, date, length, errorCode, errorDescription) in
             
             self.outstandingSessionTasks.removeValue(forKey: url)
             
@@ -242,12 +242,14 @@ class FileProviderExtension: NSFileProviderExtension {
             }
         }
         
+        /*
         if task != nil {
             
             outstandingSessionTasks[url] = task
             
             NSFileProviderManager.default.register(task!, forItemWithIdentifier: NSFileProviderItemIdentifier(identifier.rawValue)) { (error) in }
         }
+        */
     }
     
     override func itemChanged(at url: URL) {

+ 1 - 1
Share/ShareViewController.m

@@ -271,7 +271,7 @@
         NSString *fileNameForUpload = [[NCUtility sharedInstance] createFileName:fileName serverUrl:self.serverUrl account:self.activeAccount];
         NSString *fileNameServer = [NSString stringWithFormat:@"%@/%@", self.serverUrl, fileNameForUpload];
         
-        (void)[[NCCommunication shared] uploadWithServerUrlFileName:fileNameServer fileNameLocalPath:fileNameLocal dateCreationFile:nil dateModificationFile:nil customUserAgent:nil addCustomHeaders:nil progressHandler:^(NSProgress * progress) {
+        [[NCCommunication shared] uploadWithServerUrlFileName:fileNameServer fileNameLocalPath:fileNameLocal dateCreationFile:nil dateModificationFile:nil customUserAgent:nil addCustomHeaders:nil progressHandler:^(NSProgress * progress) {
             [self.hud progress:progress.fractionCompleted];
         } completionHandler:^(NSString *account, NSString *ocId, NSString *etag, NSDate *date, int64_t size, NSInteger errorCode, NSString *errorDescription) {
             [self.hud hideHud];

+ 1 - 1
iOSClient/Activity/NCActivity.swift

@@ -394,7 +394,7 @@ extension activityTableViewCell: UICollectionViewDelegate {
             
             NCUtility.sharedInstance.startActivityIndicator(view: (appDelegate.window.rootViewController?.view)!, bottom: 0)
             
-            _ = NCCommunication.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, progressHandler: { (progress) in
+            NCCommunication.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, progressHandler: { (progress) in
                 
             }) { (account, etag, date, lenght, errorCode, errorDescription) in
                 

+ 3 - 0
iOSClient/CCGlobal.h

@@ -122,6 +122,9 @@
 #define k_upload_session_foreground                     @"it.twsweb.Crypto-Cloud.upload.sessionforeground"
 #define k_upload_session_wwan                           @"it.twsweb.Crypto-Cloud.upload.sessionwwan"
 
+#define k_download_session_default                      @"download.default"
+#define k_upload_session_default                        @"upload.default"
+
 // Session Download Upload Extension
 #define k_upload_session_extension                      @"com.nextcloud.upload.session.extension"
 

+ 1 - 1
iOSClient/Main/Create cloud/NCCreateFormUploadDocuments.swift

@@ -495,7 +495,7 @@ import NCCommunication
         
         let fileNameLocalPath = CCUtility.getDirectoryUserData() + "/" + name + ".png"
 
-        _ = NCCommunication.shared.download(serverUrlFileName: preview, fileNameLocalPath: fileNameLocalPath, progressHandler: { (progress) in
+        NCCommunication.shared.download(serverUrlFileName: preview, fileNameLocalPath: fileNameLocalPath, progressHandler: { (progress) in
             
         }) { (account, etag, date, lenght, errorCode, errorDescription) in
             

+ 2 - 2
iOSClient/Main/NCDetailViewController.swift

@@ -706,7 +706,7 @@ extension NCDetailViewController: NCViewerImageViewControllerDelegate, NCViewerI
             
             metadata.session = k_download_session_foreground
             
-            _ = NCCommunication.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, progressHandler: { (progress) in
+            NCCommunication.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, progressHandler: { (progress) in
                                 
                 self.progress(Float(progress.fractionCompleted))
                 
@@ -817,7 +817,7 @@ extension NCDetailViewController: NCViewerImageViewControllerDelegate, NCViewerI
                 let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileNameView
                 let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
                                 
-                _ = NCCommunication.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, progressHandler: { (progress) in
+                NCCommunication.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, progressHandler: { (progress) in
                                     
                     self.progress(Float(progress.fractionCompleted))
                     

+ 33 - 19
iOSClient/Main/NCMainCommon.swift

@@ -143,22 +143,41 @@ class NCMainCommon: NSObject, NCAudioRecorderViewControllerDelegate, UIDocumentI
         
         var actionReloadDatasource = k_action_NULL
         var metadata = metadata
+        var getSession: URLSession?
         
         if metadata.session.count == 0 { return }
-        guard let session = CCNetworking.shared().getSessionfromSessionDescription(metadata.session) else { return }
+        if metadata.session == k_download_session_default || metadata.session == k_upload_session_default {
+            getSession = NCCommunication.shared.getSessionManager()
+        } else {
+            getSession = CCNetworking.shared().getSessionfromSessionDescription(metadata.session)
+        }
+        guard let session = getSession else { return }
         
         session.getTasksWithCompletionHandler { (dataTasks, uploadTasks, downloadTasks) in
             
             var cancel = false
             
-            // DOWNLOAD
-            if metadata.session.count > 0 && metadata.session.contains("download") {
-                for task in downloadTasks {
-                    if task.taskIdentifier == metadata.sessionTaskIdentifier {
-                        task.cancel()
-                        cancel = true
-                    }
+            for task in dataTasks {
+                if task.taskIdentifier == metadata.sessionTaskIdentifier {
+                    task.cancel()
+                    cancel = true
+                }
+            }
+            for task in uploadTasks {
+                if task.taskIdentifier == metadata.sessionTaskIdentifier {
+                    task.cancel()
+                    cancel = true
+                }
+            }
+            for task in downloadTasks {
+                if task.taskIdentifier == metadata.sessionTaskIdentifier {
+                    task.cancel()
+                    cancel = true
                 }
+            }
+            
+            // DOWNLOAD
+            if metadata.session.contains("download") {
                 if cancel == false {
                     NCManageDatabase.sharedInstance.setMetadataSession("", sessionError: "", sessionSelector: "", sessionTaskIdentifier: Int(k_taskIdentifierDone), status: Int(k_metadataStatusNormal), predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                 }
@@ -166,18 +185,13 @@ class NCMainCommon: NSObject, NCAudioRecorderViewControllerDelegate, UIDocumentI
             }
             
             // UPLOAD
-            if metadata.session.count > 0 && metadata.session.contains("upload") {
-                for task in uploadTasks {
-                    if task.taskIdentifier == metadata.sessionTaskIdentifier {
-                        if uploadStatusForcedStart {
-                            metadata.status = Int(k_metadataStatusUploadForcedStart)
-                            metadata = NCManageDatabase.sharedInstance.addMetadata(metadata) ?? metadata
-                        }
-                        task.cancel()
-                        cancel = true
+            if metadata.session.contains("upload") {
+                if cancel {
+                    if uploadStatusForcedStart {
+                        metadata.status = Int(k_metadataStatusUploadForcedStart)
+                        metadata = NCManageDatabase.sharedInstance.addMetadata(metadata) ?? metadata
                     }
-                }
-                if cancel == false {
+                } else {
                     do {
                         try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
                     }

+ 7 - 8
iOSClient/Networking/NCNetworkingE2EE.swift

@@ -196,6 +196,7 @@ import CFNetwork
             metadata.typeFile = internalContenType.typeFile
             metadata.date = NCUtilityFileSystem.shared.getFileModificationDate(filePath: fileNameLocalPath) as NSDate
             metadata.size = NCUtilityFileSystem.shared.getFileSize(filePath: fileNameLocalPath)
+            metadata.session = k_upload_session_default
             
             if metadata.size > Double(k_max_filesize_E2EE) {
                 NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_uploadedFile), object: nil, userInfo: ["metadata":metadata, "errorCode":k_CCErrorInternalError, "errorDescription":"E2E Error file too big"])
@@ -218,7 +219,8 @@ import CFNetwork
                 CCUtility.moveFile(atPath: fileNamePath, toPath: fileNameLocalPath)
                 extractMetadata.fileName = fileNameIdentifier
                 extractMetadata.e2eEncrypted = true
-                
+                extractMetadata.session = k_upload_session_default
+
                 if extractMetadata.size > Double(k_max_filesize_E2EE) {
                     NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_uploadedFile), object: nil, userInfo: ["metadata":metadata, "errorCode":k_CCErrorInternalError, "errorDescription":"E2E Error file too big"])
                     return
@@ -277,7 +279,7 @@ import CFNetwork
             
             if errorCode == 0 && e2eToken != nil {
                 
-                let task = NCCommunication.shared.upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, dateCreationFile: metadataForUpload.date as Date, dateModificationFile: metadataForUpload.date as Date, addCustomHeaders: ["e2e-token":e2eToken!], progressHandler: { (progress) in
+                NCCommunication.shared.upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, dateCreationFile: metadataForUpload.date as Date, dateModificationFile: metadataForUpload.date as Date, addCustomHeaders: ["e2e-token":e2eToken!], progressHandler: { (progress) in
                     
                     NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_progressTask), object: nil, userInfo: ["account":metadataForUpload.account, "ocId":metadataForUpload.ocId, "serverUrl":metadataForUpload.serverUrl, "status":NSNumber(value: k_metadataStatusInUpload), "progress":NSNumber(value: progress.fractionCompleted), "totalBytes":NSNumber(value: progress.totalUnitCount), "totalBytesExpected":NSNumber(value: progress.completedUnitCount)])
                     
@@ -307,7 +309,6 @@ import CFNetwork
                         
                         if (metadataForUpload.status == k_metadataStatusUploadForcedStart) {
                             
-                            metadataForUpload.session = k_upload_session
                             metadataForUpload.sessionError = ""
                             metadataForUpload.sessionTaskIdentifier = 0
                             metadataForUpload.status = Int(k_metadataStatusInUpload)
@@ -336,14 +337,12 @@ import CFNetwork
                     NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_uploadedFile), object: nil, userInfo: ["metadata":metadataForUpload, "errorCode":errorCode, "errorDescription":errorDescription ?? ""])
                 }
                 
-                guard let taskUpload = task else {
-                    return
-                }
-                
+               
+                /*
                 NCManageDatabase.sharedInstance.setMetadataSession(metadataForUpload.session, sessionError: "", sessionSelector: nil, sessionTaskIdentifier: taskUpload.taskIdentifier, status: Int(k_metadataStatusUploading), predicate: NSPredicate(format: "ocId == %@", metadataForUpload.ocId))
                 
                 NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_uploadFileStart), object: nil, userInfo: ["ocId":metadataForUpload.ocId, "task":taskUpload, "serverUrl":metadataForUpload.serverUrl, "account": metadataForUpload.account])
-                    
+                */
                 print("[LOG] Upload file " + metadataForUpload.fileNameView)
             }
         }

+ 1 - 1
iOSClient/Viewer/NCViewerRichdocument.swift

@@ -145,7 +145,7 @@ class NCViewerRichdocument: WKWebView, WKNavigationDelegate, WKScriptMessageHand
                             NCUtility.sharedInstance.startActivityIndicator(view: self, bottom: 0)
                         }
                         
-                        _ = NCCommunication.shared.download(serverUrlFileName: urlString, fileNameLocalPath: fileNameLocalPath, progressHandler: { (progress) in
+                        NCCommunication.shared.download(serverUrlFileName: urlString, fileNameLocalPath: fileNameLocalPath, progressHandler: { (progress) in
                             
                         }, completionHandler: { (account, etag, date, lenght, errorCode, errorDescription) in