Browse Source

improved code

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 năm trước cách đây
mục cha
commit
a2984616db

+ 3 - 1
iOSClient/Data/NCManageDatabase+Metadata.swift

@@ -680,7 +680,9 @@ extension NCManageDatabase {
             serverUrl = ".."
             serverUrl = ".."
         } else {
         } else {
             fileName = (serverUrl as NSString).lastPathComponent
             fileName = (serverUrl as NSString).lastPathComponent
-            serverUrl = NCUtilityFileSystem.shared.deletingLastPathComponent(account: account, serverUrl: serverUrl)
+            if let path = NCUtilityFileSystem.shared.deleteLastPath(serverUrlPath: serverUrl) {
+                serverUrl = path
+            }
         }
         }
 
 
         guard let result = realm.objects(tableMetadata.self).filter("account == %@ AND serverUrl == %@ AND fileName == %@", account, serverUrl, fileName).first else { return nil }
         guard let result = realm.objects(tableMetadata.self).filter("account == %@ AND serverUrl == %@ AND fileName == %@", account, serverUrl, fileName).first else { return nil }

+ 3 - 1
iOSClient/Main/NCFunctionCenter.swift

@@ -573,7 +573,9 @@ import Photos
             listViewController.insert(vc, at: 0)
             listViewController.insert(vc, at: 0)
 
 
             if serverUrl != homeUrl {
             if serverUrl != homeUrl {
-                serverUrl = NCUtilityFileSystem.shared.deletingLastPathComponent(account: appDelegate.account, serverUrl: serverUrl)
+                if let path = NCUtilityFileSystem.shared.deleteLastPath(serverUrlPath: serverUrl) {
+                    serverUrl = path
+                }
             } else {
             } else {
                 break
                 break
             }
             }

+ 7 - 3
iOSClient/Settings/CCManageAutoUpload.m

@@ -394,8 +394,9 @@
 - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type items:(NSArray *)items overwrite:(BOOL)overwrite copy:(BOOL)copy move:(BOOL)move
 - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type items:(NSArray *)items overwrite:(BOOL)overwrite copy:(BOOL)copy move:(BOOL)move
 {
 {
     if (serverUrl != nil) {
     if (serverUrl != nil) {
-        
-        if ([serverUrl isEqualToString:[[NCUtilityFileSystem shared] getHomeServerWithAccount:appDelegate.account]]) {
+
+        NSString* home = [[NCUtilityFileSystem shared] getHomeServerWithAccount:appDelegate.account];
+        if ([serverUrl isEqualToString:home]) {
             NKError *error = [[NKError alloc] initWithErrorCode:NCGlobal.shared.errorInternalError errorDescription:@"_autoupload_error_select_folder_"];
             NKError *error = [[NKError alloc] initWithErrorCode:NCGlobal.shared.errorInternalError errorDescription:@"_autoupload_error_select_folder_"];
             [[NCContentPresenter shared] messageNotification:@"_error_" error:error delay:[[NCGlobal shared] dismissAfterSecond] type:messageTypeError];
             [[NCContentPresenter shared] messageNotification:@"_error_" error:error delay:[[NCGlobal shared] dismissAfterSecond] type:messageTypeError];
             return;
             return;
@@ -403,7 +404,10 @@
         
         
         // Settings new folder Automatatic upload
         // Settings new folder Automatatic upload
         [[NCManageDatabase shared] setAccountAutoUploadFileName:serverUrl.lastPathComponent];
         [[NCManageDatabase shared] setAccountAutoUploadFileName:serverUrl.lastPathComponent];
-        [[NCManageDatabase shared] setAccountAutoUploadDirectory:[[NCUtilityFileSystem shared] deletingLastPathComponentWithAccount:appDelegate.account serverUrl:serverUrl] urlBase:appDelegate.urlBase account:appDelegate.account];
+        NSString *path = [[NCUtilityFileSystem shared] deleteLastPathWithServerUrlPath:serverUrl home:home];
+        if (path != nil) {
+            [[NCManageDatabase shared] setAccountAutoUploadDirectory:path urlBase:appDelegate.urlBase account:appDelegate.account];
+        }
         // Reload
         // Reload
         [self.tableView reloadData];
         [self.tableView reloadData];
     }
     }

+ 5 - 1
iOSClient/Utility/CCUtility.m

@@ -1356,7 +1356,11 @@
             if (directory.e2eEncrypted == true) {
             if (directory.e2eEncrypted == true) {
                 return true;
                 return true;
             }
             }
-            serverUrl = [[NCUtilityFileSystem shared] deletingLastPathComponentWithAccount:account serverUrl:serverUrl];
+            NSString* home = [[NCUtilityFileSystem shared] getHomeServerWithAccount:account];
+            NSString* path = [[NCUtilityFileSystem shared] deleteLastPathWithServerUrlPath:serverUrl home:home];
+            if (path != nil) {
+                serverUrl = path;
+            }
             directory = [[NCManageDatabase shared] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, serverUrl]];
             directory = [[NCManageDatabase shared] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, serverUrl]];
         }
         }
         
         

+ 1 - 9
iOSClient/Utility/NCUtilityFileSystem.swift

@@ -174,15 +174,7 @@ class NCUtilityFileSystem: NSObject {
         return path
         return path
     }
     }
 
 
-    @objc func deletingLastPathComponent(account: String, serverUrl: String) -> String {
-
-        if getHomeServer(account: account) == serverUrl { return serverUrl }
-        let fileName = (serverUrl as NSString).lastPathComponent
-        let serverUrl = serverUrl.replacingOccurrences(of: "/" + fileName, with: "", options: String.CompareOptions.backwards, range: nil)
-        return serverUrl
-    }
-
-    func deleteLastPath(serverUrlPath: String, home: String? = nil) -> String? {
+    @objc func deleteLastPath(serverUrlPath: String, home: String? = nil) -> String? {
 
 
         var returnString: String?
         var returnString: String?