Skip to content

Commit

Permalink
Add more debug actions to inspect / clean database. It seems that aut…
Browse files Browse the repository at this point in the history
…omatic artwork download creates useless image objects.
  • Loading branch information
cyco committed Jan 4, 2016
1 parent 9d2a0a8 commit fbad88e
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion OpenEmu/OEPrefDebugController.m
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ - (void)OE_setupKeyDescription
Button(@"Cancel OpenVGDB Update", @selector(cancelOpenVGDBUpdate:)),

Group(@"Database Actions"),
Button(@"Delete useless image objects", @selector(removeUselessImages:)),
Button(@"Delete Artwork that can be downloaded", @selector(removeArtworkWithRemoteBacking:)),
Button(@"Sync games without artwork", @selector(syncGamesWithoutArtwork:)),
Button(@"Download missing artwork", @selector(downloadMissingArtwork:)),
Button(@"Remove untracked artwork files", @selector(removeUntrackedImageFiles:)),
Button(@"Cleanup rom hashes", @selector(cleanupHashes:)),
Expand Down Expand Up @@ -443,6 +445,28 @@ - (void)cancelOpenVGDBUpdate:(id)sender
}

#pragma mark - Database actions
- (void)removeUselessImages:(id)sender
{
// removes all image objects that are neither on disc nor have a source
OELibraryDatabase *library = [OELibraryDatabase defaultDatabase];
NSManagedObjectContext *context = [library mainThreadContext];
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:[OEDBImage entityName]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"relativePath == nil and source == nil"];
[request setPredicate:predicate];

NSError *error = nil;
NSArray *result = [context executeFetchRequest:request error:&error];
if(!result)
{
DLog(@"Could not execute fetch request: %@", error);
return;
}

[result makeObjectsPerformSelector:@selector(delete)];
[context save:nil];
NSLog(@"Deleted %ld images!", result.count);
}

- (void)removeArtworkWithRemoteBacking:(id)sender
{
OELibraryDatabase *library = [OELibraryDatabase defaultDatabase];
Expand Down Expand Up @@ -476,6 +500,28 @@ - (void)removeArtworkWithRemoteBacking:(id)sender
NSLog(@"Deleted %ld image files!", count);
}

- (void)syncGamesWithoutArtwork:(id)sender
{
OELibraryDatabase *library = [OELibraryDatabase defaultDatabase];
NSManagedObjectContext *context = [library mainThreadContext];
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:[OEDBGame entityName]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"boxImage == nil"];
[request setPredicate:predicate];
NSError *error = nil;
NSArray *result = [context executeFetchRequest:request error:&error];
if(!result)
{
DLog(@"Could not execute fetch request: %@", error);
return;
}

NSLog(@"Found %ld games", [result count]);
for(OEDBGame *game in result){
[game requestInfoSync];
}
}


- (void)downloadMissingArtwork:(id)sender
{
OEHUDAlert *alert = [OEHUDAlert alertWithMessageText:NSLocalizedString(@"While performing this operation OpenEmu will be unresponsive.","")
Expand Down Expand Up @@ -684,7 +730,22 @@ - (IBAction)sanityCheck:(id)sender
}
if(counts[0]) NSLog(@"Found %ld images without game!", counts[0]);


// Look for images without source
allImages = [OEDBImage allObjectsInContext:context];
counts[0] = 0;
counts[1] = 0;
for(OEDBImage *image in allImages)
{
if(image.source == nil || [image.source isEqualToString:@""])
counts[0] ++;
if(image.relativePath == nil || [image.relativePath isEqualToString:@""])
counts[1] ++;
if(image.image == nil)
counts[2] ++;
}
if(counts[0]) NSLog(@"Found %ld images without source!", counts[0]);
if(counts[1]) NSLog(@"Found %ld images without local path!", counts[1]);

NSLog(@"= Done =");
}
#pragma mark -
Expand Down

0 comments on commit fbad88e

Please sign in to comment.