|
@@ -495,16 +495,18 @@
|
|
|
if (localfile != nil && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, metadata.fileID]]) {
|
|
|
|
|
|
[[NCManageDatabase sharedInstance] setMetadataSession:@"" sessionError:@"" sessionSelector:@"" sessionSelectorPost:@"" sessionTaskIdentifier:k_taskIdentifierDone sessionTaskIdentifierPlist:k_taskIdentifierDone predicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadata.fileID]];
|
|
|
-
|
|
|
- if ([[self getDelegate:metadata.fileID] respondsToSelector:@selector(downloadFileSuccess:serverUrl:selector:selectorPost:)])
|
|
|
- [[self getDelegate:metadata.fileID] downloadFileSuccess:metadata.fileID serverUrl:serverUrl selector:selector selectorPost:selectorPost];
|
|
|
-
|
|
|
+
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if ([[self getDelegate:metadata.fileID] respondsToSelector:@selector(downloadFileSuccess:serverUrl:selector:selectorPost:)])
|
|
|
+ [[self getDelegate:metadata.fileID] downloadFileSuccess:metadata.fileID serverUrl:serverUrl selector:selector selectorPost:selectorPost];
|
|
|
+ });
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- [self downloaURLSession:metadata.fileNameData fileNamePrint:metadata.fileNamePrint serverUrl:serverUrl fileID:metadata.fileID session:session taskStatus:taskStatus selector:selector];
|
|
|
-
|
|
|
[[NCManageDatabase sharedInstance] setMetadataSession:session sessionError:@"" sessionSelector:selector sessionSelectorPost:selectorPost sessionTaskIdentifier:k_taskIdentifierNULL sessionTaskIdentifierPlist:k_taskIdentifierNULL predicate:[NSPredicate predicateWithFormat:@"fileID = %@",metadata.fileID]];
|
|
|
+
|
|
|
+ [self downloaURLSession:metadata.fileNameData fileNamePrint:metadata.fileNamePrint serverUrl:serverUrl fileID:metadata.fileID session:session taskStatus:taskStatus selector:selector];
|
|
|
}
|
|
|
|
|
|
if (downloadPlist) {
|
|
@@ -519,9 +521,9 @@
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- [self downloaURLSession:metadata.fileName fileNamePrint:metadata.fileNamePrint serverUrl:serverUrl fileID:metadata.fileID session:session taskStatus:taskStatus selector:selector];
|
|
|
-
|
|
|
[[NCManageDatabase sharedInstance] setMetadataSession:session sessionError:@"" sessionSelector:selector sessionSelectorPost:selectorPost sessionTaskIdentifier:k_taskIdentifierNULL sessionTaskIdentifierPlist:k_taskIdentifierNULL predicate:[NSPredicate predicateWithFormat:@"fileID = %@",metadata.fileID]];
|
|
|
+
|
|
|
+ [self downloaURLSession:metadata.fileName fileNamePrint:metadata.fileNamePrint serverUrl:serverUrl fileID:metadata.fileID session:session taskStatus:taskStatus selector:selector];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -550,8 +552,10 @@
|
|
|
else if (taskStatus == k_taskStatusSuspend) [downloadTask suspend];
|
|
|
else if (taskStatus == k_taskStatusResume) [downloadTask resume];
|
|
|
|
|
|
- if ([[self getDelegate:fileID] respondsToSelector:@selector(downloadTaskSave:)])
|
|
|
- [[self getDelegate:fileID] downloadTaskSave:downloadTask];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if ([[self getDelegate:fileID] respondsToSelector:@selector(downloadTaskSave:)])
|
|
|
+ [[self getDelegate:fileID] downloadTaskSave:downloadTask];
|
|
|
+ });
|
|
|
|
|
|
if (downloadTask == nil) {
|
|
|
|
|
@@ -578,13 +582,15 @@
|
|
|
NSLog(@"[LOG] downloadFileSession %@ - %@ Task [%lu %lu]", fileID, fileNamePrint, (unsigned long)sessionTaskIdentifier, (unsigned long)sessionTaskIdentifierPlist);
|
|
|
}
|
|
|
|
|
|
- // Refresh datasource if is not a Plist
|
|
|
- if ([_delegate respondsToSelector:@selector(reloadDatasource:fileID:selector:)] && [CCUtility isCryptoPlistString:fileName] == NO)
|
|
|
- [_delegate reloadDatasource:serverUrl fileID:fileID selector:selector];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ // Refresh datasource if is not a Plist
|
|
|
+ if ([_delegate respondsToSelector:@selector(reloadDatasource:fileID:selector:)] && [CCUtility isCryptoPlistString:fileName] == NO)
|
|
|
+ [_delegate reloadDatasource:serverUrl fileID:fileID selector:selector];
|
|
|
|
|
|
#ifndef EXTENSION
|
|
|
[app updateApplicationIconBadgeNumber];
|
|
|
#endif
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
|
|
@@ -676,8 +682,10 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if ([[self getDelegate:fileID] respondsToSelector:@selector(downloadFileFailure:serverUrl:selector:message:errorCode:)])
|
|
|
- [[self getDelegate:fileID] downloadFileFailure:fileID serverUrl:serverUrl selector:selector message:[CCError manageErrorKCF:errorCode withNumberError:YES] errorCode:errorCode];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if ([[self getDelegate:fileID] respondsToSelector:@selector(downloadFileFailure:serverUrl:selector:message:errorCode:)])
|
|
|
+ [[self getDelegate:fileID] downloadFileFailure:fileID serverUrl:serverUrl selector:selector message:[CCError manageErrorKCF:errorCode withNumberError:YES] errorCode:errorCode];
|
|
|
+ });
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -721,9 +729,11 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if ([[self getDelegate:fileID] respondsToSelector:@selector(downloadFileSuccess:serverUrl:selector:selectorPost:)])
|
|
|
- [[self getDelegate:fileID] downloadFileSuccess:fileID serverUrl:serverUrl selector:selector selectorPost:selectorPost];
|
|
|
- }
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if ([[self getDelegate:fileID] respondsToSelector:@selector(downloadFileSuccess:serverUrl:selector:selectorPost:)])
|
|
|
+ [[self getDelegate:fileID] downloadFileSuccess:fileID serverUrl:serverUrl selector:selector selectorPost:selectorPost];
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
@@ -751,8 +761,11 @@
|
|
|
|
|
|
[[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:@"Internal error image/video not found" type:k_activityTypeFailure verbose:k_activityVerboseHigh activeUrl:_activeUrl];
|
|
|
|
|
|
- if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
- [delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:@"Internal error image/video not found" errorCode: k_CCErrorInternalError];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
+ [delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:@"Internal error image/video not found" errorCode: k_CCErrorInternalError];
|
|
|
+ });
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -784,10 +797,10 @@
|
|
|
|
|
|
if (AVAssetExportSessionStatusCompleted == exportSession.status) {
|
|
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ //dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
[self upload:fileName serverUrl:serverUrl cryptated:cryptated template:NO onlyPlist:NO fileNameTemplate:nil assetLocalIdentifier:assetLocalIdentifier session:session taskStatus:taskStatus selector:selector selectorPost:selectorPost errorCode:errorCode delegate:delegate];
|
|
|
- });
|
|
|
+ //});
|
|
|
|
|
|
} else if (AVAssetExportSessionStatusFailed == exportSession.status) {
|
|
|
|
|
@@ -795,7 +808,6 @@
|
|
|
[[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:NSLocalizedString(@"_read_file_error_", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
// Error for uploadFileFailure
|
|
|
if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
[delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:@"_read_file_error_" errorCode:[NSError errorWithDomain:@"it.twsweb.cryptocloud" code:kCFURLErrorFileDoesNotExist userInfo:nil].code];
|
|
@@ -812,7 +824,6 @@
|
|
|
[[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:NSLocalizedString(@"_read_file_error_", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
// Error for uploadFileFailure
|
|
|
if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
[delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:@"_read_file_error_" errorCode:[NSError errorWithDomain:@"it.twsweb.cryptocloud" code:kCFURLErrorFileDoesNotExist userInfo:nil].code];
|
|
@@ -838,20 +849,16 @@
|
|
|
|
|
|
// Activity
|
|
|
[[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:NSLocalizedString(@"_read_file_error_", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
// Error for uploadFileFailure
|
|
|
if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
[delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:@"_read_file_error_" errorCode:error.code];
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
- [self upload:fileName serverUrl:serverUrl cryptated:cryptated template:NO onlyPlist:NO fileNameTemplate:nil assetLocalIdentifier:assetLocalIdentifier session:session taskStatus:taskStatus selector:selector selectorPost:selectorPost errorCode:errorCode delegate:delegate];
|
|
|
- });
|
|
|
+
|
|
|
+ [self upload:fileName serverUrl:serverUrl cryptated:cryptated template:NO onlyPlist:NO fileNameTemplate:nil assetLocalIdentifier:assetLocalIdentifier session:session taskStatus:taskStatus selector:selector selectorPost:selectorPost errorCode:errorCode delegate:delegate];
|
|
|
}
|
|
|
}];
|
|
|
}
|
|
@@ -999,68 +1006,68 @@
|
|
|
|
|
|
if (errorCode == 403) {
|
|
|
|
|
|
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:fileName message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+
|
|
|
+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:fileName message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
|
|
|
+ UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
|
|
|
|
|
|
- // Activity
|
|
|
- [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:uploadID action:k_activityDebugActionUpload selector:selector note:NSLocalizedString(@"_file_already_exists_", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
+ // Activity
|
|
|
+ [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:uploadID action:k_activityDebugActionUpload selector:selector note:NSLocalizedString(@"_file_already_exists_", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
// Error for uploadFileFailure
|
|
|
if ([[self getDelegate:uploadID] respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
[[self getDelegate:uploadID] uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:NSLocalizedString(@"_file_already_exists_", nil) errorCode:403];
|
|
|
- });
|
|
|
|
|
|
- return;
|
|
|
- }];
|
|
|
+ return;
|
|
|
+ }];
|
|
|
|
|
|
- UIAlertAction *overwriteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_overwrite_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
|
|
+ UIAlertAction *overwriteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_overwrite_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
|
|
|
|
|
- // -- remove record --
|
|
|
+ // -- remove record --
|
|
|
|
|
|
- tableMetadata *metadataDelete = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND fileName = %@ AND directoryID = %@", _activeAccount, [fileNameCrypto stringByAppendingString:@".plist"], directoryID]];
|
|
|
+ tableMetadata *metadataDelete = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND fileName = %@ AND directoryID = %@", _activeAccount, [fileNameCrypto stringByAppendingString:@".plist"], directoryID]];
|
|
|
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, metadataDelete.fileID] error:nil];
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", _directoryUser, metadataDelete.fileID] error:nil];
|
|
|
+ [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, metadataDelete.fileID] error:nil];
|
|
|
+ [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", _directoryUser, metadataDelete.fileID] error:nil];
|
|
|
|
|
|
- if (metadataDelete.directory && serverUrl) {
|
|
|
+ if (metadataDelete.directory && serverUrl) {
|
|
|
|
|
|
- NSString *dirForDelete = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadataDelete.fileNameData];
|
|
|
+ NSString *dirForDelete = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadataDelete.fileNameData];
|
|
|
|
|
|
- [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:dirForDelete];
|
|
|
- }
|
|
|
+ [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:dirForDelete];
|
|
|
+ }
|
|
|
|
|
|
- [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadataDelete.fileID]];
|
|
|
- [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadataDelete.fileID]];
|
|
|
+ [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadataDelete.fileID]];
|
|
|
+ [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadataDelete.fileID]];
|
|
|
|
|
|
#ifndef EXTENSION
|
|
|
- [CCGraphics createNewImageFrom:fileName directoryUser:_directoryUser fileNameTo:uploadID fileNamePrint:fileName size:@"m" imageForUpload:YES typeFile:metadata.typeFile writePreview:YES optimizedFileName:NO];
|
|
|
+ [CCGraphics createNewImageFrom:fileName directoryUser:_directoryUser fileNameTo:uploadID fileNamePrint:fileName size:@"m" imageForUpload:YES typeFile:metadata.typeFile writePreview:YES optimizedFileName:NO];
|
|
|
#endif
|
|
|
|
|
|
- if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])
|
|
|
- [[CCCrypto sharedManager] addPlistImage:[NSString stringWithFormat:@"%@/%@", _directoryUser, [fileNameCrypto stringByAppendingString:@".plist"]] fileNamePathImage:[NSTemporaryDirectory() stringByAppendingString:uploadID]];
|
|
|
+ if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])
|
|
|
+ [[CCCrypto sharedManager] addPlistImage:[NSString stringWithFormat:@"%@/%@", _directoryUser, [fileNameCrypto stringByAppendingString:@".plist"]] fileNamePathImage:[NSTemporaryDirectory() stringByAppendingString:uploadID]];
|
|
|
|
|
|
- metadata = [[NCManageDatabase sharedInstance] addMetadata:metadata activeUrl:_activeUrl];
|
|
|
+ metadata = [[NCManageDatabase sharedInstance] addMetadata:metadata activeUrl:_activeUrl];
|
|
|
|
|
|
- // DATA
|
|
|
- [self uploadURLSession:fileNameCrypto fileNamePrint:fileName serverUrl:serverUrl sessionID:uploadID session:metadata.session taskStatus:taskStatus assetLocalIdentifier:assetLocalIdentifier cryptated:cryptated onlyPlist:onlyPlist selector:selector];
|
|
|
+ // DATA
|
|
|
+ [self uploadURLSession:fileNameCrypto fileNamePrint:fileName serverUrl:serverUrl sessionID:uploadID session:metadata.session taskStatus:taskStatus assetLocalIdentifier:assetLocalIdentifier cryptated:cryptated onlyPlist:onlyPlist selector:selector];
|
|
|
|
|
|
- // PLIST
|
|
|
- [self uploadURLSession:[fileNameCrypto stringByAppendingString:@".plist"] fileNamePrint:fileName serverUrl:serverUrl sessionID:uploadID session:metadata.session taskStatus:taskStatus assetLocalIdentifier:assetLocalIdentifier cryptated:cryptated onlyPlist:onlyPlist selector:selector];
|
|
|
- }];
|
|
|
+ // PLIST
|
|
|
+ [self uploadURLSession:[fileNameCrypto stringByAppendingString:@".plist"] fileNamePrint:fileName serverUrl:serverUrl sessionID:uploadID session:metadata.session taskStatus:taskStatus assetLocalIdentifier:assetLocalIdentifier cryptated:cryptated onlyPlist:onlyPlist selector:selector];
|
|
|
+ }];
|
|
|
|
|
|
- [alertController addAction:cancelAction];
|
|
|
- [alertController addAction:overwriteAction];
|
|
|
+ [alertController addAction:cancelAction];
|
|
|
+ [alertController addAction:overwriteAction];
|
|
|
|
|
|
- UIWindow *alertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
|
|
|
- alertWindow.rootViewController = [[UIViewController alloc]init];
|
|
|
- alertWindow.windowLevel = UIWindowLevelAlert + 1;
|
|
|
+ UIWindow *alertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
|
|
|
+ alertWindow.rootViewController = [[UIViewController alloc]init];
|
|
|
+ alertWindow.windowLevel = UIWindowLevelAlert + 1;
|
|
|
|
|
|
- [alertWindow makeKeyAndVisible];
|
|
|
+ [alertWindow makeKeyAndVisible];
|
|
|
|
|
|
- [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
|
|
|
+ [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
|
|
|
+ });
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -1102,60 +1109,60 @@
|
|
|
// File exists ???
|
|
|
if (errorCode == 403) {
|
|
|
|
|
|
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:fileName message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+
|
|
|
+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:fileName message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
|
|
|
+ UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
|
|
|
|
|
|
- // Activity
|
|
|
- [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:uploadID action:k_activityDebugActionUpload selector:selector note:NSLocalizedString(@"_file_already_exists_", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
+ // Activity
|
|
|
+ [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:uploadID action:k_activityDebugActionUpload selector:selector note:NSLocalizedString(@"_file_already_exists_", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
// Error for uploadFileFailure
|
|
|
if ([[self getDelegate:uploadID] respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
[[self getDelegate:uploadID] uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:NSLocalizedString(@"_file_already_exists_", nil) errorCode:403];
|
|
|
- });
|
|
|
|
|
|
- return;
|
|
|
- }];
|
|
|
+ return;
|
|
|
+ }];
|
|
|
|
|
|
- UIAlertAction *overwriteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_overwrite_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
|
|
+ UIAlertAction *overwriteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_overwrite_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
|
|
|
|
|
- // -- remove record --
|
|
|
- tableMetadata *metadataDelete = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND fileName = %@ AND directoryID = %@", _activeAccount, fileName, directoryID]];
|
|
|
+ // -- remove record --
|
|
|
+ tableMetadata *metadataDelete = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND fileName = %@ AND directoryID = %@", _activeAccount, fileName, directoryID]];
|
|
|
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, metadataDelete.fileID] error:nil];
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", _directoryUser, metadataDelete.fileID] error:nil];
|
|
|
+ [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, metadataDelete.fileID] error:nil];
|
|
|
+ [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", _directoryUser, metadataDelete.fileID] error:nil];
|
|
|
|
|
|
- if (metadataDelete.directory && serverUrl) {
|
|
|
+ if (metadataDelete.directory && serverUrl) {
|
|
|
|
|
|
- NSString *dirForDelete = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadataDelete.fileNameData];
|
|
|
+ NSString *dirForDelete = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadataDelete.fileNameData];
|
|
|
|
|
|
- [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:dirForDelete];
|
|
|
- }
|
|
|
+ [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:dirForDelete];
|
|
|
+ }
|
|
|
|
|
|
- [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadataDelete.fileID]];
|
|
|
- [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadataDelete.fileID]];
|
|
|
+ [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadataDelete.fileID]];
|
|
|
+ [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadataDelete.fileID]];
|
|
|
|
|
|
- // -- Go to Upload --
|
|
|
- [CCGraphics createNewImageFrom:metadata.fileNamePrint directoryUser:_directoryUser fileNameTo:metadata.fileID fileNamePrint:metadata.fileNamePrint size:@"m" imageForUpload:YES typeFile:metadata.typeFile writePreview:YES optimizedFileName:NO];
|
|
|
+ // -- Go to Upload --
|
|
|
+ [CCGraphics createNewImageFrom:metadata.fileNamePrint directoryUser:_directoryUser fileNameTo:metadata.fileID fileNamePrint:metadata.fileNamePrint size:@"m" imageForUpload:YES typeFile:metadata.typeFile writePreview:YES optimizedFileName:NO];
|
|
|
|
|
|
- //[CCCoreData addMetadata:metadata activeAccount:_activeAccount activeUrl:_activeUrl context:_context];
|
|
|
- metadata = [[NCManageDatabase sharedInstance] addMetadata:metadata activeUrl:_activeUrl];
|
|
|
+ //[CCCoreData addMetadata:metadata activeAccount:_activeAccount activeUrl:_activeUrl context:_context];
|
|
|
+ metadata = [[NCManageDatabase sharedInstance] addMetadata:metadata activeUrl:_activeUrl];
|
|
|
|
|
|
- [self uploadURLSession:fileName fileNamePrint:fileName serverUrl:serverUrl sessionID:uploadID session:metadata.session taskStatus:taskStatus assetLocalIdentifier:assetLocalIdentifier cryptated:cryptated onlyPlist:onlyPlist selector:selector];
|
|
|
- }];
|
|
|
+ [self uploadURLSession:fileName fileNamePrint:fileName serverUrl:serverUrl sessionID:uploadID session:metadata.session taskStatus:taskStatus assetLocalIdentifier:assetLocalIdentifier cryptated:cryptated onlyPlist:onlyPlist selector:selector];
|
|
|
+ }];
|
|
|
|
|
|
- [alertController addAction:cancelAction];
|
|
|
- [alertController addAction:overwriteAction];
|
|
|
+ [alertController addAction:cancelAction];
|
|
|
+ [alertController addAction:overwriteAction];
|
|
|
|
|
|
- UIWindow *alertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
|
|
|
- alertWindow.rootViewController = [[UIViewController alloc] init];
|
|
|
- alertWindow.windowLevel = UIWindowLevelAlert + 1;
|
|
|
+ UIWindow *alertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
|
|
|
+ alertWindow.rootViewController = [[UIViewController alloc] init];
|
|
|
+ alertWindow.windowLevel = UIWindowLevelAlert + 1;
|
|
|
|
|
|
- [alertWindow makeKeyAndVisible];
|
|
|
+ [alertWindow makeKeyAndVisible];
|
|
|
|
|
|
- [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
|
|
|
+ [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
|
|
|
+ });
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -1164,7 +1171,6 @@
|
|
|
#ifndef EXTENSION
|
|
|
[CCGraphics createNewImageFrom:metadata.fileNamePrint directoryUser:_directoryUser fileNameTo:metadata.fileID fileNamePrint:metadata.fileNamePrint size:@"m" imageForUpload:YES typeFile:metadata.typeFile writePreview:YES optimizedFileName:NO];
|
|
|
#endif
|
|
|
- //[CCCoreData addMetadata:metadata activeAccount:_activeAccount activeUrl:_activeUrl context:_context];
|
|
|
metadata = [[NCManageDatabase sharedInstance] addMetadata:metadata activeUrl:_activeUrl];
|
|
|
|
|
|
[self uploadURLSession:fileName fileNamePrint:fileName serverUrl:serverUrl sessionID:uploadID session:metadata.session taskStatus:taskStatus assetLocalIdentifier:assetLocalIdentifier cryptated:cryptated onlyPlist:onlyPlist selector:selector];
|
|
@@ -1252,19 +1258,17 @@
|
|
|
// file NOT exists
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileNameForUpload]] == NO) {
|
|
|
|
|
|
+ // Activity
|
|
|
+ [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:sessionID action:k_activityDebugActionUpload selector:selector note:NSLocalizedString(@"_file_not_present_", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
+
|
|
|
+ [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"sessionID = %@ AND account = %@", sessionID, _activeAccount]];
|
|
|
+
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
- // Activity
|
|
|
- [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:sessionID action:k_activityDebugActionUpload selector:selector note:NSLocalizedString(@"_file_not_present_", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
-
|
|
|
// Error for uploadFileFailure
|
|
|
if ([[self getDelegate:sessionID] respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
[[self getDelegate:sessionID] uploadFileFailure:nil fileID:sessionID serverUrl:serverUrl selector:selector message:NSLocalizedString(@"_file_not_present_", nil) errorCode:404];
|
|
|
-
|
|
|
- [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"sessionID = %@ AND account = %@", sessionID, _activeAccount]];
|
|
|
-
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -1278,8 +1282,10 @@
|
|
|
else if (taskStatus == k_taskStatusSuspend) [uploadTask suspend];
|
|
|
else if (taskStatus == k_taskStatusResume) [uploadTask resume];
|
|
|
|
|
|
- if ([[self getDelegate:sessionID] respondsToSelector:@selector(uploadTaskSave:)])
|
|
|
- [[self getDelegate:sessionID] uploadTaskSave:uploadTask];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if ([[self getDelegate:sessionID] respondsToSelector:@selector(uploadTaskSave:)])
|
|
|
+ [[self getDelegate:sessionID] uploadTaskSave:uploadTask];
|
|
|
+ });
|
|
|
|
|
|
// COREDATA
|
|
|
|
|
@@ -1313,7 +1319,6 @@
|
|
|
}
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
// refresh main
|
|
|
if ([self.delegate respondsToSelector:@selector(reloadDatasource:fileID:selector:)])
|
|
|
[self.delegate reloadDatasource:serverUrl fileID:nil selector:selector];
|
|
@@ -1390,8 +1395,10 @@
|
|
|
[[NCManageDatabase sharedInstance] setMetadataSession:nil sessionError:[NSString stringWithFormat:@"%@", @(errorCode)] sessionSelector:nil sessionSelectorPost:nil sessionTaskIdentifier:sessionTaskIdentifier sessionTaskIdentifierPlist:sessionTaskIdentifierPlist predicate:[NSPredicate predicateWithFormat:@"sessionID = %@ AND account = %@", metadata.sessionID, _activeAccount]];
|
|
|
}
|
|
|
|
|
|
- if ([[self getDelegate:sessionID] respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
- [[self getDelegate:sessionID] uploadFileFailure:nil fileID:fileID serverUrl:serverUrl selector:metadata.sessionSelector message:[CCError manageErrorKCF:errorCode withNumberError:YES] errorCode:errorCode];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if ([[self getDelegate:sessionID] respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
+ [[self getDelegate:sessionID] uploadFileFailure:nil fileID:fileID serverUrl:serverUrl selector:metadata.sessionSelector message:[CCError manageErrorKCF:errorCode withNumberError:YES] errorCode:errorCode];
|
|
|
+ });
|
|
|
|
|
|
return;
|
|
|
}
|
|
@@ -1481,8 +1488,10 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if ([[self getDelegate:sessionID] respondsToSelector:@selector(uploadFileSuccess:fileID:serverUrl:selector:selectorPost:)])
|
|
|
- [[self getDelegate:sessionID] uploadFileSuccess:nil fileID:metadata.fileID serverUrl:serverUrl selector:metadata.sessionSelector selectorPost:metadata.sessionSelectorPost];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if ([[self getDelegate:sessionID] respondsToSelector:@selector(uploadFileSuccess:fileID:serverUrl:selector:selectorPost:)])
|
|
|
+ [[self getDelegate:sessionID] uploadFileSuccess:nil fileID:metadata.fileID serverUrl:serverUrl selector:metadata.sessionSelector selectorPost:metadata.sessionSelectorPost];
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1530,8 +1539,10 @@
|
|
|
|
|
|
[[NCManageDatabase sharedInstance] setMetadataSession:nil sessionError:[NSString stringWithFormat:@"%@", @k_CCErrorTaskDownloadNotFound] sessionSelector:nil sessionSelectorPost:nil sessionTaskIdentifier:k_taskIdentifierError sessionTaskIdentifierPlist:k_taskIdentifierNULL predicate:[NSPredicate predicateWithFormat:@"fileID = %@ ", metadata.fileID]];
|
|
|
|
|
|
- if ([self.delegate respondsToSelector:@selector(reloadDatasource:fileID:selector:)])
|
|
|
- [self.delegate reloadDatasource:[[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID] fileID:metadata.fileID selector:nil];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if ([self.delegate respondsToSelector:@selector(reloadDatasource:fileID:selector:)])
|
|
|
+ [self.delegate reloadDatasource:[[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID] fileID:metadata.fileID selector:nil];
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
// PLIST
|
|
@@ -1541,8 +1552,10 @@
|
|
|
|
|
|
[[NCManageDatabase sharedInstance] setMetadataSession:@"" sessionError:@"" sessionSelector:@"" sessionSelectorPost:@"" sessionTaskIdentifier:k_taskIdentifierNULL sessionTaskIdentifierPlist:k_taskIdentifierDone predicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadata.fileID]];
|
|
|
|
|
|
- if ([self.delegate respondsToSelector:@selector(reloadDatasource:fileID:selector:)])
|
|
|
- [self.delegate reloadDatasource:[[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID] fileID:metadata.fileID selector:nil];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if ([self.delegate respondsToSelector:@selector(reloadDatasource:fileID:selector:)])
|
|
|
+ [self.delegate reloadDatasource:[[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID] fileID:metadata.fileID selector:nil];
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
}];
|
|
@@ -1575,7 +1588,6 @@
|
|
|
}
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
for (NSString *serverUrl in serversUrl)
|
|
|
if ([self.delegate respondsToSelector:@selector(reloadDatasource:fileID:selector:)])
|
|
|
[self.delegate reloadDatasource:serverUrl fileID:nil selector:nil];
|
|
@@ -1656,7 +1668,6 @@
|
|
|
}
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
for (NSString *directoryID in directoryIDs)
|
|
|
if ([self.delegate respondsToSelector:@selector(reloadDatasource:fileID:selector:)])
|
|
|
[self.delegate reloadDatasource:[[NCManageDatabase sharedInstance] getServerUrl:directoryID] fileID:nil selector:nil];
|
|
@@ -1704,7 +1715,6 @@
|
|
|
NSLog(@"[LOG] Verify read file success, but files already processed");
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
if ([self.delegate respondsToSelector:@selector(reloadDatasource:fileID:selector:)])
|
|
|
[self.delegate reloadDatasource:[[NCManageDatabase sharedInstance] getServerUrl:directoryID] fileID:metadataTemp.fileID selector:metadataNet.selector];
|
|
|
});
|