12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import Foundation
- class FileProviderDomain: NSObject {
-
- @objc func registerDomains() {
-
- NSFileProviderManager.getDomainsWithCompletionHandler { (fileProviderDomain, error) in
-
- var domains:[String] = []
- let pathRelativeToDocumentStorage = NSFileProviderManager.default.documentStorageURL.absoluteString
- let accounts = NCManageDatabase.sharedInstance.getAllAccount()
-
- for domain in fileProviderDomain {
- domains.append(domain.identifier.rawValue)
- }
-
-
- for domain in domains {
- var domainFound = false
- for account in accounts {
- guard let urlBase = NSURL(string: account.urlBase) else { continue }
- guard let host = urlBase.host else { continue }
- let accountDomain = account.userID + " (" + host + ")"
- if domain == accountDomain {
- domainFound = true
- break
- }
- }
- if !domainFound {
- let domainRawValue = NSFileProviderDomain(identifier: NSFileProviderDomainIdentifier(rawValue: domain), displayName: domain, pathRelativeToDocumentStorage: pathRelativeToDocumentStorage)
- NSFileProviderManager.remove(domainRawValue, completionHandler: { (error) in
- if error != nil {
- print("Error domain: \(domainRawValue) error: \(String(describing: error))")
- }
- })
- }
- }
-
-
- for account in accounts {
- var domainFound = false
- guard let urlBase = NSURL(string: account.urlBase) else { continue }
- guard let host = urlBase.host else { continue }
- let accountDomain = account.userID + " (" + host + ")"
- for domain in domains {
- if domain == accountDomain {
- domainFound = true
- break
- }
- }
- if !domainFound {
- let domainRawValue = NSFileProviderDomain(identifier: NSFileProviderDomainIdentifier(rawValue: accountDomain), displayName: accountDomain, pathRelativeToDocumentStorage: pathRelativeToDocumentStorage)
- NSFileProviderManager.add(domainRawValue, completionHandler: { (error) in
- if error != nil {
- print("Error domain: \(domainRawValue) error: \(String(describing: error))")
- }
- })
- }
- }
- }
- }
-
- @objc func removeAllDomains() {
-
- NSFileProviderManager.removeAllDomains { (_) in }
- }
-
- @objc func recreateDomains() {
-
- NSFileProviderManager.removeAllDomains { (_) in
- self.recreateDomains()
- }
- }
- }
|