marinofaggiana 4 lat temu
rodzic
commit
d1ffd86f1f

+ 5 - 6
iOSClient/AppDelegate.m

@@ -240,7 +240,7 @@
     [[NCUtility sharedInstance] deleteAssetLocalIdentifiersWithAccount:self.activeAccount sessionSelector:selectorUploadAutoUpload];
    
     // Brand
-#if defined(HC)
+    #if defined(HC)
     tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
     if (account.hcIsTrial == true || account.hcTrialExpired == true || account.hcNextGroupExpirationGroupExpired == true) {
         
@@ -249,7 +249,7 @@
         
         [self.window.rootViewController presentViewController:vc animated:YES completion:nil];
     }
-#endif
+    #endif
 }
 
 //
@@ -1212,8 +1212,7 @@
                     metadataForUpload.status = k_metadataStatusInUpload;
                     tableMetadata *metadata = [[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
                     
-//                    [[CCNetworking sharedNetworking] uploadFile:metadata taskStatus:k_taskStatusResume];
-                    [[NCNetworkingE2EE shared] uploadWithMetadata:metadata];
+                    [[NCNetworking shared] uploadWithMetadata:metadata e2eEncrypted:true];
                     
                     break;
                                         
@@ -1662,9 +1661,9 @@
 
 - (BOOL)upgrade
 {
-#ifdef DEBUG
+    #ifdef DEBUG
     //self.maintenanceMode = YES;
-#endif
+    #endif
     
     NSString *actualVersion = [CCUtility getVersion];
     NSString *actualBuild = [CCUtility getBuild];

+ 2 - 2
iOSClient/Main/Menu/AppDelegate+Menu.swift

@@ -68,7 +68,7 @@ extension AppDelegate {
             )
         )
 
-#if HC
+        #if HC
         actions.append(
             NCMenuAction(
                 title: NSLocalizedString("_im_create_new_file", tableName: "IMLocalizable", bundle: Bundle.main, value: "", comment: ""),
@@ -78,7 +78,7 @@ extension AppDelegate {
                 }
             )
         )
-#endif
+        #endif
       
         if NCCommunication.shared.isNetworkReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_text}) && !isEncrypted {
             let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_text})!

+ 2 - 2
iOSClient/Main/NCMainCommon.swift

@@ -1023,7 +1023,7 @@ class NCNetworkingMain: NSObject, IMImagemeterViewerDelegate {
     
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
 
-#if HC
+    #if HC
     // IMImagemeterViewerDelegate
     func closeImagemeterViewer(metadata: tableMetadata?, bundleDirectory: String) {
         guard let metadata = metadata else { return }
@@ -1051,7 +1051,7 @@ class NCNetworkingMain: NSObject, IMImagemeterViewerDelegate {
         // Remove bundle directory
         try? FileManager.default.removeItem(atPath: bundleDirectory)
     }
-#endif
+    #endif
     
     @objc func downloadThumbnail(with metadata: tableMetadata, view: Any, indexPath: IndexPath) {
         operationQueueNetworkingMain.addOperation(NCOperationNetworkingMain.init(metadata: metadata, view: view, indexPath: indexPath, networkingFunc: "downloadThumbnail"))

+ 2 - 2
iOSClient/Media/NCMedia.swift

@@ -603,11 +603,11 @@ extension NCMedia {
     func search(lteDate: Date, gteDate: Date, addPast: Bool, insertPrevius: Int,setDistantPast: Bool, debug: String) {
         
         // ----- DEBUG -----
-#if DEBUG
+        #if DEBUG
         let dateFormatter = DateFormatter()
         dateFormatter.dateFormat = "dd-MM-yyyy HH:mm"
         print("[LOG] Search: addPast \(addPast), distantPass: \(setDistantPast), Lte: " + dateFormatter.string(from: lteDate) + " - Gte: " + dateFormatter.string(from: gteDate) + " DEBUG: " + debug)
-#endif
+        #endif
         // -----------------
         
         if (appDelegate.activeAccount == nil || appDelegate.activeAccount.count == 0 || appDelegate.maintenanceMode == true) {

+ 74 - 7
iOSClient/Networking/NCNetworking.swift

@@ -46,7 +46,7 @@ import NCCommunication
        
     func networkReachabilityObserver(_ typeReachability: NCCommunicationCommon.typeReachability) {
         
-#if !EXTENSION
+        #if !EXTENSION
         if typeReachability == NCCommunicationCommon.typeReachability.reachableCellular || typeReachability == NCCommunicationCommon.typeReachability.reachableEthernetOrWiFi {
             
             if !lastReachability {
@@ -63,7 +63,7 @@ import NCCommunication
         }
         
         NotificationCenter.default.post(name: NSNotification.Name(rawValue: k_notificationCenter_setTitleMain), object: nil, userInfo: nil)
-#endif        
+        #endif
     }
     
     func authenticationChallenge(_ challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
@@ -167,7 +167,7 @@ import NCCommunication
         return result
     }
     
-    //MARK: - Download
+    //MARK: - Transfer
     
     @objc func download(metadata: tableMetadata, selector: String, setFavorite: Bool = false) {
         
@@ -205,12 +205,12 @@ import NCCommunication
                 metadata.status = Int(k_metadataStatusNormal)
                 metadata.sessionTaskIdentifier = Int(k_taskIdentifierDone)
                           
-#if !EXTENSION
+                #if !EXTENSION
                 if let result = NCManageDatabase.sharedInstance.getE2eEncryption(predicate: NSPredicate(format: "fileNameIdentifier == %@ AND serverUrl == %@", metadata.fileName, metadata.serverUrl)) {
                     
                     NCEndToEndEncryption.sharedManager()?.decryptFileName(metadata.fileName, fileNameView: metadata.fileNameView, ocId: metadata.ocId, key: result.key, initializationVector: result.initializationVector, authenticationTag: result.authenticationTag)
                 }
-#endif
+                #endif
                 NCManageDatabase.sharedInstance.addLocalFile(metadata: metadata)
                 
             } else if errorCode == Int(CFNetworkErrors.cfurlErrorCancelled.rawValue) {
@@ -229,13 +229,13 @@ import NCCommunication
                 metadata.sessionError = errorDescription
                 metadata.sessionTaskIdentifier = Int(k_taskIdentifierDone)
                 
-#if !EXTENSION
+                #if !EXTENSION
                 if errorCode == 401 || errorCode == 403 {
                     NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: metadata.account)
                 } else if errorCode == Int(CFNetworkErrors.cfurlErrorServerCertificateUntrusted.rawValue) {
                     CCUtility.setCertificateError(metadata.account, error: true)
                 }
-#endif
+                #endif
             }
             
             if let result = NCManageDatabase.sharedInstance.addMetadata(metadata) { metadata = result }
@@ -244,6 +244,73 @@ import NCCommunication
         }
     }
     
+    @objc func upload(metadata: tableMetadata, e2eEncrypted: Bool) {
+           
+        var metadataForUpload: tableMetadata?
+        let internalContenType = NCCommunicationCommon.shared.getInternalContenType(fileName: metadata.fileNameView, contentType: metadata.contentType, directory: false)
+        var fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
+        let fileNameIdentifier = CCUtility.generateRandomIdentifier()!
+           
+        guard let account = NCManageDatabase.sharedInstance.getAccount(predicate: NSPredicate(format: "account == %@", metadata.account)) else {
+            NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_uploadedFile), object: nil, userInfo: ["metadata":metadata, "errorCode":k_CCErrorInternalError, "errorDescription":"Internal error"])
+            return
+        }
+           
+        if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
+               
+            metadata.fileName = fileNameIdentifier
+            metadata.e2eEncrypted = true
+            metadata.contentType = internalContenType.contentType
+            metadata.iconName = internalContenType.iconName
+            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"])
+                return
+            }
+               
+            metadataForUpload = NCManageDatabase.sharedInstance.addMetadata(metadata)
+            
+            #if !EXTENSION
+            if e2eEncrypted {
+                NCNetworkingE2EE.shared.upload(metadataForUpload: metadataForUpload!, account: account)
+            }
+            #endif
+            
+        } else {
+               
+            CCUtility.extractImageVideoFromAssetLocalIdentifier(forUpload: metadata, notification: true) { (extractMetadata, fileNamePath) in
+                   
+                guard let extractMetadata = extractMetadata else {
+                    NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+                    return
+                }
+                       
+                fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(extractMetadata.ocId, fileNameView: extractMetadata.fileNameView)
+                CCUtility.moveFile(atPath: fileNamePath, toPath: fileNameLocalPath)
+                extractMetadata.fileName = fileNameIdentifier
+                extractMetadata.e2eEncrypted = true
+                extractMetadata.session = k_upload_session_default
+
+                if e2eEncrypted && (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
+                }
+                       
+                metadataForUpload = NCManageDatabase.sharedInstance.addMetadata(extractMetadata)
+                
+                #if !EXTENSION
+                if e2eEncrypted {
+                    NCNetworkingE2EE.shared.upload(metadataForUpload: metadataForUpload!, account: account)
+                }
+                #endif
+            }
+        }
+    }
+    
     //MARK: - WebDav Read file, folder
     
     @objc func readFolder(serverUrl: String, account: String, completion: @escaping (_ account: String, _ metadataFolder: tableMetadata?, _ metadatas: [tableMetadata]?, _ errorCode: Int, _ errorDescription: String)->()) {

+ 2 - 58
iOSClient/Networking/NCNetworkingE2EE.swift

@@ -178,64 +178,8 @@ import CFNetwork
     }
     
     //MARK: - Upload
-    @objc func upload(metadata: tableMetadata) {
-        
-        var metadataForUpload: tableMetadata?
-        let internalContenType = NCCommunicationCommon.shared.getInternalContenType(fileName: metadata.fileNameView, contentType: metadata.contentType, directory: false)
-        var fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
-        let fileNameIdentifier = CCUtility.generateRandomIdentifier()!
-        
-        guard let account = NCManageDatabase.sharedInstance.getAccount(predicate: NSPredicate(format: "account == %@", metadata.account)) else {
-            NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_uploadedFile), object: nil, userInfo: ["metadata":metadata, "errorCode":k_CCErrorInternalError, "errorDescription":"Internal error"])
-            return
-        }
-        
-        if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-            
-            metadata.fileName = fileNameIdentifier
-            metadata.e2eEncrypted = true
-            metadata.contentType = internalContenType.contentType
-            metadata.iconName = internalContenType.iconName
-            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"])
-                return
-            }
-            
-            metadataForUpload = NCManageDatabase.sharedInstance.addMetadata(metadata)
-            self.upload(metadataForUpload: metadataForUpload!, account: account)
-            
-        } else {
-            
-            CCUtility.extractImageVideoFromAssetLocalIdentifier(forUpload: metadata, notification: true) { (extractMetadata, fileNamePath) in
-                
-                guard let extractMetadata = extractMetadata else {
-                    NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                    return
-                }
-                
-                fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(extractMetadata.ocId, fileNameView: extractMetadata.fileNameView)
-                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
-                }
-                
-                metadataForUpload = NCManageDatabase.sharedInstance.addMetadata(extractMetadata)
-                self.upload(metadataForUpload: metadataForUpload!, account: account)
-            }
-        }
-    }
-        
-    private func upload(metadataForUpload: tableMetadata, account: tableAccount) {
+    
+    func upload(metadataForUpload: tableMetadata, account: tableAccount) {
         
         let object = tableE2eEncryption()
         var key: NSString?, initializationVector: NSString?, authenticationTag: NSString?

+ 3 - 3
iOSClient/Networking/NCNetworkingNotificationCenter.swift

@@ -89,7 +89,7 @@ import Foundation
                             metadata.typeFile = k_metadataTypeFile_unknown
                         }
                         
-        #if HC
+                        #if HC
                         if metadata.typeFile == k_metadataTypeFile_imagemeter {
                             
                             if !IMUtility.shared.IMUnzip(metadata: metadata) {
@@ -107,12 +107,12 @@ import Foundation
                             
                             return
                         }
-        #else
+                        #else
                         if metadata.typeFile == k_metadataTypeFile_imagemeter {
                             NCMainCommon.sharedInstance.openIn(metadata: metadata, selector: selector)
                             return
                         }
-        #endif
+                        #endif
                         
                         if metadata.typeFile == k_metadataTypeFile_compress || metadata.typeFile == k_metadataTypeFile_unknown {
 

+ 2 - 2
iOSClient/Security/NCEndToEndEncryption.m

@@ -197,10 +197,10 @@
     if(keyBytes)
         free(keyBytes);
     
-#ifdef DEBUG
+    #ifdef DEBUG
     // Save to disk [DEBUG MODE]
     [self saveToDiskPEMWithCert:x509 key:pkey directory:directory];
-#endif
+    #endif
     
     return YES;
 }

+ 2 - 2
iOSClient/Settings/CCManageAccount.m

@@ -300,9 +300,9 @@
         [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"editUserProfile"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
         [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
         [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
-#if defined(HC)
+        #if defined(HC)
         row.action.viewControllerClass = [HCEditProfile class];
-#endif
+        #endif
         if (listAccount.count == 0) row.disabled = @YES;
         [section addFormRow:row];
     }

+ 2 - 2
iOSClient/Settings/NCManageEndToEndEncryption.m

@@ -128,7 +128,7 @@
         [section addFormRow:row];   
     }
     
-#ifdef DEBUG
+    #ifdef DEBUG
     // Section DELETE KEYS -------------------------------------------------
     
     section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"Delete server keys ", nil)];
@@ -151,7 +151,7 @@
     [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
     row.action.formSelector = @selector(deletePrivateKey:);
     [section addFormRow:row];
-#endif
+    #endif
     
     self.tableView.showsVerticalScrollIndicator = NO;
     self.form = form;

+ 2 - 2
iOSClient/Utility/CCUtility.m

@@ -992,13 +992,13 @@
     [CCUtility addSkipBackupAttributeToItemAtURL:[[CCUtility getDirectoryGroup] URLByAppendingPathComponent:k_DirectoryProviderStorage]];
     [CCUtility addSkipBackupAttributeToItemAtURL:[[CCUtility getDirectoryGroup] URLByAppendingPathComponent:k_appUserData]];
     
-#ifdef DEBUG
+    #ifdef DEBUG
     NSLog(@"[LOG] Copy DB on Documents directory");
     NSString *atPathDB = [NSString stringWithFormat:@"%@/nextcloud.realm", [[dirGroup URLByAppendingPathComponent:k_appDatabaseNextcloud] path]];
     NSString *toPathDB = [NSString stringWithFormat:@"%@/nextcloud.realm", [CCUtility getDirectoryDocuments]];
     [[NSFileManager defaultManager] removeItemAtPath:toPathDB error:nil];
     [[NSFileManager defaultManager] copyItemAtPath:atPathDB toPath:toPathDB error:nil];
-#endif
+    #endif
 }
 
 + (NSURL *)getDirectoryGroup