浏览代码

NCUtilityFileSystem.shared.directoryProviderStorage

Marino Faggiana 1 年之前
父节点
当前提交
192454bef3

+ 1 - 1
File Provider Extension/FileProviderExtension.swift

@@ -60,7 +60,7 @@ class FileProviderExtension: NSFileProviderExtension, NCNetworkingDelegate {
         super.init()
 
         // Create directory File Provider Storage
-        CCUtility.getDirectoryProviderStorage()
+        _ = NCUtilityFileSystem.shared.directoryProviderStorage
         // Configure URLSession
         _ = NCNetworking.shared.sessionManagerBackgroundExtension
     }

+ 1 - 3
iOSClient/AppDelegate.swift

@@ -236,9 +236,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
         // Clear older files
         let days = NCKeychain().cleanUpDay
-        if let directory = CCUtility.getDirectoryProviderStorage() {
-            NCUtilityFileSystem.shared.cleanUp(directory: directory, days: TimeInterval(days))
-        }
+        NCUtilityFileSystem.shared.cleanUp(directory: NCUtilityFileSystem.shared.directoryProviderStorage, days: TimeInterval(days))
 
         NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterApplicationWillResignActive)
     }

+ 2 - 2
iOSClient/Media/NCMediaCache.swift

@@ -48,7 +48,7 @@ import NextcloudKit
         metadatas.removeAll()
         getMetadatasMedia(account: account)
 
-        guard !metadatas.isEmpty, let directory = CCUtility.getDirectoryProviderStorage() else { return }
+        guard !metadatas.isEmpty else { return }
         let ext = ".preview.ico"
         let manager = FileManager.default
         let resourceKeys = Set<URLResourceKey>([.nameKey, .pathKey, .fileSizeKey, .creationDateKey])
@@ -64,7 +64,7 @@ import NextcloudKit
             ocIdEtag[metadata.ocId] = metadata.etag
         }
 
-        if let enumerator = manager.enumerator(at: URL(fileURLWithPath: directory), includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles]) {
+        if let enumerator = manager.enumerator(at: URL(fileURLWithPath: NCUtilityFileSystem.shared.directoryProviderStorage), includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles]) {
             for case let fileURL as URL in enumerator where fileURL.lastPathComponent.hasSuffix(ext) {
                 let fileName = fileURL.lastPathComponent
                 let ocId = fileURL.deletingLastPathComponent().lastPathComponent

+ 1 - 1
iOSClient/Settings/CCAdvanced.m

@@ -430,7 +430,7 @@
 - (void)calculateSize
 {
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-        NSString *directory = CCUtility.getDirectoryProviderStorage;
+        NSString *directory =  [[NCUtilityFileSystem shared] directoryProviderStorage];
         int64_t totalSize = [[NCUtilityFileSystem shared] getDirectorySizeWithDirectory:directory];
         sectionSize.footerTitle = [NSString stringWithFormat:@"%@. (%@ %@)", NSLocalizedString(@"_clear_cache_footer_", nil), NSLocalizedString(@"_used_space_", nil), [CCUtility transformedSize:totalSize]];
             

+ 0 - 1
iOSClient/Utility/CCUtility.h

@@ -49,7 +49,6 @@
 
 + (void)createDirectoryStandard;
 
-+ (NSString *)getDirectoryProviderStorage;
 + (NSString *)getDirectoryProviderStorageOcId:(NSString *)ocId;
 + (NSString *)getDirectoryProviderStorageOcId:(NSString *)ocId fileNameView:(NSString *)fileNameView;
 + (NSString *)getDirectoryProviderStorageIconOcId:(NSString *)ocId etag:(NSString *)etag;

+ 15 - 0
iOSClient/Utility/NCUtilityFileSystem.swift

@@ -70,6 +70,21 @@ class NCUtilityFileSystem: NSObject {
         return ""
     }
 
+    @objc var directoryProviderStorage: String {
+        if let directoryGroup = fileManager.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroups) {
+            let path = directoryGroup.appendingPathComponent(NCGlobal.shared.directoryProviderStorage).path
+            if !fileManager.fileExists(atPath: path) {
+                do {
+                    try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true)
+                } catch {
+                    return ""
+                }
+            }
+            return path
+        }
+        return ""
+    }
+
     @objc func getFileSize(filePath: String) -> Int64 {
 
         do {