Browse Source

intro, incrementalNumber, removeAll()

Marino Faggiana 1 year ago
parent
commit
d7adcf29e7

+ 2 - 1
Share/NCShareExtension+Files.swift

@@ -118,7 +118,8 @@ class NCFilesExtensionHandler {
                 if let url = item as? URL, url.isFileURL, !url.lastPathComponent.isEmpty {
                 if let url = item as? URL, url.isFileURL, !url.lastPathComponent.isEmpty {
                     originalName = url.lastPathComponent
                     originalName = url.lastPathComponent
 
 
-                    if fileNames.contains(originalName), let incrementalNumber = CCUtility.getIncrementalNumber() {
+                    if fileNames.contains(originalName) {
+                        let incrementalNumber = NCKeychain().incrementalNumber
                         originalName = "\(url.deletingPathExtension().lastPathComponent) \(incrementalNumber).\(url.pathExtension)"
                         originalName = "\(url.deletingPathExtension().lastPathComponent) \(incrementalNumber).\(url.pathExtension)"
                     }
                     }
                 }
                 }

+ 3 - 2
iOSClient/AppDelegate.swift

@@ -140,6 +140,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         } else {
         } else {
 
 
             CCUtility.deleteAllChainStore()
             CCUtility.deleteAllChainStore()
+            NCKeychain().removeAll()
             if let bundleID = Bundle.main.bundleIdentifier {
             if let bundleID = Bundle.main.bundleIdentifier {
                 UserDefaults.standard.removePersistentDomain(forName: bundleID)
                 UserDefaults.standard.removePersistentDomain(forName: bundleID)
             }
             }
@@ -170,12 +171,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
 
         // Intro
         // Intro
         if NCBrandOptions.shared.disable_intro {
         if NCBrandOptions.shared.disable_intro {
-            CCUtility.setIntro(true)
+            NCKeychain().intro = true
             if account.isEmpty {
             if account.isEmpty {
                 openLogin(viewController: nil, selector: NCGlobal.shared.introLogin, openLoginWeb: false)
                 openLogin(viewController: nil, selector: NCGlobal.shared.introLogin, openLoginWeb: false)
             }
             }
         } else {
         } else {
-            if !CCUtility.getIntro() {
+            if !NCKeychain().intro {
                 if let viewController = UIStoryboard(name: "NCIntro", bundle: nil).instantiateInitialViewController() {
                 if let viewController = UIStoryboard(name: "NCIntro", bundle: nil).instantiateInitialViewController() {
                     let navigationController = NCLoginNavigationController(rootViewController: viewController)
                     let navigationController = NCLoginNavigationController(rootViewController: viewController)
                     window?.rootViewController = navigationController
                     window?.rootViewController = navigationController

+ 1 - 1
iOSClient/Extensions/PHAsset+Extension.swift

@@ -30,7 +30,7 @@ extension PHAsset {
             return resource.originalFilename as NSString
             return resource.originalFilename as NSString
         } else {
         } else {
             return self.value(forKey: "filename") as? NSString
             return self.value(forKey: "filename") as? NSString
-            ?? ("IMG_" + CCUtility.getIncrementalNumber() + getExtension()) as NSString
+            ?? ("IMG_" + NCKeychain().incrementalNumber + getExtension()) as NSString
         }
         }
     }
     }
 
 

+ 2 - 2
iOSClient/Login/NCLogin.swift

@@ -407,10 +407,10 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
 
 
                     self.appDelegate.changeAccount(account, userProfile: userProfile)
                     self.appDelegate.changeAccount(account, userProfile: userProfile)
 
 
-                    if CCUtility.getIntro() {
+                    if NCKeychain().intro {
                         self.dismiss(animated: true)
                         self.dismiss(animated: true)
                     } else {
                     } else {
-                        CCUtility.setIntro(true)
+                        NCKeychain().intro = true
                         if self.presentingViewController == nil {
                         if self.presentingViewController == nil {
                             let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
                             let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
                             viewController?.modalPresentationStyle = .fullScreen
                             viewController?.modalPresentationStyle = .fullScreen

+ 2 - 2
iOSClient/Login/NCLoginWeb.swift

@@ -303,10 +303,10 @@ extension NCLoginWeb: WKNavigationDelegate {
 
 
                 self.appDelegate.changeAccount(account, userProfile: userProfile)
                 self.appDelegate.changeAccount(account, userProfile: userProfile)
 
 
-                if CCUtility.getIntro() {
+                if NCKeychain().intro {
                     self.dismiss(animated: true)
                     self.dismiss(animated: true)
                 } else {
                 } else {
-                    CCUtility.setIntro(true)
+                    NCKeychain().intro = true
                     if self.presentingViewController == nil {
                     if self.presentingViewController == nil {
                         if let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() {
                         if let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() {
                             viewController.modalPresentationStyle = .fullScreen
                             viewController.modalPresentationStyle = .fullScreen

+ 1 - 1
iOSClient/Main/NCActionCenter.swift

@@ -523,7 +523,7 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec
                 guard !results.ext.isEmpty,
                 guard !results.ext.isEmpty,
                       let data = UIPasteboard.general.data(forPasteboardType: item.key, inItemSet: IndexSet([index]))?.first
                       let data = UIPasteboard.general.data(forPasteboardType: item.key, inItemSet: IndexSet([index]))?.first
                 else { continue }
                 else { continue }
-                let fileName = results.name + "_" + CCUtility.getIncrementalNumber() + "." + results.ext
+                let fileName = results.name + "_" + NCKeychain().incrementalNumber + "." + results.ext
                 let serverUrlFileName = serverUrl + "/" + fileName
                 let serverUrlFileName = serverUrl + "/" + fileName
                 let ocIdUpload = UUID().uuidString
                 let ocIdUpload = UUID().uuidString
                 let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(ocIdUpload, fileNameView: fileName)!
                 let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(ocIdUpload, fileNameView: fileName)!

+ 1 - 0
iOSClient/Settings/CCAdvanced.m

@@ -466,6 +466,7 @@
             [CCUtility removeTemporaryDirectory];
             [CCUtility removeTemporaryDirectory];
 
 
             [CCUtility deleteAllChainStore];
             [CCUtility deleteAllChainStore];
+            [[[NCKeychain alloc] init] removeAll];
 
 
             exit(0);
             exit(0);
         });
         });

+ 1 - 0
iOSClient/Settings/NCSettingsBundleHelper.swift

@@ -48,6 +48,7 @@ class NCSettingsBundleHelper: NSObject {
             CCUtility.removeTemporaryDirectory()
             CCUtility.removeTemporaryDirectory()
 
 
             CCUtility.deleteAllChainStore()
             CCUtility.deleteAllChainStore()
+            NCKeychain().removeAll()
             NCManageDatabase.shared.removeDB()
             NCManageDatabase.shared.removeDB()
 
 
             DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
             DispatchQueue.main.asyncAfter(deadline: .now() + delay) {

+ 0 - 9
iOSClient/Utility/CCUtility.h

@@ -40,15 +40,6 @@
 // GET/SET
 // GET/SET
 
 
 + (void)deleteAllChainStore;
 + (void)deleteAllChainStore;
-+ (void)storeAllChainInService;
-
-+ (NSString *)getGroupBySettings;
-+ (void)setGroupBySettings:(NSString *)groupby;
-
-+ (BOOL)getIntro;
-+ (void)setIntro:(BOOL)set;
-
-+ (NSString *)getIncrementalNumber;
 
 
 + (NSString *)getAccountExt;
 + (NSString *)getAccountExt;
 + (void)setAccountExt:(NSString *)account;
 + (void)setAccountExt:(NSString *)account;

+ 1 - 71
iOSClient/Utility/CCUtility.m

@@ -48,78 +48,8 @@
     [UICKeyChainStore removeAllItemsForService:NCGlobal.shared.serviceShareKeyChain];
     [UICKeyChainStore removeAllItemsForService:NCGlobal.shared.serviceShareKeyChain];
 }
 }
 
 
-+ (void)storeAllChainInService
-{
-    UICKeyChainStore *store = [UICKeyChainStore keyChainStore];
-
-    NSArray *items = store.allItems;
-
-    for (NSDictionary *item in items) {
-
-        [UICKeyChainStore setString:[item objectForKey:@"value"] forKey:[item objectForKey:@"key"] service:NCGlobal.shared.serviceShareKeyChain];
-        [UICKeyChainStore removeItemForKey:[item objectForKey:@"key"]];
-    }
-}
-
 #pragma ------------------------------ GET/SET
 #pragma ------------------------------ GET/SET
 
 
-+ (NSString *)getGroupBySettings
-{
-    NSString *groupby = [UICKeyChainStore stringForKey:@"groupby" service:NCGlobal.shared.serviceShareKeyChain];
-
-    if (groupby == nil) {
-
-        [self setGroupBySettings:@"none"];
-        return @"none";
-    }
-
-    return @"none";
-
-    //return groupby;
-}
-
-+ (void)setGroupBySettings:(NSString *)groupby
-{
-    [UICKeyChainStore setString:groupby forKey:@"groupby" service:NCGlobal.shared.serviceShareKeyChain];
-}
-
-+ (BOOL)getIntro
-{
-    // Set compatibility old version don't touch me
-    if ([[UICKeyChainStore stringForKey:[INTRO_MessageType stringByAppendingString:@"Intro"] service:NCGlobal.shared.serviceShareKeyChain] boolValue] == YES) {
-        [CCUtility setIntro:YES];
-        return YES;
-    }
-
-    return [[UICKeyChainStore stringForKey:@"intro" service:NCGlobal.shared.serviceShareKeyChain] boolValue];
-}
-
-+ (BOOL)getIntroMessageOldVersion
-{
-    NSString *key = [INTRO_MessageType stringByAppendingString:@"Intro"];
-
-    return [[UICKeyChainStore stringForKey:key service:NCGlobal.shared.serviceShareKeyChain] boolValue];
-}
-
-+ (void)setIntro:(BOOL)set
-{
-    NSString *sIntro = (set) ? @"true" : @"false";
-    [UICKeyChainStore setString:sIntro forKey:@"intro" service:NCGlobal.shared.serviceShareKeyChain];
-
-}
-
-+ (NSString *)getIncrementalNumber
-{
-    long number = [[UICKeyChainStore stringForKey:@"incrementalnumber" service:NCGlobal.shared.serviceShareKeyChain] intValue];
-
-    number++;
-    if (number >= 9999) number = 1;
-
-    [UICKeyChainStore setString:[NSString stringWithFormat:@"%ld", number] forKey:@"incrementalnumber" service:NCGlobal.shared.serviceShareKeyChain];
-
-    return [NSString stringWithFormat:@"%04ld", number];
-}
-
 + (NSString *)getAccountExt
 + (NSString *)getAccountExt
 {
 {
     return [UICKeyChainStore stringForKey:@"accountExt" service:NCGlobal.shared.serviceShareKeyChain];
     return [UICKeyChainStore stringForKey:@"accountExt" service:NCGlobal.shared.serviceShareKeyChain];
@@ -794,7 +724,7 @@
 
 
     NSString *numberFileName;
     NSString *numberFileName;
     if ([fileName length] > 8) numberFileName = [fileName substringWithRange:NSMakeRange(04, 04)];
     if ([fileName length] > 8) numberFileName = [fileName substringWithRange:NSMakeRange(04, 04)];
-    else numberFileName = [CCUtility getIncrementalNumber];
+    else numberFileName = [NCKeychain alloc].incrementalNumber;
 
 
     NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
     NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
     [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
     [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];

+ 28 - 0
iOSClient/Utility/NCKeychain.swift

@@ -36,6 +36,10 @@ import KeychainAccess
         }
         }
     }
     }
 
 
+    @objc func removeAll() {
+        try? keychain.removeAll()
+    }
+
     var typeFilterScanDocument: NCGlobal.TypeFilterScanDocument {
     var typeFilterScanDocument: NCGlobal.TypeFilterScanDocument {
         get {
         get {
             if let rawValue = try? keychain.get("ScanDocumentTypeFilter"), let value = NCGlobal.TypeFilterScanDocument(rawValue: rawValue) {
             if let rawValue = try? keychain.get("ScanDocumentTypeFilter"), let value = NCGlobal.TypeFilterScanDocument(rawValue: rawValue) {
@@ -95,4 +99,28 @@ import KeychainAccess
             keychain["enableTouchFaceID"] = String(newValue)
             keychain["enableTouchFaceID"] = String(newValue)
         }
         }
     }
     }
+
+    var intro: Bool {
+        get {
+            migrate(key: "intro")
+            if let value = try? keychain.get("intro"), let result = Bool(value) {
+                return result
+            }
+            return false
+        }
+        set {
+            keychain["intro"] = String(newValue)
+        }
+    }
+
+    @objc var incrementalNumber: String {
+        migrate(key: "incrementalnumber")
+        var incrementalString = String(format: "%04ld", 0)
+        if let value = try? keychain.get("incrementalnumber"), var result = Int(value) {
+            result += 1
+            incrementalString = String(format: "%04ld", result)
+        }
+        keychain["incrementalnumber"] = incrementalString
+        return incrementalString
+    }
 }
 }

+ 1 - 0
iOSClient/Utility/NCUtility.swift

@@ -220,6 +220,7 @@ class NCUtility: NSObject {
         CCUtility.createDirectoryStandard()
         CCUtility.createDirectoryStandard()
 
 
         CCUtility.deleteAllChainStore()
         CCUtility.deleteAllChainStore()
+        NCKeychain().removeAll()
     }
     }
 #endif
 #endif