Browse Source

rewrite destinationURL

Marino Faggiana 8 years ago
parent
commit
5538dd8fa9

+ 46 - 9
Picker/DocumentPickerViewController.swift

@@ -57,6 +57,7 @@ class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCN
     
     
     var localServerUrl : String?
     var localServerUrl : String?
     var thumbnailInLoading = [String: IndexPath]()
     var thumbnailInLoading = [String: IndexPath]()
+    var destinationURL : URL?
     
     
     lazy var networkingOperationQueue : OperationQueue = {
     lazy var networkingOperationQueue : OperationQueue = {
         
         
@@ -362,9 +363,8 @@ class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCN
     func uploadFileSuccess(_ fileID: String!, serverUrl: String!, selector: String!, selectorPost: String!) {
     func uploadFileSuccess(_ fileID: String!, serverUrl: String!, selector: String!, selectorPost: String!) {
         
         
         hud.hideHud()
         hud.hideHud()
-        let url = URL(string: "file://\(directoryUser!)/\(fileID!)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!)
         
         
-        dismissGrantingAccess(to: nil)
+        dismissGrantingAccess(to: self.destinationURL)
     }
     }
     
     
     //  MARK: - Download Thumbnail
     //  MARK: - Download Thumbnail
@@ -424,26 +424,37 @@ extension DocumentPickerViewController {
             
             
             let fileName = sourceURL.lastPathComponent
             let fileName = sourceURL.lastPathComponent
             
             
-            guard let destinationURL = URL(string: "file://\(directoryUser!)/\(fileName)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!) else {
+            guard let destinationURLDirectoryUser = URL(string: "file://\(directoryUser!)/\(fileName)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!) else {
                 
                 
                 return
                 return
             }
             }
+            
+            self.destinationURL = appGroupContainerURL()?.appendingPathComponent(fileName)
+            
+            // copy sourceURL on DirectoryUser
+            do {
+                try FileManager.default.removeItem(at: destinationURLDirectoryUser)
+            } catch _ {
+                print("file do not exists")
+            }
+            do {
+                try FileManager.default.copyItem(at: sourceURL, to: destinationURLDirectoryUser)
+            } catch _ {
+                print("file do not exists")
+                return
+            }
 
 
             fileCoordinator.coordinate(readingItemAt: sourceURL, options: .withoutChanges, error: nil, byAccessor: { [weak self] newURL in
             fileCoordinator.coordinate(readingItemAt: sourceURL, options: .withoutChanges, error: nil, byAccessor: { [weak self] newURL in
                 
                 
                 // Remove destination file
                 // Remove destination file
                 do {
                 do {
-                    
-                    try FileManager.default.removeItem(at: destinationURL)
-                    
+                    try FileManager.default.removeItem(at: (self?.destinationURL)!)
                 } catch _ {
                 } catch _ {
-                    
                     print("file do not exists")
                     print("file do not exists")
                 }
                 }
                 
                 
                 do {
                 do {
-                    
-                    try FileManager.default.copyItem(at: sourceURL, to: destinationURL)
+                    try FileManager.default.copyItem(at: sourceURL, to: (self?.destinationURL)!)
                     
                     
                     // Upload fileName to Cloud
                     // Upload fileName to Cloud
                     
                     
@@ -473,6 +484,32 @@ extension DocumentPickerViewController {
             dismiss(animated: true, completion: nil)
             dismiss(animated: true, completion: nil)
         }
         }
     }
     }
+    
+    func appGroupContainerURL() -> URL? {
+        
+        let fileManager = FileManager.default
+        guard let groupURL = fileManager
+            .containerURL(forSecurityApplicationGroupIdentifier: capabilitiesGroups) else {
+                return nil
+        }
+        
+        let storagePathUrl = groupURL.appendingPathComponent("File Provider Storage")
+        let storagePath = storagePathUrl.path
+        
+        if !fileManager.fileExists(atPath: storagePath) {
+            do {
+                try fileManager.createDirectory(atPath: storagePath,
+                                                withIntermediateDirectories: false,
+                                                attributes: nil)
+            } catch let error {
+                print("error creating filepath: \(error)")
+                return nil
+            }
+        }
+        
+        return storagePathUrl
+    }
+
 }
 }
 
 
 
 

+ 0 - 1
iOSClient/Utility/CCUtility.h

@@ -142,7 +142,6 @@
 
 
 + (void)moveFileAtPath:(NSString *)atPath toPath:(NSString *)toPath;
 + (void)moveFileAtPath:(NSString *)atPath toPath:(NSString *)toPath;
 + (void)copyFileAtPath:(NSString *)atPath toPath:(NSString *)toPath;
 + (void)copyFileAtPath:(NSString *)atPath toPath:(NSString *)toPath;
-+ (void)createSymbolicLinkAtURL:(NSURL *)atURL destinationURL:( NSURL *)destinationURL;
 + (void)removeAllFileID_UPLOAD_ActiveUser:(NSString *)activeUser activeUrl:(NSString *)activeUrl;
 + (void)removeAllFileID_UPLOAD_ActiveUser:(NSString *)activeUser activeUrl:(NSString *)activeUrl;
 
 
 + (NSString *)deletingLastPathComponentFromServerUrl:(NSString *)serverUrl;
 + (NSString *)deletingLastPathComponentFromServerUrl:(NSString *)serverUrl;

+ 0 - 6
iOSClient/Utility/CCUtility.m

@@ -609,12 +609,6 @@
     }
     }
 }
 }
 
 
-+ (void)createSymbolicLinkAtURL:(NSURL *)atURL destinationURL:( NSURL *)destinationURL
-{
-    [[NSFileManager defaultManager] removeItemAtURL:destinationURL error:nil];
-    [[NSFileManager defaultManager] createSymbolicLinkAtURL:atURL withDestinationURL:destinationURL error:nil];
-}
-
 + (void)removeAllFileID_UPLOAD_ActiveUser:(NSString *)activeUser activeUrl:(NSString *)activeUrl
 + (void)removeAllFileID_UPLOAD_ActiveUser:(NSString *)activeUser activeUrl:(NSString *)activeUrl
 {
 {
     NSString *file;
     NSString *file;