NSFileManager *fm;
NSEnumerator *e;
NSString *path;
+
+ if (debugOn) {
+ NSLog(@"BM LOOKUP pathes (%d bundles loaded): %@ / %@",
+ NSCountMapTable(self->loadedBundles), _resourceName, _type);
+ }
fm = [NSFileManager defaultManager];
result = [NSMutableArray arrayWithCapacity:64];
+ // TODO: look in loaded bundles
+
+ /* check physical pathes */
+
e = [self->bundleSearchPaths objectEnumerator];
- while ((path = [e nextObject])) {
- BOOL isDir = NO;
+ while ((path = [e nextObject]) != nil) {
+ NSEnumerator *dir;
+ BOOL isDir = NO;
+ NSString *tmp, *bundleDirPath;
+ id info = nil;
- if ([fm fileExistsAtPath:path isDirectory:&isDir]) {
- NSString *tmp;
- id info = nil;
- if (!isDir) continue;
-
- /* check whether an appropriate bundle is contained in 'path' */
- {
- NSEnumerator *dir;
-
- dir = [[fm directoryContentsAtPath:path] objectEnumerator];
- while ((tmp = [dir nextObject])) {
- NSDictionary *bundleInfo = nil;
- NSEnumerator *providedResources = nil;
- NSString *infoPath;
- id info;
+ if (![fm fileExistsAtPath:path isDirectory:&isDir])
+ continue;
+
+ if (!isDir) continue;
+
+ /* check whether an appropriate bundle is contained in 'path' */
+
+ dir = [[fm directoryContentsAtPath:path] objectEnumerator];
+ while ((bundleDirPath = [dir nextObject]) != nil) {
+ NSDictionary *bundleInfo = nil;
+ NSEnumerator *providedResources = nil;
+ NSString *infoPath;
+ id info;
- tmp = [path stringByAppendingPathComponent:tmp];
- infoPath = [self makeBundleInfoPath:tmp];
-
- if ((bundleInfo = NSMapGet(self->pathToBundleInfo, infoPath)) == nil) {
- if (![fm fileExistsAtPath:infoPath])
- continue;
-
- bundleInfo = [self _loadBundleInfoAtExistingPath:infoPath];
- }
-
- providedResources =
- [[(NSDictionary *)[bundleInfo objectForKey:@"provides"]
- objectForKey:_type]
- objectEnumerator];
- if (providedResources == nil) continue;
+ bundleDirPath = [path stringByAppendingPathComponent:bundleDirPath];
+ infoPath = [self makeBundleInfoPath:bundleDirPath];
+
+ // TODO: can we use _doesBundleInfo:path:providedResource:... ?
+ if ((bundleInfo = NSMapGet(self->pathToBundleInfo, infoPath))==nil) {
+ if (![fm fileExistsAtPath:infoPath])
+ continue;
- // scan provide array
- while ((info = [providedResources nextObject])) {
- NSString *name;
+ bundleInfo = [self _loadBundleInfoAtExistingPath:infoPath];
+ }
+
+ providedResources =
+ [[(NSDictionary *)[bundleInfo objectForKey:@"provides"]
+ objectForKey:_type]
+ objectEnumerator];
+ if (providedResources == nil) continue;
+
+ /* scan 'provides' array */
+ while ((info = [providedResources nextObject])) {
+ NSString *name;
- name = [[(NSDictionary *)info objectForKey:@"name"] stringValue];
- if (name == nil) continue;
-
- if (_resourceName) {
- if (![name isEqualToString:_resourceName])
- continue;
- }
- if (_selector) {
- if (!_selector(name, _type, tmp, info, self, _context))
- continue;
- }
-
- [result addObject:tmp];
- break;
- }
- }
+ name = [[(NSDictionary *)info objectForKey:@"name"] stringValue];
+ if (name == nil) continue;
+
+ if (_resourceName != nil) {
+ if (![name isEqualToString:_resourceName])
+ continue;
+ }
+ if (_selector != NULL) {
+ if (!_selector(name, _type, bundleDirPath, info, self, _context))
+ continue;
+ }
+
+ [result addObject:bundleDirPath];
+ break;
}
+ }
+
+ /* check for direct match (NGBundlePath element is a bundle) */
+
+ tmp = [self makeBundleInfoPath:path];
- /* check for direct match */
-
- tmp = [self makeBundleInfoPath:path];
-
- if ((info = NSMapGet(self->pathToBundleInfo, tmp)) == nil) {
- if ([fm fileExistsAtPath:tmp])
- info = [self _loadBundleInfoAtExistingPath:tmp];
- }
-
- [self _processInfoForProvidedResources:info ofType:_type path:path
- resourceName:_resourceName resourceSelector:_selector
- context:_context
- andAddToResultArray:result];
+ if ((info = NSMapGet(self->pathToBundleInfo, tmp)) == nil) {
+ if ([fm fileExistsAtPath:tmp])
+ info = [self _loadBundleInfoAtExistingPath:tmp];
}
+
+ [self _processInfoForProvidedResources:info ofType:_type path:path
+ resourceName:_resourceName resourceSelector:_selector
+ context:_context
+ andAddToResultArray:result];
}
+
+ if ([result count] == 0) {
+ [self logWithFormat:
+ @"Note(%s): method does not search in loaded bundles for "
+ @"resources of type '%@'",
+ __PRETTY_FUNCTION__, _type];
+ }
+
return [[result copy] autorelease];
}
- (NSString *)description {
char buffer[1024];
-
+
sprintf (buffer,
"<%s %p fullPath: %s infoDictionary: %p loaded=%s>",
(char*)object_get_class_name(self),