Эх сурвалжийг харах

coding

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 жил өмнө
parent
commit
e8009e8331

+ 2 - 2
iOSClient/Brand/NCBrand.swift

@@ -324,9 +324,9 @@ class NCBrandColor: NSObject {
         }
         
         createImagesThemingColor()
-        #if !EXTENSION
+#if !EXTENSION
         NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeTheming)
-        #endif
+#endif
     }
 
     private func stepCalc(steps: Int, color1: CGColor, color2: CGColor) -> [CGFloat] {

+ 4 - 4
iOSClient/Data/NCManageDatabase.swift

@@ -111,10 +111,10 @@ class NCManageDatabase: NSObject {
             } catch {
                 if let databaseFileUrlPath = databaseFileUrlPath {
                     do {
-                        #if !EXTENSION
+#if !EXTENSION
                         let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_database_corrupt_")
                         NCContentPresenter.shared.showError(error: error, priority: .max)
-                        #endif
+#endif
                         NKCommon.shared.writeLog("DATABASE CORRUPT: removed")
                         try FileManager.default.removeItem(at: databaseFileUrlPath)
                     } catch {}
@@ -135,10 +135,10 @@ class NCManageDatabase: NSObject {
         } catch {
             if let databaseFileUrlPath = databaseFileUrlPath {
                 do {
-                    #if !EXTENSION
+#if !EXTENSION
                     let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_database_corrupt_")
                     NCContentPresenter.shared.showError(error: error, priority: .max)
-                    #endif
+#endif
                     NKCommon.shared.writeLog("DATABASE CORRUPT: removed")
                     try FileManager.default.removeItem(at: databaseFileUrlPath)
                 } catch {}

+ 33 - 33
iOSClient/Networking/NCNetworking.swift

@@ -79,7 +79,7 @@ import Photos
         return session
     }()
 
-    #if EXTENSION
+#if EXTENSION
     @objc public lazy var sessionManagerBackgroundExtension: URLSession = {
         let configuration = URLSessionConfiguration.background(withIdentifier: sessionIdentifierBackgroundExtension)
         configuration.allowsCellularAccess = true
@@ -91,7 +91,7 @@ import Photos
         let session = URLSession(configuration: configuration, delegate: NKBackground.shared, delegateQueue: OperationQueue.main)
         return session
     }()
-    #endif
+#endif
 
     // REQUESTS
 
@@ -103,19 +103,19 @@ import Photos
     override init() {
         super.init()
 
-        #if EXTENSION
+#if EXTENSION
         _ = sessionIdentifierBackgroundExtension
-        #else
+#else
         _ = sessionManagerBackground
         _ = sessionManagerBackgroundWWan
-        #endif
+#endif
     }
 
     // MARK: - Communication Delegate
 
     func networkReachabilityObserver(_ typeReachability: NKCommon.typeReachability) {
 
-        #if !EXTENSION
+#if !EXTENSION
         if typeReachability == NKCommon.typeReachability.reachableCellular || typeReachability == NKCommon.typeReachability.reachableEthernetOrWiFi {
             if !lastReachability {
                 NCService.shared.startRequestServicesServer()
@@ -129,7 +129,7 @@ import Photos
             lastReachability = false
         }
         networkReachability = typeReachability
-        #endif
+#endif
     }
 
     func authenticationChallenge(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
@@ -148,13 +148,13 @@ import Photos
 
     func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) {
 
-        #if !EXTENSION
+#if !EXTENSION
         if let appDelegate = UIApplication.shared.delegate as? AppDelegate, let completionHandler = appDelegate.backgroundSessionCompletionHandler {
             NKCommon.shared.writeLog("[INFO] Called urlSessionDidFinishEvents for Background URLSession")
             appDelegate.backgroundSessionCompletionHandler = nil
             completionHandler()
         }
-        #endif
+#endif
     }
 
     // MARK: - Pinning check
@@ -194,9 +194,9 @@ import Photos
         if isTrusted {
             completionHandler(URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
         } else {
-            #if !EXTENSION
+#if !EXTENSION
             DispatchQueue.main.async { (UIApplication.shared.delegate as? AppDelegate)?.trustCertificateError(host: host) }
-            #endif
+#endif
             completionHandler(URLSession.AuthChallengeDisposition.performDefaultHandling, nil)
         }
     }
@@ -366,12 +366,12 @@ import Photos
 
                 NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: "", sessionError: "", sessionSelector: selector, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusNormal, etag: etag)
                 NCManageDatabase.shared.addLocalFile(metadata: metadata)
-                #if !EXTENSION
+#if !EXTENSION
                 if let result = NCManageDatabase.shared.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)
                 }
                 CCUtility.setExif(metadata) { _, _, _, _, _ in }
-                #endif
+#endif
                 NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadedFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account, "selector": selector, "error": error])
 
             } else {
@@ -397,12 +397,12 @@ import Photos
         NKCommon.shared.writeLog("[INFO] Upload file \(metadata.fileNameView) with Identifier \(metadata.assetLocalIdentifier) with size \(metadata.size) [CHUNCK \(metadata.chunk), E2EE \(isDirectoryE2EE)]")
 
         if isDirectoryE2EE {
-            #if !EXTENSION_FILE_PROVIDER_EXTENSION && !EXTENSION_WIDGET
+#if !EXTENSION_FILE_PROVIDER_EXTENSION && !EXTENSION_WIDGET
             Task {
                 let error = await NCNetworkingE2EEUpload.shared.upload(metadata: metadata, uploadE2EEDelegate: uploadE2EEDelegate)
                 completion(error)
             }
-            #endif
+#endif
         } else if metadata.chunk {
             uploadChunkedFile(metadata: metadata, start: start, progressHandler: progressHandler) { error in
                 completion(error)
@@ -508,9 +508,9 @@ import Photos
 
     func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: NSDate?, size: Int64, description: String?, task: URLSessionTask, error: NKError) {
         var isApplicationStateActive = false
-        #if !EXTENSION
+#if !EXTENSION
         isApplicationStateActive = UIApplication.shared.applicationState == .active
-        #endif
+#endif
         DispatchQueue.global().async {
             guard self.delegate == nil, let metadata = NCManageDatabase.shared.getMetadataFromOcId(description) else {
                 self.delegate?.uploadComplete?(fileName: fileName, serverUrl: serverUrl, ocId: ocId, etag: etag, date: date, size: size, description: description, task: task, error: error)
@@ -578,10 +578,10 @@ import Photos
                             NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                             NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadCancelFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account])
                         }))
-                        #if !EXTENSION
+#if !EXTENSION
                         let appDelegate = UIApplication.shared.delegate as! AppDelegate
                         appDelegate.window?.rootViewController?.present(alertController, animated: true)
-                        #endif
+#endif
                     }
 
                 } else {
@@ -736,9 +736,9 @@ import Photos
             }
         }
 
-        #if !EXTENSION
+#if !EXTENSION
         NCOperationQueue.shared.downloadCancelAll()
-        #endif
+#endif
     }
 
     func cancelAllDownloadTransfer() {
@@ -753,9 +753,9 @@ import Photos
             }
         }
 
-        #if !EXTENSION
+#if !EXTENSION
         NCOperationQueue.shared.downloadCancelAll()
-        #endif
+#endif
     }
 
     // MARK: - WebDav Read file, folder
@@ -1032,12 +1032,12 @@ import Photos
         let fileName = fileName.trimmingCharacters(in: .whitespacesAndNewlines)
         
         if isDirectoryEncrypted {
-            #if !EXTENSION
+#if !EXTENSION
             Task {
                 let error = await NCNetworkingE2EECreateFolder.shared.createFolder(fileName: fileName, serverUrl: serverUrl, account: account, urlBase: urlBase, userId: userId)
                 completion(error)
             }
-            #endif
+#endif
         } else {
             createFolderPlain(fileName: fileName, serverUrl: serverUrl, account: account, urlBase: urlBase, overwrite: overwrite, completion: completion)
         }
@@ -1168,7 +1168,7 @@ import Photos
         let metadataLive = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata)
 
         if isDirectoryEncrypted {
-            #if !EXTENSION
+#if !EXTENSION
             Task {
                 if let metadataLive = metadataLive {
                     let error = await NCNetworkingE2EEDelete.shared.delete(metadata: metadataLive)
@@ -1183,7 +1183,7 @@ import Photos
                     completion(error)
                 }
             }
-            #endif
+#endif
         } else {
             if metadataLive == nil {
                 self.deleteMetadataPlain(metadata, customHeader: nil, completion: completion)
@@ -1268,11 +1268,11 @@ import Photos
         NextcloudKit.shared.setFavorite(fileName: fileName, favorite: favorite) { account, error in
             if error == .success && metadata.account == account {
                 NCManageDatabase.shared.setMetadataFavorite(ocId: metadata.ocId, favorite: favorite)
-                #if !EXTENSION
+#if !EXTENSION
                 if favorite {
                     NCOperationQueue.shared.synchronizationMetadata(metadata, selector: NCGlobal.shared.selectorReadFile)
                 }
-                #endif
+#endif
                 NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterFavoriteFile, userInfo: ["ocId": ocId, "serverUrl": metadata.serverUrl])
             }
             completion(error)
@@ -1292,11 +1292,11 @@ import Photos
             NCManageDatabase.shared.convertFilesToMetadatas(files, useMetadataFolder: false) { _, _, metadatas in
                 NCManageDatabase.shared.updateMetadatasFavorite(account: account, metadatas: metadatas)
                 if selector != NCGlobal.shared.selectorListingFavorite {
-                    #if !EXTENSION
+#if !EXTENSION
                     for metadata in metadatas {
                         NCOperationQueue.shared.synchronizationMetadata(metadata, selector: selector)
                     }
-                    #endif
+#endif
                 }
                 completion(account, metadatas, error)
             }
@@ -1331,7 +1331,7 @@ import Photos
         let fileNameNewLive = (fileNameNew as NSString).deletingPathExtension + ".mov"
 
         if isDirectoryEncrypted {
-            #if !EXTENSION
+#if !EXTENSION
             Task {
                 if let metadataLive = metadataLive {
                     let error = await NCNetworkingE2EERename.shared.rename(metadata: metadataLive, fileNameNew: fileNameNew)
@@ -1346,7 +1346,7 @@ import Photos
                     DispatchQueue.main.async { completion(error) }
                 }
             }
-            #endif
+#endif
         } else {
             if metadataLive == nil {
                 renameMetadataPlain(metadata, fileNameNew: fileNameNew, completion: completion)

+ 2 - 2
iOSClient/Security/NCEndToEndEncryption.m

@@ -205,10 +205,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;
 }

+ 47 - 65
iOSClient/Settings/NCManageE2EE.swift

@@ -162,12 +162,12 @@ struct NCViewE2EE: View {
 
         VStack {
             VStack {
-
+                
                 if manageE2EE.isEndToEndEnabled {
-
+                    
                     List {
-
-                        Section(header: SectionView(height: 10), footer:Text(manageE2EE.statusOfService + "\n" + "End-to-End Encription " + versionE2EE)) {
+                        
+                        Section(header: SectionView(height: 10), footer:Text(manageE2EE.statusOfService + "\n" + "End-to-End Encryption " + versionE2EE)) {
                             Label {
                                 Text(NSLocalizedString("_e2e_settings_activated_", comment: ""))
                                     .font(NCBrandFont.shared.settings)
@@ -179,17 +179,17 @@ struct NCViewE2EE: View {
                                     .foregroundColor(.green)
                             }
                         }
-
+                        
                         Label {
                             Text(NSLocalizedString("_e2e_settings_read_passphrase_", comment: ""))
                                 .font(NCBrandFont.shared.settings)
                                 .onTapGesture {
-                                if CCUtility.getPasscode().isEmpty {
-                                    NCContentPresenter.shared.showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
-                                } else {
-                                    manageE2EE.requestPasscodeType("readPassphrase")
+                                    if CCUtility.getPasscode().isEmpty {
+                                        NCContentPresenter.shared.showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
+                                    } else {
+                                        manageE2EE.requestPasscodeType("readPassphrase")
+                                    }
                                 }
-                            }
                         } icon: {
                             Image(systemName: "doc.plaintext")
                                 .resizable()
@@ -197,17 +197,17 @@ struct NCViewE2EE: View {
                                 .frame(width: 25, height: 25)
                                 .foregroundColor(Color(UIColor.systemGray))
                         }
-
+                        
                         Label {
                             Text(NSLocalizedString("_e2e_settings_remove_", comment: ""))
                                 .font(NCBrandFont.shared.settings)
                                 .onTapGesture {
-                                if CCUtility.getPasscode().isEmpty {
-                                    NCContentPresenter.shared.showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
-                                } else {
-                                    manageE2EE.requestPasscodeType("removeLocallyEncryption")
+                                    if CCUtility.getPasscode().isEmpty {
+                                        NCContentPresenter.shared.showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
+                                    } else {
+                                        manageE2EE.requestPasscodeType("removeLocallyEncryption")
+                                    }
                                 }
-                            }
                         } icon: {
                             Image(systemName: "trash.circle")
                                 .resizable()
@@ -215,63 +215,45 @@ struct NCViewE2EE: View {
                                 .frame(width: 25, height: 25)
                                 .foregroundColor(Color.red)
                         }
-
-                    #if DEBUG
+                        
+#if DEBUG
                         DeleteCerificateSection()
-                    #endif
+#endif
                     }
+                    
                 } else {
-
-
-                }
-
-
-
-
-                /*
-                if manageE2EE.isEndToEndEnabled {
-                    Text(NSLocalizedString("_e2e_settings_activated_", comment: ""))
-                } else {
-                    Button(action: {
-                        if CCUtility.getPasscode().isEmpty {
-                            NCContentPresenter.shared.showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
-                        } else {
-                            manageE2EE.requestPasscodeType("startE2E")
-                        }
-                    }, label: {
-                        Text(NSLocalizedString("_e2e_settings_start_", comment: ""))
-                    })
-                }
-
-                if manageE2EE.isEndToEndEnabled {
-                    Button(action: {
-                        if CCUtility.getPasscode().isEmpty {
-                            NCContentPresenter.shared.showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
-                        } else {
-                            manageE2EE.requestPasscodeType("readPassphrase")
-                        }
-                    }, label: {
-                        Text(NSLocalizedString("_e2e_settings_read_passphrase_", comment: ""))
-                    })
-                }
-
-                if manageE2EE.isEndToEndEnabled {
-                    Button(action: {
-                        if CCUtility.getPasscode().isEmpty {
-                            NCContentPresenter.shared.showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
-                        } else {
-                            manageE2EE.requestPasscodeType("removeLocallyEncryption")
+                    
+                    List {
+                        
+                        Section(header: SectionView(height: 10), footer:Text(manageE2EE.statusOfService + "\n" + "End-to-End Encryption " + versionE2EE)) {
+                            Label {
+                                Text(NSLocalizedString("_e2e_settings_activated_", comment: ""))
+                                    .font(NCBrandFont.shared.settings)
+                                    .onTapGesture {
+                                        if CCUtility.getPasscode().isEmpty {
+                                            NCContentPresenter.shared.showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
+                                        } else {
+                                            manageE2EE.requestPasscodeType("startE2E")
+                                        }
+                                    }
+                            } icon: {
+                                Image(systemName: "doc.plaintext")
+                                    .resizable()
+                                    .scaledToFit()
+                                    .frame(width: 25, height: 25)
+                                    .foregroundColor(Color(UIColor.systemGray))
+                            }
                         }
-                    }, label: {
-                        Text(NSLocalizedString("_e2e_settings_remove_", comment: ""))
-                    })
+                        
+#if DEBUG
+                        DeleteCerificateSection()
+#endif
+                    }
                 }
-                */
             }
-            //Text("Versione 12")
         }
         .background(Color(UIColor.systemGroupedBackground))
-        .navigationTitle("Cifratura End-To-End")
+        .navigationTitle(NSLocalizedString("_e2e_settings_", comment: ""))
     }
 }
 

+ 2 - 2
iOSClient/Settings/NCManageEndToEndEncryption.m

@@ -122,7 +122,7 @@
         [section addFormRow:row];   
     }
     
-    #ifdef DEBUG
+#ifdef DEBUG
     // Section DELETE KEYS -------------------------------------------------
     
     section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"Delete server keys ", nil)];
@@ -145,7 +145,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;

+ 3 - 3
iOSClient/Utility/NCActivityIndicator.swift

@@ -62,7 +62,7 @@ class NCActivityIndicator: NSObject {
             self.viewActivityIndicator?.layer.masksToBounds = true
             self.viewActivityIndicator?.backgroundColor = .clear
 
-            #if !EXTENSION
+#if !EXTENSION
             if backgroundView == nil {
                 if let window = (UIApplication.shared.connectedScenes.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }.first { $0.isKeyWindow }) {
                     self.viewBackgroundActivityIndicator?.removeFromSuperview()
@@ -74,9 +74,9 @@ class NCActivityIndicator: NSObject {
             } else {
                 self.viewBackgroundActivityIndicator = backgroundView
             }
-            #else
+#else
             self.viewBackgroundActivityIndicator = backgroundView
-            #endif
+#endif
 
             // VIEW ACTIVITY INDICATOR
 

+ 8 - 8
iOSClient/Utility/NCAskAuthorization.swift

@@ -40,9 +40,9 @@ class NCAskAuthorization: NSObject {
         case AVAudioSession.RecordPermission.denied:
             let alert = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_err_permission_microphone_", comment: ""), preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: NSLocalizedString("_open_settings_", comment: ""), style: .default, handler: { _ in
-                #if !EXTENSION
+#if !EXTENSION
                 UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
-                #endif
+#endif
                 completion(false)
             }))
             alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
@@ -78,9 +78,9 @@ class NCAskAuthorization: NSObject {
         case PHAuthorizationStatus.denied, PHAuthorizationStatus.limited, PHAuthorizationStatus.restricted:
             let alert = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_err_permission_photolibrary_", comment: ""), preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: NSLocalizedString("_open_settings_", comment: ""), style: .default, handler: { _ in
-                #if !EXTENSION
+#if !EXTENSION
                 UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
-                #endif
+#endif
                 completion(false)
             }))
             alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
@@ -94,9 +94,9 @@ class NCAskAuthorization: NSObject {
             isRequesting = true
             PHPhotoLibrary.requestAuthorization { allowed in
                 self.isRequesting = false
-                #if !EXTENSION
+#if !EXTENSION
                 DispatchQueue.main.async { (UIApplication.shared.delegate as? AppDelegate)?.hidePrivacyProtectionWindow() }
-                #endif
+#endif
                 DispatchQueue.main.async {
                     if allowed == PHAuthorizationStatus.authorized {
                         completion(true)
@@ -112,7 +112,7 @@ class NCAskAuthorization: NSObject {
         }
     }
 
-    #if !EXTENSION
+#if !EXTENSION
     func checkBackgroundRefreshStatus() {
         switch UIApplication.shared.backgroundRefreshStatus {
         case .available:
@@ -128,5 +128,5 @@ class NCAskAuthorization: NSObject {
             print("Unknown property")
         }
     }
-    #endif
+#endif
 }

+ 2 - 2
iOSClient/Utility/NCUtility.swift

@@ -207,7 +207,7 @@ class NCUtility: NSObject {
         return Array(Set(editor))
     }
 
-    #if !EXTENSION
+#if !EXTENSION
     @objc func removeAllSettings() {
 
         URLCache.shared.memoryCapacity = 0
@@ -226,7 +226,7 @@ class NCUtility: NSObject {
 
         CCUtility.deleteAllChainStore()
     }
-    #endif
+#endif
 
     @objc func permissionsContainsString(_ metadataPermissions: String, permissions: String) -> Bool {