瀏覽代碼

recursive offline

Marino Faggiana 8 年之前
父節點
當前提交
1996803b66
共有 3 個文件被更改,包括 62 次插入58 次删除
  1. 11 5
      iOSClient/Main/CCMain.m
  2. 1 1
      iOSClient/Offline/CCOfflineFolder.h
  3. 50 52
      iOSClient/Offline/CCOfflineFolder.m

+ 11 - 5
iOSClient/Main/CCMain.m

@@ -362,9 +362,12 @@
         }
     }
     if (alertView.tag == alertOfflineFolder && buttonIndex == 1) {
-     
-        [[CCOfflineFolder sharedOfflineFolder] addRemoveOfflineFolder:[CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData]];
-        [self performSelector:@selector(getDataSourceWithReloadTableView) withObject:nil afterDelay:0.5];
+        
+        NSString *dir = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
+        
+        [[CCOfflineFolder sharedOfflineFolder] addOfflineFolder:dir];
+        
+        [self performSelector:@selector(getDataSourceWithReloadTableView) withObject:nil afterDelay:0.1];
     }
 }
 
@@ -4346,8 +4349,11 @@
                                             
                                         } else {
                                             
-                                            [[CCOfflineFolder sharedOfflineFolder] addRemoveOfflineFolder:[CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData]];
-                                            [self performSelector:@selector(getDataSourceWithReloadTableView) withObject:nil afterDelay:0.5];
+                                            NSString *dir = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
+                                            
+                                            [CCCoreData setOfflineDirectory:dir offline:NO activeAccount:app.activeAccount];
+                                            
+                                            [self performSelector:@selector(getDataSourceWithReloadTableView) withObject:nil];
                                         }
                                     }];
         }

+ 1 - 1
iOSClient/Offline/CCOfflineFolder.h

@@ -34,7 +34,7 @@
 + (CCOfflineFolder *)sharedOfflineFolder;
 
 - (void)readFolderOffline;
-- (void)addRemoveOfflineFolder:(NSString *)serverUrl;
+- (void)addOfflineFolder:(NSString *)serverUrl;
 
 - (void)verifyChangeMedatas:(NSArray *)allRecordMetadatas serverUrl:(NSString *)serverUrl directoryID:(NSString *)directoryID account:(NSString *)account offline:(BOOL)offline;
 

+ 50 - 52
iOSClient/Offline/CCOfflineFolder.m

@@ -78,31 +78,24 @@
 }
 
 //
-// Add - Remove Folder offline
+// Add Folder offline
 //
-- (void)addRemoveOfflineFolder:(NSString *)serverUrl
+- (void)addOfflineFolder:(NSString *)serverUrl
 {
-    BOOL offline = [CCCoreData isOfflineDirectory:serverUrl activeAccount:app.activeAccount];
     NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount];
     
-    if (offline) {
+    // Set offline directory
+    [CCCoreData setOfflineDirectory:serverUrl offline:YES activeAccount:app.activeAccount];
         
-        [CCCoreData setOfflineDirectory:serverUrl offline:NO activeAccount:app.activeAccount];
+    CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
         
-    } else {
+    metadataNet.action = actionReadFolder;
+    metadataNet.directoryID = directoryID;
+    metadataNet.priority = NSOperationQueuePriorityVeryHigh;
+    metadataNet.selector = selectorReadFolder;
+    metadataNet.serverUrl = serverUrl;
         
-        [CCCoreData setOfflineDirectory:serverUrl offline:YES activeAccount:app.activeAccount];
-        
-        CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-        
-        metadataNet.action = actionReadFolder;
-        metadataNet.directoryID = directoryID;
-        metadataNet.priority = NSOperationQueuePriorityVeryHigh;
-        metadataNet.selector = selectorReadFolder;
-        metadataNet.serverUrl = serverUrl;
-        
-        [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-    }
+    [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
 }
 
 #pragma --------------------------------------------------------------------------------------------
@@ -168,53 +161,58 @@
         
         for (CCMetadata *metadata in metadatas) {
             
-            // no dir
-            if (metadata.directory)
-                continue;
+            // dir recursive
+            if (metadata.directory) {
+                NSString *dir = [CCUtility stringAppendServerUrl:metadataNet.serverUrl addServerUrl:metadata.fileNameData];
+                
+                [[CCOfflineFolder sharedOfflineFolder] addOfflineFolder:dir];
+                
+            } else {
             
-            NSInteger typeFilename = [CCUtility getTypeFileName:metadata.fileName];
+                NSInteger typeFilename = [CCUtility getTypeFileName:metadata.fileName];
             
-            // reject crypto
-            if (typeFilename == metadataTypeFilenameCrypto) continue;
+                // reject crypto
+                if (typeFilename == metadataTypeFilenameCrypto) continue;
             
-            // Verify if the plist is complited
-            if (typeFilename == metadataTypeFilenamePlist) {
+                // Verify if the plist is complited
+                if (typeFilename == metadataTypeFilenamePlist) {
                 
-                BOOL isCryptoComplete = NO;
-                NSString *fileNameCrypto = [CCUtility trasformedFileNamePlistInCrypto:metadata.fileName];
+                    BOOL isCryptoComplete = NO;
+                    NSString *fileNameCrypto = [CCUtility trasformedFileNamePlistInCrypto:metadata.fileName];
                 
-                for (CCMetadata *completeMetadata in metadatas) {
+                    for (CCMetadata *completeMetadata in metadatas) {
                     
-                    if (completeMetadata.cryptated == NO) continue;
-                    else  if ([completeMetadata.fileName isEqualToString:fileNameCrypto]) {
-                        isCryptoComplete = YES;
-                        break;
+                        if (completeMetadata.cryptated == NO) continue;
+                        else  if ([completeMetadata.fileName isEqualToString:fileNameCrypto]) {
+                            isCryptoComplete = YES;
+                            break;
+                        }
                     }
+                    if (isCryptoComplete == NO) continue;
                 }
-                if (isCryptoComplete == NO) continue;
-            }
         
-            // Error password
-            if (metadata.errorPasscode)
-                continue;
+                // Error password
+                if (metadata.errorPasscode)
+                    continue;
             
-            // Plist not download
-            if (metadata.cryptated && [metadata.title length] == 0)
-                continue;
+                // Plist not download
+                if (metadata.cryptated && [metadata.title length] == 0)
+                    continue;
             
-            // It's in session
-            BOOL recordInSession = NO;
-            for (TableMetadata *record in recordsInSessions) {
-                if ([record.fileID isEqualToString:metadata.fileID]) {
-                    recordInSession = YES;
-                    break;
+                // It's in session
+                BOOL recordInSession = NO;
+                for (TableMetadata *record in recordsInSessions) {
+                    if ([record.fileID isEqualToString:metadata.fileID]) {
+                        recordInSession = YES;
+                        break;
+                    }
                 }
-            }
-            if (recordInSession)
-                continue;
+                if (recordInSession)
+                    continue;
             
-            // Ohhhh INSERT
-            [metadatasForOfflineFolder addObject:metadata];
+                // Ohhhh INSERT
+                [metadatasForOfflineFolder addObject:metadata];
+            }
         }
         
         if ([metadatasForOfflineFolder count] > 0)