Browse Source

New createIDfromAccount

Marino Faggiana 6 years ago
parent
commit
82d5338153

+ 1 - 1
iOSClient/Database/NCManageDatabase.swift

@@ -803,7 +803,7 @@ class NCManageDatabase: NSObject {
             result = tableDirectory()
             result!.account = account
                 
-            result!.directoryID = NSUUID().uuidString.replacingOccurrences(of: "-", with: "").lowercased()
+            result!.directoryID = CCUtility.createIDfromAccount(account, serverUrl: serverUrl) //NSUUID().uuidString.replacingOccurrences(of: "-", with: "").lowercased()
             result!.e2eEncrypted = encrypted
             result!.favorite = favorite
             if let fileID = fileID {

+ 2 - 1
iOSClient/Utility/CCUtility.h

@@ -190,7 +190,6 @@
 + (void)moveFileAtPath:(NSString *)atPath toPath:(NSString *)toPath;
 + (void)copyFileAtPath:(NSString *)atPath toPath:(NSString *)toPath;
 + (void)removeFileAtPath:(NSString *)atPath;
-+ (void)removeAllFileID_UPLOAD_ActiveUser:(NSString *)activeUser activeUrl:(NSString *)activeUrl;
 
 + (NSString *)deletingLastPathComponentFromServerUrl:(NSString *)serverUrl;
 + (NSString *)firtsPathComponentFromServerUrl:(NSString *)serverUrl activeUrl:(NSString *)activeUrl;
@@ -208,6 +207,8 @@
 
 + (void)writeData:(NSData *)data fileNamePath:(NSString *)fileNamePath;
 
++ (NSString *)createIDfromAccount:(NSString *)account serverUrl:(NSString *)serverUrl;
+
 // ===== E2E Encrypted =====
 
 + (NSString *)generateRandomIdentifier;

+ 15 - 16
iOSClient/Utility/CCUtility.m

@@ -982,22 +982,6 @@
     }
 }
 
-+ (void)removeAllFileID_UPLOAD_ActiveUser:(NSString *)activeUser activeUrl:(NSString *)activeUrl
-{
-    NSString *file;
-    NSString *dir;
-    
-    dir = [self getDirectoryActiveUser:activeUser activeUrl:activeUrl];
-    
-    NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dir];
-    
-    while (file = [enumerator nextObject]) {
-        
-        if ([file rangeOfString:@"ID_UPLOAD_"].location != NSNotFound)
-            [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dir, file] error:nil];
-    }
-}
-
 + (NSString *)deletingLastPathComponentFromServerUrl:(NSString *)serverUrl
 {
     NSURL *url = [[NSURL URLWithString:[serverUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]] URLByDeletingLastPathComponent];
@@ -1119,6 +1103,21 @@
     [data writeToFile:fileNamePath atomically:YES];
 }
 
++ (NSString *)createIDfromAccount:(NSString *)account serverUrl:(NSString *)serverUrl
+{
+    NSArray *arrayForbiddenCharacters = [NSArray arrayWithObjects:@"\\",@"<",@">",@":",@"\"",@"|",@"?",@"*",@"/",@" ", @".", @"-", @"@", nil];
+    
+    for (NSString *currentCharacter in arrayForbiddenCharacters) {
+        account = [account stringByReplacingOccurrencesOfString:currentCharacter withString:@""];
+    }
+    
+    for (NSString *currentCharacter in arrayForbiddenCharacters) {
+        serverUrl = [serverUrl stringByReplacingOccurrencesOfString:currentCharacter withString:@""];
+    }
+    
+    return [[account stringByAppendingString:serverUrl] lowercaseString];
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== E2E Encrypted =====
 #pragma --------------------------------------------------------------------------------------------