Marino Faggiana 6 жил өмнө
parent
commit
5ecf7e3abb

+ 15 - 14
iOSClient/AppDelegate.m

@@ -1508,9 +1508,9 @@
 }
 
 // Method called from iOS system to send a file from other app.
-- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
+- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options
 {
-    NSLog(@"[LOG] URL from %@ application", sourceApplication);
+    NSError *error;
     NSLog(@"[LOG] the path is: %@", url.path);
         
     NSArray *splitedUrl = [url.path componentsSeparatedByString:@"/"];
@@ -1518,21 +1518,22 @@
     
     if (self.activeAccount) {
         
-        [[NSFileManager defaultManager]moveItemAtPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Inbox"] stringByAppendingPathComponent:self.fileNameUpload] toPath:[NSTemporaryDirectory() stringByAppendingString:self.fileNameUpload] error:nil];
+        [[NSFileManager defaultManager]removeItemAtPath:[NSTemporaryDirectory() stringByAppendingString:self.fileNameUpload] error:nil];
+        [[NSFileManager defaultManager]moveItemAtPath:url.path toPath:[NSTemporaryDirectory() stringByAppendingString:self.fileNameUpload] error:&error];
         
-        UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
-        UINavigationController *splitNavigationController = [splitViewController.viewControllers firstObject];
-        
-        UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"CCUploadFromOtherUpp" bundle:nil] instantiateViewControllerWithIdentifier:@"CCUploadNavigationViewController"];
-        
-        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-            [splitNavigationController presentViewController:navigationController animated:YES completion:nil];
-        });
+        if (error == nil) {
+            
+            UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
+            UINavigationController *splitNavigationController = [splitViewController.viewControllers firstObject];
+            
+            UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"CCUploadFromOtherUpp" bundle:nil] instantiateViewControllerWithIdentifier:@"CCUploadNavigationViewController"];
+            
+            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+                [splitNavigationController presentViewController:navigationController animated:YES completion:nil];
+            });
+        }
     }
     
-    // remove from InBox
-    [[NSFileManager defaultManager] removeItemAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Inbox"] error:nil];
-    
     return YES;
 }
 

+ 23 - 18
iOSClient/AutoUpload/NCAutoUpload.m

@@ -406,24 +406,29 @@
             prevServerUrl = serverUrl;
         }
         
-        tableMetadata *metadataForUpload = [tableMetadata new];
-        
-        metadataForUpload.account = appDelegate.activeAccount;
-        metadataForUpload.assetLocalIdentifier = asset.localIdentifier;
-        metadataForUpload.date = [NSDate new];
-        metadataForUpload.directoryID = directoryID;
-        metadataForUpload.fileID = [directoryID stringByAppendingString:fileName];
-        metadataForUpload.fileName = fileName;
-        metadataForUpload.fileNameView = fileName;
-        metadataForUpload.session = session;
-        metadataForUpload.sessionSelector = selector;
-        metadataForUpload.status = k_metadataStatusWaitUpload;
-
-        [metadataFull addObject:metadataForUpload];
-        
-        // Update database Auto Upload
-        if ([selector isEqualToString:selectorUploadAutoUpload])
-            [self addQueueUploadAndPhotoLibrary:metadataForUpload asset:asset];
+        // Check il file already exists
+        tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"directoryID == %@ AND fileNameView == %@", directoryID, fileName]];
+        if (!metadata) {
+        
+            tableMetadata *metadataForUpload = [tableMetadata new];
+            
+            metadataForUpload.account = appDelegate.activeAccount;
+            metadataForUpload.assetLocalIdentifier = asset.localIdentifier;
+            metadataForUpload.date = [NSDate new];
+            metadataForUpload.directoryID = directoryID;
+            metadataForUpload.fileID = [directoryID stringByAppendingString:fileName];
+            metadataForUpload.fileName = fileName;
+            metadataForUpload.fileNameView = fileName;
+            metadataForUpload.session = session;
+            metadataForUpload.sessionSelector = selector;
+            metadataForUpload.status = k_metadataStatusWaitUpload;
+
+            [metadataFull addObject:metadataForUpload];
+            
+            // Update database Auto Upload
+            if ([selector isEqualToString:selectorUploadAutoUpload])
+                [self addQueueUploadAndPhotoLibrary:metadataForUpload asset:asset];
+        }
     }
     
     // Insert all assets (Full) in tableQueueUpload

+ 39 - 10
iOSClient/Main/CCMain.m

@@ -723,11 +723,41 @@
                     metadataForUpload.sessionSelector = selectorUploadFile;
                     metadataForUpload.status = k_metadataStatusWaitUpload;
                     
-                    // Add Medtadata for upload
-                    (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
-                    [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
-                    
-                    [self reloadDatasource];
+                    // Check il file already exists
+                    tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"directoryID == %@ AND fileNameView == %@", directoryID, fileName]];
+                    if (metadata) {
+                        
+                        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:fileName message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
+                        
+                        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
+                            // NO OVERWITE
+                        }];
+                        UIAlertAction *overwriteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_overwrite_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+                            
+                            // Remove record metadata
+                            [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID] clearDateReadDirectoryID:metadata.directoryID];
+                            
+                            // Add Medtadata for upload
+                            (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
+                            [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
+                        }];
+                        
+                        [alertController addAction:cancelAction];
+                        [alertController addAction:overwriteAction];
+                        
+                        UIWindow *alertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
+                        alertWindow.rootViewController = [[UIViewController alloc]init];
+                        alertWindow.windowLevel = UIWindowLevelAlert + 1;
+                        [alertWindow makeKeyAndVisible];
+                        [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
+                        
+                    } else {
+                        
+                        // Add Medtadata for upload
+                        (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
+                        [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
+
+                    }
                     
                 } else {
                     
@@ -1373,9 +1403,11 @@
             }];
             UIAlertAction *overwriteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_overwrite_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                 
+                // Remove record metadata
+                [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID] clearDateReadDirectoryID:metadata.directoryID];
+
                 // Add Medtadata for upload
                 (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
-                // Start upload now
                 [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
             }];
             
@@ -1392,12 +1424,9 @@
             
             // Add Medtadata for upload
             (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
+            [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
         }
     }
-    
-    [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
-
-    [self reloadDatasource];
 }
 
 #pragma --------------------------------------------------------------------------------------------