@@ -468,6 +468,68 @@ -(NSString*) fullPathFromRelativePathIgnoringResolutions:(NSString*)relPath
468
468
return ret;
469
469
}
470
470
471
+ - (NSArray *)fullPathsOfFileNameInAllSearchPaths : (NSString *)filename
472
+ {
473
+ NSMutableArray *result = [NSMutableArray array ];
474
+
475
+ for (NSString *path in self.searchPath )
476
+ {
477
+ NSString *aPath = [path stringByAppendingPathComponent: filename];
478
+ NSFileManager *fileManager = [NSFileManager defaultManager ];
479
+
480
+ if ([fileManager fileExistsAtPath: aPath])
481
+ {
482
+ [result addObject: aPath];
483
+ continue ;
484
+ }
485
+
486
+ NSString *file = [aPath lastPathComponent ];
487
+ NSString *file_path = [aPath stringByDeletingLastPathComponent ];
488
+ // Default to normal resource directory
489
+ NSString *foundPath = [[NSBundle mainBundle ] pathForResource: file
490
+ ofType: nil
491
+ inDirectory: file_path];
492
+ if (foundPath)
493
+ {
494
+ [result addObject: aPath];
495
+ }
496
+ }
497
+
498
+ return result;
499
+ }
500
+
501
+ - (void )loadAndAddFilenameLookupDictionaryFromFile : (NSString *)filename
502
+ {
503
+ NSString *fullpath = [self fullPathForFilenameIgnoringResolutions: filename];
504
+ if ( fullpath ) {
505
+ NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile: fullpath];
506
+
507
+ NSDictionary *metadata = dict[@" metadata" ];
508
+ NSInteger version = [metadata[@" version" ] integerValue ];
509
+ if ( version != 1 ) {
510
+ CCLOG (@" cocos2d: ERROR: Invalid filenameLookup dictionary version: %ld . Filename: %@ " , (long )version, filename);
511
+ return ;
512
+ }
513
+
514
+ NSDictionary *filenames = dict[@" filenames" ];
515
+ NSMutableDictionary *newFileLookup = [NSMutableDictionary dictionary ];
516
+ [newFileLookup addEntriesFromDictionary: filenames];
517
+ [newFileLookup addEntriesFromDictionary: _filenameLookup];
518
+
519
+ self.filenameLookup = newFileLookup;
520
+ }
521
+ }
522
+
523
+ - (void )loadFileNameLookupsInAllSearchPathsWithName : (NSString *)filename
524
+ {
525
+ NSArray *paths = [self fullPathsOfFileNameInAllSearchPaths: filename];
526
+
527
+ for (NSString *fileLookupFullPath in paths)
528
+ {
529
+ [self loadAndAddFilenameLookupDictionaryFromFile: fileLookupFullPath];
530
+ }
531
+ }
532
+
471
533
-(NSString *) fullPathForFilename : (NSString *)filename
472
534
{
473
535
return [self fullPathForFilename: filename contentScale: NULL ];
0 commit comments