瀏覽代碼

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 <fkuehne@videolan.org>
Tobias Conradi 10 年之前
父節點
當前提交
4bb4d28888
共有 1 個文件被更改,包括 17 次插入5 次删除
  1. 17 5
      Sources/VLCAppDelegate.m

+ 17 - 5
Sources/VLCAppDelegate.m

@@ -278,16 +278,28 @@
 - (void)updateMediaList
 - (void)updateMediaList
 {
 {
     NSString *directoryPath = [self directoryPath];
     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;
     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]) {
         if ([fileName isSupportedMediaFormat] || [fileName isSupportedAudioMediaFormat]) {
-            [filePaths addObject:[directoryPath stringByAppendingPathComponent:fileName]];
+            [filePaths addObject:filePath];
 
 
             /* exclude media files from backup (QA1719) */
             /* exclude media files from backup (QA1719) */
-            fileURL = [NSURL fileURLWithPath:[directoryPath stringByAppendingPathComponent:fileName]];
+            fileURL = [NSURL fileURLWithPath:filePath];
             [fileURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
             [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];
     [[MLMediaLibrary sharedMediaLibrary] addFilePaths:filePaths];