Marino Faggiana пре 6 година
родитељ
комит
9a8c7e77d6

+ 28 - 25
File Provider Extension/FileProviderEnumerator.swift

@@ -148,36 +148,39 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
                 
                 if self.providerData.listServerUrlEtag[serverUrl] == nil || self.providerData.listServerUrlEtag[serverUrl] != metadata!.etag || metadatasFromDB == nil {
                     
-                    ocNetworking?.readFolder(serverUrl, depth: "1", account: self.providerData.account, success: { (account, metadatas, metadataFolder) in
+                    ocNetworking?.readFolder(withAccount: self.providerData.account, serverUrl: serverUrl, depth: "1", completion: { (account, metadatas, metadataFolder, message, errorCode) in
                         
-                        if metadataFolder != nil {
-                            // Update directory etag
-                            NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: metadataFolder!.etag, fileID: metadataFolder!.fileID, encrypted: metadataFolder!.e2eEncrypted, account: self.providerData.account)
-                            // Save etag for this serverUrl
-                            self.providerData.listServerUrlEtag[serverUrl] = metadataFolder!.etag
-                        }
-                        
-                        if metadatas != nil {
+                        if errorCode == 0 && account == self.providerData.account {
                             
-                            NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND (status == %d OR status == %d)", self.providerData.account, serverUrl, k_metadataStatusNormal, k_metadataStatusHide))
-                            
-                            NCManageDatabase.sharedInstance.setDateReadDirectory(serverUrl: serverUrl, account: self.providerData.account) 
-
-                            let metadatasInDownload = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND (status == %d OR status == %d OR status == %d OR status == %d)", self.providerData.account, serverUrl, k_metadataStatusWaitDownload, k_metadataStatusInDownload, k_metadataStatusDownloading, k_metadataStatusDownloadError), sorted: nil, ascending: false)
+                            if metadataFolder != nil {
+                                // Update directory etag
+                                NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: metadataFolder!.etag, fileID: metadataFolder!.fileID, encrypted: metadataFolder!.e2eEncrypted, account: self.providerData.account)
+                                // Save etag for this serverUrl
+                                self.providerData.listServerUrlEtag[serverUrl] = metadataFolder!.etag
+                            }
                             
-                            _ = NCManageDatabase.sharedInstance.addMetadatas(metadatas as! [tableMetadata])
-                            if metadatasInDownload != nil {
-                                _ = NCManageDatabase.sharedInstance.addMetadatas(metadatasInDownload!)
+                            if metadatas != nil {
+                                
+                                NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND (status == %d OR status == %d)", self.providerData.account, serverUrl, k_metadataStatusNormal, k_metadataStatusHide))
+                                
+                                NCManageDatabase.sharedInstance.setDateReadDirectory(serverUrl: serverUrl, account: self.providerData.account)
+                                
+                                let metadatasInDownload = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND (status == %d OR status == %d OR status == %d OR status == %d)", self.providerData.account, serverUrl, k_metadataStatusWaitDownload, k_metadataStatusInDownload, k_metadataStatusDownloading, k_metadataStatusDownloadError), sorted: nil, ascending: false)
+                                
+                                _ = NCManageDatabase.sharedInstance.addMetadatas(metadatas as! [tableMetadata])
+                                if metadatasInDownload != nil {
+                                    _ = NCManageDatabase.sharedInstance.addMetadatas(metadatasInDownload!)
+                                }
                             }
+                            
+                            metadatasFromDB = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.providerData.account, serverUrl), sorted: "fileName", ascending: true)
+                            
+                            self.selectFirstPageItems(metadatasFromDB, observer: observer)
+                            
+                        } else if errorCode != 0 {
+                            
+                            self.selectFirstPageItems(metadatasFromDB, observer: observer)
                         }
-                        
-                        metadatasFromDB = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.providerData.account, serverUrl), sorted: "fileName", ascending: true)
-                        
-                        self.selectFirstPageItems(metadatasFromDB, observer: observer)
-                        
-                    }, failure: { (account, errorMessage, errorCode) in
-                        
-                        self.selectFirstPageItems(metadatasFromDB, observer: observer)
                     })
                     
                 } else {

+ 92 - 86
iOSClient/Login/CCLogin.m

@@ -169,52 +169,55 @@
     if ([self.baseUrl.text hasSuffix:@"/"])
         self.baseUrl.text = [self.baseUrl.text substringToIndex:[self.baseUrl.text length] - 1];
     
-    OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:self metadataNet:nil withUser:@"" withUserID:@"" withPassword:@"" withUrl:nil];
-    [ocNetworking serverStatus:self.baseUrl.text success:^(NSString *serverProductName, NSInteger versionMajor, NSInteger versionMicro, NSInteger versionMinor) {
+    OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:self metadataNet:nil withUser:nil withUserID:nil withPassword:nil withUrl:nil];
+    [ocNetworking serverStatusUrl:self.baseUrl.text completion:^(NSString *serverProductName, NSInteger versionMajor, NSInteger versionMicro, NSInteger versionMinor, NSString *message, NSInteger errorCode) {
         
-        [self.activity stopAnimating];
-        self.login.enabled = YES;
-        
-        // Login Flow
-        if (_user.hidden && _password.hidden && versionMajor >= k_flow_version_available) {
-            
-            appDelegate.activeLoginWeb = [CCLoginWeb new];
-            appDelegate.activeLoginWeb.loginType = _loginType;
-            appDelegate.activeLoginWeb.delegate = self;
-            appDelegate.activeLoginWeb.urlBase = self.baseUrl.text;
+        if (errorCode == 0) {
             
-            [appDelegate.activeLoginWeb open:self];
-        }
-        
-        // NO Login Flow available
-        if (versionMajor < k_flow_version_available) {
-            
-            [self.loginTypeView setHidden:YES];
-            
-            _imageUser.hidden = NO;
-            _user.hidden = NO;
-            _imagePassword.hidden = NO;
-            _password.hidden = NO;
+            [self.activity stopAnimating];
+            self.login.enabled = YES;
             
-            [_user becomeFirstResponder];
-        }
-        
-    } failure:^(NSString *message, NSInteger errorCode) {
-        
-        [self.activity stopAnimating];
-        self.login.enabled = YES;
-        
-        if (errorCode == NSURLErrorServerCertificateUntrusted) {
+            // Login Flow
+            if (_user.hidden && _password.hidden && versionMajor >= k_flow_version_available) {
+                
+                appDelegate.activeLoginWeb = [CCLoginWeb new];
+                appDelegate.activeLoginWeb.loginType = _loginType;
+                appDelegate.activeLoginWeb.delegate = self;
+                appDelegate.activeLoginWeb.urlBase = self.baseUrl.text;
+                
+                [appDelegate.activeLoginWeb open:self];
+            }
             
-            [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
+            // NO Login Flow available
+            if (versionMajor < k_flow_version_available) {
+                
+                [self.loginTypeView setHidden:YES];
+                
+                _imageUser.hidden = NO;
+                _user.hidden = NO;
+                _imagePassword.hidden = NO;
+                _password.hidden = NO;
+                
+                [_user becomeFirstResponder];
+            }
             
         } else {
             
-            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_connection_error_", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
-            UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
+            [self.activity stopAnimating];
+            self.login.enabled = YES;
             
-            [alertController addAction:okAction];
-            [self presentViewController:alertController animated:YES completion:nil];
+            if (errorCode == NSURLErrorServerCertificateUntrusted) {
+                
+                [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:message viewController:self delegate:self];
+                
+            } else {
+                
+                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_connection_error_", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
+                UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
+                
+                [alertController addAction:okAction];
+                [self presentViewController:alertController animated:YES completion:nil];
+            }
         }
     }];
 }
@@ -295,62 +298,65 @@
         self.login.enabled = NO;
         [self.activity startAnimating];
 
-        [ocNetworking checkServer:[NSString stringWithFormat:@"%@%@", url, k_webDAV] success:^{
+        [ocNetworking checkServerUrl:[NSString stringWithFormat:@"%@%@", url, k_webDAV] completion:^(NSString *message, NSInteger errorCode) {
             
-            [self.activity stopAnimating];
-            
-            // account
-            NSString *account = [NSString stringWithFormat:@"%@ %@", user, url];
-            
-            if (_loginType == k_login_Modify_Password) {
-                
-                // Change Password
-                tableAccount *tbAccount = [[NCManageDatabase sharedInstance] setAccountPassword:account password:password];
-                
-                // Setting appDelegate active account
-                [appDelegate settingActiveAccount:tbAccount.account activeUrl:tbAccount.url activeUser:tbAccount.user activeUserID:tbAccount.userID activePassword:tbAccount.password];
-                
-                [self.delegate loginSuccess:_loginType];
-                
-                [self dismissViewControllerAnimated:YES completion:nil];
-                
-            } else {
-
-                // STOP Intro
-                [CCUtility setIntro:YES];
+            if (errorCode == 0) {
                 
-                // LOGOUT
-                [appDelegate unsubscribingNextcloudServerPushNotification];
+                [self.activity stopAnimating];
                 
-                [[NCManageDatabase sharedInstance] deleteAccount:account];
-                [[NCManageDatabase sharedInstance] addAccount:account url:url user:user password:password loginFlow:false];
+                // account
+                NSString *account = [NSString stringWithFormat:@"%@ %@", user, url];
                 
-                tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:account];
-                
-                // Setting appDelegate active account
-                [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:tableAccount.password];
-                
-                [self.delegate loginSuccess:_loginType];
-                
-                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+                if (_loginType == k_login_Modify_Password) {
+                    
+                    // Change Password
+                    tableAccount *tbAccount = [[NCManageDatabase sharedInstance] setAccountPassword:account password:password];
+                    
+                    // Setting appDelegate active account
+                    [appDelegate settingActiveAccount:tbAccount.account activeUrl:tbAccount.url activeUser:tbAccount.user activeUserID:tbAccount.userID activePassword:tbAccount.password];
+                    
+                    [self.delegate loginSuccess:_loginType];
+                    
                     [self dismissViewControllerAnimated:YES completion:nil];
-                });
-            }
-            
-        } failure:^(NSString *message, NSInteger errorCode) {
-            
-            self.login.enabled = YES;
-            [self.activity stopAnimating];
-            
-            if (errorCode != NSURLErrorServerCertificateUntrusted) {
+                    
+                } else {
+                    
+                    // STOP Intro
+                    [CCUtility setIntro:YES];
+                    
+                    // LOGOUT
+                    [appDelegate unsubscribingNextcloudServerPushNotification];
+                    
+                    [[NCManageDatabase sharedInstance] deleteAccount:account];
+                    [[NCManageDatabase sharedInstance] addAccount:account url:url user:user password:password loginFlow:false];
+                    
+                    tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:account];
+                    
+                    // Setting appDelegate active account
+                    [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:tableAccount.password];
+                    
+                    [self.delegate loginSuccess:_loginType];
+                    
+                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+                        [self dismissViewControllerAnimated:YES completion:nil];
+                    });
+                }
                 
-                NSString *messageAlert = [NSString stringWithFormat:@"%@.\n%@", NSLocalizedString(@"_not_possible_connect_to_server_", nil), message];
+            } else {
                 
-                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:messageAlert preferredStyle:UIAlertControllerStyleAlert];
-                UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
+                self.login.enabled = YES;
+                [self.activity stopAnimating];
                 
-                [alertController addAction:okAction];
-                [self presentViewController:alertController animated:YES completion:nil];
+                if (errorCode != NSURLErrorServerCertificateUntrusted) {
+                    
+                    NSString *messageAlert = [NSString stringWithFormat:@"%@.\n%@", NSLocalizedString(@"_not_possible_connect_to_server_", nil), message];
+                    
+                    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:messageAlert preferredStyle:UIAlertControllerStyleAlert];
+                    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
+                    
+                    [alertController addAction:okAction];
+                    [self presentViewController:alertController animated:YES completion:nil];
+                }
             }
         }];
     }

+ 19 - 17
iOSClient/Main/CCMain.m

@@ -1216,7 +1216,6 @@
         // Enable change user
         [_imageTitleHome setUserInteractionEnabled:YES];
         
-        _loadingFolder = NO;
         [self tableViewReloadData];
     }
     
@@ -1274,26 +1273,29 @@
     [self tableViewReloadData];
     
     OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:nil withUserID:nil withPassword:nil withUrl:nil];
-    [ocNetworking readFolder:serverUrl depth:@"1" account:appDelegate.activeAccount success:^(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder) {
-        
-        [self insertMetadatasWithAccount:account serverUrl:serverUrl metadataFolder:metadataFolder metadatas:metadatas];
-        
-    } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
+    [ocNetworking readFolderWithAccount:appDelegate.activeAccount serverUrl:serverUrl depth:@"1" completion:^(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder, NSString *message, NSInteger errorCode) {
         
-        _loadingFolder = NO;
-        
-        // Unauthorized
-        if (errorCode == kOCErrorServerUnauthorized) {
+        if (errorCode == 0) {
+            
+            [self insertMetadatasWithAccount:account serverUrl:serverUrl metadataFolder:metadataFolder metadatas:metadatas];
             
-            [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
-       
         } else {
-        
-            [self tableViewReloadData];
-            [_imageTitleHome setUserInteractionEnabled:YES];
-            [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
-            [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl fileID:nil action:k_action_NULL];
+            
+            // Unauthorized
+            if (errorCode == kOCErrorServerUnauthorized) {
+                
+                [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
+                
+            } else {
+                
+                [self tableViewReloadData];
+                [_imageTitleHome setUserInteractionEnabled:YES];
+                [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
+                [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl fileID:nil action:k_action_NULL];
+            }
         }
+        
+        _loadingFolder = NO;
     }];
 }
 

+ 17 - 19
iOSClient/Move/CCMove.m

@@ -298,44 +298,42 @@
 - (void)readFolder
 {
     OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:nil withUserID:nil withPassword:nil withUrl:nil];
-    [ocNetworking readFolder:_serverUrl depth:@"1" account:activeAccount success:^(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder) {
-        
-        if ([account isEqualToString:activeAccount]) {
+    [ocNetworking readFolderWithAccount:activeAccount serverUrl:_serverUrl depth:@"1" completion:^(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder, NSString *message, NSInteger errorCode) {
         
+        if (errorCode == 0 && [account isEqualToString:activeAccount]) {
+            
             // Update directory etag
             [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:_serverUrl serverUrlTo:nil etag:metadataFolder.etag fileID:metadataFolder.fileID encrypted:metadataFolder.e2eEncrypted account:activeAccount];
             [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND (status == %d OR status == %d)", activeAccount, _serverUrl, k_metadataStatusNormal, k_metadataStatusHide]];
             [[NCManageDatabase sharedInstance] setDateReadDirectoryWithServerUrl:_serverUrl account:activeAccount];
-        
+            
             NSArray *metadatasInDownload = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND (status == %d OR status == %d OR status == %d OR status == %d)", activeAccount, _serverUrl, k_metadataStatusWaitDownload, k_metadataStatusInDownload, k_metadataStatusDownloading, k_metadataStatusDownloadError] sorted:nil ascending:NO];
-        
+            
             // insert in Database
             (void)[[NCManageDatabase sharedInstance] addMetadatas:metadatas];
             // reinsert metadatas in Download
             if (metadatasInDownload) {
                 (void)[[NCManageDatabase sharedInstance] addMetadatas:metadatasInDownload];
             }
+            
+        } else if (errorCode != 0) {
+            
+            self.move.enabled = NO;
+            
+            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_",nil) message:message preferredStyle:UIAlertControllerStyleAlert];
+            
+            [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+            }]];
+            
+            [self presentViewController:alertController animated:YES completion:nil];
         }
-     
-        _loadingFolder = NO;
-        
-        [self.tableView reloadData];
-        
-    } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
         
         _loadingFolder = NO;
-        self.move.enabled = NO;
         
         [self.tableView reloadData];
         
-        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_",nil) message:message preferredStyle:UIAlertControllerStyleAlert];
-        
-        [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-        }]];
-        
-        [self presentViewController:alertController animated:YES completion:nil];
     }];
-
+    
     _loadingFolder = YES;
     [self.tableView reloadData];
 }

+ 7 - 8
iOSClient/Networking/NCService.swift

@@ -370,16 +370,15 @@ class NCService: NSObject, OCNetworkingDelegate {
     private func requestServerStatus() {
 
         let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: appDelegate.activeUser, withUserID: appDelegate.activeUserID, withPassword: appDelegate.activePassword, withUrl: appDelegate.activeUrl)
-        ocNetworking?.serverStatus(appDelegate.activeUrl, success: { (serverProductName, versionMajor, versionMicro, versionMinor) in
-            
-            if serverProductName == "owncloud" {
-                self.appDelegate.messageNotification("_warning_", description: "_warning_owncloud_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.info, errorCode: Int(k_CCErrorInternalError))
-            } else if versionMajor <= k_nextcloud_unsupported {
-                self.appDelegate.messageNotification("_warning_", description: "_warning_unsupported_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.info, errorCode: Int(k_CCErrorInternalError))
+        ocNetworking?.serverStatusUrl(appDelegate.activeUrl, completion: { (serverProductName, versionMajor, versionMicro, versionMinor, message, errorCode) in
+            if errorCode == 0 {
+                if serverProductName == "owncloud" {
+                    self.appDelegate.messageNotification("_warning_", description: "_warning_owncloud_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.info, errorCode: Int(k_CCErrorInternalError))
+                } else if versionMajor <= k_nextcloud_unsupported {
+                    self.appDelegate.messageNotification("_warning_", description: "_warning_unsupported_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.info, errorCode: Int(k_CCErrorInternalError))
+                }
             }
             
-        }, failure: { (message, errorCode) in
-            //
         })
     }
 }

+ 4 - 4
iOSClient/Networking/OCNetworking.h

@@ -42,8 +42,8 @@
 @property (nonatomic, assign) BOOL isExecuting;
 @property (nonatomic, assign) BOOL isFinished;
 
-- (void)checkServer:(NSString *)serverUrl success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
-- (void)serverStatus:(NSString *)serverUrl success:(void(^)(NSString *serverProductName, NSInteger versionMajor, NSInteger versionMicro, NSInteger versionMinor))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
+- (void)checkServerUrl:(NSString *)serverUrl completion:(void (^)(NSString *message, NSInteger errorCode))completion;
+- (void)serverStatusUrl:(NSString *)serverUrl completion:(void(^)(NSString *serverProductName, NSInteger versionMajor, NSInteger versionMicro, NSInteger versionMinor, NSString *message, NSInteger errorCode))completion;
 
 - (NSURLSessionTask *)downloadFileNameServerUrl:(NSString *)fileNameServerUrl fileNameLocalPath:(NSString *)fileNameLocalPath communication:(OCCommunication *)communication success:(void (^)(int64_t length, NSString *etag, NSDate *date))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 
@@ -53,9 +53,9 @@
 
 //- (void)downloadThumbnailWithMetadata:(tableMetadata*)metadata withWidth:(CGFloat)width andHeight:(CGFloat)height completion:(void (^)(NSString *message, NSInteger errorCode))completion;
 - (void)downloadPreviewWithMetadata:(tableMetadata*)metadata withWidth:(CGFloat)width andHeight:(CGFloat)height completion:(void (^)(NSString *message, NSInteger errorCode))completion;
-- (void)downloadPreviewTrashWithFileID:(NSString *)fileID fileName:(NSString *)fileName account:(NSString *)account completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
+- (void)downloadPreviewTrashWithAccount:(NSString *)account FileID:(NSString *)fileID fileName:(NSString *)fileName completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
 
-- (void)readFolder:(NSString *)serverUrl depth:(NSString *)depth account:(NSString *)account success:(void(^)(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder))success failure:(void (^)(NSString *account, NSString *message, NSInteger errorCode))failure;
+- (void)readFolderWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl depth:(NSString *)depth completion:(void(^)(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder, NSString *message, NSInteger errorCode))completion;
 
 - (void)readFile:(NSString *)fileName serverUrl:(NSString *)serverUrl account:(NSString *)account success:(void(^)(NSString *account, tableMetadata *metadata))success failure:(void (^)(NSString *account, NSString *message, NSInteger errorCode))failure;
 

+ 13 - 13
iOSClient/Networking/OCNetworking.m

@@ -132,7 +132,7 @@
 #pragma mark ===== Server =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)checkServer:(NSString *)serverUrl success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure
+- (void)checkServerUrl:(NSString *)serverUrl completion:(void (^)(NSString *message, NSInteger errorCode))completion
 {
     OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
     
@@ -141,7 +141,7 @@
         
     [communication checkServer:serverUrl onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
         
-        success();
+        completion(nil, 0);
             
     } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
         
@@ -157,11 +157,11 @@
         else
             message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
     
-        failure(message, errorCode);
+        completion(message, errorCode);
     }];
 }
 
-- (void)serverStatus:(NSString *)serverUrl success:(void(^)(NSString *serverProductName, NSInteger versionMajor, NSInteger versionMicro, NSInteger versionMinor))success failure:(void (^)(NSString *message, NSInteger errorCode))failure
+- (void)serverStatusUrl:(NSString *)serverUrl completion:(void(^)(NSString *serverProductName, NSInteger versionMajor, NSInteger versionMicro, NSInteger versionMinor, NSString *message, NSInteger errorCode))completion
 {
     NSString *urlTest = [serverUrl stringByAppendingString:k_serverStatus];
     
@@ -200,7 +200,7 @@
                 else
                     message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
                 
-                failure(message, errorCode);
+                completion(nil, 0, 0, 0, message, errorCode);
                 
             } else {
                 
@@ -216,7 +216,7 @@
                 NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
                 
                 if (error) {
-                    failure(error.description, error.code);
+                    completion(nil, 0, 0, 0, error.description, error.code);
                     return;
                 }
                 
@@ -237,7 +237,7 @@
                     versionMicro = [arrayVersion[2] integerValue];
                 }
                 
-                success(serverProductName, versionMajor, versionMicro, versionMinor);
+                completion(serverProductName, versionMajor, versionMicro, versionMinor, nil, 0);
             }
         });
         
@@ -441,7 +441,7 @@
 }
 */
 
-- (void)downloadPreviewTrashWithFileID:(NSString *)fileID fileName:(NSString *)fileName account:(NSString *)account completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
+- (void)downloadPreviewTrashWithAccount:(NSString *)account FileID:(NSString *)fileID fileName:(NSString *)fileName completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
 {
     NSString *file = [NSString stringWithFormat:@"%@/%@.ico", [CCUtility getDirectoryProviderStorageFileID:fileID], fileName];
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
@@ -528,11 +528,11 @@
 #pragma mark ===== Read Folder =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)readFolder:(NSString *)serverUrl depth:(NSString *)depth account:(NSString *)account success:(void(^)(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder))success failure:(void (^)(NSString *account, NSString *message, NSInteger errorCode))failure
+- (void)readFolderWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl depth:(NSString *)depth completion:(void(^)(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
-        failure(account, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
+        completion(account, nil, nil, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
     }
     
     OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
@@ -550,7 +550,7 @@
                 
             [appDelegate messageNotification:@"Server error" description:@"Read Folder WebDAV : [items NULL] please fix" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
 #endif
-            failure(account, NSLocalizedString(@"Read Folder WebDAV : [items NULL] please fix", nil), k_CCErrorInternalError);
+            completion(account, nil, nil, NSLocalizedString(@"Read Folder WebDAV : [items NULL] please fix", nil), k_CCErrorInternalError);
 
         } else {
                 
@@ -615,7 +615,7 @@
                 }
                     
                 dispatch_async(dispatch_get_main_queue(), ^{
-                    success(account, metadatas, metadataFolder);
+                    completion(account, metadatas, metadataFolder, nil, 0);
                 });
             });
         }
@@ -641,7 +641,7 @@
         // Activity
         [[NCManageDatabase sharedInstance] addActivityClient:serverUrl fileID:@"" action:k_activityDebugActionReadFolder selector:@"" note:[error.userInfo valueForKey:@"NSLocalizedDescription"] type:k_activityTypeFailure verbose:k_activityVerboseHigh activeUrl:tableAccount.url];
 
-        failure(account, message, errorCode);
+        completion(account, nil, nil, message, errorCode);
     }];
 }
 

+ 11 - 16
iOSClient/Select/NCSelect.swift

@@ -475,9 +475,9 @@ class NCSelect: UIViewController ,UICollectionViewDataSource, UICollectionViewDe
         collectionView.reloadData()
         
         let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: nil, withUserID: nil, withPassword: nil, withUrl: nil)
-        ocNetworking?.readFolder(serverUrl, depth: "1", account: appDelegate.activeAccount, success: { (account, metadatas, metadataFolder) in
+        ocNetworking?.readFolder(withAccount: appDelegate.activeAccount, serverUrl: serverUrl, depth: "1", completion: { (account, metadatas, metadataFolder, message, errorCode) in
             
-            if account == self.appDelegate.activeAccount {
+            if errorCode == 0 && account == self.appDelegate.activeAccount {
             
                 self.metadataFolder = metadataFolder
                 
@@ -492,20 +492,15 @@ class NCSelect: UIViewController ,UICollectionViewDataSource, UICollectionViewDe
                     
                     _ = NCManageDatabase.sharedInstance.addMetadatas(metadatasInDownload)
                 }
-            }
-            
-            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
-                self.networkInProgress = false
-                self.loadDatasource(withLoadFolder: false)
-            }
-            
-        }, failure: { (account, message, errorCode) in
-                        
-            self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
-            
-            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
-                self.networkInProgress = false
-                self.loadDatasource(withLoadFolder: false)
+                
+            } else if errorCode != 0 {
+                
+                self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+                
+                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
+                    self.networkInProgress = false
+                    self.loadDatasource(withLoadFolder: false)
+                }
             }
         })
     }

+ 105 - 107
iOSClient/Synchronize/CCSynchronize.m

@@ -61,145 +61,143 @@
 - (void)readFolder:(NSString *)serverUrl selector:(NSString *)selector
 {
     OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:nil withUserID:nil withPassword:nil withUrl:nil];
-    [ocNetworking readFolder:serverUrl depth:@"1" account:appDelegate.activeAccount success:^(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder) {
+    [ocNetworking readFolderWithAccount:appDelegate.activeAccount serverUrl:serverUrl depth:@"1" completion:^(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder, NSString *message, NSInteger errorCode) {
         
-        tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
-        if (tableAccount == nil) {
-            return;
-        }
-        
-        // Add/update self Folder
-        if (!metadataFolder || !metadatas || [metadatas count] == 0) {
-            if (metadataFolder.serverUrl != nil) {
-                [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataFolder.serverUrl fileID:nil action:k_action_NULL];
-            }
-            return;
-        }
-        
-        // Add metadata and update etag Directory
-        (void)[[NCManageDatabase sharedInstance] addMetadata:metadataFolder];
-        [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:serverUrl serverUrlTo:nil etag:metadataFolder.etag fileID:metadataFolder.fileID encrypted:metadataFolder.e2eEncrypted account:account];
-        
-        // reload folder ../ *
-        [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataFolder.serverUrl fileID:nil action:k_action_NULL];
-        
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
-            
-            NSMutableArray *metadatasForVerifyChange = [NSMutableArray new];
-            NSMutableArray *addMetadatas = [NSMutableArray new];
+        if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
             
-            NSArray *recordsInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND session != ''", account, serverUrl] sorted:nil ascending:NO];
+            tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
+            if (tableAccount == nil) {
+                return;
+            }
             
-            // ----- Test : (DELETE) -----
+            // Add/update self Folder
+            if (!metadataFolder || !metadatas || [metadatas count] == 0) {
+                if (metadataFolder.serverUrl != nil) {
+                    [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataFolder.serverUrl fileID:nil action:k_action_NULL];
+                }
+                return;
+            }
             
-            NSMutableArray *metadatasNotPresents = [NSMutableArray new];
+            // Add metadata and update etag Directory
+            (void)[[NCManageDatabase sharedInstance] addMetadata:metadataFolder];
+            [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:serverUrl serverUrlTo:nil etag:metadataFolder.etag fileID:metadataFolder.fileID encrypted:metadataFolder.e2eEncrypted account:account];
             
-            NSArray *tableMetadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND session == ''", account, serverUrl] sorted:nil ascending:NO];
+            // reload folder ../ *
+            [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadataFolder.serverUrl fileID:nil action:k_action_NULL];
             
-            for (tableMetadata *record in tableMetadatas) {
+            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
                 
-                BOOL fileIDFound = NO;
+                NSMutableArray *metadatasForVerifyChange = [NSMutableArray new];
+                NSMutableArray *addMetadatas = [NSMutableArray new];
                 
-                for (tableMetadata *metadata in metadatas) {
-                    
-                    if ([record.fileID isEqualToString:metadata.fileID]) {
-                        fileIDFound = YES;
-                        break;
-                    }
-                }
+                NSArray *recordsInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND session != ''", account, serverUrl] sorted:nil ascending:NO];
                 
-                if (!fileIDFound)
-                    [metadatasNotPresents addObject:record];
-            }
-            
-            // delete metadata not present
-            for (tableMetadata *metadata in metadatasNotPresents) {
+                // ----- Test : (DELETE) -----
+                
+                NSMutableArray *metadatasNotPresents = [NSMutableArray new];
                 
-                [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID] error:nil];
+                NSArray *tableMetadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND session == ''", account, serverUrl] sorted:nil ascending:NO];
                 
-                if (metadata.directory && serverUrl) {
+                for (tableMetadata *record in tableMetadatas) {
                     
-                    NSString *dirForDelete = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileName];
+                    BOOL fileIDFound = NO;
+                    
+                    for (tableMetadata *metadata in metadatas) {
+                        
+                        if ([record.fileID isEqualToString:metadata.fileID]) {
+                            fileIDFound = YES;
+                            break;
+                        }
+                    }
                     
-                    [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:dirForDelete account:metadata.account];
+                    if (!fileIDFound)
+                        [metadatasNotPresents addObject:record];
                 }
                 
-                [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
-                [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
-                [[NCManageDatabase sharedInstance] deletePhotosWithFileID:metadata.fileID];
-            }
-            
-            dispatch_async(dispatch_get_main_queue(), ^{
-                if ([metadatasNotPresents count] > 0)
-                    [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl fileID:nil action:k_action_NULL];
-            });
-            
-            // ----- Test : (MODIFY) -----
-            
-            for (tableMetadata *metadata in metadatas) {
-                
-                // RECURSIVE DIRECTORY MODE
-                if (metadata.directory) {
-                                        
-                    // Verify if do not exists this Metadata
-                    tableMetadata *result = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
-                    
-                    if (!result)
-                        (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
-                    
-                    [self readFolder:[CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileName] selector:selector];
+                // delete metadata not present
+                for (tableMetadata *metadata in metadatasNotPresents) {
                     
-                } else {
+                    [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID] error:nil];
                     
-                    if ([selector isEqualToString:selectorReadFolderWithDownload]) {
+                    if (metadata.directory && serverUrl) {
                         
-                        // It's in session
-                        BOOL recordInSession = NO;
-                        for (tableMetadata *record in recordsInSessions) {
-                            if ([record.fileID isEqualToString:metadata.fileID]) {
-                                recordInSession = YES;
-                                break;
-                            }
-                        }
+                        NSString *dirForDelete = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileName];
                         
-                        if (recordInSession)
-                            continue;
-                        
-                        // Ohhhh INSERT
-                        [metadatasForVerifyChange addObject:metadata];
+                        [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:dirForDelete account:metadata.account];
                     }
                     
-                    if ([selector isEqualToString:selectorReadFolder]) {
+                    [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
+                    [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
+                    [[NCManageDatabase sharedInstance] deletePhotosWithFileID:metadata.fileID];
+                }
+                
+                dispatch_async(dispatch_get_main_queue(), ^{
+                    if ([metadatasNotPresents count] > 0)
+                        [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl fileID:nil action:k_action_NULL];
+                });
+                
+                // ----- Test : (MODIFY) -----
+                
+                for (tableMetadata *metadata in metadatas) {
+                    
+                    // RECURSIVE DIRECTORY MODE
+                    if (metadata.directory) {
                         
                         // Verify if do not exists this Metadata
                         tableMetadata *result = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
                         
                         if (!result)
-                            [addMetadatas addObject:metadata];
+                            (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
+                        
+                        [self readFolder:[CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileName] selector:selector];
+                        
+                    } else {
+                        
+                        if ([selector isEqualToString:selectorReadFolderWithDownload]) {
+                            
+                            // It's in session
+                            BOOL recordInSession = NO;
+                            for (tableMetadata *record in recordsInSessions) {
+                                if ([record.fileID isEqualToString:metadata.fileID]) {
+                                    recordInSession = YES;
+                                    break;
+                                }
+                            }
+                            
+                            if (recordInSession)
+                                continue;
+                            
+                            // Ohhhh INSERT
+                            [metadatasForVerifyChange addObject:metadata];
+                        }
+                        
+                        if ([selector isEqualToString:selectorReadFolder]) {
+                            
+                            // Verify if do not exists this Metadata
+                            tableMetadata *result = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
+                            
+                            if (!result)
+                                [addMetadatas addObject:metadata];
+                        }
                     }
                 }
-            }
-            
-            if ([addMetadatas count] > 0)
-                (void)[[NCManageDatabase sharedInstance] addMetadatas:addMetadatas];
-            
-            if ([metadatasForVerifyChange count] > 0)
-                [self verifyChangeMedatas:metadatasForVerifyChange serverUrl:serverUrl account:account withDownload:YES];
-        });
+                
+                if ([addMetadatas count] > 0)
+                    (void)[[NCManageDatabase sharedInstance] addMetadatas:addMetadatas];
+                
+                if ([metadatasForVerifyChange count] > 0)
+                    [self verifyChangeMedatas:metadatasForVerifyChange serverUrl:serverUrl account:account withDownload:YES];
+            });
             
-    } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
+        } else {
         
-        // Folder not present, remove it
-        if (errorCode == 404) {
-            [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:serverUrl account:account];
-            [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl fileID:nil action:k_action_NULL];
+            // Folder not present, remove it
+            if (errorCode == 404) {
+                [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:serverUrl account:account];
+                [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl fileID:nil action:k_action_NULL];
+            }
         }
-        
-        return;
     }];
-    
-    
-    
 }
 
 #pragma --------------------------------------------------------------------------------------------

+ 1 - 1
iOSClient/Trash/NCTrash.swift

@@ -543,7 +543,7 @@ class NCTrash: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
     func downloadThumbnail(with tableTrash: tableTrash, indexPath: IndexPath) {
                 
         let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: nil, withUserID: nil, withPassword: nil, withUrl: nil)
-        ocNetworking?.downloadPreviewTrash(withFileID: tableTrash.fileID, fileName: tableTrash.fileName, account: appDelegate.activeAccount, completion: { (account, message, errorCode) in
+        ocNetworking?.downloadPreviewTrash(withAccount: appDelegate.activeAccount, fileID: tableTrash.fileID, fileName: tableTrash.fileName, completion: { (account, message, errorCode) in
             if errorCode == 0 && account == self.appDelegate.activeAccount && CCUtility.fileProviderStorageIconExists(tableTrash.fileID, fileNameView: tableTrash.fileName) {
                 self.collectionView.reloadItems(at: [indexPath])
             }