|
@@ -1292,83 +1292,4 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-+ (void)verifyVersionCoreData:(UIViewController *)vc
|
|
|
-{
|
|
|
- NSString *applicationName = [[[NSBundle mainBundle] infoDictionary] valueForKey:(NSString *)kCFBundleNameKey];
|
|
|
-
|
|
|
- // Get the path for our model (in this case it's named 'cache')
|
|
|
- NSURL *url = [[NSBundle mainBundle] URLForResource:@"cryptocloud" withExtension:@"momd"];
|
|
|
- NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[[NSManagedObjectModel alloc] initWithContentsOfURL:url]]; /* get a coordinator */
|
|
|
- NSString *sourceStoreType = nil;/* type for the source store, or nil if not known */ ;
|
|
|
- NSString *path = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) firstObject];
|
|
|
- // Figure out the full path where our store is located
|
|
|
- path = [path stringByAppendingFormat:@"/%@/cryptocloud", applicationName];
|
|
|
- NSURL *sourceStoreURL = [NSURL fileURLWithPath:path]; /* URL for the source store */ ;
|
|
|
- NSError *error = nil;
|
|
|
-
|
|
|
- NSDictionary *sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:sourceStoreType URL:sourceStoreURL error:&error];
|
|
|
-
|
|
|
- if (sourceMetadata == nil) {
|
|
|
-
|
|
|
- NSLog(@"[LOG] Error checking migration validity");
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- if (![[psc managedObjectModel] isConfiguration:nil compatibleWithStoreMetadata:sourceMetadata]) {
|
|
|
-
|
|
|
- UIAlertController * alert= [UIAlertController alertControllerWithTitle:nil message:NSLocalizedString(@"_required_new_database_", nil) preferredStyle:UIAlertControllerStyleAlert];
|
|
|
- UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault
|
|
|
- handler:^(UIAlertAction * action) {
|
|
|
- [alert dismissViewControllerAnimated:YES completion:nil];
|
|
|
- }];
|
|
|
- [alert addAction:ok];
|
|
|
- [vc presentViewController:alert animated:YES completion:nil];
|
|
|
-
|
|
|
- // Delete CoreData store
|
|
|
- NSFileManager *manager = [NSFileManager defaultManager];
|
|
|
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
|
|
- NSString *directory = [[paths lastObject] stringByAppendingPathComponent:applicationName];
|
|
|
- NSArray *files = [manager contentsOfDirectoryAtPath:directory error:nil];
|
|
|
- NSError *error;
|
|
|
-
|
|
|
- for(NSString *filename in files) {
|
|
|
- [manager removeItemAtPath:[directory stringByAppendingPathComponent:filename] error:&error];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#pragma --------------------------------------------------------------------------------------------
|
|
|
-#pragma mark ===== Flush Database =====
|
|
|
-#pragma --------------------------------------------------------------------------------------------
|
|
|
-
|
|
|
-+ (void)flushTableLocalFileAccount:(NSString *)account
|
|
|
-{
|
|
|
- NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
|
|
|
-
|
|
|
- if (account) {
|
|
|
-
|
|
|
- [TableLocalFile MR_deleteAllMatchingPredicate:[NSPredicate predicateWithFormat:@"(account == %@)", account] inContext:context];
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- [TableLocalFile MR_truncateAllInContext:context];
|
|
|
- }
|
|
|
-
|
|
|
- [context MR_saveToPersistentStoreAndWait];
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-+ (void)flushAllDatabase
|
|
|
-{
|
|
|
- NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
|
|
|
-
|
|
|
- [TableAccount MR_truncateAllInContext:context];
|
|
|
- [TableDirectory MR_truncateAllInContext:context];
|
|
|
- [TableLocalFile MR_truncateAllInContext:context];
|
|
|
-
|
|
|
- [context MR_saveToPersistentStoreAndWait];
|
|
|
-}
|
|
|
-
|
|
|
@end
|