Selaa lähdekoodia

Do not overwrite existing file with a new created textfile #460

Marino Faggiana 7 vuotta sitten
vanhempi
commit
c74d6f13bd
1 muutettua tiedostoa jossa 28 lisäystä ja 0 poistoa
  1. 28 0
      iOSClient/Create/CCCreateCloud.swift

+ 28 - 0
iOSClient/Create/CCCreateCloud.swift

@@ -599,6 +599,34 @@ class CreateFormUploadFile: XLFormViewController, CCMoveDelegate {
                 fileNameSave = (name as! NSString).deletingPathExtension + ".txt"
         }
         
+        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))
+        
+        if (metadata != nil) {
+            
+            let alertController = UIAlertController(title: fileNameSave, message: NSLocalizedString("_file_already_exists_", comment: ""), preferredStyle: .alert)
+            
+            let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .default) { (action:UIAlertAction) in
+            }
+            
+            let overwriteAction = UIAlertAction(title: NSLocalizedString("_overwrite_", comment: ""), style: .cancel) { (action:UIAlertAction) in
+                self.dismissAndUpload(fileNameSave)
+            }
+            
+            alertController.addAction(cancelAction)
+            alertController.addAction(overwriteAction)
+            
+            self.present(alertController, animated: true, completion:nil)
+        } else {
+            
+           dismissAndUpload(fileNameSave)
+        }
+    }
+    
+    func dismissAndUpload(_ fileNameSave: String) {
+        
         self.dismiss(animated: true, completion: {
             
             let data = self.text.data(using: .utf8)