Skip to content

Commit

Permalink
Merge commit '550bbea1fdbe9ee7eb9b7efd84c39cbbd43c6a3f'
Browse files Browse the repository at this point in the history
* commit '550bbea1fdbe9ee7eb9b7efd84c39cbbd43c6a3f':
  Fix issue karelia#92, Loading of "Albums" node of Photos media library takes very long on large libraries
  Give user guidance on what to do when Lightroom catalog version and Lightroom version are out of step
  Always defer check for database version until root node population is imminent
  Eliminate warning about unimplemented method
  Defer Lightroom database version check
  Mitigate karelia#90, Accessing the root node of a Photos library for the first time within an app session takes very long for large libraries
  Fix karelia#89, Lightroom library not always accessible when running sandboxed
  • Loading branch information
danielpunkass committed May 19, 2017
2 parents f17371b + 550bbea commit d1f5b39
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 69 deletions.
9 changes: 9 additions & 0 deletions IMBAppleMediaLibraryParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,17 @@ - (BOOL)hiddenMediaObject:(MLMediaObject *)mediaObject
return [((NSNumber *)mediaObject.attributes[@"Hidden"]) boolValue];
}

/**
Returns an identifier for the IMBObject that is valid across app sessions.
Returns nil for IMBNodeObjects since computation of the identifier for those is potentially expensive and
node objects are not provided to the client app anyhow.
*/
- (NSString *)persistentResourceIdentifierForObject:(IMBObject *)inObject
{
if ([inObject isKindOfClass:[IMBNodeObject class]]) {
return nil;
}
return [[self mediaObjectForObject:inObject].URL absoluteString];
}

Expand Down
4 changes: 2 additions & 2 deletions IMBLightroom2Parser.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ + (NSArray*) concreteParserInstancesForMediaType:(NSString*)inMediaType
// This method creates the immediate subnodes of the "Lightroom" root node. The two subnodes are "Folders"
// and "Collections"...

- (void) populateSubnodesForRootNode:(IMBNode*)inRootNode
- (void) populateSubnodesForRootNode:(IMBNode*)inRootNode error:(NSError**)outError
{
NSMutableArray* subnodes = [inRootNode mutableArrayForPopulatingSubnodes];
NSMutableArray* objects = [NSMutableArray array];
Expand Down Expand Up @@ -171,7 +171,7 @@ - (void) populateSubnodesForRootNode:(IMBNode*)inRootNode

// Add the Collections node...

[super populateSubnodesForRootNode:inRootNode];
[super populateSubnodesForRootNode:inRootNode error:outError];
}


Expand Down
8 changes: 6 additions & 2 deletions IMBLightroom3Parser.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ + (NSString*) lightroomAppBundleIdentifier
return @"com.adobe.Lightroom3";
}

+ (NSString *)lightroomAppVersion
{
return @"3";
}

//----------------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -197,8 +201,8 @@ - (BOOL) checkDatabaseVersion
else if (databaseVersionLong >= 400000) {
return NO;
}

return YES;
return YES;
}

return NO;
Expand Down
8 changes: 6 additions & 2 deletions IMBLightroom4Parser.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ + (NSString*) lightroomAppBundleIdentifier
return @"com.adobe.Lightroom4";
}

+ (NSString *)lightroomAppVersion
{
return @"4";
}

//----------------------------------------------------------------------------------------------------------------------

Expand All @@ -122,8 +126,8 @@ - (BOOL) checkDatabaseVersion
else if (databaseVersionLong >= 500000) {
return NO;
}
return YES;
return YES;
}

return NO;
Expand Down
9 changes: 7 additions & 2 deletions IMBLightroom5Parser.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ + (NSString *)lightroomAppBundleIdentifier
return @"com.adobe.Lightroom5";
}

+ (NSString *)lightroomAppVersion
{
return @"5";
}

// ----------------------------------------------------------------------------------------------------------------------


Expand All @@ -126,8 +131,8 @@ - (BOOL)checkDatabaseVersion
else if (databaseVersionLong >= 600000) {
return NO;
}

return YES;
return YES;
}

return NO;
Expand Down
10 changes: 7 additions & 3 deletions IMBLightroom6Parser.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ + (NSString *)lightroomAppBundleIdentifier
return @"com.adobe.Lightroom6";
}

// ----------------------------------------------------------------------------------------------------------------------
+ (NSString *)lightroomAppVersion
{
return @"6";
}

// ----------------------------------------------------------------------------------------------------------------------

- (BOOL)checkDatabaseVersion
{
Expand All @@ -126,8 +130,8 @@ - (BOOL)checkDatabaseVersion
else if (databaseVersionLong >= 700000) {
return NO;
}

return YES;
return YES;
}

return NO;
Expand Down
2 changes: 2 additions & 0 deletions IMBLightroomModernParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@

}

+ (NSString *)lightroomAppVersion;

- (NSNumber*) databaseVersion;

+ (NSData*) previewDataForLightroomObject:(IMBLightroomObject*)lightroomObject maximumSize:(NSNumber*)maximumSize;
Expand Down
66 changes: 49 additions & 17 deletions IMBLightroomModernParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "NSObject+iMedia.h"
#import "NSFileManager+iMedia.h"
#import "NSImage+iMedia.h"
#import "NSURL+iMedia.h"
#import "NSWorkspace+iMedia.h"
#import "SBUtilities.h"
#import <Quartz/Quartz.h>
Expand Down Expand Up @@ -92,11 +93,16 @@ @implementation IMBLightroomModernParser
//----------------------------------------------------------------------------------------------------------------------


+ (NSString *)lightroomAppVersion
{
[self imb_throwAbstractBaseClassExceptionForSelector:_cmd];
}

// Unique identifier for this parser...

+ (NSString*) identifier
{
[[self class] imb_throwAbstractBaseClassExceptionForSelector:_cmd];
[self imb_throwAbstractBaseClassExceptionForSelector:_cmd];

return nil;
}
Expand Down Expand Up @@ -126,21 +132,22 @@ + (NSArray*) concreteParserInstancesForMediaType:(NSString*)inMediaType
if ([self lightroomPath] != nil) {
NSArray* libraryPaths = [self libraryPaths];

for (NSString* libraryPath in libraryPaths) {
IMBLightroomModernParser* parser = [[[[self class] alloc] init] autorelease];
parser.identifier = [NSString stringWithFormat:@"%@:/%@",[[self class] identifier],libraryPath];
parser.mediaSource = [NSURL fileURLWithPath:libraryPath];
parser.mediaType = inMediaType;
parser.shouldDisplayLibraryName = libraryPaths.count > 1;

if (! [parser checkDatabaseVersion]) {
continue;
}

[parserInstances addObject:parser];
}
}

for (NSString* libraryPath in libraryPaths) {
NSURL *libraryPathURL = [NSURL fileURLWithPath:libraryPath];
IMBResourceAccessibility libraryAccessibility = [libraryPathURL imb_accessibility];

if (libraryAccessibility != kIMBResourceDoesNotExist) {
IMBLightroomModernParser* parser = [[[[self class] alloc] init] autorelease];
parser.identifier = [NSString stringWithFormat:@"%@:/%@",[[self class] identifier],libraryPath];
parser.mediaSource = libraryPathURL;
parser.mediaType = inMediaType;
parser.shouldDisplayLibraryName = libraryPaths.count > 1;

[parserInstances addObject:parser];
}
}
}

return parserInstances;
}

Expand Down Expand Up @@ -180,8 +187,33 @@ - (NSNumber*) databaseVersion
// This method creates the immediate subnodes of the "Lightroom" root node. The two subnodes are "Folders"
// and "Collections"...

- (void) populateSubnodesForRootNode:(IMBNode*)inRootNode
- (void) populateSubnodesForRootNode:(IMBNode*)inRootNode error:(NSError**)outError
{
if (! [self checkDatabaseVersion]) {
if (outError != NULL) {
NSString *lightroomVersion = [[self class] lightroomAppVersion];
NSString *localizedErrorDescriptionFormat = NSLocalizedStringWithDefaultValue(
@"IMBLightroomParser.IncompatibleCatalogVersion",
nil, IMBBundle(),
@"Catalog %@ is associated with Lightroom version %@ but has an incompatible version.\n\nYou may want to try to open it with Lightroom %@ first to update it. If successful please re-start the application.",
@"Warning when Lightroom database version check fails");
NSString *localizedErrorDescription = [NSString stringWithFormat:localizedErrorDescriptionFormat, [self.mediaSource path], lightroomVersion, lightroomVersion];

NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
localizedErrorDescription, NSLocalizedDescriptionKey, nil];

*outError = [NSError errorWithDomain:kIMBErrorDomain code:1 userInfo:userInfo];
}

// Use empty array for subnodes and objects. This prevents further attempts at populating the node
[inRootNode mutableArrayForPopulatingSubnodes];
inRootNode.objects = [NSArray array];

//inRootNode.accessibility = kIMBResourceDoesNotExist;

return;
}

NSMutableArray* subnodes = [inRootNode mutableArrayForPopulatingSubnodes];
NSMutableArray* objects = [NSMutableArray array];
inRootNode.displayedObjectCount = 0;
Expand Down
2 changes: 1 addition & 1 deletion IMBLightroomParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ IMBLightroomNodeType;

@interface IMBLightroomParser (Subclassers)

- (void) populateSubnodesForRootNode:(IMBNode*)inRootNode;
- (void) populateSubnodesForRootNode:(IMBNode*)inRootNode error:(NSError**)outError;
- (void) populateSubnodesForRootFoldersNode:(IMBNode*)inFoldersNode;
- (void) populateSubnodesForFolderNode:(IMBNode*)inParentNode;
- (void) populateSubnodesForCollectionNode:(IMBNode*)inRootNode;
Expand Down
6 changes: 3 additions & 3 deletions IMBLightroomParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ - (BOOL) populateNode:(IMBNode*)inNode error:(NSError**)outError
// Create subnodes for the root node as needed...

if ([inNode isTopLevelNode])
{
[self populateSubnodesForRootNode:inNode];
{
[self populateSubnodesForRootNode:inNode error:outError];
}
else {
NSDictionary* attributes = inNode.attributes;
Expand Down Expand Up @@ -689,7 +689,7 @@ - (NSData*) bookmarkForObject:(IMBObject*)inObject error:(NSError**)outError
// This method creates the immediate subnodes of the "Lightroom" root node. The two subnodes are "Folders"
// and "Collections"...

- (void) populateSubnodesForRootNode:(IMBNode*)inRootNode
- (void) populateSubnodesForRootNode:(IMBNode*)inRootNode error:(NSError**)outError
{
[self populateSubnodesForCollectionNode:inRootNode];
}
Expand Down
Loading

0 comments on commit d1f5b39

Please sign in to comment.