From b04be78f20f7fbccd64d9dcf032d7d9a6a5ebd76 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Mon, 25 Jul 2022 19:35:11 -0700 Subject: [PATCH] [Playlist Loader] Extend deduplication to CUEs CUEs will now deduplicate playlist entries based on their dependencies, and prevent loading redundant tracks if you add an entire directory, or use the option to add a directory when adding single files from it. Signed-off-by: Christopher Snowhill --- Playlist/PlaylistLoader.m | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Playlist/PlaylistLoader.m b/Playlist/PlaylistLoader.m index f7ea25e32..9bfda679e 100644 --- a/Playlist/PlaylistLoader.m +++ b/Playlist/PlaylistLoader.m @@ -342,6 +342,7 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc NSMutableArray *fileURLs = [NSMutableArray array]; NSMutableArray *validURLs = [NSMutableArray array]; NSMutableArray *folderURLs = [NSMutableArray array]; + NSMutableArray *dependencyURLs = [NSMutableArray array]; NSDictionary *xmlData = nil; BOOL addOtherFilesInFolder = [[NSUserDefaults standardUserDefaults] boolForKey:@"addOtherFilesInFolders"]; @@ -423,6 +424,9 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc // Make sure the container isn't added twice. [uniqueURLs addObject:url]; + + // Find the dependencies + NSArray *depURLs = [AudioContainer dependencyUrlsForContainerURL:url]; BOOL localFound = NO; for(NSURL *u in urls) { @@ -431,6 +435,16 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc break; } } + if(depURLs) { + [dependencyURLs addObjectsFromArray:depURLs]; + + for(NSURL *u in depURLs) { + if([u isFileURL]) { + localFound = YES; + break; + } + } + } if(localFound) { [[SandboxBroker sharedSandboxBroker] requestFolderForFile:url]; } @@ -459,6 +473,16 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc // Deduplication of contained URLs [fileURLs removeObjectsInArray:containedURLs]; + [fileURLs removeObjectsInArray:dependencyURLs]; + for(NSURL *u in dependencyURLs) { + for(NSUInteger c = 0; c < [containedURLs count];) { + if([[u path] isEqualToString:[containedURLs[c] path]]) { + [containedURLs removeObjectAtIndex:c]; + } else { + ++c; + } + } + } DLog(@"File urls: %@", fileURLs);