浏览代码

file discoverer: add property so we can force it to reveal everything it found

Felix Paul Kühne 9 年之前
父节点
当前提交
0d93650a82
共有 3 个文件被更改,包括 63 次插入47 次删除
  1. 1 0
      Sources/VLCMediaFileDiscoverer.h
  2. 60 46
      Sources/VLCMediaFileDiscoverer.m
  3. 2 1
      VLC for iOS.xcodeproj/project.pbxproj

+ 1 - 0
Sources/VLCMediaFileDiscoverer.h

@@ -33,6 +33,7 @@
  * \note _MUST_ be set before starting the discovery
  */
 @property (readwrite, retain, nonatomic) NSString *directoryPath;
+@property (readwrite, nonatomic) BOOL filterResultsForPlayability;
 
 - (void)addObserver:(id<VLCMediaFileDiscovererDelegate>)delegate;
 - (void)removeObserver:(id<VLCMediaFileDiscovererDelegate>)delegate;

+ 60 - 46
Sources/VLCMediaFileDiscoverer.m

@@ -46,6 +46,7 @@ const float MediaTimerInterval = 2.f;
     static VLCMediaFileDiscoverer *instance;
     dispatch_once(&onceToken, ^{
         instance = [VLCMediaFileDiscoverer new];
+        instance.filterResultsForPlayability = YES;
     });
 
     return instance;
@@ -162,32 +163,37 @@ const float MediaTimerInterval = 2.f;
         NSMutableArray *addedFiles = [NSMutableArray arrayWithArray:[foundFiles filteredArrayUsingPredicate:filterPredicate]];
 
         for (NSString *fileName in addedFiles) {
-            if ([fileName isSupportedMediaFormat] || [fileName isSupportedAudioMediaFormat]) {
-                [_addedFilesMapping setObject:@(0) forKey:fileName];
-                [self notifyFileAdded:fileName loading:YES];
-            } else {
-                BOOL isDirectory = NO;
-                NSString *directoryPath = [self directoryPath];
-                NSString *filePath = [directoryPath stringByAppendingPathComponent:fileName];
-                BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:filePath isDirectory:&isDirectory];
+            BOOL isDirectory = NO;
+            NSString *directoryPath = [self directoryPath];
+            NSString *filePath = [directoryPath stringByAppendingPathComponent:fileName];
+            BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:filePath isDirectory:&isDirectory];
 
+            if (exists && !isDirectory) {
+                if (self.filterResultsForPlayability) {
+                    if ([fileName isSupportedMediaFormat] || [fileName isSupportedAudioMediaFormat]) {
+                        [_addedFilesMapping setObject:@(0) forKey:fileName];
+                        [self notifyFileAdded:fileName loading:YES];
+                    }
+                } else {
+                    [_addedFilesMapping setObject:@(0) forKey:fileName];
+                    [self notifyFileAdded:fileName loading:YES];
+                }
+            } else if (exists && isDirectory) {
                 // add folders
-                if (exists && isDirectory) {
-                    NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filePath error:nil];
-                    for (NSString* file in files) {
-                        NSString *fullFilePath = [directoryPath stringByAppendingPathComponent:file];
-                        isDirectory = NO;
-                        exists = [[NSFileManager defaultManager] fileExistsAtPath:fullFilePath isDirectory:&isDirectory];
-                        //only add folders or files in folders
-                        if ((exists && isDirectory) || ![filePath.lastPathComponent isEqualToString:@"Documents"]) {
-                            NSString *folderpath = [filePath stringByReplacingOccurrencesOfString:directoryPath withString:@""];
-                            if (![folderpath isEqualToString:@""]) {
-                                folderpath = [folderpath stringByAppendingString:@"/"];
-                            }
-                            NSString *path = [folderpath stringByAppendingString:file];
-                            [_addedFilesMapping setObject:@(0) forKey:path];
-                            [self notifyFileAdded:path loading:YES];
+                NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filePath error:nil];
+                for (NSString* file in files) {
+                    NSString *fullFilePath = [directoryPath stringByAppendingPathComponent:file];
+                    isDirectory = NO;
+                    exists = [[NSFileManager defaultManager] fileExistsAtPath:fullFilePath isDirectory:&isDirectory];
+                    //only add folders or files in folders
+                    if ((exists && isDirectory) || ![filePath.lastPathComponent isEqualToString:@"Documents"]) {
+                        NSString *folderpath = [filePath stringByReplacingOccurrencesOfString:directoryPath withString:@""];
+                        if (![folderpath isEqualToString:@""]) {
+                            folderpath = [folderpath stringByAppendingString:@"/"];
                         }
+                        NSString *path = [folderpath stringByAppendingString:file];
+                        [_addedFilesMapping setObject:@(0) forKey:path];
+                        [self notifyFileAdded:path loading:YES];
                     }
                 }
             }
@@ -195,7 +201,7 @@ const float MediaTimerInterval = 2.f;
 
         if (![_addMediaTimer isValid]) {
             _addMediaTimer = [NSTimer scheduledTimerWithTimeInterval:MediaTimerInterval
-                                          target:self selector:@selector(addFileTimerFired)
+                                                              target:self selector:@selector(addFileTimerFired)
                                                             userInfo:nil repeats:YES];
         }
     }
@@ -262,32 +268,40 @@ const float MediaTimerInterval = 2.f;
         NSString *filePath = [directoryPath stringByAppendingPathComponent:fileName];
         [foundFiles removeObject:fileName];
 
-        if ([fileName isSupportedMediaFormat] || [fileName isSupportedAudioMediaFormat]) {
-            [filePaths addObject:filePath];
+        BOOL isDirectory = NO;
+        BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:filePath isDirectory:&isDirectory];
 
-            /* exclude media files from backup (QA1719) */
-            fileURL = [NSURL fileURLWithPath:filePath];
-            [fileURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
-        } else {
-            BOOL isDirectory = NO;
-            BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:filePath isDirectory:&isDirectory];
+        if (exists && !isDirectory) {
+            if (self.filterResultsForPlayability) {
+                if ([fileName isSupportedMediaFormat] || [fileName isSupportedAudioMediaFormat]) {
+                    [filePaths addObject:filePath];
 
+                    /* exclude media files from backup (QA1719) */
+                    fileURL = [NSURL fileURLWithPath:filePath];
+                    [fileURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
+                }
+            } else {
+                [filePaths addObject:filePath];
+
+                /* exclude media files from backup (QA1719) */
+                fileURL = [NSURL fileURLWithPath:filePath];
+                [fileURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
+            }
+        } else if (exists && isDirectory) {
             // add folders
-            if (exists && isDirectory) {
-                NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filePath error:nil];
-                for (NSString* file in files) {
-                    NSString *fullFilePath = [directoryPath stringByAppendingPathComponent:file];
-                    isDirectory = NO;
-                    exists = [[NSFileManager defaultManager] fileExistsAtPath:fullFilePath isDirectory:&isDirectory];
-                    //only add folders or files in folders
-                    if ((exists && isDirectory) || ![filePath.lastPathComponent isEqualToString:@"Documents"]) {
-                        NSString *folderpath = [filePath stringByReplacingOccurrencesOfString:directoryPath withString:@""];
-                        if (![folderpath isEqualToString:@""]) {
-                            folderpath = [folderpath stringByAppendingString:@"/"];
-                        }
-                        NSString *path = [folderpath stringByAppendingString:file];
-                        [foundFiles addObject:path];
+            NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filePath error:nil];
+            for (NSString* file in files) {
+                NSString *fullFilePath = [directoryPath stringByAppendingPathComponent:file];
+                isDirectory = NO;
+                exists = [[NSFileManager defaultManager] fileExistsAtPath:fullFilePath isDirectory:&isDirectory];
+                //only add folders or files in folders
+                if ((exists && isDirectory) || ![filePath.lastPathComponent isEqualToString:@"Documents"]) {
+                    NSString *folderpath = [filePath stringByReplacingOccurrencesOfString:directoryPath withString:@""];
+                    if (![folderpath isEqualToString:@""]) {
+                        folderpath = [folderpath stringByAppendingString:@"/"];
                     }
+                    NSString *path = [folderpath stringByAppendingString:file];
+                    [foundFiles addObject:path];
                 }
             }
         }

+ 2 - 1
VLC for iOS.xcodeproj/project.pbxproj

@@ -1703,7 +1703,6 @@
 				7DF383B41BF20E4600D71A5C /* Network dialogs */,
 				DD2789DF1B67A79700CED769 /* WatchSupport */,
 				7DBB788E1B305D8300894467 /* Keychain & random singletons */,
-				A7D03A4817A4249F0022C16F /* MediaDiscovering */,
 				7D2339AB176DE70E008D223C /* Menu */,
 				7D31002117B676D500E6516D /* Local Network Connectivity */,
 				7D5F7AB9175265B2006CCCFA /* Playback */,
@@ -2109,6 +2108,7 @@
 				7D30F3CF183AB2AC00FFC021 /* VLCMediaFileDiscoverer.m */,
 			);
 			name = MediaDiscovering;
+			path = ../AspenProject;
 			sourceTree = "<group>";
 		};
 		CC1BBC441704936500A20CBF /* External VLC Libraries */ = {
@@ -2311,6 +2311,7 @@
 		DD7110ED1AF38AFD00854776 /* SharedSources */ = {
 			isa = PBXGroup;
 			children = (
+				A7D03A4817A4249F0022C16F /* MediaDiscovering */,
 				7D5F7ABA175265CB006CCCFA /* HTTP Connectivity */,
 				7D4DFEA81BDF982400979881 /* Cloud Integration */,
 				7DEC8BE21BD6880C006E1093 /* UI Elements */,