Skip to content

Instantly share code, notes, and snippets.

@toco
Last active August 29, 2015 14:06
Show Gist options
  • Save toco/cea5112e0343f84eeae4 to your computer and use it in GitHub Desktop.
Save toco/cea5112e0343f84eeae4 to your computer and use it in GitHub Desktop.
Add support for directories when scanning documents directory.
diff --git a/Sources/VLCAppDelegate.m b/Sources/VLCAppDelegate.m
index ef5f12f..e80422b 100644
--- a/Sources/VLCAppDelegate.m
+++ b/Sources/VLCAppDelegate.m
@@ -278,16 +278,28 @@
- (void)updateMediaList
{
NSString *directoryPath = [self directoryPath];
- NSArray *foundFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:nil];
- NSMutableArray *filePaths = [NSMutableArray arrayWithCapacity:[foundFiles count]];
+ NSMutableArray *foundFiles = [NSMutableArray arrayWithObject:@""];
+ NSMutableArray *filePaths = [NSMutableArray array];
NSURL *fileURL;
- for (NSString *fileName in foundFiles) {
+ while (foundFiles.count) {
+ NSString *fileName = foundFiles.firstObject;
+ NSString *filePath = [directoryPath stringByAppendingPathComponent:fileName];
+ [foundFiles removeObject:fileName];
+
if ([fileName isSupportedMediaFormat] || [fileName isSupportedAudioMediaFormat]) {
- [filePaths addObject:[directoryPath stringByAppendingPathComponent:fileName]];
+ [filePaths addObject:filePath];
/* exclude media files from backup (QA1719) */
- fileURL = [NSURL fileURLWithPath:[directoryPath stringByAppendingPathComponent:fileName]];
+ fileURL = [NSURL fileURLWithPath:filePath];
[fileURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
+ } else {
+
+ BOOL isDirectory = NO;
+ BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:filePath isDirectory:&isDirectory];
+ // add folders
+ if (exists && isDirectory) {
+ [foundFiles addObjectsFromArray:[[NSFileManager defaultManager] contentsOfDirectoryAtPath:filePath error:nil]];
+ }
}
}
[[MLMediaLibrary sharedMediaLibrary] addFilePaths:filePaths];
@toco
Copy link
Author

toco commented Sep 16, 2014

I don't see any recents change in MediaLibraryKit regarding file path handling.
This patch works with http://git.videolan.org/?p=MediaLibraryKit.git;a=commit;h=eb2587e0c2220ce6766762e4599f3ddbfe86996b.
I've sent a full patch to Caro for testing and pushing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment