| | 123 | - (NSManagedObjectContext *)createV1Moc:(NSString *)storeFile |
| | 124 | { |
| | 125 | NSURL *storeUrl = [NSURL fileURLWithPath:storeFile]; |
| | 126 | NSError *error = nil; |
| | 127 | |
| | 128 | NSString *mopath = [[NSBundle bundleForClass:[self class]] pathForResource:@"Sapphire" ofType:@"momd"]; |
| | 129 | mopath = [mopath stringByAppendingPathComponent:@"SapphireV1.mom"]; |
| | 130 | NSURL *mourl = [NSURL fileURLWithPath:mopath]; |
| | 131 | NSManagedObjectModel *model = [[NSManagedObjectModel alloc] initWithContentsOfURL:mourl]; |
| | 132 | |
| | 133 | NSPersistentStoreCoordinator *coord = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model]; |
| | 134 | if(![coord addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) |
| | 135 | { |
| | 136 | SapphireLog(SAPPHIRE_LOG_ALL, SAPPHIRE_LOG_LEVEL_ERROR, @"Could not add store: %@", error); |
| | 137 | |
| | 138 | [coord release]; |
| | 139 | [model release]; |
| | 140 | return nil; |
| | 141 | } |
| | 142 | |
| | 143 | NSManagedObjectContext *retmoc = [[NSManagedObjectContext alloc] init]; |
| | 144 | [retmoc setUndoManager:nil]; |
| | 145 | [retmoc setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy]; |
| | 146 | [retmoc setPersistentStoreCoordinator:coord]; |
| | 147 | |
| | 148 | [model release]; |
| | 149 | [coord release]; |
| | 150 | |
| | 151 | return retmoc; |
| | 152 | } |
| | 153 | |
| 117 | | NSString *plistFile = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/metaData.plist"]; |
| 118 | | [SapphireMetaDataSupport importPlist:[plistFile stringByDeletingLastPathComponent] intoContext:moc withDisplay:self]; |
| | 157 | NSString *v1StoreFile = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/metaData.sapphireData"]; |
| | 158 | NSFileManager *fm = [NSFileManager defaultManager]; |
| | 159 | if([fm fileExistsAtPath:v1StoreFile]) |
| | 160 | { |
| | 161 | NSManagedObjectContext *oldContext = [self createV1Moc:v1StoreFile]; |
| | 162 | if(oldContext != nil) |
| | 163 | [SapphireMetaDataSupport importV1Store:oldContext intoContext:moc withDisplay:self]; |
| | 164 | } |
| | 165 | else |
| | 166 | { |
| | 167 | NSString *plistFile = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/metaData.plist"]; |
| | 168 | [SapphireMetaDataSupport importPlist:[plistFile stringByDeletingLastPathComponent] intoContext:moc withDisplay:self]; |
| | 169 | } |