marinofaggiana 4 years ago
parent
commit
d6c8bc03a8

+ 0 - 82
File Provider Extension/FileProviderExtension+NetworkingDelegate.swift

@@ -1,82 +0,0 @@
-//
-//  FileProviderExtension+NetworkingDelegate.swift
-//  File Provider Extension
-//
-//  Created by Marino Faggiana on 02/11/2019.
-//  Copyright © 2019 Marino Faggiana. All rights reserved.
-//
-//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-import FileProvider
-import NCCommunication
-
-extension FileProviderExtension: NCNetworkingDelegate {
-
-    func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: NSDate?, size: Int64, description: String?, task: URLSessionTask, errorCode: Int, errorDescription: String) {
-                
-        guard let ocIdTemp = description else { return }
-        guard let metadataTemp = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocIdTemp) else { return }
-        let metadata = tableMetadata.init(value: metadataTemp)
-        
-        let url = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(ocIdTemp, fileNameView: fileName))
-        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
-            self.outstandingSessionTasks.removeValue(forKey: url)
-        }
-        outstandingOcIdTemp[ocIdTemp] = ocId
-        
-        if errorCode == 0 {
-            
-            // New file
-            if ocId != ocIdTemp {
-                // Signal update
-                fileProviderData.sharedInstance.signalEnumerator(ocId: metadata.ocId, delete: true)
-            }
-                        
-            metadata.fileName = fileName
-            metadata.serverUrl = serverUrl
-            if let etag = etag { metadata.etag = etag }
-            if let ocId = ocId { metadata.ocId = ocId }
-            if let date = date { metadata.date = date }
-            metadata.permissions = "RGDNVW"
-            metadata.session = ""
-            metadata.size = Double(size)
-            metadata.status = Int(k_metadataStatusNormal)
-                  
-            NCManageDatabase.sharedInstance.addMetadata(metadata)
-            NCManageDatabase.sharedInstance.addLocalFile(metadata: metadata)
-            
-            // New file
-            if ocId != ocIdTemp {
-            
-                NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", ocIdTemp))
-                
-                // File system
-                let atPath = CCUtility.getDirectoryProviderStorageOcId(ocIdTemp)
-                let toPath = CCUtility.getDirectoryProviderStorageOcId(ocId)
-                CCUtility.copyFile(atPath: atPath, toPath: toPath)
-            }
-            
-            fileProviderData.sharedInstance.signalEnumerator(ocId: metadata.ocId, update: true)
-            
-        } else {
-            
-            NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", ocIdTemp))
-            
-            fileProviderData.sharedInstance.signalEnumerator(ocId: ocIdTemp, delete: true)
-        }
-    }
-}

+ 59 - 1
File Provider Extension/FileProviderExtension.swift

@@ -50,7 +50,7 @@ import Alamofire
  
    -------------------------------------------------------------------------------------------------------------------------------------------- */
 
-class FileProviderExtension: NSFileProviderExtension {
+class FileProviderExtension: NSFileProviderExtension, NCNetworkingDelegate {
     
     var outstandingSessionTasks: [URL: URLSessionTask] = [:]
     var outstandingOcIdTemp: [String: String] = [:]
@@ -377,4 +377,62 @@ class FileProviderExtension: NSFileProviderExtension {
             }
         }
     }
+    
+    func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: NSDate?, size: Int64, description: String?, task: URLSessionTask, errorCode: Int, errorDescription: String) {
+                
+        guard let ocIdTemp = description else { return }
+        guard let metadataTemp = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocIdTemp) else { return }
+        let metadata = tableMetadata.init(value: metadataTemp)
+        
+        let url = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(ocIdTemp, fileNameView: fileName))
+        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
+            self.outstandingSessionTasks.removeValue(forKey: url)
+        }
+        outstandingOcIdTemp[ocIdTemp] = ocId
+        
+        if errorCode == 0 {
+            
+            // New file
+            if ocId != ocIdTemp {
+                // Signal update
+                fileProviderData.sharedInstance.signalEnumerator(ocId: metadata.ocId, delete: true)
+            }
+                        
+            metadata.fileName = fileName
+            metadata.serverUrl = serverUrl
+            if let etag = etag { metadata.etag = etag }
+            if let ocId = ocId { metadata.ocId = ocId }
+            if let date = date { metadata.date = date }
+            metadata.permissions = "RGDNVW"
+            metadata.session = ""
+            metadata.size = Double(size)
+            metadata.status = Int(k_metadataStatusNormal)
+                  
+            NCManageDatabase.sharedInstance.addMetadata(metadata)
+            NCManageDatabase.sharedInstance.addLocalFile(metadata: metadata)
+            
+            // New file
+            if ocId != ocIdTemp {
+            
+                NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", ocIdTemp))
+                
+                // File system
+                let atPath = CCUtility.getDirectoryProviderStorageOcId(ocIdTemp)
+                let toPath = CCUtility.getDirectoryProviderStorageOcId(ocId)
+                CCUtility.copyFile(atPath: atPath, toPath: toPath)
+            }
+            
+            fileProviderData.sharedInstance.signalEnumerator(ocId: metadata.ocId, update: true)
+            
+        } else {
+            
+            NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", ocIdTemp))
+            
+            fileProviderData.sharedInstance.signalEnumerator(ocId: ocIdTemp, delete: true)
+        }
+    }
+
 }
+
+
+    

+ 0 - 4
Nextcloud.xcodeproj/project.pbxproj

@@ -72,7 +72,6 @@
 		F7169A1D1EE590930086BD69 /* NCSharesCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F7169A1A1EE590930086BD69 /* NCSharesCell.m */; };
 		F7169A1E1EE590930086BD69 /* NCSharesCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7169A1B1EE590930086BD69 /* NCSharesCell.xib */; };
 		F716FE7823795E5000FABE50 /* NCCommunication.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F716FE7723795E5000FABE50 /* NCCommunication.framework */; settings = {ATTRIBUTES = (Required, ); }; };
-		F716FE7A23795EC500FABE50 /* FileProviderExtension+NetworkingDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F716FE7923795EC500FABE50 /* FileProviderExtension+NetworkingDelegate.swift */; };
 		F717402D24F699A5000C87D5 /* NCFavorite.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F717402B24F699A5000C87D5 /* NCFavorite.storyboard */; };
 		F717402E24F699A5000C87D5 /* NCFavorite.swift in Sources */ = {isa = PBXBuildFile; fileRef = F717402C24F699A5000C87D5 /* NCFavorite.swift */; };
 		F7226EDC1EE4089300EBECB1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7226EDB1EE4089300EBECB1 /* Main.storyboard */; };
@@ -414,7 +413,6 @@
 		F7169A301EE59BB70086BD69 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/Localizable.strings; sourceTree = "<group>"; };
 		F7169A4C1EE59C640086BD69 /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/Localizable.strings; sourceTree = "<group>"; };
 		F716FE7723795E5000FABE50 /* NCCommunication.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NCCommunication.framework; path = Carthage/Build/iOS/NCCommunication.framework; sourceTree = "<group>"; };
-		F716FE7923795EC500FABE50 /* FileProviderExtension+NetworkingDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FileProviderExtension+NetworkingDelegate.swift"; sourceTree = "<group>"; };
 		F717402B24F699A5000C87D5 /* NCFavorite.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = NCFavorite.storyboard; sourceTree = "<group>"; };
 		F717402C24F699A5000C87D5 /* NCFavorite.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCFavorite.swift; sourceTree = "<group>"; };
 		F7226EDB1EE4089300EBECB1 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
@@ -1032,7 +1030,6 @@
 				F7434B5F20E2440600417916 /* FileProviderExtension-Bridging-Header.h */,
 				F771E3D220E2392D00AFB62D /* FileProviderExtension.swift */,
 				F771E3F420E239B400AFB62D /* FileProviderExtension+Actions.swift */,
-				F716FE7923795EC500FABE50 /* FileProviderExtension+NetworkingDelegate.swift */,
 				F771E3F520E239B400AFB62D /* FileProviderExtension+Thumbnail.swift */,
 				F771E3D420E2392D00AFB62D /* FileProviderItem.swift */,
 				F76673EF22C90433007ED366 /* FileProviderUtility.swift */,
@@ -1986,7 +1983,6 @@
 				F771E3D520E2392D00AFB62D /* FileProviderItem.swift in Sources */,
 				F7434B3620E23FE000417916 /* NCManageDatabase.swift in Sources */,
 				F70460542499095400BB98A7 /* NotificationCenter+MainThread.swift in Sources */,
-				F716FE7A23795EC500FABE50 /* FileProviderExtension+NetworkingDelegate.swift in Sources */,
 				F785EEA42461A4A600B3F945 /* NCUtility.swift in Sources */,
 				F771E3F320E239A600AFB62D /* FileProviderData.swift in Sources */,
 				F771E3D720E2392D00AFB62D /* FileProviderEnumerator.swift in Sources */,