Marino Faggiana 6 سال پیش
والد
کامیت
f26cbd22a4
3فایلهای تغییر یافته به همراه25 افزوده شده و 21 حذف شده
  1. 5 7
      iOSClient/Create/CCCreateCloud.swift
  2. 12 9
      iOSClient/Main/CCMain.m
  3. 8 5
      iOSClient/UploadFromOtherUpp/CCUploadFromOtherUpp.m

+ 5 - 7
iOSClient/Create/CCCreateCloud.swift

@@ -602,7 +602,7 @@ class CreateFormUploadFile: XLFormViewController, CCMoveDelegate {
         guard let directoryID = NCManageDatabase.sharedInstance.getDirectoryID(self.serverUrl) else {
             return
         }
-        let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account == %@ AND directoryID == %@ AND fileNameView == %@", appDelegate.activeAccount, directoryID, fileNameSave))
+        let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "directoryID == %@ AND fileNameView == %@", directoryID, fileNameSave))
         
         if (metadata != nil) {
             
@@ -612,7 +612,7 @@ class CreateFormUploadFile: XLFormViewController, CCMoveDelegate {
             }
             
             let overwriteAction = UIAlertAction(title: NSLocalizedString("_overwrite_", comment: ""), style: .cancel) { (action:UIAlertAction) in
-                self.dismissAndUpload(fileNameSave)
+                self.dismissAndUpload(fileNameSave, fileID: metadata!.fileID, directoryID: directoryID)
             }
             
             alertController.addAction(cancelAction)
@@ -621,18 +621,16 @@ class CreateFormUploadFile: XLFormViewController, CCMoveDelegate {
             self.present(alertController, animated: true, completion:nil)
             
         } else {
-            
-           dismissAndUpload(fileNameSave)
+           let directoryID = NCManageDatabase.sharedInstance.getDirectoryID(self.serverUrl)!
+           dismissAndUpload(fileNameSave, fileID: directoryID + fileNameSave, directoryID: directoryID)
         }
     }
     
-    func dismissAndUpload(_ fileNameSave: String) {
+    func dismissAndUpload(_ fileNameSave: String, fileID: String, directoryID: String) {
         
         self.dismiss(animated: true, completion: {
             
             let data = self.text.data(using: .utf8)
-            let directoryID = NCManageDatabase.sharedInstance.getDirectoryID(self.serverUrl)!
-            let fileID = directoryID + fileNameSave
             let success = FileManager.default.createFile(atPath: CCUtility.getDirectoryProviderStorageFileID(fileID, fileNameView: fileNameSave), contents: data, attributes: nil)
             
             if success {

+ 12 - 9
iOSClient/Main/CCMain.m

@@ -3542,16 +3542,16 @@
 - (void)pasteFile:(id)sender
 {
     UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
-    [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
+    [self uploadFilePasteArray:[pasteboard items]];
 }
 
 - (void)pasteFiles:(id)sender
 {
     UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
-    [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
+    [self uploadFilePasteArray:[pasteboard items]];
 }
 
-- (void)uploadFilePasteArray:(NSArray *)items cryptated:(BOOL)cryptated
+- (void)uploadFilePasteArray:(NSArray *)items
 {
     float timer = 0;
     
@@ -3561,7 +3561,8 @@
         
         NSData *dataFileID = [dic objectForKey: k_metadataKeyedUnarchiver];
         NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
-        
+        NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:self.serverUrl];
+
         tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
         
         if (metadata) {
@@ -3569,15 +3570,17 @@
             if ([CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView]) {
                 
                 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, timer * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-                        
+                    
+                    NSString *fileName = [[NCUtility sharedInstance] createFileName:metadata.fileName directoryID:directoryID];
+                    
                     tableMetadata *metadataForUpload = [tableMetadata new];
                         
                     metadataForUpload.account = appDelegate.activeAccount;
                     metadataForUpload.date = [NSDate new];
-                    metadataForUpload.directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:self.serverUrl];
-                    metadataForUpload.fileID = [metadataForUpload.directoryID stringByAppendingString:metadata.fileName];
-                    metadataForUpload.fileName = metadata.fileName;
-                    metadataForUpload.fileNameView = metadata.fileNameView;
+                    metadataForUpload.directoryID = directoryID;
+                    metadataForUpload.fileID = [directoryID stringByAppendingString:metadata.fileName];
+                    metadataForUpload.fileName = fileName;
+                    metadataForUpload.fileNameView = fileName;
                     metadataForUpload.session = k_upload_session;
                     metadataForUpload.sessionSelector = selectorUploadFile;
                     metadataForUpload.status = k_metadataStatusWaitUpload;

+ 8 - 5
iOSClient/UploadFromOtherUpp/CCUploadFromOtherUpp.m

@@ -173,20 +173,23 @@
 
 -(void)upload
 {
+    NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrlLocal];
+    NSString *fileName = [[NCUtility sharedInstance] createFileName:appDelegate.fileNameUpload directoryID:directoryID];
+    
     tableMetadata *metadataForUpload = [tableMetadata new];
     
     metadataForUpload.account = appDelegate.activeAccount;
     metadataForUpload.date = [NSDate new];
-    metadataForUpload.directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrlLocal];
-    metadataForUpload.fileID = [metadataForUpload.directoryID stringByAppendingString:appDelegate.fileNameUpload];
-    metadataForUpload.fileName = appDelegate.fileNameUpload;
-    metadataForUpload.fileNameView = appDelegate.fileNameUpload;
+    metadataForUpload.directoryID = directoryID;
+    metadataForUpload.fileID = [directoryID stringByAppendingString:appDelegate.fileNameUpload];
+    metadataForUpload.fileName = fileName;
+    metadataForUpload.fileNameView = fileName;
     metadataForUpload.session = k_upload_session;
     metadataForUpload.sessionSelector = selectorUploadFile;
     metadataForUpload.status = k_metadataStatusWaitUpload;
     
     // Prepare file and directory
-    [CCUtility copyFileAtPath:[NSTemporaryDirectory() stringByAppendingString:appDelegate.fileNameUpload] toPath:[CCUtility getDirectoryProviderStorageFileID:metadataForUpload.fileID fileNameView:appDelegate.fileNameUpload]];
+    [CCUtility copyFileAtPath:[NSTemporaryDirectory() stringByAppendingString:appDelegate.fileNameUpload] toPath:[CCUtility getDirectoryProviderStorageFileID:metadataForUpload.fileID fileNameView:fileName]];
     
     // Add Medtadata for upload
     (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];