Эх сурвалжийг харах

Modify routine automatic upload

Marino Faggiana 8 жил өмнө
parent
commit
9d5d5e07e6

+ 1 - 0
iOSClient/Networking/OCNetworking.h

@@ -45,6 +45,7 @@
 
 - (NSError *)readFileSync:(NSString *)filePathName;
 - (NSError *)checkServerSync:(NSString *)serverUrl;
+- (BOOL)automaticCreateFolderSync:(NSString *)folderPathName;
 
 @end
 

+ 43 - 0
iOSClient/Networking/OCNetworking.m

@@ -686,6 +686,49 @@
     }];
 }
 
+- (BOOL)automaticCreateFolderSync:(NSString *)folderPathName
+{
+    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
+    __block BOOL noError = YES;
+    
+    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
+    
+    [communication setCredentialsWithUser:_activeUser andPassword:_activePassword];
+    [communication setUserAgent:[CCUtility getUserAgent]];
+    
+    [communication readFile:folderPathName onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer) {
+        
+        dispatch_semaphore_signal(semaphore);
+        
+    } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
+        
+        TableAccount *recordAccount = [CCCoreData getActiveAccount];
+
+        [communication createFolder:folderPathName onCommunication:communication withForbiddenCharactersSupported:YES successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
+            
+            [CCCoreData clearDateReadAccount:recordAccount.account serverUrl:[CCUtility deletingLastPathComponentFromServerUrl:folderPathName] directoryID:nil];
+            
+            dispatch_semaphore_signal(semaphore);
+            
+        } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
+            
+            noError = NO;
+            
+            dispatch_semaphore_signal(semaphore);
+            
+        } errorBeforeRequest:^(NSError *error) {
+            
+            noError = NO;
+            dispatch_semaphore_signal(semaphore);
+        }];
+    }];
+    
+    while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW))
+        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
+    
+    return noError;
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark =====  Delete =====
 #pragma --------------------------------------------------------------------------------------------

+ 1 - 1
iOSClient/PhotosCameraUpload/CCPhotosCameraUpload.h

@@ -51,6 +51,6 @@
 - (void)downloadFileFailure:(NSInteger)errorCode;
 
 - (void)reloadDatasourceForced;
-- (BOOL)automaticCreateFolder:(NSString *)folderPathName;
+//- (BOOL)automaticCreateFolder:(NSString *)folderPathName;
 
 @end

+ 2 - 0
iOSClient/PhotosCameraUpload/CCPhotosCameraUpload.m

@@ -1263,6 +1263,7 @@
     [app updateApplicationIconBadgeNumber];
 }
 
+/*
 - (BOOL)automaticCreateFolder:(NSString *)folderPathName
 {
     OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
@@ -1303,6 +1304,7 @@
     
     return noError;
 }
+*/
 
 -(void)endLoadingAssets
 {