Marino Faggiana 7 anos atrás
pai
commit
681e347a27

+ 6 - 3
Picker/Picker-Bridging-Header.h

@@ -2,12 +2,15 @@
 //  Use this file to import your target's public headers that you would like to expose to Swift.
 //
 
-#import <MagicalRecord/MagicalRecord.h>
-#import "TableAccount+CoreDataClass.h"
 #import "CCNetworking.h"
 #import "OCNetworking.h"
-#import "CCCoreData.h"
 #import "CCGlobal.h"
 #import "CCHud.h"
 #import "BKPasscodeViewController.h"
 #import "CCBKPasscode.h"
+
+#import "OCActivity.h"
+#import "OCUserProfile.h"
+#import "OCCapabilities.h"
+#import "OCExternalSites.h"
+#import "OCSharedDto.h"

+ 7 - 0
Share Ext/Share Ext-Bridging-Header.h

@@ -4,3 +4,10 @@
 
 #import "CCHud.h"
 #import "ShareViewController.h"
+
+#import "OCActivity.h"
+#import "OCUserProfile.h"
+#import "OCCapabilities.h"
+#import "OCExternalSites.h"
+#import "OCSharedDto.h"
+

+ 0 - 4
Share Ext/ShareViewController.h

@@ -21,8 +21,6 @@
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //
 
-#import <MagicalRecord/MagicalRecord.h>
-
 #import "OCCommunication.h"
 #import "AFURLSessionManager.h"
 #import "MBProgressHUD.h"
@@ -37,8 +35,6 @@
 #import "CCError.h"
 #import "CCHud.h"
 
-#import "TableAccount+CoreDataClass.h"
-
 @interface ShareViewController : UIViewController <UITableViewDelegate, OCNetworkingDelegate, MBProgressHUDDelegate, BKPasscodeViewControllerDelegate, CCNetworkingDelegate, CCMoveDelegate>
 
 @property (nonatomic, strong) NSOperationQueue *networkingOperationQueue;

+ 0 - 112
iOSClient/FileSystem/CCCoreData.h

@@ -23,17 +23,8 @@
 
 #import <Foundation/Foundation.h>
 #import <CoreData/CoreData.h>
-
-#import <Photos/Photos.h>
 #import <MagicalRecord/MagicalRecord.h>
 
-#import "OCSharedDto.h"
-#import "CCUtility.h"
-#import "CCGraphics.h"
-#import "OCUserProfile.h"
-#import "OCActivity.h"
-#import "OCExternalSites.h"
-#import "OCCapabilities.h"
 #import "TableAccount+CoreDataClass.h"
 #import "TableCertificates+CoreDataClass.h"
 #import "TableDirectory+CoreDataClass.h"
@@ -43,110 +34,7 @@
 
 @interface CCCoreData : NSObject
 
-// ===== Account =====
-
 + (NSArray *)getAllAccount;
-
-// ===== Metadata =====
-
-/*
-//+ (void)addMetadata:(tableMetadata *)metadata activeAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl context:(NSManagedObjectContext *)context;
-+ (void)deleteMetadataWithPredicate:(NSPredicate *)predicate;
-+ (void)moveMetadata:(NSString *)fileName directoryID:(NSString *)directoryID directoryIDTo:(NSString *)directoryIDTo activeAccount:(NSString *)activeAccount;
-+ (void)updateMetadata:(tableMetadata *)metadata predicate:(NSPredicate *)predicate activeAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl context:(NSManagedObjectContext *)context;
-+ (void)setMetadataSession:(NSString *)session sessionError:(NSString *)sessionError sessionSelector:(NSString *)sessionSelector sessionSelectorPost:(NSString *)sessionSelectorPost sessionTaskIdentifier:(NSInteger)sessionTaskIdentifier sessionTaskIdentifierPlist:(NSInteger)sessionTaskIdentifierPlist predicate:(NSPredicate *)predicate context:(NSManagedObjectContext *)context;
-+ (void)setMetadataFavoriteFileID:(NSString *)fileID favorite:(BOOL)favorite activeAccount:(NSString *)activeAccount context:(NSManagedObjectContext *)context;
-
-+ (TableMetadata *)getTableMetadataWithPreficate:(NSPredicate *)predicate;
-+ (NSArray *)getTableMetadataWithPredicate:(NSPredicate *)predicate context:(NSManagedObjectContext *)context;
-+ (NSArray *)getTableMetadataWithPredicate:(NSPredicate *)predicate fieldOrder:(NSString *)fieldOrder ascending:(BOOL)ascending;
-+ (tableMetadata *)getMetadataWithPreficate:(NSPredicate *)predicate context:(NSManagedObjectContext *)context;
-+ (tableMetadata *)getMetadataAtIndex:(NSPredicate *)predicate fieldOrder:(NSString *)fieldOrder ascending:(BOOL)ascending objectAtIndex:(NSUInteger)index;
-+ (tableMetadata *)getMetadataFromFileName:(NSString *)fileName directoryID:(NSString *)directoryID activeAccount:(NSString *)activeAccount context:(NSManagedObjectContext *)context;
-
-+ (NSArray *)getTableMetadataDownloadAccount:(NSString *)activeAccount;
-+ (NSArray *)getTableMetadataDownloadWWanAccount:(NSString *)activeAccount;
-+ (NSArray *)getTableMetadataUploadAccount:(NSString *)activeAccount;
-+ (NSArray *)getTableMetadataUploadWWanAccount:(NSString *)activeAccount;
-
-+ (NSArray *)getRecordsTableMetadataPhotosCameraUpload:(NSString *)serverUrl activeAccount:(NSString *)activeAccount;
-
-+ (void)removeOfflineAllFileFromServerUrl:(NSString *)serverUrl activeAccount:(NSString *)activeAccount;
-*/
-
-// ===== Directory =====
-
-/*
-+ (NSString *)addDirectory:(NSString *)serverUrl permissions:(NSString *)permissions activeAccount:(NSString *)activeAccount;
-+ (void)updateDirectoryEtagServerUrl:(NSString *)serverUrl fileID:(NSString *)fileID activeAccount:(NSString *)activeAccount;
-+ (void)deleteDirectoryFromPredicate:(NSPredicate *)predicate;
-+ (NSArray *)deleteDirectoryAndSubDirectory:(NSString *)serverUrl activeAccount:(NSString *)activeAccount;
-+ (void)renameDirectory:(NSString *)serverUrl serverUrlTo:(NSString *)serverUrlTo activeAccount:(NSString *)activeAccount;
-
-+ (void)setDateReadDirectoryID:(NSString *)directoryID activeAccount:(NSString *)activeAccount;
-+ (NSDate *)getDateReadDirectoryID:(NSString *)directoryID activeAccount:(NSString *)activeAccount;
-
-+ (void)setDirectoryRev:(NSString *)rev serverUrl:(NSString *)serverUrl activeAccount:(NSString *)activeAccount;
-+ (NSString *)getDirectoryRevFromServerUrl:(NSString *)serverUrl activeAccount:(NSString *)activeAccount;
-
-+ (TableDirectory *)getTableDirectoryWithPreficate:(NSPredicate *)predicate;
-+ (NSArray *)getDirectoryIDsFromBeginsWithServerUrl:(NSString *)serverUrl activeAccount:(NSString *)activeAccount;
-+ (NSString *)getDirectoryIDFromServerUrl:(NSString *)serverUrl activeAccount:(NSString *)activeAccount;
-+ (NSString *)getServerUrlFromDirectoryID:(NSString *)directoryID activeAccount:(NSString *)activeAccount;
-
-+ (void)clearDateReadAccount:(NSString *)activeAccount serverUrl:(NSString *)serverUrl directoryID:(NSString *)directoryID;
-+ (void)clearAllDateReadDirectory;
-
-+ (BOOL)isDirectoryOutOfDate:(int)numAddDay directoryID:(NSString *)directoryID activeAccount:(NSString *)activeAccount;
-
-+ (void)removeOfflineDirectoryID:(NSString *)directoryID activeAccount:(NSString *)activeAccount;
-+ (NSArray *)getOfflineDirectoryActiveAccount:(NSString *)activeAccount;
-+ (void)setOfflineDirectoryServerUrl:(NSString *)serverUrl offline:(BOOL)offline activeAccount:(NSString *)activeAccount;
-+ (BOOL)isOfflineDirectoryServerUrl:(NSString *)serverUrl activeAccount:(NSString *)activeAccount;
-
-+ (BOOL)setDirectoryLock:(NSString *)serverUrl activeAccount:(NSString *)activeAccount;
-+ (BOOL)setDirectoryUnLock:(NSString *)serverUrl activeAccount:(NSString *)activeAccount;
-+ (void)setAllDirectoryUnLockForAccount:(NSString *)activeAccount;
-+ (BOOL)isDirectoryLock:(NSString *)serverUrl activeAccount:(NSString *)activeAccount;
-+ (BOOL)isBlockZone:(NSString *)serverUrl activeAccount:(NSString *)activeAccount;
-*/
-
-// ===== LocalFile =====
-/*
-+ (void)addLocalFile:(tableMetadata *)metadata activeAccount:(NSString *)activeAccount;
-+ (void)deleteLocalFileWithPredicate:(NSPredicate *)predicate;
-
-+ (void)renameLocalFileWithEtag:(NSString *)fileID fileNameTo:(NSString *)fileNameTo fileNamePrintTo:(NSString *)fileNamePrintTo activeAccount:(NSString *)activeAccount;
-+ (void)updateLocalFileModel:(tableMetadata *)metadata activeAccount:(NSString *)activeAccount;
-
-+ (TableLocalFile *)getLocalFileWithEtag:(NSString *)fileID activeAccount:(NSString *)activeAccount;
-+ (NSArray *)getTableLocalFileWithPredicate:(NSPredicate *)predicate;
-
-// ===== Offline LocalFile =====
-
-+ (void)setOfflineLocalEtag:(NSString *)fileID offline:(BOOL)offline activeAccount:(NSString *)activeAccount;
-+ (BOOL)isOfflineLocalEtag:(NSString *)fileID activeAccount:(NSString *)activeAccount;
-+ (NSArray *)getOfflineLocalFileActiveAccount:(NSString *)activeAccount directoryUser:(NSString *)directoryUser;
-*/
-
-// ===== GeoInformation =====
-
-/*
-+ (NSArray *)getGeoInformationLocalFromEtag:(NSString *)fileID activeAccount:(NSString *)activeAccount;
-+ (void)setGeoInformationLocalFromEtag:(NSString *)fileID exifDate:(NSDate *)exifDate exifLatitude:(NSString *)exifLatitude exifLongitude:(NSString *)exifLongitude activeAccount:(NSString *)activeAccount;
-+ (void)setGeoInformationLocalNull;
-*/
-
-// ===== Certificates =====
-
 + (NSMutableArray *)getAllCertificatesLocationOldDB;
 
-
-// ===== File System =====
-/*
-+ (BOOL)downloadFile:(tableMetadata *)metadata directoryUser:(NSString *)directoryUser activeAccount:(NSString *)activeAccount;
-+ (void)downloadFilePlist:(tableMetadata *)metadata activeAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl directoryUser:(NSString *)directoryUser;
-+ (void)deleteFile:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl directoryUser:(NSString *)directoryUser activeAccount:(NSString *)activeAccount;
-*/
-
 @end

+ 2 - 1205
iOSClient/FileSystem/CCCoreData.m

@@ -22,23 +22,15 @@
 //
 
 #import "CCCoreData.h"
-#import "CCNetworking.h"
-#import "NCBridgeSwift.h"
 
 @implementation CCCoreData
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Account =====
-#pragma --------------------------------------------------------------------------------------------
-
 + (NSArray *)getAllAccount
 {
     NSMutableArray *accounts = [NSMutableArray new];
     NSArray *records;
     
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-    
-    records = [TableAccount MR_findAllInContext:context];
+    records = [TableAccount MR_find];
     
     for (TableAccount *tableAccount in records)
         [accounts addObject:tableAccount];
@@ -46,891 +38,11 @@
     return accounts;
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Metadata =====
-#pragma --------------------------------------------------------------------------------------------
-
-/*
-+ (void)addMetadata:(tableMetadata *)metadata activeAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl context:(NSManagedObjectContext *)context
-{
-    if (context == nil)
-        context = [NSManagedObjectContext MR_context];
-
-    // remove all fileID (BUG 2.10)
-    [TableMetadata MR_deleteAllMatchingPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (fileID == %@)", activeAccount, metadata.fileID] inContext:context];
-    [context MR_saveToPersistentStoreAndWait];
-    
-    // remove record if exists
-    [TableMetadata MR_deleteAllMatchingPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (fileName == %@) AND (directoryID == %@)", activeAccount, metadata.fileName, metadata.directoryID] inContext:context];
-    [context MR_saveToPersistentStoreAndWait];
-    
-    // create new record Metadata
-    TableMetadata *record = [TableMetadata MR_createEntityInContext:context];
-
-    // set default value
-    metadata.sessionTaskIdentifier = k_taskIdentifierDone;
-    metadata.sessionTaskIdentifierPlist = k_taskIdentifierDone;
-
-    // Insert metdata -> entity
-    [self insertMetadataInEntity:metadata recordMetadata:record activeAccount:activeAccount activeUrl:activeUrl];
-    
-    // Aggiorniamo la data nella directory (ottimizzazione v 2.10)
-    [self setDateReadDirectoryID:metadata.directoryID activeAccount:activeAccount];
-    
-    [context MR_saveToPersistentStoreAndWait];
-}
-
-
-+ (void)deleteMetadataWithPredicate:(NSPredicate *)predicate
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-            
-        NSString *directoryID;
-        NSArray *records = [TableMetadata MR_findAllWithPredicate:predicate inContext:localContext];
-            
-        for(TableMetadata *record in records) {
-            
-            // Aggiorniamo la data nella directory (ottimizzazione v 2.10)
-            if ([directoryID isEqualToString:record.directoryID] == NO)
-                [self setDateReadDirectoryID:record.directoryID activeAccount:record.account];
-                
-            directoryID = record.directoryID;
-            
-            [record MR_deleteEntityInContext:localContext];
-        }
-    }];
-}
-
-+ (void)moveMetadata:(NSString *)fileName directoryID:(NSString *)directoryID directoryIDTo:(NSString *)directoryIDTo activeAccount:(NSString *)activeAccount
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-        
-        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (fileName == %@) AND (directoryID == %@)", activeAccount, fileName, directoryID];
-        TableMetadata *record = [TableMetadata MR_findFirstWithPredicate:predicate inContext:localContext];
-        
-        if (record) {
-            
-            record.directoryID = directoryIDTo;
-            
-            // Aggiorniamo la data nella directory (ottimizzazione v 2.10)
-            [self setDateReadDirectoryID:directoryID activeAccount:activeAccount];
-            [self setDateReadDirectoryID:directoryIDTo activeAccount:activeAccount];
-        }
-    }];
-}
-
-+ (void)updateMetadata:(tableMetadata *)metadata predicate:(NSPredicate *)predicate activeAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl context:(NSManagedObjectContext *)context
-{
-    TableMetadata *record;
-    
-    if (context == nil)
-        context = [NSManagedObjectContext MR_defaultContext];
-    
-    record = [TableMetadata MR_findFirstWithPredicate:predicate inContext:context];
-    
-    if (record) {
-        
-        [self insertMetadataInEntity:metadata recordMetadata:record activeAccount:activeAccount activeUrl:activeUrl];
-        
-        // Aggiorniamo la data nella directory (ottimizzazione v 2.10)
-        [self setDateReadDirectoryID:metadata.directoryID activeAccount:activeAccount];
-        
-        [context MR_saveToPersistentStoreAndWait];
-    }
-}
-
-+ (void)setMetadataSession:(NSString *)session sessionError:(NSString *)sessionError sessionSelector:(NSString *)sessionSelector sessionSelectorPost:(NSString *)sessionSelectorPost sessionTaskIdentifier:(NSInteger)sessionTaskIdentifier sessionTaskIdentifierPlist:(NSInteger)sessionTaskIdentifierPlist predicate:(NSPredicate *)predicate context:(NSManagedObjectContext *)context
-{
-    if (context == nil)
-        context = [NSManagedObjectContext MR_defaultContext];
-    
-    NSArray *records = [TableMetadata MR_findAllWithPredicate:predicate inContext:context];
-    NSMutableSet *directoryIDs = [[NSMutableSet alloc] init];
-    NSString *directoryID;
-    
-    for(TableMetadata *record in records) {
-                
-        if (session) record.session = session;
-        if (sessionError) record.sessionError = sessionError;
-        if (sessionSelector) record.sessionSelector = sessionSelector;
-        if (sessionSelectorPost) record.sessionSelectorPost = sessionSelectorPost;
-        if (sessionTaskIdentifier != k_taskIdentifierNULL) record.sessionTaskIdentifier = [NSNumber numberWithInteger:sessionTaskIdentifier];
-        if (sessionTaskIdentifierPlist != k_taskIdentifierNULL) record.sessionTaskIdentifierPlist = [NSNumber numberWithInteger:sessionTaskIdentifierPlist];
-        
-        [directoryIDs addObject:record.directoryID];
-        
-        // Aggiorniamo la data nella directory (ottimizzazione v 2.10)
-        if ([directoryID isEqualToString:record.directoryID] == NO)
-            [self setDateReadDirectoryID:record.directoryID activeAccount:record.account];
-        
-        directoryID = record.directoryID;
-    }
-    
-    [context MR_saveToPersistentStoreAndWait];
-}
-
-+ (void)setMetadataFavoriteFileID:(NSString *)fileID favorite:(BOOL)favorite activeAccount:(NSString *)activeAccount context:(NSManagedObjectContext *)context
-{
-    if (context == nil)
-        context = [NSManagedObjectContext MR_defaultContext];
-    
-    TableMetadata *tableMetadata = [TableMetadata MR_findFirstWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (fileID == %@)", activeAccount, fileID] inContext:context];
-    
-    if (tableMetadata) {
-        
-        tableMetadata.favorite = [NSNumber numberWithBool:favorite];
-        
-        // Aggiorniamo la data nella directory (ottimizzazione v 2.10)
-        [self setDateReadDirectoryID:tableMetadata.directoryID activeAccount:activeAccount];
-        
-        [context MR_saveToPersistentStoreAndWait];
-    }
-}
-
-+ (tableMetadata *)getMetadataWithPreficate:(NSPredicate *)predicate context:(NSManagedObjectContext *)context
-{
-    if (context == nil)
-        context = [NSManagedObjectContext MR_defaultContext];
-    
-    TableMetadata *record;
-    
-    record = [TableMetadata MR_findFirstWithPredicate:predicate inContext:context];
-    
-    if (record) {
-        
-        return [self insertEntityInMetadata:record];
-        
-    } else return nil;
-}
-
-+ (TableMetadata *)getTableMetadataWithPreficate:(NSPredicate *)predicate
-{
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-    
-    return [TableMetadata MR_findFirstWithPredicate:predicate inContext:context];
-}
-
-+ (NSArray *)getTableMetadataWithPredicate:(NSPredicate *)predicate context:(NSManagedObjectContext *)context
-{
-    if (context == nil)
-        context = [NSManagedObjectContext MR_defaultContext];
-    
-    return [TableMetadata MR_findAllWithPredicate:predicate inContext:context];
-}
-
-+ (NSArray *)getTableMetadataWithPredicate:(NSPredicate *)predicate fieldOrder:(NSString *)fieldOrder ascending:(BOOL)ascending
-{
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-    NSArray *records = [[NSArray alloc] init];
-    NSSortDescriptor *descriptor;
-    
-    records = [TableMetadata MR_findAllWithPredicate:predicate inContext:context];
-        
-    if ([records count] == 0) return nil;
-    
-    if ([fieldOrder isEqualToString:@"fileName"]) descriptor = [[NSSortDescriptor alloc] initWithKey:@"fileNamePrint" ascending:ascending selector:@selector(localizedCaseInsensitiveCompare:)];
-    
-    else if ([fieldOrder isEqualToString:@"fileDate"]) descriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:ascending selector:nil];
-    
-    else if ([fieldOrder isEqualToString:@"sessionTaskIdentifier"]) descriptor = [[NSSortDescriptor alloc] initWithKey:@"sessionTaskIdentifier" ascending:ascending selector:nil];
-        
-    else descriptor = [[NSSortDescriptor alloc] initWithKey:fieldOrder ascending:ascending selector:@selector(localizedCaseInsensitiveCompare:)];
-    
-    return [records sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor, nil]];
-}
-
-+ (tableMetadata *)getMetadataAtIndex:(NSPredicate *)predicate fieldOrder:(NSString *)fieldOrder ascending:(BOOL)ascending objectAtIndex:(NSUInteger)index
-{
-    NSArray *records = [self getTableMetadataWithPredicate:predicate fieldOrder:fieldOrder ascending:ascending];
-    
-    TableMetadata *record = [records objectAtIndex:index];
-    
-    return [self insertEntityInMetadata:record];
-}
-
-+ (tableMetadata *)getMetadataFromFileName:(NSString *)fileName directoryID:(NSString *)directoryID activeAccount:(NSString *)activeAccount context:(NSManagedObjectContext *)context
-{
-    if (fileName == nil || directoryID == nil || activeAccount == nil)
-        return nil;
-    
-    if (context == nil)
-        context = [NSManagedObjectContext MR_defaultContext];
-    
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND ((fileName == %@) OR (fileNameData == %@))", activeAccount, directoryID, fileName, fileName];
-
-    TableMetadata *record = [TableMetadata MR_findFirstWithPredicate:predicate inContext:context];
-    
-    if (record) return [self insertEntityInMetadata:record];
-    else return nil;
-}
-
-+ (NSArray *)getTableMetadataDownloadAccount:(NSString *)activeAccount
-{
-    return [self getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND ((session == %@) || (session == %@)) AND ((sessionTaskIdentifier != %i) OR (sessionTaskIdentifierPlist != %i))", activeAccount, k_download_session, k_download_session_foreground, k_taskIdentifierDone, k_taskIdentifierDone] context:nil];
-}
-
-+ (NSArray *)getTableMetadataDownloadWWanAccount:(NSString *)activeAccount
-{
-    return [self getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (session == %@) AND ((sessionTaskIdentifier != %i) OR (sessionTaskIdentifierPlist != %i))", activeAccount, k_download_session_wwan, k_taskIdentifierDone, k_taskIdentifierDone] context:nil];
-}
-
-+ (NSArray *)getTableMetadataUploadAccount:(NSString *)activeAccount
-{
-    return [self getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND ((session == %@) || (session == %@)) AND ((sessionTaskIdentifier != %i) OR (sessionTaskIdentifierPlist != %i))", activeAccount, k_upload_session, k_upload_session_foreground, k_taskIdentifierDone, k_taskIdentifierDone] context:nil];
-}
-
-+ (NSArray *)getTableMetadataUploadWWanAccount:(NSString *)activeAccount
-{
-    return [self getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (session == %@) AND ((sessionTaskIdentifier != %i) OR (sessionTaskIdentifierPlist != %i))", activeAccount, k_upload_session_wwan, k_taskIdentifierDone, k_taskIdentifierDone] context:nil];
-}
-
-+ (NSArray *)getRecordsTableMetadataPhotosCameraUpload:(NSString *)serverUrl activeAccount:(NSString *)activeAccount
-{
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-    
-    NSMutableArray *recordsPhotosCameraUpload = [[NSMutableArray alloc] init];
-    NSArray *tableDirectoryes = [self getDirectoryIDsFromBeginsWithServerUrl:serverUrl activeAccount:activeAccount];
-    
-    for (TableDirectory *record in tableDirectoryes) {
-                
-        NSArray *records = [TableMetadata MR_findAllWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND ((session == NULL) OR (session == '')) AND (type == 'file') AND ((typeFile == %@) OR (typeFile == %@))", activeAccount, record.directoryID, k_metadataTypeFile_image, k_metadataTypeFile_video] inContext:context];
-        
-        if ([records count] > 0)
-            [recordsPhotosCameraUpload addObjectsFromArray:records];
-    }
-    
-    // test
-    if ([recordsPhotosCameraUpload count] == 0) return nil;
-    
-    // Order
-    NSString *fieldOrder = [CCUtility getOrderSettings];
-    BOOL ascending = [CCUtility getAscendingSettings];
-    NSSortDescriptor *descriptor;
-    
-    if ([fieldOrder isEqualToString:@"fileName"]) descriptor = [[NSSortDescriptor alloc] initWithKey:@"fileNamePrint" ascending:ascending selector:@selector(localizedCaseInsensitiveCompare:)];
-    else if ([fieldOrder isEqualToString:@"fileDate"]) descriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:ascending selector:nil];
-    else if ([fieldOrder isEqualToString:@"sessionTaskIdentifier"]) descriptor = [[NSSortDescriptor alloc] initWithKey:@"sessionTaskIdentifier" ascending:ascending selector:nil];
-    else descriptor = [[NSSortDescriptor alloc] initWithKey:fieldOrder ascending:ascending selector:@selector(localizedCaseInsensitiveCompare:)];
-    
-    return [recordsPhotosCameraUpload sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor, nil]];
-}
-
-+ (void)removeOfflineAllFileFromServerUrl:(NSString *)serverUrl activeAccount:(NSString *)activeAccount
-{
-    NSString *directoryID = [self getDirectoryIDFromServerUrl:serverUrl activeAccount:activeAccount];
-    
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-        
-        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", activeAccount, directoryID];
-        NSArray *records = [TableMetadata MR_findAllWithPredicate:predicate];
-        
-        for (TableMetadata *record in records)
-            [self setOfflineLocalFileID:record.fileID offline:NO activeAccount:activeAccount];
-    }];
-}
-*/
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Directory =====
-#pragma --------------------------------------------------------------------------------------------
-/*
-+ (NSString *)addDirectory:(NSString *)serverUrl permissions:(NSString *)permissions activeAccount:(NSString *)activeAccount
-{
-    NSString *directoryID;
-    
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-
-    TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:[NSPredicate predicateWithFormat:@"(serverUrl == %@) AND (account == %@)", serverUrl, activeAccount] inContext:context];
-    
-    if (record) {
-     
-        directoryID = record.directoryID;
-        if (permissions) record.permissions = permissions;
-        
-    } else {
-        
-        TableDirectory *record = [TableDirectory MR_createEntityInContext:context];
-        
-        record.account = activeAccount;
-        record.directoryID = [CCUtility createRandomString:16];
-        directoryID = record.directoryID;
-        if (permissions) record.permissions = permissions;
-        record.serverUrl = serverUrl;
-    }
-    
-    [context MR_saveToPersistentStoreAndWait];
-
-    return directoryID;
-}
-
-+ (void)updateDirectoryEtagServerUrl:(NSString *)serverUrl fileID:(NSString *)fileID activeAccount:(NSString *)activeAccount
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-        
-        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(serverUrl == %@) AND (account == %@)", serverUrl, activeAccount];
-        TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate inContext:localContext];
-        
-        if (record)
-            record.rev = fileID;
-    }];
-}
-
-+ (void)deleteDirectoryFromPredicate:(NSPredicate *)predicate
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-
-        [TableDirectory MR_deleteAllMatchingPredicate:predicate inContext:localContext];
-    }];
-}
-
-+ (NSArray *)deleteDirectoryAndSubDirectory:(NSString *)serverUrl activeAccount:(NSString *)activeAccount
-{
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@)", activeAccount];
-
-    NSMutableArray *directoryIDs = [[NSMutableArray alloc] init];
-    
-    NSArray *tableDirectorys = [TableDirectory MR_findAllWithPredicate:predicate inContext:context];
-    
-    for(TableDirectory *recordDirectory in tableDirectorys) {
-        
-        NSLog(@"[LOG] %@", recordDirectory.serverUrl);
-        
-        if ([recordDirectory.serverUrl hasPrefix:serverUrl]) {
-            
-            // List directoryIDs removed
-            [directoryIDs addObject:recordDirectory.directoryID];
-            
-            // remove all TableMetadata
-            NSLog(@"[LOG] %@", recordDirectory.directoryID);
-            
-            // remove directory in Metadata come cazzo si fa a saperlo
-            //[TableMetadata MR_findAllWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", activeAccount, recordDirectory.directoryID] inContext:context];
-            
-            NSArray *tableMetadatas = [TableMetadata MR_findAllWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", activeAccount, recordDirectory.directoryID] inContext:context];
-            
-            for(TableMetadata *recordMetadata in tableMetadatas) {
-                
-                // remove if in session
-                if ([recordMetadata.session length] >0) {
-                    if (recordMetadata.sessionTaskIdentifier >= 0)
-                        [[CCNetworking sharedNetworking] settingSession:recordMetadata.session sessionTaskIdentifier:[recordMetadata.sessionTaskIdentifier integerValue] taskStatus: k_taskStatusCancel];
-                    
-                    if (recordMetadata.sessionTaskIdentifierPlist >= 0)
-                        [[CCNetworking sharedNetworking] settingSession:recordMetadata.session sessionTaskIdentifier:[recordMetadata.sessionTaskIdentifierPlist integerValue] taskStatus: k_taskStatusCancel];
-
-                }
-                
-                // remove file local
-                NSLog(@"[LOG] %@", recordMetadata.fileID);
-                [self deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (fileID == %@)", activeAccount, recordMetadata.fileID]];
-                [recordMetadata MR_deleteEntityInContext:context];
-            }
-            
-            [recordDirectory MR_deleteEntityInContext:context];
-        }
-    }
-
-    [context MR_saveToPersistentStoreAndWait];
-    
-    return directoryIDs;
-}
-
-+ (void)renameDirectory:(NSString *)serverUrl serverUrlTo:(NSString *)serverUrlTo activeAccount:(NSString *)activeAccount
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-        
-        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(serverUrl == %@) AND (account == %@)", serverUrl, activeAccount];
-        TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate inContext:localContext];
-        
-        if (record)
-            record.serverUrl = serverUrlTo;
-    }];
-}
-
-+ (void)setDateReadDirectoryID:(NSString *)directoryID activeAccount:(NSString *)activeAccount
-{
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-    
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(directoryID == %@) AND (account == %@)", directoryID, activeAccount];
-    TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate inContext:context];
-    
-    if (record) {
-        
-        record.dateReadDirectory = [NSDate date];
-    
-        [context MR_saveToPersistentStoreAndWait];        
-    }
-}
-
-+ (TableDirectory *)getTableDirectoryWithPreficate:(NSPredicate *)predicate
-{
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-    
-    return [TableDirectory MR_findFirstWithPredicate:predicate inContext:context];
-}
-
-+ (NSDate *)getDateReadDirectoryID:(NSString *)directoryID activeAccount:(NSString *)activeAccount
-{
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-    
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(directoryID == %@) AND (account == %@)", directoryID, activeAccount];
-    TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate inContext:context];
-    
-    if (record) return record.dateReadDirectory;
-    else return nil;
-}
-
-+ (void)setDirectoryRev:(NSString *)rev serverUrl:(NSString *)serverUrl activeAccount:(NSString *)activeAccount
-{
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-    
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(serverUrl == %@) AND (account == %@)", serverUrl, activeAccount];
-    TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate inContext:context];
-    
-    if (record) {
-        
-        record.rev = rev;
-        
-        [context MR_saveToPersistentStoreAndWait];
-    }
-}
-
-+ (NSString *)getDirectoryRevFromServerUrl:(NSString *)serverUrl activeAccount:(NSString *)activeAccount
-{
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(serverUrl == %@) AND (account == %@)", serverUrl, activeAccount];
-    
-    TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate];
-    
-    if (record) return record.rev;
-    else return nil;
-}
-
-+ (NSArray *)getDirectoryIDsFromBeginsWithServerUrl:(NSString *)serverUrl activeAccount:(NSString *)activeAccount
-{
-    NSString *serverUrlBeginWith = serverUrl;
-    
-    if (![serverUrl hasSuffix:@"/"])
-        serverUrlBeginWith = [serverUrl stringByAppendingString:@"/"];
-        
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"((serverUrl == %@) OR (serverUrl BEGINSWITH %@)) AND (account == %@)", serverUrl, serverUrlBeginWith, activeAccount];
-    
-    return [TableDirectory MR_findAllWithPredicate:predicate];
-}
-
-+ (NSString *)getDirectoryIDFromServerUrl:(NSString *)serverUrl activeAccount:(NSString *)activeAccount
-{
-    if (serverUrl == nil) return nil;
-    
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(serverUrl == %@) AND (account == %@)", serverUrl, activeAccount];
-    
-    TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate];
-    if (record) return record.directoryID;
-    else {
-        return [self addDirectory:serverUrl permissions:nil activeAccount:activeAccount];
-    }
-    return nil;
-}
-
-+ (NSString *)getServerUrlFromDirectoryID:(NSString *)directoryID activeAccount:(NSString *)activeAccount
-{
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(directoryID == %@) AND (account == %@)", directoryID, activeAccount];
-    TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate];
-    
-    if (record) return record.serverUrl;
-    else return nil;
-}
-
-+ (void)clearDateReadAccount:(NSString *)activeAccount serverUrl:(NSString *)serverUrl directoryID:(NSString *)directoryID
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-        
-        NSPredicate *predicate;
-        
-        if ([serverUrl length] > 0)
-            predicate = [NSPredicate predicateWithFormat:@"(serverUrl == %@) AND (account == %@)", serverUrl, activeAccount];
-        
-        if ([directoryID length] > 0)
-            predicate = [NSPredicate predicateWithFormat:@"(directoryID == %@) AND (account == %@)", directoryID, activeAccount];
-        
-        TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate inContext:localContext];
-        
-        if (record) {
-            
-            record.dateReadDirectory = NULL;
-            record.rev = @"";
-        }
-    }];
-}
-
-+ (void)clearAllDateReadDirectory
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-        
-        NSArray *records = [TableDirectory MR_findAllInContext:localContext];
-        
-        for (TableDirectory *record in records) {
-            
-            record.dateReadDirectory = NULL;
-            record.rev = @"";
-        }
-    }];
-}
-
-+ (BOOL)isDirectoryOutOfDate:(int)numAddDay directoryID:(NSString *)directoryID activeAccount:(NSString *)activeAccount
-{
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", activeAccount, directoryID];
-    TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate];
-    
-    if (record == nil || record.dateReadDirectory == nil) {
-        return YES;
-    }
-    
-    NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
-    [dateComponents setWeekday:numAddDay];
-    NSCalendar *calendar = [NSCalendar currentCalendar];
-    
-    NSDate *datePlus = [calendar dateByAddingComponents:dateComponents toDate:record.dateReadDirectory options:0];
-    NSDate *now = [NSDate date];
-    
-    // usa la Cache se richiesto e se la data è entro X giorni dall'ultima volta che l'hai letta.
-    if ([now compare:datePlus] == NSOrderedDescending) {
-        return YES;
-    }
-    
-    return NO;
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Offline Directory =====
-#pragma --------------------------------------------------------------------------------------------
-
-+ (void)removeOfflineDirectoryID:(NSString *)directoryID activeAccount:(NSString *)activeAccount
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-
-        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(directoryID == %@) AND (account == %@) AND (offline == 1)", directoryID, activeAccount];
-        TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate inContext:localContext];
-    
-        if (record)
-            record.offline = [NSNumber numberWithBool:FALSE];
-    }];
-}
-
-+ (NSArray *)getOfflineDirectoryActiveAccount:(NSString *)activeAccount
-{
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (offline == 1)", activeAccount];
-    NSArray *recordsTable = [TableDirectory MR_findAllWithPredicate:predicate];
-    
-    // Order by serverUrl
-    NSArray *sortedRecordsTable = [recordsTable sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
-        
-        TableDirectory *record1 = obj1, *record2 = obj2;
-        
-        return [record1.serverUrl compare:record2.serverUrl];
-        
-    }];
-    
-    return sortedRecordsTable;
-}
-
-+ (void)setOfflineDirectoryServerUrl:(NSString *)serverUrl offline:(BOOL)offline activeAccount:(NSString *)activeAccount
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-
-        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(serverUrl == %@) AND (account == %@)", serverUrl, activeAccount];
-        TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate inContext:localContext];
-    
-        if (record)
-            record.offline = [NSNumber numberWithBool:offline];
-    }];
-}
-
-+ (BOOL)isOfflineDirectoryServerUrl:(NSString *)serverUrl activeAccount:(NSString *)activeAccount
-{
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(serverUrl == %@) AND (offline == 1) AND (account == %@)", serverUrl, activeAccount];
-    TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate];
-    
-    if (record) return YES;
-    else return NO;
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Directory Lock =====
-#pragma --------------------------------------------------------------------------------------------
-
-+ (BOOL)setDirectoryLock:(NSString *)serverUrl activeAccount:(NSString *)activeAccount
-{
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(directoryID == %@) AND (account == %@)", [self getDirectoryIDFromServerUrl:serverUrl activeAccount:activeAccount], activeAccount];
-    TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate inContext:context];
-    
-    if (record) {
-        
-        record.lock = [NSNumber numberWithBool:YES];
-        
-        [context MR_saveToPersistentStoreAndWait];
-
-        return YES;
-    }
-    else return NO;
-}
-
-+ (BOOL)setDirectoryUnLock:(NSString *)serverUrl activeAccount:(NSString *)activeAccount
-{
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(directoryID == %@) AND (account == %@)", [self getDirectoryIDFromServerUrl:serverUrl activeAccount:activeAccount], activeAccount];
-    TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate inContext:context];
-    
-    if (record) {
-        
-        record.lock = [NSNumber numberWithBool:NO];
-        
-        [context MR_saveToPersistentStoreAndWait];
-        
-        return YES;
-    }
-    else return NO;
-}
-
-+ (void)setAllDirectoryUnLockForAccount:(NSString *)activeAccount
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-        
-        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@)", activeAccount];
-        NSArray *records = [TableDirectory MR_findAllWithPredicate:predicate inContext:localContext];
-        
-        for(TableDirectory *record in records)
-            record.lock = [NSNumber numberWithBool:NO];
-    }];
-}
-
-+ (BOOL)isDirectoryLock:(NSString *)serverUrl activeAccount:(NSString *)activeAccount
-{
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(directoryID == %@) AND (lock == 1) AND (account == %@)", [self getDirectoryIDFromServerUrl:serverUrl activeAccount:activeAccount], activeAccount];
-    TableDirectory *record = [TableDirectory MR_findFirstWithPredicate:predicate];
-    
-    if (record) return YES;
-    else return NO;
-}
-
-+ (BOOL)isBlockZone:(NSString *)serverUrl activeAccount:(NSString *)activeAccount
-{
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (directory == 1)", activeAccount];
-    NSArray *records = [TableMetadata MR_findAllWithPredicate:predicate];
-    
-    if ([records count] > 0) {
-        
-        NSArray *pathComponents = [serverUrl pathComponents];
-        
-        for (NSString *fileName in pathComponents) {
-            
-            for(TableMetadata *record in records){
-                
-                NSString *fileNameEntity = [CCUtility trasformedFileNamePlistInCrypto:record.fileName];
-                NSString *directoryID = record.directoryID;
-                NSString *serverUrlEntity = [self getServerUrlFromDirectoryID:directoryID activeAccount:activeAccount];
-                
-                if([fileName isEqualToString:fileNameEntity]) {
-                    
-                    NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrlEntity addFileName:fileNameEntity];
-                    
-                    BOOL risultato = [self isDirectoryLock:lockServerUrl activeAccount:activeAccount];
-                    if (risultato) return YES;
-                }
-                
-            }
-        }
-    }
- 
-    return NO;
-}
-*/
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== LocalFile =====
-#pragma --------------------------------------------------------------------------------------------
-
-+ (void)addLocalFile:(tableMetadata *)metadata activeAccount:(NSString *)activeAccount
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-        
-        BOOL offline = NO;
-    
-        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (fileID == %@)", activeAccount, metadata.fileID];
-        TableLocalFile *record = [TableLocalFile MR_findFirstWithPredicate:predicate inContext:localContext];
-        
-        if (record) {
-            
-            offline = [[record valueForKey:@"offline"] boolValue];
-            
-            [record MR_deleteEntityInContext:localContext];
-        }
-        
-        record = [TableLocalFile MR_createEntityInContext:localContext];
-        
-        record.account = activeAccount;
-        record.date = metadata.date;
-        record.fileID = metadata.fileID;
-    
-        record.exifDate = [NSDate date];
-        record.exifLatitude = @"-1";
-        record.exifLongitude = @"-1";
-        
-        record.offline = [NSNumber numberWithBool:offline];
-        record.fileName = metadata.fileName;
-        record.fileNamePrint = metadata.fileNamePrint;
-        record.rev = metadata.rev;
-        record.size = [NSNumber numberWithLong:metadata.size];
-    }];
-}
-
-+ (void)deleteLocalFileWithPredicate:(NSPredicate *)predicate
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-        
-        [TableLocalFile MR_deleteAllMatchingPredicate:predicate inContext:localContext];
-    }];
-}
-
-+ (void)renameLocalFileWithEtag:(NSString *)fileID fileNameTo:(NSString *)fileNameTo fileNamePrintTo:(NSString *)fileNamePrintTo activeAccount:(NSString *)activeAccount
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-        
-        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, activeAccount];
-        TableLocalFile *record = [TableLocalFile MR_findFirstWithPredicate:predicate inContext:localContext];
-    
-        if (record) {
-            
-            if (fileNameTo)record.fileName = fileNameTo;
-            if (fileNamePrintTo)record.fileNamePrint = fileNamePrintTo;
-        }
-    }];
-}
-
-+ (void)updateLocalFileModel:(tableMetadata *)metadata activeAccount:(NSString *)activeAccount
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-        
-        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (fileName == %@)", activeAccount, metadata.fileName];
-        TableLocalFile *record = [TableLocalFile MR_findFirstWithPredicate:predicate inContext:localContext];
-    
-        if (record) {
-            
-            record.fileID = metadata.fileID;
-            record.date = metadata.date;
-            record.fileNamePrint = metadata.fileNamePrint;
-        
-        } else {
-        
-            [self addLocalFile:metadata activeAccount:activeAccount];
-        }
-    }];
-}
-
-+ (TableLocalFile *)getLocalFileWithEtag:(NSString *)fileID activeAccount:(NSString *)activeAccount
-{
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, activeAccount];
-    TableLocalFile *record = [TableLocalFile MR_findFirstWithPredicate:predicate];
-    
-    if (record) {
-        
-        return record;
-    } else return nil;
-}
-
-+ (NSMutableArray *)getTableLocalFileWithPredicate:(NSPredicate *)predicate controlZombie:(BOOL)controlZombie activeAccount:(NSString *)activeAccount directoryUser:(NSString *)directoryUser
-{
-    NSMutableArray *ritorno = [[NSMutableArray alloc] init];
-    
-    NSArray *records = [TableLocalFile MR_findAllWithPredicate:predicate];
-    
-    if ([records count] > 0) {
-        
-        // verifichiamo esistano tutti i file altrimenti rimuoviamo il record
-        for(TableLocalFile *record in records){
-            
-            if (controlZombie) {
-                
-                NSString *fileID = record.fileID;
-                NSString *FilePathEtag = [NSString stringWithFormat:@"%@/%@", directoryUser, fileID];
-                NSString *FilePathFileName = [NSString stringWithFormat:@"%@/%@", directoryUser, record.fileName];
-                if (![[NSFileManager defaultManager] fileExistsAtPath:FilePathEtag] && ![[NSFileManager defaultManager] fileExistsAtPath:FilePathFileName] && controlZombie) {
-                    
-                    // non esiste nè il file fileID e nemmeno il plist, eliminiamolo.
-                    [self deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, activeAccount]];
-                    
-                    
-                } else [ritorno addObject:record];
-            } else [ritorno addObject:record];
-        }
-        
-    } else return nil;
-    
-    if ([ritorno count] == 0) return nil;
-    else return ritorno;
-}
-
-+ (NSArray *)getTableLocalFileWithPredicate:(NSPredicate *)predicate
-{
-    return [TableLocalFile MR_findAllWithPredicate:predicate];
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== GeoInformation =====
-#pragma --------------------------------------------------------------------------------------------
-
-+ (NSArray *)getGeoInformationLocalFromEtag:(NSString *)fileID activeAccount:(NSString *)activeAccount
-{
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, activeAccount];
-    TableLocalFile *record = [TableLocalFile MR_findFirstWithPredicate:predicate];
-    
-    if (record) return [[NSArray alloc] initWithObjects:record.exifDate, record.exifLatitude, record.exifLongitude, nil];
-    else return nil;
-}
-
-+ (void)setGeoInformationLocalFromEtag:(NSString *)fileID exifDate:(NSDate *)exifDate exifLatitude:(NSString *)exifLatitude exifLongitude:(NSString *)exifLongitude activeAccount:(NSString *)activeAccount
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-        
-        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (fileID == %@)", activeAccount, fileID];
-        TableLocalFile *record = [TableLocalFile MR_findFirstWithPredicate:predicate inContext:localContext];
-    
-        if (record) {
-            
-            record.exifDate = exifDate;
-            record.exifLatitude = exifLatitude;
-            record.exifLongitude = exifLongitude;
-        }
-    }];
-}
-
-+ (void)setGeoInformationLocalNull
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-        
-        NSArray *records = [TableLocalFile MR_findAllInContext:localContext];
-        
-        for (TableLocalFile *record in records) {
-            
-            if ([record.exifLatitude doubleValue] != 0 || [record.exifLongitude doubleValue] != 0) {
-                record.exifLatitude = @"9999";
-                record.exifLongitude = @"9999";
-            }
-        }
-    }];
-}
-
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Certificates =====
-#pragma --------------------------------------------------------------------------------------------
-
 + (NSMutableArray *)getAllCertificatesLocationOldDB
 {
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
     NSMutableArray *output = [NSMutableArray new];
     
-    NSArray *records = [TableCertificates MR_findAllInContext:context];
+    NSArray *records = [TableCertificates MR_findAll];
     
     for (TableCertificates *record in records) {
         
@@ -942,319 +54,4 @@
     return output;
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Share =====
-#pragma --------------------------------------------------------------------------------------------
-/*
-+ (void)setShareLink:(NSString *)share fileName:(NSString *)fileName serverUrl:(NSString *)serverUrl sharesLink:(NSMutableDictionary *)sharesLink activeAccount:(NSString *)activeAccount
-{    
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (fileName == %@) AND (serverUrl == %@)", activeAccount, fileName, serverUrl];
-    TableShare *record = [TableShare MR_findFirstWithPredicate:predicate inContext:context];
-    
-    if (record) {
-        
-        record.shareLink = share;
-        
-    } else {
-        
-        TableShare *record = [TableShare MR_createEntityInContext:context];
-        
-        record.account = activeAccount;
-        record.fileName = fileName;
-        record.serverUrl = serverUrl;
-        record.shareLink = share;
-    }
-    
-    [context MR_saveToPersistentStoreAndWait];
-    
-    if (share && serverUrl && fileName)
-        [sharesLink setObject:share forKey:[serverUrl stringByAppendingString:fileName]];
-}
-
-+ (void)setShareUserAndGroup:(NSString *)share fileName:(NSString *)fileName serverUrl:(NSString *)serverUrl sharesUserAndGroup:(NSMutableDictionary *)sharesUserAndGroup activeAccount:(NSString *)activeAccount
-{
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (fileName == %@) AND (serverUrl == %@)", activeAccount, fileName, serverUrl];
-    TableShare *record = [TableShare MR_findFirstWithPredicate:predicate inContext:context];
-    
-    if (record) {
-        
-        record.shareUserAndGroup = share;
-        
-    } else {
-        
-        TableShare *record = [TableShare MR_createEntityInContext:context];
-        
-        record.account = activeAccount;
-        record.fileName = fileName;
-        record.serverUrl = serverUrl;
-        record.shareUserAndGroup = share;
-        
-    }
-    
-    [context MR_saveToPersistentStoreAndWait];
-
-    [sharesUserAndGroup setObject:share forKey:[serverUrl stringByAppendingString:fileName]];
-}
-
-+ (void)unShare:(NSString *)share fileName:(NSString *)fileName serverUrl:(NSString *)serverUrl sharesLink:(NSMutableDictionary *)sharesLink sharesUserAndGroup:(NSMutableDictionary *)sharesUserAndGroup activeAccount:(NSString *)activeAccount
-{
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND ((shareLink CONTAINS %@) OR (shareUserAndGroup CONTAINS %@))", activeAccount, share, share];
-    
-    TableShare *record = [TableShare MR_findFirstWithPredicate:predicate inContext:context];
-    
-    if (record) {
-        
-        if ([record.shareLink containsString:share]) record.shareLink = @"";
-        if ([record.shareUserAndGroup containsString:share]) {
-            
-            NSMutableArray *shares = [[NSMutableArray alloc] initWithArray:[record.shareUserAndGroup componentsSeparatedByString:@","]];
-            [shares removeObject:share];
-            record.shareUserAndGroup = [shares componentsJoinedByString:@","];
-        }
-        
-        if ([record.shareLink length] == 0 && [record.shareUserAndGroup length] == 0)
-            [record MR_deleteEntityInContext:context];
-        
-        [context MR_saveToPersistentStoreAndWait];
-        
-        if ([record.shareLink length] > 0) [sharesLink setObject:record.shareLink forKey:[serverUrl stringByAppendingString:fileName]];
-        else [sharesLink removeObjectForKey:[serverUrl stringByAppendingString:fileName]];
-        
-        if ([record.shareUserAndGroup length] > 0) [sharesUserAndGroup setObject:record.shareUserAndGroup forKey:[serverUrl stringByAppendingString:fileName]];
-        else [sharesUserAndGroup removeObjectForKey:[serverUrl stringByAppendingString:fileName]];
-    }
-}
-
-+ (void)removeAllShareActiveAccount:(NSString *)activeAccount sharesLink:(NSMutableDictionary *)sharesLink sharesUserAndGroup:(NSMutableDictionary *)sharesUserAndGroup
-{
-    NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
-    
-    [TableShare MR_deleteAllMatchingPredicate:[NSPredicate predicateWithFormat:@"account == %@", activeAccount] inContext:context];
-    [context MR_saveToPersistentStoreAndWait];
-
-    [sharesLink removeAllObjects];
-    [sharesUserAndGroup removeAllObjects];
-}
-
-+ (void)updateShare:(NSDictionary *)items sharesLink:(NSMutableDictionary *)sharesLink sharesUserAndGroup:(NSMutableDictionary *)sharesUserAndGroup activeAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl
-{
-    // rimuovi tutte le condivisioni
-    [self removeAllShareActiveAccount:activeAccount sharesLink:sharesLink sharesUserAndGroup:sharesUserAndGroup];
-    
-    NSMutableArray *itemsLink = [[NSMutableArray alloc] init];
-    NSMutableArray *itemsUsersAndGroups = [[NSMutableArray alloc] init];
-        
-    for (NSString *idRemoteShared in items) {
-            
-        OCSharedDto *item = [items objectForKey:idRemoteShared];
-            
-        if (item.shareType == shareTypeLink) [itemsLink addObject:item];
-        
-        if ([[item shareWith] length] > 0 && (item.shareType == shareTypeUser || item.shareType == shareTypeGroup || item.shareType == shareTypeRemote)) [itemsUsersAndGroups addObject:item];
-    }
-        
-    // Link
-    for (OCSharedDto *item in itemsLink) {
-            
-        NSString *fullPath = [[CCUtility getHomeServerUrlActiveUrl:activeUrl] stringByAppendingString:item.path];
-            
-        NSString *fileName = [fullPath lastPathComponent];
-        NSString *serverUrl = [fullPath substringToIndex:([fullPath length]-[fileName length]-1)];
-        if ([serverUrl hasSuffix:@"/"]) serverUrl = [serverUrl substringToIndex:[serverUrl length] - 1];
-            
-        if ([@(item.idRemoteShared) stringValue])
-            [self setShareLink:[@(item.idRemoteShared) stringValue] fileName:fileName serverUrl:serverUrl sharesLink:sharesLink activeAccount:activeAccount];
-    }
-        
-    // Condivisioni
-    NSMutableDictionary *paths = [[NSMutableDictionary alloc] init];
-        
-    // Creazione dizionario
-    for (OCSharedDto *item in itemsUsersAndGroups) {
-            
-        if ([paths objectForKey:item.path]) {
-                
-            NSMutableArray *share = [paths objectForKey:item.path];
-            [share addObject:[@(item.idRemoteShared) stringValue]];
-            [paths setObject:share forKey:item.path];
-                
-        } else {
-                
-            NSMutableArray *share = [[NSMutableArray alloc] initWithObjects:[@(item.idRemoteShared) stringValue], nil];
-            [paths setObject:share forKey:item.path];
-        }
-    }
-        
-    // Scrittura su DB
-    for (NSString *path in paths) {
-            
-        NSArray *items = [paths objectForKey:path];
-        NSString *share = [items componentsJoinedByString:@","];
-            
-        NSLog(@"[LOG] share %@", share);
-            
-        NSString *fullPath = [[CCUtility getHomeServerUrlActiveUrl:activeUrl] stringByAppendingString:path];
-            
-        NSString *fileName = [fullPath lastPathComponent];
-        NSString *serverUrl = [fullPath substringToIndex:([fullPath length]-[fileName length]-1)];
-        if ([serverUrl hasSuffix:@"/"]) serverUrl = [serverUrl substringToIndex:[serverUrl length] - 1];
-            
-        if (share)
-            [self setShareUserAndGroup:share fileName:fileName serverUrl:serverUrl sharesUserAndGroup:sharesUserAndGroup activeAccount:activeAccount];
-    }
-}
-
-+ (void)populateSharesVariableFromDBActiveAccount:(NSString *)activeAccount sharesLink:(NSMutableDictionary *)sharesLink sharesUserAndGroup:(NSMutableDictionary *)sharesUserAndGroup
-{
-    [sharesLink removeAllObjects];
-    [sharesUserAndGroup removeAllObjects];
-    
-    NSArray *records = [TableShare MR_findAllWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@)", activeAccount]];
-    
-    for (TableShare *record in records) {
-        
-        if ([record.shareLink length] > 0 && record.serverUrl && record.fileName)
-            [sharesLink setObject:record.shareLink forKey:[record.serverUrl stringByAppendingString:record.fileName]];
-        
-        if ([record.shareUserAndGroup length] > 0 && record.serverUrl && record.fileName)
-            [sharesUserAndGroup setObject:record.shareUserAndGroup forKey:[record.serverUrl stringByAppendingString:record.fileName]];
-    }
-    
-    return;
-}
-*/
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Offline =====
-#pragma --------------------------------------------------------------------------------------------
-/*
-+ (NSArray *)getHomeOfflineActiveAccount:(NSString *)activeAccount directoryUser:(NSString *)directoryUser fieldOrder:(NSString *)fieldOrder ascending:(BOOL)ascending
-{
-    NSMutableArray *tableMetadatas = [NSMutableArray new];
-    NSArray *directoriesOffline = [self getOfflineDirectoryActiveAccount:activeAccount];
-    NSString *father = @"";
-    NSSortDescriptor *descriptor;
-
-    // Add directory
-    
-    for (TableDirectory *directory in directoriesOffline) {
-        
-        if (![directory.serverUrl containsString:father]) {
-            
-            father = directory.serverUrl;
-            
-            NSString *upDir = [CCUtility deletingLastPathComponentFromServerUrl:father];
-            NSString *directoryID = [self getDirectoryIDFromServerUrl:upDir activeAccount:activeAccount];
-            NSString *fileName = [father lastPathComponent];
-            
-            if (upDir && directoryID && fileName) {
-            
-                NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(directoryID == %@) AND (account == %@) AND (directory == 1) AND (fileNameData == %@)", directoryID, activeAccount, fileName];
-                //TableMetadata *tableMetadata = [self getTableMetadataWithPreficate:predicate];
-                tableMetadata *metadata =  [[NCManageDatabase sharedInstance] getMetadataWithPreficate:predicate];
-                
-                if (metadata)
-                    [tableMetadatas addObject:metadata];
-            }
-        }
-    }
-    
-    // Add files
-    
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (offline == 1)", activeAccount];
-    NSArray *localFiles = [CCCoreData getTableLocalFileWithPredicate:predicate];
-    
-    for (TableLocalFile *localFile in localFiles) {
-        
-        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (fileID == %@)", activeAccount, localFile.fileID];
-        //TableMetadata *tableMetadata = [self getTableMetadataWithPreficate:predicate];
-        tableMetadata *metadata =  [[NCManageDatabase sharedInstance] getMetadataWithPreficate:predicate];
-        
-        if (metadata)
-            [tableMetadatas addObject:metadata];
-    }
-    
-    // Order
-    
-    if ([fieldOrder isEqualToString:@"fileName"]) descriptor = [[NSSortDescriptor alloc] initWithKey:@"fileNamePrint" ascending:ascending selector:@selector(localizedCaseInsensitiveCompare:)];
-    
-    else if ([fieldOrder isEqualToString:@"fileDate"]) descriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:ascending selector:nil];
-    
-    else if ([fieldOrder isEqualToString:@"sessionTaskIdentifier"]) descriptor = [[NSSortDescriptor alloc] initWithKey:@"sessionTaskIdentifier" ascending:ascending selector:nil];
-    
-    else descriptor = [[NSSortDescriptor alloc] initWithKey:fieldOrder ascending:ascending selector:@selector(localizedCaseInsensitiveCompare:)];
-
-    return [tableMetadatas sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor, nil]];//[NSArray arrayWithArray:tableMetadatas];
-}
-*/
-/*
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== File System =====
-#pragma --------------------------------------------------------------------------------------------
-
-+ (BOOL)downloadFile:(tableMetadata *)metadata directoryUser:(NSString *)directoryUser activeAccount:(NSString *)activeAccount
-{
-    // ----------------------------------------- FILESYSTEM ------------------------------------------
-    
-    // if encrypted, rewrite
-    if (metadata.cryptated == YES)
-        if ([[CCCrypto sharedManager] decrypt:metadata.fileID fileNameDecrypted:metadata.fileID fileNamePrint:metadata.fileNamePrint password:[[CCCrypto sharedManager] getKeyPasscode:metadata.uuid] directoryUser:directoryUser] == 0) return NO;
-    
-    // ------------------------------------------ COREDATA -------------------------------------------
-    
-    // add/update Table Local File
-    [self addLocalFile:metadata activeAccount:activeAccount];
-    
-    // EXIF
-    if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image])
-        [CCExifGeo setExifLocalTableEtag:metadata directoryUser:directoryUser activeAccount:activeAccount];
-    
-    // Icon
-    [CCGraphics createNewImageFrom:metadata.fileID directoryUser:directoryUser fileNameTo:metadata.fileID fileNamePrint:metadata.fileNamePrint size:@"m" imageForUpload:NO typeFile:metadata.typeFile writePreview:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
-    
-    return YES;
-}
-
-+ (void)downloadFilePlist:(tableMetadata *)metadata activeAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl directoryUser:(NSString *)directoryUser
-{
-    metadata = [[NCManageDatabase sharedInstance] copyTableMetadata:metadata];
-    
-    metadata =  [CCUtility insertInformationPlist:metadata directoryUser:directoryUser];    
-    [[NCManageDatabase sharedInstance] updateMetadata:metadata activeUrl:activeUrl];
-    
-    // se è un template aggiorniamo anche nel FileSystem
-    if ([metadata.type isEqualToString: k_metadataType_template]){
-        [self updateLocalFileModel:metadata activeAccount:activeAccount];
-    }
-}
-
-+ (void)deleteFile:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl directoryUser:(NSString *)directoryUser activeAccount:(NSString *)activeAccount
-{
-    if (!metadata) return;
-    
-    // ----------------------------------------- FILESYSTEM ------------------------------------------
-    
-    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID] error:nil];
-    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", directoryUser, metadata.fileID] error:nil];
-    
-    // ------------------------------------------ DATABASE -------------------------------------------
-
-    // se è una directory cancelliamo tutto quello che è della directory
-    if (metadata.directory && serverUrl) {
-        
-        NSString *dirForDelete = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileNameData];
-        
-        [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:dirForDelete];
-    }
-    
-    [self deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadata.fileID, activeAccount]];
-    [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadata.fileID, activeAccount]];
-}
-*/
-
 @end

+ 1 - 0
iOSClient/Nextcloud-Bridging-Header.h

@@ -9,6 +9,7 @@
 #import "CCManageAccount.h"
 #import "CCGraphics.h"
 
+#import "OCUserProfile.h"
 #import "OCNotifications.h"
 #import "OCNotificationsAction.h"
 #import "OCFrameworkConstants.h"