12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199 |
- //
- // FileProviderExtension.swift
- // Files
- //
- // Created by Marino Faggiana on 26/03/18.
- // Copyright © 2018 TWS. All rights reserved.
- //
- // Author Marino Faggiana <m.faggiana@twsweb.it>
- //
- // 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 UIKit
- import MobileCoreServices
- var ocNetworking: OCnetworking?
- var account = ""
- var accountUser = ""
- var accountUserID = ""
- var accountPassword = ""
- var accountUrl = ""
- var homeServerUrl = ""
- var directoryUser = ""
- // Directory
- var groupURL: URL?
- var fileProviderStorageURL: URL?
- var importDocumentURL: URL?
- var changeDocumentURL: URL?
- // List
- var listUpdateItems = [NSFileProviderItem]()
- var listFavoriteIdentifierRank = [String:NSNumber]()
- var fileNamePathImport = [String]()
- var timerUpload: Timer?
- class FileProvider: NSFileProviderExtension, CCNetworkingDelegate {
-
- override init() {
-
- super.init()
-
- setupActiveAccount()
-
- if #available(iOSApplicationExtension 11.0, *) {
-
- listFavoriteIdentifierRank = NCManageDatabase.sharedInstance.getTableMetadatasDirectoryFavoriteIdentifierRank()
-
- // Timer for upload
- if timerUpload == nil {
-
- timerUpload = Timer.init(timeInterval: TimeInterval(k_timerProcessAutoDownloadUpload), repeats: true, block: { (Timer) in
-
- let tasks = CCNetworking.shared().getUploadTasksExtensionSession()
- if tasks == nil {
- let records = NCManageDatabase.sharedInstance.getQueueUpload(predicate: NSPredicate(format: "account = %@ AND selector = %@ AND lock == true AND path != nil", account, selectorUploadFile))
- if records != nil && records!.count > 0 {
- NCManageDatabase.sharedInstance.unlockAllQueueUploadInPath()
- }
- }
-
- self.uploadFile()
- })
-
- RunLoop.main.add(timerUpload!, forMode: .defaultRunLoopMode)
- }
-
- } else {
-
- NSFileCoordinator().coordinate(writingItemAt: self.documentStorageURL, options: [], error: nil, byAccessor: { newURL in
- do {
- try FileManager.default.createDirectory(at: newURL, withIntermediateDirectories: true, attributes: nil)
- } catch let error {
- print("error: \(error)")
- }
- })
- }
- }
-
- // MARK: - Enumeration
-
- override func enumerator(for containerItemIdentifier: NSFileProviderItemIdentifier) throws -> NSFileProviderEnumerator {
-
- /* ONLY iOS 11*/
- guard #available(iOS 11, *) else {
- throw NSError(domain: NSCocoaErrorDomain, code: NSFileNoSuchFileError, userInfo:[:])
- }
-
- var maybeEnumerator: NSFileProviderEnumerator? = nil
- if (containerItemIdentifier == NSFileProviderItemIdentifier.rootContainer) {
- maybeEnumerator = FileProviderEnumerator(enumeratedItemIdentifier: containerItemIdentifier)
- } else if (containerItemIdentifier == NSFileProviderItemIdentifier.workingSet) {
- maybeEnumerator = FileProviderEnumeratorWorkingSet(enumeratedItemIdentifier: containerItemIdentifier)
- } else {
- // determine if the item is a directory or a file
- // - for a directory, instantiate an enumerator of its subitems
- // - for a file, instantiate an enumerator that observes changes to the file
- let item = try self.item(for: containerItemIdentifier)
-
- if item.typeIdentifier == kUTTypeFolder as String {
- maybeEnumerator = FileProviderEnumerator(enumeratedItemIdentifier: containerItemIdentifier)
- } else {
- maybeEnumerator = FileProviderEnumeratorFile(enumeratedItemIdentifier: containerItemIdentifier)
- }
- }
-
- guard let enumerator = maybeEnumerator else {
- throw NSError(domain: NSCocoaErrorDomain, code: NSFeatureUnsupportedError, userInfo:[:])
- }
-
- return enumerator
- }
-
- // MARK: - Item
- override func item(for identifier: NSFileProviderItemIdentifier) throws -> NSFileProviderItem {
-
- /* ONLY iOS 11*/
- guard #available(iOS 11, *) else {
- throw NSError(domain: NSCocoaErrorDomain, code: NSFileNoSuchFileError, userInfo:[:])
- }
- if identifier == .rootContainer {
-
- if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account = %@ AND serverUrl = %@", account, homeServerUrl)) {
-
- let metadata = tableMetadata()
-
- metadata.account = account
- metadata.directory = true
- metadata.directoryID = directory.directoryID
- metadata.fileID = identifier.rawValue
- metadata.fileName = NCBrandOptions.sharedInstance.brand
- metadata.fileNameView = NCBrandOptions.sharedInstance.brand
- metadata.typeFile = k_metadataTypeFile_directory
-
- return FileProviderItem(metadata: metadata, serverUrl: homeServerUrl)
- }
-
- } else {
-
- if let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, identifier.rawValue)) {
- if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account = %@ AND directoryID = %@", account, metadata.directoryID)) {
- return FileProviderItem(metadata: metadata, serverUrl: directory.serverUrl)
- }
- }
- }
-
- // implement the actual lookup
- throw NSFileProviderError(.noSuchItem)
- }
-
- override func urlForItem(withPersistentIdentifier identifier: NSFileProviderItemIdentifier) -> URL? {
-
- /* ONLY iOS 11*/
- guard #available(iOS 11, *) else {
- return nil
- }
-
- // resolve the given identifier to a file on disk
- guard let item = try? item(for: identifier) else {
- return nil
- }
-
- // in this implementation, all paths are structured as <base storage directory>/<item identifier>/<item file name>
-
- let manager = NSFileProviderManager.default
- var url = manager.documentStorageURL.appendingPathComponent(identifier.rawValue, isDirectory: true)
-
- if item.typeIdentifier == (kUTTypeFolder as String) {
- url = url.appendingPathComponent(item.filename, isDirectory:true)
- } else {
- url = url.appendingPathComponent(item.filename, isDirectory:false)
- }
-
- return url
- }
-
- override func persistentIdentifierForItem(at url: URL) -> NSFileProviderItemIdentifier? {
-
- // resolve the given URL to a persistent identifier using a database
- let pathComponents = url.pathComponents
-
- // exploit the fact that the path structure has been defined as
- // <base storage directory>/<item identifier>/<item file name> above
- assert(pathComponents.count > 2)
-
- let itemIdentifier = NSFileProviderItemIdentifier(pathComponents[pathComponents.count - 2])
- return itemIdentifier
- }
-
- // MARK: - Managing Shared Files
-
- override func providePlaceholder(at url: URL, completionHandler: @escaping (Error?) -> Void) {
-
- if #available(iOSApplicationExtension 11.0, *) {
- guard let identifier = persistentIdentifierForItem(at: url) else {
- completionHandler(NSFileProviderError(.noSuchItem))
- return
- }
- do {
- let fileProviderItem = try item(for: identifier)
- let placeholderURL = NSFileProviderManager.placeholderURL(for: url)
- try NSFileProviderManager.writePlaceholder(at: placeholderURL,withMetadata: fileProviderItem)
- completionHandler(nil)
- } catch let error {
- print("error: \(error)")
- completionHandler(error)
- }
-
- } else {
-
- let fileName = url.lastPathComponent
- let placeholderURL = NSFileProviderExtension.placeholderURL(for: self.documentStorageURL.appendingPathComponent(fileName))
- let fileSize = 0
- let metadata = [AnyHashable(URLResourceKey.fileSizeKey): fileSize]
- do {
- try NSFileProviderExtension.writePlaceholder(at: placeholderURL, withMetadata: metadata as! [URLResourceKey : Any])
- } catch let error {
- print("error: \(error)")
- }
- completionHandler(nil)
- }
- }
- override func startProvidingItem(at url: URL, completionHandler: @escaping ((_ error: Error?) -> Void)) {
-
- if #available(iOSApplicationExtension 11.0, *) {
- let pathComponents = url.pathComponents
- let identifier = NSFileProviderItemIdentifier(pathComponents[pathComponents.count - 2])
- var localEtag = ""
- var localEtagFPE = ""
-
- // If identifier is a temp return
- if identifier.rawValue.contains(k_uploadSessionID) {
- completionHandler(nil)
- return
- }
-
- guard let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, identifier.rawValue)) else {
- completionHandler(NSFileProviderError(.noSuchItem))
- return
- }
-
- let tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, identifier.rawValue))
- if tableLocalFile != nil {
- localEtag = tableLocalFile!.etag
- localEtagFPE = tableLocalFile!.etagFPE
- }
-
- if (localEtagFPE != "") {
-
- // Verify last version on "Local Table"
- if localEtag != localEtagFPE {
- if self.copyFile("\(directoryUser)/\(identifier.rawValue)", toPath: url.path) == nil {
- NCManageDatabase.sharedInstance.setLocalFile(fileID: identifier.rawValue, date: nil, exifDate: nil, exifLatitude: nil, exifLongitude: nil, fileName: nil, etag: nil, etagFPE: localEtag)
- }
- }
-
- completionHandler(nil)
- return
- }
-
- guard let serverUrl = NCManageDatabase.sharedInstance.getServerUrl(metadata.directoryID) else {
- completionHandler(NSFileProviderError(.noSuchItem))
- return
- }
-
- // delete prev file + ico on Directory User
- _ = self.deleteFile("\(directoryUser)/\(metadata.fileID)")
- _ = self.deleteFile("\(directoryUser)/\(metadata.fileID).ico")
- let task = ocNetworking?.downloadFileNameServerUrl("\(serverUrl)/\(metadata.fileName)", fileNameLocalPath: "\(directoryUser)/\(metadata.fileID)", communication: CCNetworking.shared().sharedOCCommunicationExtensionDownload(metadata.fileName), success: { (lenght, etag, date) in
-
- // copy download file to url
- _ = self.copyFile("\(directoryUser)/\(metadata.fileID)", toPath: url.path)
-
- // update DB Local
- metadata.date = date! as NSDate
- metadata.etag = etag!
- NCManageDatabase.sharedInstance.addLocalFile(metadata: metadata)
- NCManageDatabase.sharedInstance.setLocalFile(fileID: metadata.fileID, date: date! as NSDate, exifDate: nil, exifLatitude: nil, exifLongitude: nil, fileName: nil, etag: etag, etagFPE: etag)
-
- // Update DB Metadata
- _ = NCManageDatabase.sharedInstance.addMetadata(metadata)
- completionHandler(nil)
-
- }, failure: { (errorMessage, errorCode) in
- completionHandler(NSFileProviderError(.serverUnreachable))
- })
-
- if task != nil {
- NSFileProviderManager.default.register(task!, forItemWithIdentifier: NSFileProviderItemIdentifier(identifier.rawValue)) { (error) in }
- }
-
- } else {
-
- guard let fileData = try? Data(contentsOf: url) else {
- completionHandler(nil)
- return
- }
- do {
- _ = try fileData.write(to: url, options: NSData.WritingOptions())
- completionHandler(nil)
- } catch let error {
- print("error: \(error)")
- completionHandler(error)
- }
- }
- }
-
- override func itemChanged(at url: URL) {
-
- if #available(iOSApplicationExtension 11.0, *) {
-
- let fileName = url.lastPathComponent
- let pathComponents = url.pathComponents
- let changeDocumentPath = changeDocumentURL!.path + "/" + fileName
- let importDocumentPath = importDocumentURL!.path + "/" + fileName
- let metadataNet = CCMetadataNet()
- assert(pathComponents.count > 2)
- let identifier = NSFileProviderItemIdentifier(pathComponents[pathComponents.count - 2])
-
- guard let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, identifier.rawValue)) else {
- return
- }
-
- guard let serverUrl = NCManageDatabase.sharedInstance.getServerUrl(metadata.directoryID) else {
- return
- }
-
- // Refresh
- self.refreshEnumerator(identifier: identifier, serverUrl: serverUrl)
-
- // Copy file to Change Document & if exists on Import Document
- _ = self.copyFile(url.path, toPath: changeDocumentPath)
- if FileManager.default.fileExists(atPath: importDocumentPath) {
- _ = self.copyFile(url.path, toPath: importDocumentPath)
- }
-
- metadataNet.account = account
- metadataNet.assetLocalIdentifier = k_assetLocalIdentifierFileProviderStorage + identifier.rawValue
- metadataNet.fileName = fileName
- metadataNet.path = changeDocumentPath
- metadataNet.selector = selectorUploadFile
- metadataNet.selectorPost = ""
- metadataNet.serverUrl = serverUrl
- metadataNet.session = k_upload_session_extension
- metadataNet.taskStatus = Int(k_taskStatusResume)
-
- _ = NCManageDatabase.sharedInstance.addQueueUpload(metadataNet: metadataNet)
-
- self.uploadFile()
-
- } else {
-
- let fileSize = (try! FileManager.default.attributesOfItem(atPath: url.path)[FileAttributeKey.size] as! NSNumber).uint64Value
- NSLog("[LOG] Item changed at URL %@ %lu", url as NSURL, fileSize)
-
- guard let account = NCManageDatabase.sharedInstance.getAccountActive() else {
- self.stopProvidingItem(at: url)
- return
- }
- guard let fileName = CCUtility.getFileNameExt() else {
- self.stopProvidingItem(at: url)
- return
- }
- // -------> Fix : Clear FileName for twice Office 365
- CCUtility.setFileNameExt("")
- // --------------------------------------------------
- if (fileName != url.lastPathComponent) {
- self.stopProvidingItem(at: url)
- return
- }
- guard let serverUrl = CCUtility.getServerUrlExt() else {
- self.stopProvidingItem(at: url)
- return
- }
- guard let directoryID = NCManageDatabase.sharedInstance.getDirectoryID(serverUrl) else {
- self.stopProvidingItem(at: url)
- return
- }
-
- let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "fileName == %@ AND directoryID == %@", fileName, directoryID))
- if metadata != nil {
-
- // Update
- let uploadID = k_uploadSessionID + CCUtility.createRandomString(16)
- let directoryUser = CCUtility.getDirectoryActiveUser(account.user, activeUrl: account.url)
- let destinationDirectoryUser = "\(directoryUser!)/\(uploadID)"
-
- // copy sourceURL on directoryUser
- _ = self.copyFile(url.path, toPath: destinationDirectoryUser)
-
- // Prepare for send Metadata
- metadata!.sessionID = uploadID
- metadata!.session = k_upload_session
- metadata!.sessionTaskIdentifier = Int(k_taskIdentifierWaitStart)
- _ = NCManageDatabase.sharedInstance.updateMetadata(metadata!)
-
- } else {
-
- // New
- let directoryUser = CCUtility.getDirectoryActiveUser(account.user, activeUrl: account.url)
- let destinationDirectoryUser = "\(directoryUser!)/\(fileName)"
-
- _ = self.copyFile(url.path, toPath: destinationDirectoryUser)
- CCNetworking.shared().uploadFile(fileName, serverUrl: serverUrl, assetLocalIdentifier: nil, fileID: "", session: k_upload_session, taskStatus: Int(k_taskStatusResume), selector: nil, selectorPost: nil, errorCode: 0, delegate: self)
- }
- self.stopProvidingItem(at: url)
- }
- }
-
- override func stopProvidingItem(at url: URL) {
- // Called after the last claim to the file has been released. At this point, it is safe for the file provider to remove the content file.
- // Care should be taken that the corresponding placeholder file stays behind after the content file has been deleted.
-
- // Called after the last claim to the file has been released. At this point, it is safe for the file provider to remove the content file.
-
- // look up whether the file has local changes
- let fileHasLocalChanges = false
-
- if !fileHasLocalChanges {
- // remove the existing file to free up space
- do {
- _ = try FileManager.default.removeItem(at: url)
- } catch let error {
- print("error: \(error)")
- }
-
- // write out a placeholder to facilitate future property lookups
- self.providePlaceholder(at: url, completionHandler: { error in
- // handle any error, do any necessary cleanup
- })
- }
- }
-
- // MARK: - Accessing Thumbnails
-
- override func fetchThumbnails(for itemIdentifiers: [NSFileProviderItemIdentifier], requestedSize size: CGSize, perThumbnailCompletionHandler: @escaping (NSFileProviderItemIdentifier, Data?, Error?) -> Void, completionHandler: @escaping (Error?) -> Void) -> Progress {
-
- /* ONLY iOS 11*/
- guard #available(iOS 11, *) else {
- return Progress(totalUnitCount:0)
- }
- let progress = Progress(totalUnitCount: Int64(itemIdentifiers.count))
- var counterProgress: Int64 = 0
-
- for itemIdentifier in itemIdentifiers {
-
- if let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, itemIdentifier.rawValue)) {
-
- if (metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video) {
-
- let serverUrl = NCManageDatabase.sharedInstance.getServerUrl(metadata.directoryID)
- let fileName = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: serverUrl, activeUrl: accountUrl)
- let fileNameLocal = metadata.fileID
- ocNetworking?.downloadThumbnail(withDimOfThumbnail: "m", fileName: fileName, fileNameLocal: fileNameLocal, success: {
- do {
- let url = URL.init(fileURLWithPath: "\(directoryUser)/\(itemIdentifier.rawValue).ico")
- let data = try Data.init(contentsOf: url)
- perThumbnailCompletionHandler(itemIdentifier, data, nil)
- } catch let error {
- print("error: \(error)")
- perThumbnailCompletionHandler(itemIdentifier, nil, NSFileProviderError(.noSuchItem))
- }
-
- counterProgress += 1
- if (counterProgress == progress.totalUnitCount) {
- completionHandler(nil)
- }
-
- }, failure: { (errorMessage, errorCode) in
- perThumbnailCompletionHandler(itemIdentifier, nil, NSFileProviderError(.serverUnreachable))
-
- counterProgress += 1
- if (counterProgress == progress.totalUnitCount) {
- completionHandler(nil)
- }
- })
-
- } else {
-
- counterProgress += 1
- if (counterProgress == progress.totalUnitCount) {
- completionHandler(nil)
- }
- }
- } else {
- counterProgress += 1
- if (counterProgress == progress.totalUnitCount) {
- completionHandler(nil)
- }
- }
- }
-
- return progress
- }
-
- // MARK: - Actions
- override func createDirectory(withName directoryName: String, inParentItemIdentifier parentItemIdentifier: NSFileProviderItemIdentifier, completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void) {
- /* ONLY iOS 11*/
- guard #available(iOS 11, *) else {
- return
- }
-
- var serverUrl = ""
-
- if parentItemIdentifier == .rootContainer {
-
- serverUrl = homeServerUrl
-
- } else {
-
- guard let directoryParent = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, parentItemIdentifier.rawValue)) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- serverUrl = directoryParent.serverUrl
- }
-
- ocNetworking?.createFolder(directoryName, serverUrl: serverUrl, account: account, success: { (fileID, date) in
-
- let metadata = tableMetadata()
-
- metadata.account = account
- metadata.directory = true
- metadata.directoryID = NCManageDatabase.sharedInstance.getDirectoryID(serverUrl)!
- metadata.fileID = fileID!
- metadata.fileName = directoryName
- metadata.fileNameView = directoryName
- metadata.typeFile = k_metadataTypeFile_directory
-
- // METADATA
- guard let metadataDB = NCManageDatabase.sharedInstance.addMetadata(metadata) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- // DIRECTORY
- guard let _ = NCManageDatabase.sharedInstance.addDirectory(encrypted: false, favorite: false, fileID: fileID!, permissions: nil, serverUrl: serverUrl + "/" + directoryName) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- let item = FileProviderItem(metadata: metadataDB, serverUrl: serverUrl)
-
- completionHandler(item, nil)
-
- }, failure: { (errorMessage, errorCode) in
- completionHandler(nil, NSFileProviderError(.serverUnreachable))
- })
- }
-
- override func deleteItem(withIdentifier itemIdentifier: NSFileProviderItemIdentifier, completionHandler: @escaping (Error?) -> Void) {
-
- /* ONLY iOS 11*/
- guard #available(iOS 11, *) else {
- return
- }
-
- guard let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, itemIdentifier.rawValue)) else {
- completionHandler(nil)
- return
- }
-
- guard let serverUrl = NCManageDatabase.sharedInstance.getServerUrl(metadata.directoryID) else {
- completionHandler(nil)
- return
- }
-
- ocNetworking?.deleteFileOrFolder(metadata.fileName, serverUrl: serverUrl, success: {
-
- let fileNamePath = directoryUser + "/" + metadata.fileID
- do {
- try FileManager.default.removeItem(atPath: fileNamePath)
- } catch let error {
- print("error: \(error)")
- }
- do {
- try FileManager.default.removeItem(atPath: fileNamePath + ".ico")
- } catch let error {
- print("error: \(error)")
- }
-
- if metadata.directory {
- let dirForDelete = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)
- NCManageDatabase.sharedInstance.deleteDirectoryAndSubDirectory(serverUrl: dirForDelete!)
- }
-
- NCManageDatabase.sharedInstance.deleteLocalFile(predicate: NSPredicate(format: "fileID == %@", metadata.fileID))
- NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "fileID == %@", metadata.fileID), clearDateReadDirectoryID: nil)
-
- completionHandler(nil)
-
- }, failure: { (errorMessage, errorCode) in
-
- if errorCode == 404 {
- completionHandler(nil)
- } else {
- completionHandler(NSFileProviderError(.serverUnreachable))
- }
- })
- }
-
- override func reparentItem(withIdentifier itemIdentifier: NSFileProviderItemIdentifier, toParentItemWithIdentifier parentItemIdentifier: NSFileProviderItemIdentifier, newName: String?, completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void) {
-
- /* ONLY iOS 11*/
- guard #available(iOS 11, *) else {
- return
- }
-
- var serverUrlTo = ""
- var fileNameTo = ""
- var directoryIDTo = ""
-
- guard let itemFrom = try? item(for: itemIdentifier) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- guard let metadataFrom = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, itemIdentifier.rawValue)) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- guard let serverUrlFrom = NCManageDatabase.sharedInstance.getServerUrl(metadataFrom.directoryID) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- let fileNameFrom = serverUrlFrom + "/" + itemFrom.filename
- if parentItemIdentifier == NSFileProviderItemIdentifier.rootContainer {
- serverUrlTo = homeServerUrl
- } else {
- guard let metadataTo = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, parentItemIdentifier.rawValue)) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
- serverUrlTo = NCManageDatabase.sharedInstance.getServerUrl(metadataTo.directoryID)! + "/" + metadataTo.fileName
- directoryIDTo = NCManageDatabase.sharedInstance.getDirectoryID(serverUrlTo)!
- }
-
- fileNameTo = serverUrlTo + "/" + itemFrom.filename
-
- ocNetworking?.moveFileOrFolder(fileNameFrom, fileNameTo: fileNameTo, success: {
-
- if metadataFrom.directory {
-
- NCManageDatabase.sharedInstance.deleteDirectoryAndSubDirectory(serverUrl: serverUrlFrom)
- NCManageDatabase.sharedInstance.moveMetadata(fileName: metadataFrom.fileName, directoryID: metadataFrom.directoryID, directoryIDTo: directoryIDTo)
- _ = NCManageDatabase.sharedInstance.addDirectory(encrypted: false, favorite: false, fileID: nil, permissions: nil, serverUrl: serverUrlTo)
-
- } else {
- NCManageDatabase.sharedInstance.moveMetadata(fileName: metadataFrom.fileName, directoryID: metadataFrom.directoryID, directoryIDTo: directoryIDTo)
- }
-
- guard let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, itemIdentifier.rawValue)) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- let item = FileProviderItem(metadata: metadata, serverUrl: serverUrlTo)
- completionHandler(item, nil)
-
- }, failure: { (errorMessage, errorCode) in
- completionHandler(nil, NSFileProviderError(.serverUnreachable))
- })
- }
-
- override func renameItem(withIdentifier itemIdentifier: NSFileProviderItemIdentifier, toName itemName: String, completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void) {
-
- /* ONLY iOS 11*/
- guard #available(iOS 11, *) else {
- return
- }
-
- guard let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, itemIdentifier.rawValue)) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- guard let serverUrl = NCManageDatabase.sharedInstance.getServerUrl(metadata.directoryID) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- guard let directoryTable = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "serverUrl = %@", serverUrl)) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- // resolve the given identifier to a file on disk
- guard let item = try? item(for: itemIdentifier) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- let fileName = serverUrl + "/" + item.filename
- let fileNameTo = serverUrl + "/" + itemName
-
- ocNetworking?.moveFileOrFolder(fileName, fileNameTo: fileNameTo, success: {
-
- metadata.fileName = itemName
- metadata.fileNameView = itemName
-
- guard let metadata = NCManageDatabase.sharedInstance.addMetadata(metadata) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- if metadata.directory {
-
- NCManageDatabase.sharedInstance.setDirectory(serverUrl: fileName, serverUrlTo: fileNameTo, etag: nil, fileID: nil, encrypted: directoryTable.e2eEncrypted)
- } else {
-
- NCManageDatabase.sharedInstance.setLocalFile(fileID: metadata.fileID, date: nil, exifDate: nil, exifLatitude: nil, exifLongitude: nil, fileName: itemName, etag: nil, etagFPE: nil)
- }
-
- completionHandler(item, nil)
-
- }, failure: { (errorMessage, errorCode) in
- completionHandler(nil, NSFileProviderError(.serverUnreachable))
- })
- }
-
- override func setFavoriteRank(_ favoriteRank: NSNumber?, forItemIdentifier itemIdentifier: NSFileProviderItemIdentifier, completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void) {
- /* ONLY iOS 11*/
- guard #available(iOS 11, *) else {
- return
- }
-
- completionHandler(nil, nil)
-
- /*
- guard let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, itemIdentifier.rawValue)) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
- guard let serverUrl = NCManageDatabase.sharedInstance.getServerUrl(metadata.directoryID) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
- // Refresh Favorite Identifier Rank
- listFavoriteIdentifierRank = NCManageDatabase.sharedInstance.getTableMetadatasDirectoryFavoriteIdentifierRank()
- if favoriteRank == nil {
- listFavoriteIdentifierRank.removeValue(forKey: itemIdentifier.rawValue)
- } else {
- let rank = listFavoriteIdentifierRank[itemIdentifier.rawValue]
- if rank == nil {
- listFavoriteIdentifierRank[itemIdentifier.rawValue] = favoriteRank//NSNumber(value: Int64(newRank))
- }
- favorite = true
- }
-
- // Call the completion handler before performing any network activity or other long-running tasks. Defer these tasks to the background
- let item = FileProviderItem(metadata: metadata, serverUrl: serverUrl)
- completionHandler(item, nil)
-
- // Change Status ? Call API Nextcloud Network
- if (favorite == true && metadata.favorite == false) || (favorite == false && metadata.favorite == true) {
-
- DispatchQueue(label: "com.nextcloud", qos: .background, attributes: .concurrent, autoreleaseFrequency: .inherit, target: nil).async {
-
- ocNetworking?.settingFavorite(metadata.fileName, serverUrl: serverUrl, favorite: favorite, success: {
-
- // Change DB
- metadata.favorite = favorite
- _ = NCManageDatabase.sharedInstance.addMetadata(metadata)
-
- // Refresh Favorite Identifier Rank
- listFavoriteIdentifierRank = NCManageDatabase.sharedInstance.getTableMetadatasDirectoryFavoriteIdentifierRank()
-
- // Refresh Item
- self.refreshEnumerator(identifier: itemIdentifier, serverUrl: serverUrl)
-
- }, failure: { (errorMessage, errorCode) in
- print("errorMessage")
- })
- }
- }
- */
- }
-
- override func setLastUsedDate(_ lastUsedDate: Date?, forItemIdentifier itemIdentifier: NSFileProviderItemIdentifier, completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void) {
- print("[LOG] setLastUsedDate")
- completionHandler(nil, nil)
- }
-
- override func setTagData(_ tagData: Data?, forItemIdentifier itemIdentifier: NSFileProviderItemIdentifier, completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void) {
-
- /* ONLY iOS 11*/
- guard #available(iOS 11, *) else {
- return
- }
-
- // Add, Remove (nil)
- NCManageDatabase.sharedInstance.addTag(itemIdentifier.rawValue, tagIOS: tagData)
-
- guard let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, itemIdentifier.rawValue)) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- guard let serverUrl = NCManageDatabase.sharedInstance.getServerUrl(metadata.directoryID) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- let item = FileProviderItem(metadata: metadata, serverUrl: serverUrl)
-
- self.refreshEnumerator(identifier: itemIdentifier, serverUrl: "WorkingSet")
-
- completionHandler(item, nil)
- }
-
- /*
- override func trashItem(withIdentifier itemIdentifier: NSFileProviderItemIdentifier, completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void) {
- print("[LOG] trashitem")
- completionHandler(nil, nil)
- }
-
- override func untrashItem(withIdentifier itemIdentifier: NSFileProviderItemIdentifier, toParentItemIdentifier parentItemIdentifier: NSFileProviderItemIdentifier?, completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void) {
- print("[LOG] untrashitem")
- completionHandler(nil, nil)
- }
- */
-
- override func importDocument(at fileURL: URL, toParentItemIdentifier parentItemIdentifier: NSFileProviderItemIdentifier, completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void) {
-
- /* ONLY iOS 11*/
- guard #available(iOS 11, *) else {
- return
- }
-
- var fileName = fileURL.lastPathComponent
- let fileCoordinator = NSFileCoordinator()
- var error: NSError?
- var directoryPredicate: NSPredicate
- var size = 0 as Double
- if parentItemIdentifier == .rootContainer {
- directoryPredicate = NSPredicate(format: "account = %@ AND serverUrl = %@", account, homeServerUrl)
- } else {
- directoryPredicate = NSPredicate(format: "account = %@ AND fileID = %@", account, parentItemIdentifier.rawValue)
- }
-
- guard let directoryParent = NCManageDatabase.sharedInstance.getTableDirectory(predicate: directoryPredicate) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- let serverUrl = directoryParent.serverUrl
-
- // --------------------------------------------- Copy file here with security access
-
- if fileURL.startAccessingSecurityScopedResource() == false {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- fileName = createFileName(fileName, directoryID: directoryParent.directoryID, serverUrl: serverUrl)
-
- let fileNameLocalPath = importDocumentURL!.appendingPathComponent(fileName)
-
- fileCoordinator.coordinate(readingItemAt: fileURL, options: NSFileCoordinator.ReadingOptions.withoutChanges, error: &error) { (url) in
- _ = self.copyFile( url.path, toPath: fileNameLocalPath.path)
- }
-
- fileURL.stopAccessingSecurityScopedResource()
-
- // ---------------------------------------------------------------------------------
-
- do {
- let attributes = try FileManager.default.attributesOfItem(atPath: fileNameLocalPath.path)
- size = attributes[FileAttributeKey.size] as! Double
- } catch let error {
- print("error: \(error)")
- }
-
- let metadata = tableMetadata()
-
- metadata.account = account
- metadata.date = NSDate()
- metadata.directory = false
- metadata.directoryID = directoryParent.directoryID
- metadata.etag = "000"
- metadata.fileID = k_uploadSessionID + directoryParent.directoryID + fileName
- metadata.fileName = fileName
- metadata.fileNameView = fileName
- metadata.size = size
- metadata.status = Double(k_metadataStatusHide)
- CCUtility.insertTypeFileIconName(fileName, metadata: metadata)
-
- guard let metadataDB = NCManageDatabase.sharedInstance.addMetadata(metadata) else {
- completionHandler(nil, NSFileProviderError(.noSuchItem))
- return
- }
-
- NCManageDatabase.sharedInstance.addLocalFile(metadata: metadata)
- NCManageDatabase.sharedInstance.setLocalFile(fileID: metadata.fileID, date: nil, exifDate: nil, exifLatitude: nil, exifLongitude: nil, fileName: nil, etag: metadata.etag, etagFPE: metadata.etag)
-
- // Create dir <base storage directory>/<item identifier>
- do {
- try FileManager.default.createDirectory(atPath: fileProviderStorageURL!.appendingPathComponent(metadata.fileID).path, withIntermediateDirectories: true, attributes: nil)
- } catch let error {
- print("error: \(error)")
- }
- // copy <base storage directory>/<item identifier>/<item file name>
- _ = self.copyFile(fileNameLocalPath.path, toPath: "\(fileProviderStorageURL!.appendingPathComponent(metadata.fileID).path)/\(metadata.fileName)")
-
- // ---------- Send the file to Nextcloud if size > 0 [Office 365] ----------
-
- if (size > 0) {
-
- let metadataNet = CCMetadataNet()
-
- metadataNet.account = account
- metadataNet.assetLocalIdentifier = k_assetLocalIdentifierFileProviderStorage + metadata.fileID
- metadataNet.fileID = k_uploadSessionID + directoryParent.directoryID + fileName
- metadataNet.fileName = fileName
- metadataNet.path = importDocumentURL!.path + "/" + metadata.fileNameView
- metadataNet.selector = selectorUploadFile
- metadataNet.selectorPost = ""
- metadataNet.serverUrl = serverUrl
- metadataNet.session = k_upload_session_extension
- metadataNet.taskStatus = Int(k_taskStatusResume)
-
- _ = NCManageDatabase.sharedInstance.addQueueUpload(metadataNet: metadataNet)
- }
- self.uploadFile()
-
- let item = FileProviderItem(metadata: metadataDB, serverUrl: serverUrl)
- completionHandler(item, nil)
- }
-
- // --------------------------------------------------------------------------------------------
- // MARK: - Upload
- // --------------------------------------------------------------------------------------------
-
- func uploadFileSuccessFailure(_ fileName: String!, fileID: String!, assetLocalIdentifier: String!, serverUrl: String!, selector: String!, selectorPost: String!, errorMessage: String!, errorCode: Int) {
-
- NCManageDatabase.sharedInstance.deleteQueueUpload(assetLocalIdentifier: assetLocalIdentifier, selector: selector)
-
- if let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, fileID)) {
-
- if (errorCode == 0) {
-
- let prevFileID = assetLocalIdentifier.replacingOccurrences(of: k_assetLocalIdentifierFileProviderStorage, with: "")
-
- NCManageDatabase.sharedInstance.setLocalFile(fileID: fileID, date: nil, exifDate: nil, exifLatitude: nil, exifLongitude: nil, fileName: nil, etag: metadata.etag, etagFPE: metadata.etag)
-
- // Change fileID
- if (prevFileID != fileID) {
-
- NCManageDatabase.sharedInstance.deleteLocalFile(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, prevFileID))
-
- // rename Directory : <base storage directory>/prevFileID/<item file name> to <base storage directory>/fileID/<item file name>
- do {
- let atPath = fileProviderStorageURL!.path + "/" + prevFileID
- let toPath = fileProviderStorageURL!.path + "/" + fileID
- try FileManager.default.moveItem(atPath: atPath, toPath: toPath)
- } catch let error as NSError {
- NSLog("Unable to create directory \(error.debugDescription)")
- }
- }
-
- let item = FileProviderItem(metadata: metadata, serverUrl: serverUrl)
- self.refreshEnumerator(identifier: item.itemIdentifier, serverUrl: serverUrl)
- }
- }
-
- uploadFile()
- }
-
- func uploadStart(_ fileID: String!, serverUrl: String!) {
-
- if let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND fileID = %@", account, fileID)) {
-
- let item = FileProviderItem(metadata: metadata, serverUrl: serverUrl)
- self.refreshEnumerator(identifier: item.itemIdentifier, serverUrl: serverUrl)
- }
- }
-
- func uploadFile() {
-
- let queueInLock = NCManageDatabase.sharedInstance.getQueueUploadInLock()
- if queueInLock != nil && queueInLock!.count == 0 {
-
- let metadataNetQueue = NCManageDatabase.sharedInstance.getQueueUploadLock(selector: selectorUploadFile, withPath: true)
- if metadataNetQueue != nil {
-
- if self.copyFile(metadataNetQueue!.path, toPath: directoryUser + "/" + metadataNetQueue!.fileName) == nil {
-
- CCNetworking.shared().uploadFile(metadataNetQueue!.fileName, serverUrl: metadataNetQueue!.serverUrl, assetLocalIdentifier: metadataNetQueue!.assetLocalIdentifier, fileID: metadataNetQueue!.fileID ,session: metadataNetQueue!.session, taskStatus: metadataNetQueue!.taskStatus, selector: metadataNetQueue!.selector, selectorPost: metadataNetQueue!.selectorPost, errorCode: 0, delegate: self)
-
- } else {
- // file not present, delete record Upload Queue
- NCManageDatabase.sharedInstance.deleteQueueUpload(path: metadataNetQueue!.path)
- }
- }
- }
- }
-
- // --------------------------------------------------------------------------------------------
- // MARK: - User Function
- // --------------------------------------------------------------------------------------------
-
- func refreshEnumerator(identifier: NSFileProviderItemIdentifier, serverUrl: String) {
-
- /* ONLY iOS 11*/
- guard #available(iOS 11, *) else {
- return
- }
-
- let item = try? self.item(for: identifier)
- if item != nil {
- var found = false
- for updateItem in listUpdateItems {
- if updateItem.itemIdentifier.rawValue == identifier.rawValue {
- found = true
- }
- }
- if !found {
- listUpdateItems.append(item!)
- }
- }
-
- if serverUrl == homeServerUrl {
- NSFileProviderManager.default.signalEnumerator(for: .rootContainer, completionHandler: { (error) in
- print("send signal rootContainer")
- })
- } else if serverUrl == "WorkingSet" {
- NSFileProviderManager.default.signalEnumerator(for: .workingSet, completionHandler: { (error) in
- print("send signal workingSet")
- })
- } else {
- if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account = %@ AND serverUrl = %@", account, serverUrl)) {
- let itemDirectory = NSFileProviderItemIdentifier(directory.fileID)
- NSFileProviderManager.default.signalEnumerator(for: itemDirectory, completionHandler: { (error) in
- print("send signal")
- })
- }
- }
- }
-
- func copyFile(_ atPath: String, toPath: String) -> Error? {
-
- var errorResult: Error?
-
- do {
- try FileManager.default.removeItem(atPath: toPath)
- } catch let error {
- print("error: \(error)")
- }
- do {
- try FileManager.default.copyItem(atPath: atPath, toPath: toPath)
- } catch let error {
- errorResult = error
- }
-
- return errorResult
- }
-
- func deleteFile(_ atPath: String) -> Error? {
-
- var errorResult: Error?
-
- do {
- try FileManager.default.removeItem(atPath: atPath)
- } catch let error {
- errorResult = error
- }
-
- return errorResult
- }
-
- func createFileName(_ fileName: String, directoryID: String, serverUrl: String) -> String {
-
- var resultFileName = fileName
- var exitLoop = false
-
- while exitLoop == false {
-
- if NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND fileNameView = %@ AND directoryID = %@", account, resultFileName, directoryID)) != nil || fileNamePathImport.contains(serverUrl+"/"+resultFileName) {
-
- var name = NSString(string: resultFileName).deletingPathExtension
- let ext = NSString(string: resultFileName).pathExtension
-
- let characters = Array(name)
-
- if characters.count < 2 {
- resultFileName = name + " " + "1" + "." + ext
- } else {
- let space = characters[characters.count-2]
- let numChar = characters[characters.count-1]
- var num = Int(String(numChar))
- if (space == " " && num != nil) {
- name = String(name.dropLast())
- num = num! + 1
- resultFileName = name + "\(num!)" + "." + ext
- } else {
- resultFileName = name + " " + "1" + "." + ext
- }
- }
-
- } else {
- exitLoop = true
- }
- }
-
- // add fileNamePathImport
- fileNamePathImport.append(serverUrl+"/"+resultFileName)
-
- return resultFileName
- }
- }
- // --------------------------------------------------------------------------------------------
- // MARK: - Setup Active Accont
- // --------------------------------------------------------------------------------------------
- func setupActiveAccount() {
-
- guard let activeAccount = NCManageDatabase.sharedInstance.getAccountActive() else {
- return
- }
-
- account = activeAccount.account
- accountUser = activeAccount.user
- accountUserID = activeAccount.userID
- accountPassword = activeAccount.password
- accountUrl = activeAccount.url
- homeServerUrl = CCUtility.getHomeServerUrlActiveUrl(activeAccount.url)
- directoryUser = CCUtility.getDirectoryActiveUser(activeAccount.user, activeUrl: activeAccount.url)
-
- ocNetworking = OCnetworking.init(delegate: nil, metadataNet: nil, withUser: accountUser, withUserID: accountUserID, withPassword: accountPassword, withUrl: accountUrl)
-
- groupURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.sharedInstance.capabilitiesGroups)
- fileProviderStorageURL = groupURL!.appendingPathComponent(k_assetLocalIdentifierFileProviderStorage)
- importDocumentURL = groupURL!.appendingPathComponent(k_assetLocalIdentifierFileProviderStorage).appendingPathComponent(k_fileProviderStorageImportDocument)
- changeDocumentURL = groupURL!.appendingPathComponent(k_assetLocalIdentifierFileProviderStorage).appendingPathComponent(k_fileProviderStorageChangeDocument)
-
- // Create dir File Provider Storage
- do {
- try FileManager.default.createDirectory(atPath: fileProviderStorageURL!.path, withIntermediateDirectories: true, attributes: nil)
- } catch let error as NSError {
- NSLog("Unable to create directory \(error.debugDescription)")
- }
-
- // Create dir for Upload
- do {
- try FileManager.default.createDirectory(atPath: importDocumentURL!.path, withIntermediateDirectories: true, attributes: nil)
- } catch let error as NSError {
- NSLog("Unable to create directory \(error.debugDescription)")
- }
-
- // Create dir for change document
- do {
- try FileManager.default.createDirectory(atPath: changeDocumentURL!.path, withIntermediateDirectories: true, attributes: nil)
- } catch let error as NSError {
- NSLog("Unable to create directory \(error.debugDescription)")
- }
- }
|