瀏覽代碼

clear code

marinofaggiana 4 年之前
父節點
當前提交
2c18dc5877
共有 4 個文件被更改,包括 19 次插入16 次删除
  1. 11 3
      iOSClient/Brand/NCBrand.swift
  2. 0 5
      iOSClient/CCGlobal.h
  3. 6 6
      iOSClient/Data/NCManageDatabase.swift
  4. 2 2
      iOSClient/Utility/CCUtility.m

+ 11 - 3
iOSClient/Brand/NCBrand.swift

@@ -216,8 +216,16 @@ class NCBrandColor: NSObject {
         return instance
     }()
 
+    // Directory on Group
+    @objc public let appDatabaseNextcloud: String   = "Library/Application Support/Nextcloud"
+
+    
+    // Database Realm
+    public let databaseDefault: String              = "nextcloud.realm"
+    public let databaseSchemaVersion: UInt64        = 153
     
-    @objc public let indexPageActivity:     Int = 0
-    @objc public let indexPageComments:     Int = 1
-    @objc public let indexPageSharing:      Int = 2
+    // NCSharePaging
+    public let indexPageActivity: Int               = 0
+    public let indexPageComments: Int               = 1
+    public let indexPageSharing: Int                = 2
 }

+ 0 - 5
iOSClient/CCGlobal.h

@@ -52,7 +52,6 @@
 
 // Directory on Group
 #define k_appApplicationSupport                         @"Library/Application Support"
-#define k_appDatabaseNextcloud                          @"Library/Application Support/Nextcloud"
 #define k_appUserData                                   @"Library/Application Support/UserData"
 #define k_appCertificates                               @"Library/Application Support/Certificates"
 #define k_appScan                                       @"Library/Application Support/Scan"
@@ -78,10 +77,6 @@
 #define k_sizePreview                                   1024
 #define k_sizeIcon                                      512
 
-// Database Realm
-#define k_databaseDefault                               @"nextcloud.realm"
-#define k_databaseSchemaVersion                         153
-
 // Database JSON
 #define k_databaseDefaultJSON                           @"nextcloud.json"
 

+ 6 - 6
iOSClient/Data/NCManageDatabase.swift

@@ -34,7 +34,7 @@ class NCManageDatabase: NSObject {
     override init() {
         
         let dirGroup = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroups)
-        let databaseFilePath = dirGroup?.appendingPathComponent("\(k_appDatabaseNextcloud)/\(k_databaseDefault)")
+        let databaseFilePath = dirGroup?.appendingPathComponent(NCBrandGlobal.shared.appDatabaseNextcloud + "/" + NCBrandGlobal.shared.databaseDefault)
 
         let bundleUrl: URL = Bundle.main.bundleURL
         let bundlePathExtension: String = bundleUrl.pathExtension
@@ -45,8 +45,8 @@ class NCManageDatabase: NSObject {
             // App Extension config
             
             let config = Realm.Configuration(
-                fileURL: dirGroup?.appendingPathComponent("\(k_appDatabaseNextcloud)/\(k_databaseDefault)"),
-                schemaVersion: UInt64(k_databaseSchemaVersion),
+                fileURL: dirGroup?.appendingPathComponent(NCBrandGlobal.shared.appDatabaseNextcloud + "/" + NCBrandGlobal.shared.databaseDefault),
+                schemaVersion: NCBrandGlobal.shared.databaseSchemaVersion,
                 objectTypes: [tableMetadata.self, tableLocalFile.self, tableDirectory.self, tableTag.self, tableAccount.self, tableCapabilities.self, tableE2eEncryption.self]
             )
             
@@ -59,7 +59,7 @@ class NCManageDatabase: NSObject {
             let configCompact = Realm.Configuration(
                 
                 fileURL: databaseFilePath,
-                schemaVersion: UInt64(k_databaseSchemaVersion),
+                schemaVersion: NCBrandGlobal.shared.databaseSchemaVersion,
                 
                 migrationBlock: { migration, oldSchemaVersion in
                                         
@@ -144,8 +144,8 @@ class NCManageDatabase: NSObject {
             }
                         
             let config = Realm.Configuration(
-                fileURL: dirGroup?.appendingPathComponent("\(k_appDatabaseNextcloud)/\(k_databaseDefault)"),
-                schemaVersion: UInt64(k_databaseSchemaVersion)
+                fileURL: dirGroup?.appendingPathComponent(NCBrandGlobal.shared.appDatabaseNextcloud + "/" + NCBrandGlobal.shared.databaseDefault),
+                schemaVersion: NCBrandGlobal.shared.databaseSchemaVersion
             )
             
             Realm.Configuration.defaultConfiguration = config

+ 2 - 2
iOSClient/Utility/CCUtility.m

@@ -1006,7 +1006,7 @@
         [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
     
     // create Directory database Nextcloud
-    path = [[dirGroup URLByAppendingPathComponent:k_appDatabaseNextcloud] path];
+    path = [[dirGroup URLByAppendingPathComponent:[[NCBrandGlobal shared] appDatabaseNextcloud]] path];
     if (![[NSFileManager defaultManager] fileExistsAtPath:path])
         [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
     [[NSFileManager defaultManager] setAttributes:@{NSFileProtectionKey:NSFileProtectionNone} ofItemAtPath:path error:nil];
@@ -1038,7 +1038,7 @@
     
     #ifdef DEBUG
     NSLog(@"[LOG] Copy DB on Documents directory");
-    NSString *atPathDB = [NSString stringWithFormat:@"%@/nextcloud.realm", [[dirGroup URLByAppendingPathComponent:k_appDatabaseNextcloud] path]];
+    NSString *atPathDB = [NSString stringWithFormat:@"%@/nextcloud.realm", [[dirGroup URLByAppendingPathComponent:[[NCBrandGlobal shared] appDatabaseNextcloud]] path]];
     NSString *toPathDB = [NSString stringWithFormat:@"%@/nextcloud.realm", [CCUtility getDirectoryDocuments]];
     [[NSFileManager defaultManager] removeItemAtPath:toPathDB error:nil];
     [[NSFileManager defaultManager] copyItemAtPath:atPathDB toPath:toPathDB error:nil];