Skip to content

Commit

Permalink
Make sure cover art files are deleted when a game’s box image changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyco committed Dec 30, 2013
1 parent b6dc687 commit ad38c71
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions OpenEmu/OEDBGame.m
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,13 @@ + (NSEntityDescription *)entityDescriptionInContext:(NSManagedObjectContext *)co

- (void)setBoxImageByImage:(NSImage *)img
{
@autoreleasepool
{
NSMutableArray *codePath = [NSMutableArray array];
[[self managedObjectContext] performBlock:^{
if([self boxImage])
{
[[self managedObjectContext] deleteObject:[self boxImage]];
[self setBoxImage:nil];
}

OEDBImage *boxImage = nil;
if(img != nil){
boxImage = [OEDBImage imageWithImage:img inLibrary:[self libraryDatabase]];
Expand All @@ -397,17 +401,22 @@ - (void)setBoxImageByImage:(NSImage *)img
{
NSSize size = NSSizeFromString(aSizeString);
// ...generate thumbnail
[codePath addObject:[NSString stringWithFormat:@"generateThumbnailForSize: %@", NSStringFromSize(size)]];
[boxImage generateThumbnailForSize:size];
}
}
[codePath addObject:[NSString stringWithFormat:@"set boxImage: %@", boxImage]];
[self setBoxImage:boxImage];
}
}];
}

- (void)setBoxImageByURL:(NSURL *)url
{
[[self managedObjectContext] performBlock:^{
if([self boxImage])
{
[[self managedObjectContext] deleteObject:[self boxImage]];
[self setBoxImage:nil];
}

OEDBImage *boxImage = [OEDBImage imageWithURL:url inLibrary:[self libraryDatabase]];

NSUserDefaults *standardDefaults = [NSUserDefaults standardUserDefaults];
Expand All @@ -421,6 +430,7 @@ - (void)setBoxImageByURL:(NSURL *)url
}

[self setBoxImage:boxImage];
}];
}

#pragma mark - NSPasteboardWriting
Expand Down

0 comments on commit ad38c71

Please sign in to comment.