Commit 2a9e020c authored by Felix Paul Kühne's avatar Felix Paul Kühne

behave correctly if MLKit is launched in read-only mode and no library was ever stored yet

parent 969af122
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* MLAlbum.m * MLAlbum.m
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Pierre d'Herbemont * Copyright (C) 2010 Pierre d'Herbemont
* Copyright (C) 2013 Felix Paul Kühne * Copyright (C) 2013-2015 Felix Paul Kühne
* $Id$ * $Id$
* *
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org> * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
{ {
NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext]; NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
if (!moc || moc.persistentStoreCoordinator == nil)
return nil;
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Album" inManagedObjectContext:moc]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Album" inManagedObjectContext:moc];
[request setEntity:entity]; [request setEntity:entity];
...@@ -49,8 +51,12 @@ ...@@ -49,8 +51,12 @@
NSFetchRequest *request = [[MLMediaLibrary sharedMediaLibrary] fetchRequestForEntity:@"Album"]; NSFetchRequest *request = [[MLMediaLibrary sharedMediaLibrary] fetchRequestForEntity:@"Album"];
[request setPredicate:[NSPredicate predicateWithFormat:@"name == %@", name]]; [request setPredicate:[NSPredicate predicateWithFormat:@"name == %@", name]];
NSArray *dbResults = [[[MLMediaLibrary sharedMediaLibrary] managedObjectContext] executeFetchRequest:request error:nil]; NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
NSAssert(dbResults, @"Can't execute fetch request"); NSArray *dbResults;
if (moc) {
dbResults = [moc executeFetchRequest:request error:nil];
NSAssert(dbResults, @"Can't execute fetch request");
}
if ([dbResults count] <= 0) if ([dbResults count] <= 0)
return nil; return nil;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* MLAlbumTrack.m * MLAlbumTrack.m
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Pierre d'Herbemont * Copyright (C) 2010 Pierre d'Herbemont
* Copyright (C) 2013 Felix Paul Kühne * Copyright (C) 2013-2015 Felix Paul Kühne
* $Id$ * $Id$
* *
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org> * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
...@@ -37,6 +37,9 @@ ...@@ -37,6 +37,9 @@
{ {
NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext]; NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
if (moc || moc.persistentStoreCoordinator == nil)
return [NSArray array];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"AlbumTrack" inManagedObjectContext:moc]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"AlbumTrack" inManagedObjectContext:moc];
[request setEntity:entity]; [request setEntity:entity];
...@@ -90,8 +93,11 @@ ...@@ -90,8 +93,11 @@
[self willChangeValueForKey:@"unread"]; [self willChangeValueForKey:@"unread"];
[self setPrimitiveUnread:unread]; [self setPrimitiveUnread:unread];
[self didChangeValueForKey:@"unread"]; [self didChangeValueForKey:@"unread"];
[[[MLMediaLibrary sharedMediaLibrary] managedObjectContext] refreshObject:[self album] mergeChanges:YES]; NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
[[[MLMediaLibrary sharedMediaLibrary] managedObjectContext] refreshObject:self mergeChanges:YES]; if (moc) {
[moc refreshObject:[self album] mergeChanges:YES];
[moc refreshObject:self mergeChanges:YES];
}
} }
@dynamic artist; @dynamic artist;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Lunettes * Lunettes
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Pierre d'Herbemont * Copyright (C) 2010 Pierre d'Herbemont
* Copyright (C) 2010-2013 VLC authors and VideoLAN * Copyright (C) 2010-2015 VLC authors and VideoLAN
* $Id$ * $Id$
* *
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org> * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
...@@ -48,6 +48,9 @@ NSString *kMLFileTypeAudio = @"audio"; ...@@ -48,6 +48,9 @@ NSString *kMLFileTypeAudio = @"audio";
{ {
NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext]; NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
if (!moc || moc.persistentStoreCoordinator == nil)
return [NSArray array];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"File" inManagedObjectContext:moc]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"File" inManagedObjectContext:moc];
[request setEntity:entity]; [request setEntity:entity];
[request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES"]]; [request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES"]];
...@@ -68,6 +71,9 @@ NSString *kMLFileTypeAudio = @"audio"; ...@@ -68,6 +71,9 @@ NSString *kMLFileTypeAudio = @"audio";
{ {
NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext]; NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
if (!moc || moc.persistentStoreCoordinator == nil)
return [NSArray array];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"File" inManagedObjectContext:moc]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"File" inManagedObjectContext:moc];
[request setEntity:entity]; [request setEntity:entity];
[request setPredicate:[NSPredicate predicateWithFormat:@"url == %@", url]]; [request setPredicate:[NSPredicate predicateWithFormat:@"url == %@", url]];
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Lunettes * Lunettes
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Pierre d'Herbemont * Copyright (C) 2010 Pierre d'Herbemont
* Copyright (C) 2010-2013 VLC authors and VideoLAN * Copyright (C) 2010-2015 VLC authors and VideoLAN
* $Id$ * $Id$
* *
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org> * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
{ {
NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext]; NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
if (!moc || moc.persistentStoreCoordinator == nil)
return [NSArray array];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Label" inManagedObjectContext:moc]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Label" inManagedObjectContext:moc];
[request setEntity:entity]; [request setEntity:entity];
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* MobileMediaLibraryKit * MobileMediaLibraryKit
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Pierre d'Herbemont * Copyright (C) 2010 Pierre d'Herbemont
* Copyright (C) 2010-2014 VLC authors and VideoLAN * Copyright (C) 2010-2015 VLC authors and VideoLAN
* $Id$ * $Id$
* *
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org> * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
...@@ -102,6 +102,9 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -102,6 +102,9 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
{ {
NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSManagedObjectContext *moc = [self managedObjectContext]; NSManagedObjectContext *moc = [self managedObjectContext];
if (!moc || moc.persistentStoreCoordinator == nil)
return nil;
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:entity inManagedObjectContext:moc]; NSEntityDescription *entityDescription = [NSEntityDescription entityForName:entity inManagedObjectContext:moc];
NSAssert(entityDescription, @"No entity"); NSAssert(entityDescription, @"No entity");
[request setEntity:entityDescription]; [request setEntity:entityDescription];
...@@ -111,12 +114,18 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -111,12 +114,18 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
- (id)createObjectForEntity:(NSString *)entity - (id)createObjectForEntity:(NSString *)entity
{ {
NSManagedObjectContext *moc = [self managedObjectContext]; NSManagedObjectContext *moc = [self managedObjectContext];
if (moc || moc.persistentStoreCoordinator == nil)
return nil;
return [NSEntityDescription insertNewObjectForEntityForName:entity inManagedObjectContext:moc]; return [NSEntityDescription insertNewObjectForEntityForName:entity inManagedObjectContext:moc];
} }
- (void)removeObject:(NSManagedObject *)object - (void)removeObject:(NSManagedObject *)object
{ {
[[self managedObjectContext] deleteObject:object]; NSManagedObjectContext *moc = [self managedObjectContext];
if (moc)
[[self managedObjectContext] deleteObject:object];
} }
#pragma mark - #pragma mark -
...@@ -207,6 +216,13 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -207,6 +216,13 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
options = mutableOptions; options = mutableOptions;
} }
if ([[self.additionalPersitentStoreOptions objectForKey:NSReadOnlyPersistentStoreOption] boolValue] == YES) {
if (![[NSFileManager defaultManager] fileExistsAtPath:self.persistentStoreURL.path]) {
APLog(@"no library was found in read-only mode, hence no functionality will be available in this session");
return nil;
}
}
NSError *error; NSError *error;
NSPersistentStore *persistentStore = [coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:self.persistentStoreURL options:options error:&error]; NSPersistentStore *persistentStore = [coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:self.persistentStoreURL options:options error:&error];
...@@ -242,6 +258,8 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -242,6 +258,8 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
_managedObjectContext = [[NSManagedObjectContext alloc] init]; _managedObjectContext = [[NSManagedObjectContext alloc] init];
[_managedObjectContext setPersistentStoreCoordinator:self.persistentStoreCoordinator]; [_managedObjectContext setPersistentStoreCoordinator:self.persistentStoreCoordinator];
if (_managedObjectContext.persistentStoreCoordinator == nil)
return nil;
[_managedObjectContext setUndoManager:nil]; [_managedObjectContext setUndoManager:nil];
[_managedObjectContext addObserver:self forKeyPath:@"hasChanges" options:NSKeyValueObservingOptionInitial context:nil]; [_managedObjectContext addObserver:self forKeyPath:@"hasChanges" options:NSKeyValueObservingOptionInitial context:nil];
return _managedObjectContext; return _managedObjectContext;
...@@ -251,6 +269,10 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -251,6 +269,10 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
{ {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(savePendingChanges) object:nil]; [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(savePendingChanges) object:nil];
NSError *error = nil; NSError *error = nil;
NSManagedObjectContext *moc = [self managedObjectContext];
if (!moc)
return;
BOOL success = [[self managedObjectContext] save:&error]; BOOL success = [[self managedObjectContext] save:&error];
NSAssert1(success, @"Can't save: %@", error); NSAssert1(success, @"Can't save: %@", error);
#if !TARGET_OS_IPHONE && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 #if !TARGET_OS_IPHONE && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
...@@ -263,7 +285,11 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -263,7 +285,11 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
- (void)save - (void)save
{ {
NSError *error = nil; NSError *error = nil;
BOOL success = [[self managedObjectContext] save:&error]; NSManagedObjectContext *moc = [self managedObjectContext];
if (!moc)
return;
BOOL success = [moc save:&error];
NSAssert1(success, @"Can't save: %@", error); NSAssert1(success, @"Can't save: %@", error);
} }
...@@ -725,7 +751,10 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -725,7 +751,10 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
[request setPredicate:[NSCompoundPredicate orPredicateWithSubpredicates:fetchPredicates]]; [request setPredicate:[NSCompoundPredicate orPredicateWithSubpredicates:fetchPredicates]];
APLog(@"Fetching"); APLog(@"Fetching");
NSArray *dbResults = [[self managedObjectContext] executeFetchRequest:request error:nil]; NSManagedObjectContext *moc = [self managedObjectContext];
if (!moc)
return;
NSArray *dbResults = [moc executeFetchRequest:request error:nil];
APLog(@"Done"); APLog(@"Done");
NSMutableArray *filePathsToAdd = [NSMutableArray arrayWithArray:filepaths]; NSMutableArray *filePathsToAdd = [NSMutableArray arrayWithArray:filepaths];
...@@ -786,10 +815,17 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -786,10 +815,17 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
NSArray *tertiaryCollection; NSArray *tertiaryCollection;
NSUInteger tertiaryCount = 0; NSUInteger tertiaryCount = 0;
NSUInteger emptyAlbumCounter = 0; NSUInteger emptyAlbumCounter = 0;
NSManagedObjectContext *moc = [self managedObjectContext];
if (!moc) {
[self libraryDidAppear];
if ([self.delegate respondsToSelector:@selector(libraryUpgradeComplete)])
[self.delegate libraryUpgradeComplete];
return;
}
for (NSUInteger x = 0; x < count; x++) { for (NSUInteger x = 0; x < count; x++) {
album = collection[x]; album = collection[x];
if (album.tracks.count < 1) if (album.tracks.count < 1)
[[self managedObjectContext] deleteObject:album]; [moc deleteObject:album];
else { else {
secondaryCollection = album.tracks.allObjects; secondaryCollection = album.tracks.allObjects;
secondaryCount = secondaryCollection.count; secondaryCount = secondaryCollection.count;
...@@ -808,7 +844,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -808,7 +844,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
} }
} }
if (emptyAlbumCounter == 0) if (emptyAlbumCounter == 0)
[[self managedObjectContext] deleteObject:album]; [moc deleteObject:album];
} }
} }
album = nil; album = nil;
...@@ -821,7 +857,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -821,7 +857,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
for (NSUInteger x = 0; x < count; x++) { for (NSUInteger x = 0; x < count; x++) {
show = collection[x]; show = collection[x];
if (show.episodes.count < 1) if (show.episodes.count < 1)
[[self managedObjectContext] deleteObject:show]; [moc deleteObject:show];
else { else {
secondaryCollection = show.episodes.allObjects; secondaryCollection = show.episodes.allObjects;
secondaryCount = secondaryCollection.count; secondaryCount = secondaryCollection.count;
...@@ -840,7 +876,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -840,7 +876,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
} }
} }
if (emptyAlbumCounter == 0) if (emptyAlbumCounter == 0)
[[self managedObjectContext] deleteObject:show]; [moc deleteObject:show];
} }
} }
...@@ -854,7 +890,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -854,7 +890,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
currentFile = allFiles[x]; currentFile = allFiles[x];
currentFilePath = [currentFile.url stringByReplacingOccurrencesOfString:@"/localhost/" withString:@"//"]; currentFilePath = [currentFile.url stringByReplacingOccurrencesOfString:@"/localhost/" withString:@"//"];
if ([seenFiles containsObject:currentFilePath]) if ([seenFiles containsObject:currentFilePath])
[[self managedObjectContext] deleteObject:currentFile]; [moc deleteObject:currentFile];
else else
[seenFiles addObject:currentFilePath]; [seenFiles addObject:currentFilePath];
} }
...@@ -872,7 +908,10 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -872,7 +908,10 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
[self libraryDidDisappear]; [self libraryDidDisappear];
// Remove no more present files // Remove no more present files
NSFetchRequest *request = [self fetchRequestForEntity:@"File"]; NSFetchRequest *request = [self fetchRequestForEntity:@"File"];
NSArray *results = [[self managedObjectContext] executeFetchRequest:request error:nil]; NSManagedObjectContext *moc = [self managedObjectContext];
if (!moc)
return;
NSArray *results = [moc executeFetchRequest:request error:nil];
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
unsigned int count = (unsigned int)results.count; unsigned int count = (unsigned int)results.count;
...@@ -888,7 +927,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -888,7 +927,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
MLAlbum *album = file.albumTrack.album; MLAlbum *album = file.albumTrack.album;
if (album.tracks.count <= 1) { if (album.tracks.count <= 1) {
@try { @try {
[[self managedObjectContext] deleteObject:album]; [moc deleteObject:album];
} }
@catch (NSException *exception) { @catch (NSException *exception) {
APLog(@"failed to nuke object because it disappeared in front of us"); APLog(@"failed to nuke object because it disappeared in front of us");
...@@ -900,7 +939,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -900,7 +939,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
MLShow *show = file.showEpisode.show; MLShow *show = file.showEpisode.show;
if (show.episodes.count <= 1) { if (show.episodes.count <= 1) {
@try { @try {
[[self managedObjectContext] deleteObject:show]; [moc deleteObject:show];
} }
@catch (NSException *exception) { @catch (NSException *exception) {
APLog(@"failed to nuke object because it disappeared in front of us"); APLog(@"failed to nuke object because it disappeared in front of us");
...@@ -913,7 +952,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -913,7 +952,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
bool thumbExists = [fileManager fileExistsAtPath:thumbPath]; bool thumbExists = [fileManager fileExistsAtPath:thumbPath];
if (thumbExists) if (thumbExists)
[fileManager removeItemAtPath:thumbPath error:nil]; [fileManager removeItemAtPath:thumbPath error:nil];
[[self managedObjectContext] deleteObject:file]; [moc deleteObject:file];
#endif #endif
} }
#if !TARGET_OS_IPHONE #if !TARGET_OS_IPHONE
...@@ -925,7 +964,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -925,7 +964,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
// Get the file to parse // Get the file to parse
request = [self fetchRequestForEntity:@"File"]; request = [self fetchRequestForEntity:@"File"];
[request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES && tracks.@count == 0"]]; [request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES && tracks.@count == 0"]];
results = [[self managedObjectContext] executeFetchRequest:request error:nil]; results = [moc executeFetchRequest:request error:nil];
for (MLFile *file in results) for (MLFile *file in results)
[[MLFileParserQueue sharedFileParserQueue] addFile:file]; [[MLFileParserQueue sharedFileParserQueue] addFile:file];
...@@ -933,7 +972,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -933,7 +972,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
// Always attempt to fetch // Always attempt to fetch
request = [self fetchRequestForEntity:@"File"]; request = [self fetchRequestForEntity:@"File"];
[request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES"]]; [request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES"]];
results = [[self managedObjectContext] executeFetchRequest:request error:nil]; results = [moc executeFetchRequest:request error:nil];
for (MLFile *file in results) { for (MLFile *file in results) {
if (!file.computedThumbnail) if (!file.computedThumbnail)
[self computeThumbnailForFile:file]; [self computeThumbnailForFile:file];
...@@ -944,7 +983,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -944,7 +983,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
// Get the thumbnails to compute // Get the thumbnails to compute
request = [self fetchRequestForEntity:@"File"]; request = [self fetchRequestForEntity:@"File"];
[request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES && hasFetchedInfo == 1 && artworkURL == nil"]]; [request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES && hasFetchedInfo == 1 && artworkURL == nil"]];
results = [[self managedObjectContext] executeFetchRequest:request error:nil]; results = [moc executeFetchRequest:request error:nil];
for (MLFile *file in results) for (MLFile *file in results)
if (!file.computedThumbnail && ![file isAlbumTrack]) if (!file.computedThumbnail && ![file isAlbumTrack])
[self computeThumbnailForFile:file]; [self computeThumbnailForFile:file];
...@@ -952,14 +991,14 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -952,14 +991,14 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
// Get to fetch meta data // Get to fetch meta data
request = [self fetchRequestForEntity:@"File"]; request = [self fetchRequestForEntity:@"File"];
[request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES && hasFetchedInfo == 0"]]; [request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES && hasFetchedInfo == 0"]];
results = [[self managedObjectContext] executeFetchRequest:request error:nil]; results = [moc executeFetchRequest:request error:nil];
for (MLFile *file in results) for (MLFile *file in results)
[self fetchMetaDataForFile:file]; [self fetchMetaDataForFile:file];
// Get to fetch show info // Get to fetch show info
request = [self fetchRequestForEntity:@"Show"]; request = [self fetchRequestForEntity:@"Show"];
[request setPredicate:[NSPredicate predicateWithFormat:@"lastSyncDate == 0"]]; [request setPredicate:[NSPredicate predicateWithFormat:@"lastSyncDate == 0"]];
results = [[self managedObjectContext] executeFetchRequest:request error:nil]; results = [moc executeFetchRequest:request error:nil];
for (MLShow *show in results) for (MLShow *show in results)
[self fetchMetaDataForShow:show]; [self fetchMetaDataForShow:show];
...@@ -969,7 +1008,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -969,7 +1008,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
[MLTVShowInfoGrabber fetchUpdatesSinceServerTime:lastServerTime andExecuteBlock:^(NSArray *updates){ [MLTVShowInfoGrabber fetchUpdatesSinceServerTime:lastServerTime andExecuteBlock:^(NSArray *updates){
NSFetchRequest *request = [self fetchRequestForEntity:@"Show"]; NSFetchRequest *request = [self fetchRequestForEntity:@"Show"];
[request setPredicate:[NSComparisonPredicate predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"theTVDBID"] rightExpression:[NSExpression expressionForConstantValue:updates] modifier:NSDirectPredicateModifier type:NSInPredicateOperatorType options:0]]; [request setPredicate:[NSComparisonPredicate predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"theTVDBID"] rightExpression:[NSExpression expressionForConstantValue:updates] modifier:NSDirectPredicateModifier type:NSInPredicateOperatorType options:0]];
NSArray *results = [[self managedObjectContext] executeFetchRequest:request error:nil]; NSArray *results = [moc executeFetchRequest:request error:nil];
for (MLShow *show in results) for (MLShow *show in results)
[self fetchMetaDataForShow:show]; [self fetchMetaDataForShow:show];
}]; }];
...@@ -1009,6 +1048,10 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -1009,6 +1048,10 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
{ {
BOOL success = YES; BOOL success = YES;
NSPersistentStoreCoordinator *coordinater = [self persistentStoreCoordinator]; NSPersistentStoreCoordinator *coordinater = [self persistentStoreCoordinator];
if (!coordinater) {
APLog(@"no persistenz store coordinator found, migration will fail");
return NO;
}
NSURL *oldStoreURL = self.persistentStoreURL; NSURL *oldStoreURL = self.persistentStoreURL;
NSPersistentStore *oldStore = [coordinater persistentStoreForURL:oldStoreURL]; NSPersistentStore *oldStore = [coordinater persistentStoreForURL:oldStoreURL];
NSString *oldThumbnailPath = self.thumbnailFolderPath; NSString *oldThumbnailPath = self.thumbnailFolderPath;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Lunettes * Lunettes
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Pierre d'Herbemont * Copyright (C) 2010 Pierre d'Herbemont
* Copyright (C) 2010-2013 VLC authors and VideoLAN * Copyright (C) 2010-2015 VLC authors and VideoLAN
* $Id$ * $Id$
* *
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org> * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
{ {
NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext]; NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
if (!moc || moc.persistentStoreCoordinator == nil)
return [NSArray array];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Show" inManagedObjectContext:moc]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Show" inManagedObjectContext:moc];
[request setEntity:entity]; [request setEntity:entity];
...@@ -50,7 +52,11 @@ ...@@ -50,7 +52,11 @@
NSFetchRequest *request = [[MLMediaLibrary sharedMediaLibrary] fetchRequestForEntity:@"Show"]; NSFetchRequest *request = [[MLMediaLibrary sharedMediaLibrary] fetchRequestForEntity:@"Show"];
[request setPredicate:[NSPredicate predicateWithFormat:@"name == %@", name]]; [request setPredicate:[NSPredicate predicateWithFormat:@"name == %@", name]];
NSArray *dbResults = [[[MLMediaLibrary sharedMediaLibrary] managedObjectContext] executeFetchRequest:request error:nil]; NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
if (!moc)
return nil;
NSArray *dbResults = [moc executeFetchRequest:request error:nil];
NSAssert(dbResults, @"Can't execute fetch request"); NSAssert(dbResults, @"Can't execute fetch request");
if ([dbResults count] <= 0) if ([dbResults count] <= 0)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Lunettes * Lunettes
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Pierre d'Herbemont * Copyright (C) 2010 Pierre d'Herbemont
* Copyright (C) 2010-2013 VLC authors and VideoLAN * Copyright (C) 2010-2015 VLC authors and VideoLAN
* $Id$ * $Id$
* *
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org> * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
{ {
NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext]; NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
if (!moc || moc.persistentStoreCoordinator == nil)
return [NSArray array];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"ShowEpisode" inManagedObjectContext:moc]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"ShowEpisode" inManagedObjectContext:moc];
[request setEntity:entity]; [request setEntity:entity];
...@@ -106,8 +108,11 @@ ...@@ -106,8 +108,11 @@
[self willChangeValueForKey:@"unread"]; [self willChangeValueForKey:@"unread"];
[self setPrimitiveUnread:unread]; [self setPrimitiveUnread:unread];
[self didChangeValueForKey:@"unread"]; [self didChangeValueForKey:@"unread"];
[[[MLMediaLibrary sharedMediaLibrary] managedObjectContext] refreshObject:[self show] mergeChanges:YES]; NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
[[[MLMediaLibrary sharedMediaLibrary] managedObjectContext] refreshObject:self mergeChanges:YES]; if (!moc)
return;
[moc refreshObject:[self show] mergeChanges:YES];
[moc refreshObject:self mergeChanges:YES];
} }
@dynamic theTVDBID; @dynamic theTVDBID;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment