Browse Source

improved code

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 years ago
parent
commit
029aff426d

+ 4 - 0
iOSClient/Data/NCManageDatabase+Metadata.swift

@@ -131,6 +131,10 @@ extension tableMetadata {
         status == NCGlobal.shared.metadataStatusInUpload || status == NCGlobal.shared.metadataStatusUploading
     }
 
+    @objc var isDirectorE2EE: Bool {
+        NCUtility.shared.isDirectoryE2EE(serverUrl: serverUrl, account: account, urlBase: urlBase, userId: userId)
+    }
+
     /// Returns false if the user is lokced out of the file. I.e. The file is locked but by somone else
     func canUnlock(as user: String) -> Bool {
         return !lock || (lockOwner == user && lockOwnerType == 0)

+ 0 - 1
iOSClient/Menu/NCCollectionViewCommon+Menu.swift

@@ -38,7 +38,6 @@ extension NCCollectionViewCommon {
 
         guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(metadata.ocId) else { return }
         let serverUrl = metadata.serverUrl + "/" + metadata.fileName
-        let isDirectoryE2EE = NCUtility.shared.isDirectoryE2EE(metadata: metadata)
         let serverUrlHome = NCUtilityFileSystem.shared.getHomeServer(urlBase: appDelegate.urlBase, userId: appDelegate.userId)
         let isOffline: Bool
 

+ 1 - 2
iOSClient/Menu/NCContextMenu.swift

@@ -102,8 +102,7 @@ class NCContextMenu: NSObject {
 
         if metadata.directory {
 
-            let isDirectoryE2EE = NCUtility.shared.isDirectoryE2EE(metadata: metadata)
-            if isDirectoryE2EE || metadata.e2eEncrypted {
+            if metadata.isDirectorE2EE || metadata.e2eEncrypted {
                 menu.append(favorite)
             } else {
                 menu.append(favorite)

+ 1 - 2
iOSClient/Menu/NCViewer+Menu.swift

@@ -35,7 +35,6 @@ extension NCViewer {
         var titleFavorite = NSLocalizedString("_add_favorites_", comment: "")
         if metadata.favorite { titleFavorite = NSLocalizedString("_remove_favorites_", comment: "") }
         let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-        let isDirectoryE2EE = NCUtility.shared.isDirectoryE2EE(metadata: metadata)
         let isOffline = localFile?.offline == true
 
         //
@@ -243,7 +242,7 @@ extension NCViewer {
         //
         // MODIFY
         //
-        if !isDirectoryE2EE && !metadata.isViewOnly && metadata.contentType != "image/gif" && (metadata.contentType == "com.adobe.pdf" || metadata.contentType == "application/pdf" || metadata.classFile == NKCommon.typeClassFile.image.rawValue) {
+        if !metadata.isDirectorE2EE && !metadata.isViewOnly && metadata.contentType != "image/gif" && (metadata.contentType == "com.adobe.pdf" || metadata.contentType == "application/pdf" || metadata.classFile == NKCommon.typeClassFile.image.rawValue) {
             actions.append(
                 NCMenuAction(
                     title: NSLocalizedString("_modify_", comment: ""),

+ 4 - 7
iOSClient/Networking/NCNetworking.swift

@@ -393,10 +393,9 @@ import Photos
                 completion: @escaping (_ error: NKError) -> () = { error in }) {
 
         let metadata = tableMetadata.init(value: metadata)
-        let isDirectoryE2EE = NCUtility.shared.isDirectoryE2EE(metadata: metadata)
-        NKCommon.shared.writeLog("[INFO] Upload file \(metadata.fileNameView) with Identifier \(metadata.assetLocalIdentifier) with size \(metadata.size) [CHUNCK \(metadata.chunk), E2EE \(isDirectoryE2EE)]")
+        NKCommon.shared.writeLog("[INFO] Upload file \(metadata.fileNameView) with Identifier \(metadata.assetLocalIdentifier) with size \(metadata.size) [CHUNCK \(metadata.chunk), E2EE \(metadata.isDirectorE2EE)]")
 
-        if isDirectoryE2EE {
+        if metadata.isDirectorE2EE {
 #if !EXTENSION_FILE_PROVIDER_EXTENSION && !EXTENSION_WIDGET
             Task {
                 let error = await NCNetworkingE2EEUpload.shared.upload(metadata: metadata, uploadE2EEDelegate: uploadE2EEDelegate)
@@ -1164,10 +1163,9 @@ import Photos
             return completion(NKError())
         }
 
-        let isDirectoryEncrypted = NCUtility.shared.isDirectoryE2EE(metadata: metadata)
         let metadataLive = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata)
 
-        if isDirectoryEncrypted {
+        if metadata.isDirectorE2EE {
 #if !EXTENSION
             Task {
                 if let metadataLive = metadataLive {
@@ -1325,12 +1323,11 @@ import Photos
 
     @objc func renameMetadata(_ metadata: tableMetadata, fileNameNew: String, viewController: UIViewController?, completion: @escaping (_ error: NKError) -> Void) {
 
-        let isDirectoryEncrypted = NCUtility.shared.isDirectoryE2EE(metadata: metadata)
         let metadataLive = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata)
         let fileNameNew = fileNameNew.trimmingCharacters(in: .whitespacesAndNewlines)
         let fileNameNewLive = (fileNameNew as NSString).deletingPathExtension + ".mov"
 
-        if isDirectoryEncrypted {
+        if metadata.isDirectorE2EE {
 #if !EXTENSION
             Task {
                 if let metadataLive = metadataLive {

+ 4 - 4
iOSClient/Networking/NCNetworkingProcessUpload.swift

@@ -114,7 +114,7 @@ class NCNetworkingProcessUpload: NSObject {
             // E2EE
             let uniqueMetadatas = metadatasUpload.unique(map: { $0.serverUrl })
             for metadata in uniqueMetadatas {
-                if NCUtility.shared.isDirectoryE2EE(metadata: metadata) {
+                if metadata.isDirectorE2EE {
                     self.pauseProcess = false
                     return completition(counterUpload)
                 }
@@ -157,20 +157,20 @@ class NCNetworkingProcessUpload: NSObject {
                             for metadata in metadatas where counterUpload < maxConcurrentOperationUpload {
 
                                 // isE2EE
-                                let isDirectoryE2EE = NCUtility.shared.isDirectoryE2EE(metadata: metadata)
+                                let isInDirectorE2EE = metadata.isDirectorE2EE
 
                                 // NO WiFi
                                 if !isWiFi && metadata.session == NCNetworking.shared.sessionIdentifierBackgroundWWan {
                                     continue
                                 }
 
-                                if applicationState != .active && (isDirectoryE2EE || metadata.chunk) {
+                                if applicationState != .active && (isInDirectorE2EE || metadata.chunk) {
                                     continue
                                 }
 
                                 if let metadata = NCManageDatabase.shared.setMetadataStatus(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusInUpload) {
                                     NCNetworking.shared.upload(metadata: metadata)
-                                    if isDirectoryE2EE || metadata.chunk {
+                                    if isInDirectorE2EE || metadata.chunk {
                                         maxConcurrentOperationUpload = 1
                                     }
                                     counterUpload += 1

+ 1 - 1
iOSClient/Networking/NCOperationQueue.swift

@@ -82,7 +82,7 @@ import NextcloudKit
 
     func delete(metadata: tableMetadata, onlyLocalCache: Bool) {
 
-        if NCUtility.shared.isDirectoryE2EE(metadata: metadata) {
+        if metadata.isDirectorE2EE {
             for case let operation as NCOperationDelete in deleteQueueE2EE.operations where operation.metadata.ocId == metadata.ocId {
                 return
             }

+ 1 - 1
iOSClient/Transfers/NCTransfers.swift

@@ -149,7 +149,7 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate {
 
         if action != #selector(startTask(_:)) { return false }
         guard let metadata = metadataTemp else { return false }
-        if NCUtility.shared.isDirectoryE2EE(metadata: metadata) { return false }
+        if metadata.isDirectorE2EE { return false }
 
         if metadata.status == NCGlobal.shared.metadataStatusWaitUpload || metadata.isUpload {
             return true

+ 1 - 2
iOSClient/Utility/CCUtility.m

@@ -1135,12 +1135,11 @@
 {
     NSString *fileNameViewPath = [self getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView];
     NSString *fileNamePath = [self getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileName];
-    BOOL isFolderEncrypted = [[NCUtility shared] isDirectoryE2EEWithMetadata:metadata];
 
     unsigned long long fileNameViewSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:fileNameViewPath error:nil] fileSize];
     unsigned long long fileNameSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:fileNamePath error:nil] fileSize];
 
-    if (isFolderEncrypted == true) {
+    if (metadata.isDirectorE2EE == true) {
         if ((fileNameSize == metadata.size || fileNameViewSize == metadata.size) && fileNameViewSize > 0) {
             return true;
         } else {

+ 1 - 2
iOSClient/Utility/NCCameraRoll.swift

@@ -87,7 +87,6 @@ class NCCameraRoll: NSObject {
         let metadata = tableMetadata.init(value: metadata)
         let chunckSize = CCUtility.getChunkSize() * 1000000
         var compatibilityFormat: Bool = false
-        let isDirectoryE2EE = NCUtility.shared.isDirectoryE2EE(metadata: metadata)
 
         func callCompletionWithError(_ error: Bool = true) {
             if error {
@@ -118,7 +117,7 @@ class NCCameraRoll: NSObject {
             metadata.contentType = "image/jpeg"
             fileNamePath = NSTemporaryDirectory() + fileName
             metadata.fileNameView = fileName
-            if !isDirectoryE2EE {
+            if !metadata.isDirectorE2EE {
                 metadata.fileName = fileName
             }
             compatibilityFormat = true

+ 0 - 3
iOSClient/Utility/NCUtility.swift

@@ -781,9 +781,6 @@ class NCUtility: NSObject {
     func isDirectoryE2EE(file: NKFile) -> Bool {
         return isDirectoryE2EE(serverUrl: file.serverUrl, account: file.account, urlBase: file.urlBase, userId: file.userId)
     }
-    @objc func isDirectoryE2EE(metadata: tableMetadata) -> Bool {
-        return isDirectoryE2EE(serverUrl: metadata.serverUrl, account: metadata.account, urlBase: metadata.urlBase, userId: metadata.userId)
-    }
     @objc func isDirectoryE2EE(serverUrl: String, account: String, urlBase: String, userId: String) -> Bool {
         if serverUrl == NCUtilityFileSystem.shared.getHomeServer(urlBase: urlBase, userId: userId) || serverUrl == ".." { return false }
         if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", account, serverUrl)) {

+ 1 - 1
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCKTVHTTPCache.swift

@@ -33,7 +33,7 @@ class NCKTVHTTPCache: NSObject {
 
     func getVideoURL(metadata: tableMetadata) -> (url: URL?, isProxy: Bool) {
 
-        if CCUtility.fileProviderStorageExists(metadata) || NCUtility.shared.isDirectoryE2EE(metadata: metadata) {
+        if CCUtility.fileProviderStorageExists(metadata) || metadata.isDirectorE2EE {
 
             return (URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)), false)
 

+ 1 - 1
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift

@@ -203,7 +203,7 @@ class NCPlayer: NSObject {
                         }))
                         alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_", value: "No", comment: ""), style: .default, handler: { _ in }))
                         self.viewController?.present(alertController, animated: true)
-                    } else if NCUtility.shared.isDirectoryE2EE(metadata: self.metadata) {
+                    } else if self.metadata.isDirectorE2EE {
                         let alertController = UIAlertController(title: NSLocalizedString("_info_", value: "Info", comment: ""), message: NSLocalizedString("_video_not_streamed_e2ee_", comment: ""), preferredStyle: .alert)
                         alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", value: "Yes", comment: ""), style: .default, handler: { _ in
                             self.downloadVideo(isEncrypted: true)