Commit 4bb4d288 authored by Tobias's avatar Tobias Committed by Felix Paul Kühne

Simple support for adding files in (sub)directories after copying via iTunes. Fixes No 2 of #9158.

The hierarchy is folder hierarchy is ignored and all files are added to a flat file list.
A more advanced fix would add labels to files in subdirectories of the documents folder, which should be done in MediaLibraryKit.
Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent dc6b8093
......@@ -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];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment