Jelajahi Sumber

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 tahun lalu
induk
melakukan
4bb4d28888
1 mengubah file dengan 17 tambahan dan 5 penghapusan
  1. 17 5
      Sources/VLCAppDelegate.m

+ 17 - 5
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];