Marino Faggiana 6 лет назад
Родитель
Сommit
0128eb2a6d

+ 0 - 3
iOSClient/AppDelegate.h

@@ -101,9 +101,6 @@
 @property (nonatomic, strong) REMenuItem *downloadItem;
 @property (nonatomic, strong) REMenuItem *saveItem;
 
-// List Change Task
-@property (nonatomic, retain) NSMutableDictionary *listChangeTask;
-
 // Reachability
 @property (nonatomic, strong) Reachability *reachability;
 @property BOOL lastReachability;

+ 1 - 76
iOSClient/AppDelegate.m

@@ -167,10 +167,7 @@
     _netQueue = [[NSOperationQueue alloc] init];
     _netQueue.name = k_queue;
     _netQueue.maxConcurrentOperationCount = k_maxConcurrentOperation;
-   
-    // Add notification change session
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionChanged:) name:k_networkingSessionNotification object:nil];
-    
+       
     // UserDefaults
     self.ncUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:[NCBrandOptions sharedInstance].capabilitiesGroups];
     
@@ -187,7 +184,6 @@
 
     // Initialization List
     self.listProgressMetadata = [[NSMutableDictionary alloc] init];
-    self.listChangeTask = [[NSMutableDictionary alloc] init];
     self.listMainVC = [[NSMutableDictionary alloc] init];
             
     // setting Reachable in back
@@ -1286,77 +1282,6 @@
     [netQueue addOperation:operation];
 }
 
-// Notification change session
-- (void)sessionChanged:(NSNotification *)notification
-{
-    NSURLSession *session;
-    NSString *fileID;
-    NSURLSessionTask *task;
-    
-    for (id object in notification.object) {
-        
-        if ([object isKindOfClass:[NSURLSession class]])
-            session = object;
-        
-        if ([object isKindOfClass:[NSString class]])
-            fileID = object;
-        
-        if ([object isKindOfClass:[NSURLSessionTask class]])
-            task = object;
-    }
-    
-    /*
-    Task
-    */
-    if (fileID && [_listChangeTask objectForKey:fileID])
-        dispatch_async(dispatch_get_main_queue(), ^{
-            [self changeTask:fileID];
-        });
-        
-    /* 
-    Session
-    */
-    if (session) {
-                
-        [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
-            
-            unsigned long numDownload = [downloadTasks count];
-            unsigned long numUpload = [uploadTasks count];
-        
-            NSLog(@"[LOG] Num Download in queue %lu, num upload in queue %lu", numDownload, numUpload);
-        }];
-    }
-}
-
-- (void)changeTask:(NSString *)fileID
-{
-    tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
-    if (!metadata) return;
-    NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
-    if (!serverUrl) return;
-
-    if ([[_listChangeTask objectForKey:fileID] isEqualToString:@"cancelUpload"]) {
-        
-        [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:fileID] error:nil];
-        [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID] clearDateReadDirectoryID:nil];
-    }
-    else if ([[_listChangeTask objectForKey:fileID] isEqualToString:@"cancelDownload"]) {
-        
-        [[NCManageDatabase sharedInstance] setMetadataSession:@"" sessionError:@"" sessionSelector:@"" sessionTaskIdentifier:k_taskIdentifierDone status:k_metadataStatusNormal predicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
-    }
-    
-    // remove ChangeTask (fileID) from the list
-    [_listChangeTask removeObjectForKey:fileID];
-    
-    // delete progress
-    [_listProgressMetadata removeObjectForKey:fileID];
-    
-    // Refresh
-    [_activeMain reloadDatasource:serverUrl];
-    [_activeFavorites reloadDatasource];
-    [_activeTransfers reloadDatasource];
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Process Load Download/Upload < k_timerProcess seconds > =====
 #pragma --------------------------------------------------------------------------------------------

+ 0 - 2
iOSClient/CCGlobal.h

@@ -105,8 +105,6 @@
 #define k_permission_can_rename                         @"N"
 #define k_permission_can_move                           @"V"
 
-#define k_networkingSessionNotification                 @"networkingSessionNotification"
-
 // Session
 #define k_domain_session_queue                          @"it.twsweb.Crypto-Cloud"
 

+ 82 - 8
iOSClient/Favorites/CCFavorites.m

@@ -126,11 +126,6 @@
     [self.tableView reloadData];
 }
 
-- (void)triggerProgressTask:(NSNotification *)notification
-{
-    [[NCMainCommon sharedInstance] triggerProgressTask:notification sectionDataSourceFileIDIndexPath:sectionDataSource.fileIDIndexPath tableView:self.tableView];
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ==== DZNEmptyDataSetSource ====
 #pragma --------------------------------------------------------------------------------------------
@@ -381,8 +376,19 @@
         
     } else {
         
-        if (errorCode != k_CCErrorFileAlreadyInDownload)
-            [appDelegate messageNotification:@"_download_file_" description:errorMessage visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
+        // File do not exists on server, remove in local
+        if (errorCode == kOCErrorServerPathNotFound || errorCode == kCFURLErrorBadServerResponse) {
+            
+            [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:fileID] error:nil];
+            
+            [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID] clearDateReadDirectoryID:nil];
+            [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
+            [[NCManageDatabase sharedInstance] deletePhotosWithFileID:fileID];
+            [appDelegate.activePhotos.fileIDHide addObject:fileID];
+        }
+        
+        [self reloadDatasource];
+        [appDelegate.activeTransfers reloadDatasource];
     }
 }
 
@@ -411,6 +417,61 @@
         [appDelegate.activeMain openWindowShare:metadata];
 }
 
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ===== Progress & Task Button =====
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)triggerProgressTask:(NSNotification *)notification
+{
+    [[NCMainCommon sharedInstance] triggerProgressTask:notification sectionDataSourceFileIDIndexPath:sectionDataSource.fileIDIndexPath tableView:self.tableView];
+}
+
+- (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
+{
+    UITouch *touch = [[event allTouches] anyObject];
+    CGPoint location = [touch locationInView:self.tableView];
+    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
+    
+    if ([[NCMainCommon sharedInstance] isValidIndexPath:indexPath tableView:self.tableView]) {
+        
+        tableMetadata *metadataSection = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
+        
+        if (metadataSection) {
+            
+            tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadataSection.fileID]];
+            if (metadata)
+                [self cancelTaskButton:metadata reloadTable:YES];
+        }
+    }
+}
+
+- (void)cancelTaskButton:(tableMetadata *)metadata reloadTable:(BOOL)reloadTable
+{
+    [[NCMainCommon sharedInstance] cancelTransferMetadata:metadata reloadDatasource:true];
+}
+
+- (void)cancelAllTask:(id)sender
+{
+    CGPoint location = [sender locationInView:self.tableView];
+    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
+    
+    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
+    
+    [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_all_task_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
+        [[NCMainCommon sharedInstance] cancelAllTransfer];
+    }]];
+    
+    [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
+    
+    alertController.popoverPresentationController.sourceView = self.view;
+    alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
+    
+    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
+        [alertController.view layoutIfNeeded];
+    
+    [self presentViewController:alertController animated:YES completion:nil];
+}
+
 #pragma mark -
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== menu action : Favorite, More, Delete [swipe] =====
@@ -448,13 +509,21 @@
 
 - (void)actionDelete:(NSIndexPath *)indexPath
 {
+    tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", _metadata.fileID]];
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
     
     [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-        
         [self deleteFile:[[NSArray alloc] initWithObjects:[_dataSource objectAtIndex:indexPath.row], nil] e2ee:false];
     }]];
     
+    if (localFile) {
+        [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_remove_local_file_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
+            [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", _metadata.fileID]];
+            [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:_metadata.fileID] error:nil];
+            [self reloadDatasource];
+        }]];
+    }
+    
     [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
     }]];
     
@@ -662,7 +731,12 @@
     
     if ([cell isKindOfClass:[CCCellMainTransfer class]]) {
         
+        // gesture Transfer
+        [((CCCellMainTransfer *)cell).transferButton.stopButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
         
+        UILongPressGestureRecognizer *stopLongGesture = [UILongPressGestureRecognizer new];
+        [stopLongGesture addTarget:self action:@selector(cancelAllTask:)];
+        [((CCCellMainTransfer *)cell).transferButton.stopButton addGestureRecognizer:stopLongGesture];
     }
    
     return cell;

+ 10 - 106
iOSClient/Main/CCMain.m

@@ -1229,13 +1229,10 @@
                     [appDelegate.activePhotos downloadFileSuccessFailure:metadata.fileName fileID:metadata.fileID serverUrl:serverUrl selector:selector errorMessage:errorMessage errorCode:errorCode];
             });
             
-        } else {
-            
-            if (errorCode != kCFURLErrorCancelled && errorCode != kOCErrorServerUnauthorized && errorCode != k_CCErrorFileAlreadyInDownload)
-                [appDelegate messageNotification:@"_download_file_" description:errorMessage visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
         }
         
         [self reloadDatasource:serverUrl];
+        [appDelegate.activeTransfers reloadDatasource];
     }
 }
 
@@ -1303,6 +1300,7 @@
     }
     
     [self reloadDatasource:serverUrl];
+    [appDelegate.activeTransfers reloadDatasource];
 }
 
 //
@@ -2203,69 +2201,8 @@
 }
 
 - (void)cancelTaskButton:(tableMetadata *)metadata reloadTable:(BOOL)reloadTable
-{    
-    NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
-    __block NSURLSessionTask *findTask;
-    
-    NSInteger sessionTaskIdentifier = metadata.sessionTaskIdentifier;
-    NSString *fileID = metadata.fileID;
-    
-    // SESSION EXTENSION
-    if ([metadata.session isEqualToString:k_download_session_extension] || [metadata.session isEqualToString:k_upload_session_extension]) {
-        
-        if ([metadata.session isEqualToString:k_upload_session_extension]) {
-            [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:fileID] error:nil];
-            [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID] clearDateReadDirectoryID:nil];
-        } else {
-            [[NCManageDatabase sharedInstance] setMetadataSession:@"" sessionError:@"" sessionSelector:@"" sessionTaskIdentifier:k_taskIdentifierDone status:k_metadataStatusNormal predicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
-        }
-    
-        [self reloadDatasource];
-        
-        return;
-    }
-    
-    // DOWNLOAD
-    if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
-        
-        [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
-            
-            for (NSURLSessionTask *task in downloadTasks)
-                if (task.taskIdentifier == sessionTaskIdentifier) {
-                    findTask = task;
-                    [appDelegate.listChangeTask setObject:@"cancelDownload" forKey:fileID];
-                    [task cancel];
-                }
-            
-            if (!findTask) {
-                
-                [appDelegate.listChangeTask setObject:@"cancelDownload" forKey:fileID];
-                NSArray *object = [[NSArray alloc] initWithObjects:session, fileID, findTask, nil];
-                [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
-            }
-        }];
-    }
-
-    // UPLOAD
-    if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
-        
-        [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
-            
-            for (NSURLSessionUploadTask *task in uploadTasks)
-                if (task.taskIdentifier == sessionTaskIdentifier) {
-                    findTask = task;
-                    [appDelegate.listChangeTask setObject:@"cancelUpload" forKey:fileID];
-                    [task cancel];
-                }
-            
-            if (!findTask) {
-                
-                [appDelegate.listChangeTask setObject:@"cancelUpload" forKey:fileID];
-                NSArray *object = [[NSArray alloc] initWithObjects:session, fileID, findTask, nil];
-                [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
-            }
-        }];
-    }
+{
+    [[NCMainCommon sharedInstance] cancelTransferMetadata:metadata reloadDatasource:true];
 }
 
 - (void)cancelAllTask:(id)sender
@@ -2276,28 +2213,7 @@
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
     
     [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_all_task_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-        
-        // Delete k_metadataStatusWaitUpload OR k_metadataStatusUploadError
-        [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (status == %d OR status == %d)", appDelegate.activeAccount, k_metadataStatusWaitUpload, k_metadataStatusUploadError] clearDateReadDirectoryID:nil];
-        
-        NSArray *metadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND status != %d AND status != %d", appDelegate.activeAccount, k_metadataStatusNormal, k_metadataStatusHide] sorted:@"fileName" ascending:true];
-        
-        for (tableMetadata *metadata in metadatas) {
-            
-            // Modify
-            if (metadata.status == k_metadataStatusWaitDownload || metadata.status == k_metadataStatusDownloadError) {
-                metadata.session = @"";
-                metadata.sessionSelector = @"";
-                metadata.status = k_metadataStatusNormal;
-                (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
-            }
-            // Cancel Task
-            if (metadata.status == k_metadataStatusDownloading || metadata.status == k_metadataStatusUploading) {
-                [self cancelTaskButton:metadata reloadTable:NO];
-            }
-        }
-        
-        [self reloadDatasource];
+        [[NCMainCommon sharedInstance] cancelAllTransfer];
     }]];
     
     [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
@@ -2630,21 +2546,6 @@
         [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Remove Local File =====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)removeLocalFile:(tableMetadata *)metadata
-{
-    [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
-    
-    [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID] error:nil];
-    
-    NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
-    if (serverUrl)
-        [self reloadDatasource:serverUrl];
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Order Table & GroupBy & DirectoryOnTop =====
 #pragma --------------------------------------------------------------------------------------------
@@ -3649,9 +3550,12 @@
         [self performSelector:@selector(deleteFile) withObject:nil];
     }]];
     
-    if (localFile || [CCUtility fileProviderStorageExists:_metadata.fileID fileName:_metadata.fileNameView]) {
+    if (localFile) {
         [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_remove_local_file_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-            [self performSelector:@selector(removeLocalFile:) withObject:_metadata];
+            [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", _metadata.fileID]];
+            [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:_metadata.fileID] error:nil];
+            [self reloadDatasource];
+            
         }]];
     }
     

+ 109 - 2
iOSClient/Main/NCMainCommon.swift

@@ -330,11 +330,118 @@ class NCMainCommon: NSObject {
         }
     }
     
-    func isValidIndexPath(_ indexPath: IndexPath, tableView: UITableView) -> Bool {
+    @objc func cancelTransferMetadata(_ metadata: tableMetadata, reloadDatasource: Bool) {
         
-        return indexPath.section < tableView.numberOfSections && indexPath.row < tableView.numberOfRows(inSection: indexPath.section)
+        let session = CCNetworking.shared().getSessionfromSessionDescription(metadata.session) as URLSession
+        
+        // SESSION EXTENSION
+        if metadata.session == k_download_session_extension || metadata.session == k_upload_session_extension {
+
+            if (metadata.session == k_upload_session_extension) {
+
+                do {
+                    try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageFileID(metadata.fileID))
+                } catch { }
+                
+                NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "fileID == %@", metadata.fileID), clearDateReadDirectoryID: metadata.directoryID)
+            } else {
+                NCManageDatabase.sharedInstance.setMetadataSession("", sessionError: "", sessionSelector: "", sessionTaskIdentifier: Int(k_taskIdentifierDone), status: Int(k_metadataStatusNormal), predicate: NSPredicate(format: "fileID == %@", metadata.fileID))
+            }
+         
+            appDelegate.activeMain.reloadDatasource()
+            appDelegate.activeFavorites.reloadDatasource()
+            if (self.appDelegate.activeTransfers != nil) {
+                self.appDelegate.activeTransfers.reloadDatasource()
+            }
+            
+            return
+        }
+        
+        session.getTasksWithCompletionHandler { (dataTasks, uploadTasks, downloadTasks) in
+            
+            // DOWNLOAD
+            if metadata.session.count > 0 && metadata.session.contains("download") {
+                for task in downloadTasks {
+                    if task.taskIdentifier == metadata.sessionTaskIdentifier {
+                        task.cancel()
+                    }
+                }
+            }
+            
+            // UPLOAD
+            if metadata.session.count > 0 && metadata.session.contains("upload") {
+                for task in uploadTasks {
+                    if task.taskIdentifier == metadata.sessionTaskIdentifier {
+                        task.cancel()
+                    }
+                }
+            }
+        }
+    }
+    
+    @objc func cancelAllTransfer() {
+
+        // Delete k_metadataStatusWaitUpload OR k_metadataStatusUploadError
+        NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "account == %@ AND (status == %d OR status == %d)", appDelegate.activeAccount, k_metadataStatusWaitUpload, k_metadataStatusUploadError), clearDateReadDirectoryID: nil)
 
+        guard let metadatas = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND status != %d AND status != %d", appDelegate.activeAccount, k_metadataStatusNormal, k_metadataStatusHide), sorted: "fileName", ascending: true) else {
+            return
+        }
+        
+        for metadata in metadatas {
+            
+            // Modify
+            if (metadata.status == k_metadataStatusWaitDownload || metadata.status == k_metadataStatusDownloadError) {
+                metadata.session = ""
+                metadata.sessionSelector = ""
+                metadata.status = Int(k_metadataStatusNormal)
+                
+                _ = NCManageDatabase.sharedInstance.addMetadata(metadata)
+            }
+            
+            // Cancel Task
+            if metadata.status == k_metadataStatusDownloading || metadata.status == k_metadataStatusUploading {
+                cancelTransferMetadata(metadata, reloadDatasource: false)
+            }
+        }
+        
+        self.appDelegate.activeMain.reloadDatasource()
+        self.appDelegate.activeFavorites.reloadDatasource()
+        if (self.appDelegate.activeTransfers != nil) {
+            self.appDelegate.activeTransfers.reloadDatasource()
+        }
     }
     
+    @objc func getMetadataFromSectionDataSourceIndexPath(_ indexPath: IndexPath, sectionDataSource: CCSectionDataSourceMetadata) -> tableMetadata? {
+        
+        let section = indexPath.section + 1;
+        let row = indexPath.row + 1;
+        let totSections = sectionDataSource.sections.count
+        
+        if totSections < section || section > totSections {
+            return nil
+        }
+        
+        let valueSection = sectionDataSource.sections.object(at: indexPath.section)
+        guard let filesID = sectionDataSource.sectionArrayRow.object(forKey: valueSection) as? NSArray else {
+            return nil
+        }
+        
+        let totRows = filesID.count
+        if totRows < row || row > totRows {
+            return nil
+        }
+        
+        let fileID = filesID.object(at: indexPath.row)
+        let metadata = sectionDataSource.allRecordsDataSource.object(forKey: fileID) as? tableMetadata
+      
+        return metadata
+    }
+    
+    @objc func isValidIndexPath(_ indexPath: IndexPath, tableView: UITableView) -> Bool {
+        
+        return indexPath.section < tableView.numberOfSections && indexPath.row < tableView.numberOfRows(inSection: indexPath.section)
+    }
+        
 }
 

+ 13 - 10
iOSClient/Networking/CCNetworking.m

@@ -404,7 +404,7 @@
         if (metadata) {
             
             NSString *etag = metadata.etag;
-            NSString *fileID = metadata.fileID;
+            //NSString *fileID = metadata.fileID;
             NSDictionary *fields = [httpResponse allHeaderFields];
             
             if (errorCode == 0) {
@@ -420,9 +420,6 @@
                     date = [NSDate date];
                 }
             }
-        
-            NSArray *object = [[NSArray alloc] initWithObjects:session, fileID, task, nil];
-            [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
             
             if (fileName.length > 0 && serverUrl.length > 0) {
                 dispatch_async(dispatch_get_main_queue(), ^{
@@ -466,10 +463,7 @@
                     date = [NSDate date];
                 }
             }
-        
-            NSArray *object = [[NSArray alloc] initWithObjects:session, fileID, task, nil];
-            [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
-        
+                
             if (fileName.length > 0 && fileID.length > 0 && serverUrl.length > 0) {
                 dispatch_async(dispatch_get_main_queue(), ^{
                     [self uploadFileSuccessFailure:metadata fileName:fileName fileID:fileID etag:etag date:date serverUrl:serverUrl errorCode:errorCode];
@@ -631,7 +625,11 @@
     
     if (errorCode != 0) {
         
-        if (errorCode != kCFURLErrorCancelled) {
+        if (errorCode == kCFURLErrorCancelled) {
+            
+            [[NCManageDatabase sharedInstance] setMetadataSession:@"" sessionError:@"" sessionSelector:@"" sessionTaskIdentifier:k_taskIdentifierDone status:k_metadataStatusNormal predicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
+            
+        } else {
             
             [[NCManageDatabase sharedInstance] setMetadataSession:nil sessionError:[CCError manageErrorKCF:errorCode withNumberError:NO] sessionSelector:nil sessionTaskIdentifier:k_taskIdentifierDone status:k_metadataStatusDownloadError predicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
         }
@@ -1039,7 +1037,12 @@
 #endif
         
         // Mark error only if not Cancelled Task
-        if (errorCode != kCFURLErrorCancelled)  {
+        if (errorCode == kCFURLErrorCancelled)  {
+            
+            [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:tempFileID] error:nil];
+            [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", tempFileID] clearDateReadDirectoryID:metadata.directoryID];
+
+        } else {
 
             [[NCManageDatabase sharedInstance] setMetadataSession:nil sessionError:[CCError manageErrorKCF:errorCode withNumberError:NO] sessionSelector:nil sessionTaskIdentifier:k_taskIdentifierDone status:k_metadataStatusUploadError predicate:[NSPredicate predicateWithFormat:@"fileID == %@", tempFileID]];
         }