|
@@ -364,7 +364,7 @@
|
|
|
});
|
|
|
|
|
|
// Create the folder for Photos & if request the subfolders
|
|
|
- if(![[NCAutoUpload sharedInstance] createFolderSubFolderAutoUploadFolderPhotos:autoUploadPath useSubFolder:tableAccount.autoUploadCreateSubfolder assets:newAssetToUpload selector:selector]) {
|
|
|
+ if(![[NCAutoUpload sharedInstance] createAutoUploadFolderPhotosWithSubFolder:tableAccount.autoUploadCreateSubfolder assets:newAssetToUpload selector:selector]) {
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
// end loading
|
|
|
[_hud hideHud];
|
|
@@ -474,23 +474,55 @@
|
|
|
#pragma mark ===== Create Folder SubFolder Auto Upload Folder Photos ====
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
|
|
|
-- (BOOL)createFolderSubFolderAutoUploadFolderPhotos:(NSString *)folderPhotos useSubFolder:(BOOL)useSubFolder assets:(PHFetchResult *)assets selector:(NSString *)selector
|
|
|
+- (BOOL)createAutoUploadFolderPhotosWithSubFolder:(BOOL)useSubFolder assets:(PHFetchResult *)assets selector:(NSString *)selector
|
|
|
{
|
|
|
NSString *fileID;
|
|
|
+ __block NSInteger errorCodeCreateFolder = 0;
|
|
|
+ NSString *autoUploadPath = [[NCManageDatabase sharedInstance] getAccountAutoUploadPath:appDelegate.activeUrl];
|
|
|
+ NSString *autoUploadFileName = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
|
|
|
+ NSString *autoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl];
|
|
|
+ BOOL encrypted = [CCUtility isFolderEncrypted:autoUploadPath account:appDelegate.activeAccount];
|
|
|
+ OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
|
|
|
+
|
|
|
+ dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
|
|
+
|
|
|
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
+
|
|
|
+ [ocNetworking createFolder:autoUploadFileName serverUrl:autoUploadDirectory account:appDelegate.activeAccount success:^(NSString *fileID, NSDate *date) {
|
|
|
+
|
|
|
+ tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND serverUrl = %@", appDelegate.activeAccount, autoUploadPath]];
|
|
|
+ if (!tableDirectory)
|
|
|
+ (void)[[NCManageDatabase sharedInstance] addDirectoryWithEncrypted:encrypted favorite:false fileID:fileID permissions:nil serverUrl:autoUploadPath];
|
|
|
+
|
|
|
+ dispatch_semaphore_signal(semaphore);
|
|
|
+
|
|
|
+ } failure:^(NSString *message, NSInteger errorCode) {
|
|
|
+
|
|
|
+ if ([selector isEqualToString:selectorUploadAutoUploadAll])
|
|
|
+ [appDelegate messageNotification:@"_error_" description:@"_error_createsubfolders_upload_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
|
|
|
+
|
|
|
+ errorCodeCreateFolder = errorCode;
|
|
|
+
|
|
|
+ dispatch_semaphore_signal(semaphore);
|
|
|
+ }];
|
|
|
+ });
|
|
|
+
|
|
|
+ while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER))
|
|
|
+ [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
|
|
|
+
|
|
|
|
|
|
- BOOL encrypted = [CCUtility isFolderEncrypted:folderPhotos account:appDelegate.activeAccount];
|
|
|
- NSError *error = [[NCNetworkingSync sharedManager] createFolder:folderPhotos user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl encrypted:encrypted fileID:&fileID];
|
|
|
+ NSError *error = [[NCNetworkingSync sharedManager] createFolder:autoUploadPath user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl encrypted:encrypted fileID:&fileID];
|
|
|
|
|
|
if (error == nil) {
|
|
|
|
|
|
- tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND serverUrl = %@", appDelegate.activeAccount, folderPhotos]];
|
|
|
+ tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND serverUrl = %@", appDelegate.activeAccount, autoUploadPath]];
|
|
|
if (!tableDirectory)
|
|
|
- (void)[[NCManageDatabase sharedInstance] addDirectoryWithEncrypted:encrypted favorite:false fileID:fileID permissions:nil serverUrl:folderPhotos];
|
|
|
+ (void)[[NCManageDatabase sharedInstance] addDirectoryWithEncrypted:encrypted favorite:false fileID:fileID permissions:nil serverUrl:autoUploadPath];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Activity
|
|
|
- [[NCManageDatabase sharedInstance] addActivityClient:folderPhotos fileID:@"" action:k_activityDebugActionAutoUpload selector:selector note:NSLocalizedStringFromTable(@"_not_possible_create_folder_", @"Error", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:appDelegate.activeUrl];
|
|
|
+ [[NCManageDatabase sharedInstance] addActivityClient:autoUploadPath fileID:@"" action:k_activityDebugActionAutoUpload selector:selector note:NSLocalizedStringFromTable(@"_not_possible_create_folder_", @"Error", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:appDelegate.activeUrl];
|
|
|
|
|
|
if ([selector isEqualToString:selectorUploadAutoUploadAll])
|
|
|
[appDelegate messageNotification:@"_error_" description:@"_error_createsubfolders_upload_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
|
|
@@ -503,7 +535,7 @@
|
|
|
|
|
|
for (NSString *dateSubFolder in [CCUtility createNameSubFolder:assets]) {
|
|
|
|
|
|
- NSString *folderPathName = [NSString stringWithFormat:@"%@/%@", folderPhotos, dateSubFolder];
|
|
|
+ NSString *folderPathName = [NSString stringWithFormat:@"%@/%@", autoUploadPath, dateSubFolder];
|
|
|
|
|
|
error = [[NCNetworkingSync sharedManager] createFolder:folderPathName user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl encrypted:encrypted fileID:&fileID];
|
|
|
|