/* Copyright (c) 2006-2007 Christopher J. W. Lloyd 2009 Markus Hitter (mah@jump-ing.de) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #import #import #import #import #import #import #import #import #import #import #import #import #import #import NSString *NSBundleDidLoadNotification=@"NSBundleDidLoadNotification"; NSString *NSLoadedClasses=@"NSLoadedClasses"; @implementation NSBundle static NSMutableArray *_allBundles=nil; static NSMutableArray *_allFrameworks=nil; static NSBundle *mainBundle=nil; static NSMapTable *nameToBundle=NULL; static NSMapTable *pathToObject=NULL; -(void)_setLoaded:(BOOL)loaded { _isLoaded=loaded; } /* Executables support: MyProgram.app/Contents//MyProgram[.exe] or MyProgram[.exe] MyProgram.app/Contents/ */ +(NSString *)bundlePathFromModulePath:(NSString *)path { NSString *result=nil; NSString *directory=[path stringByDeletingLastPathComponent]; NSString *extension=[[path pathExtension] lowercaseString]; NSString *name=[[path lastPathComponent] stringByDeletingPathExtension]; NSRange version=[name rangeOfString:@"."]; if(version.location!=NSNotFound) name=[name substringToIndex:version.location]; if(![extension isEqualToString:NSPlatformLoadableObjectFileExtension]){ NSString *check=[[directory stringByAppendingPathComponent:name] stringByAppendingPathExtension:@"app"]; if([[NSFileManager defaultManager] fileExistsAtPath:check]) result=check; else result=[[directory stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]; } else { NSString *loadablePrefix=NSPlatformLoadableObjectFilePrefix; NSString *check; if([loadablePrefix length]>0 && [name hasPrefix:loadablePrefix]) name=[name substringFromIndex:[loadablePrefix length]]; check=[[directory stringByAppendingPathComponent:name] stringByAppendingPathExtension:@"framework"]; if([[NSFileManager defaultManager] fileExistsAtPath:check]) result=check; else { check=[[[directory stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Frameworks"] stringByAppendingPathComponent:[name stringByAppendingPathExtension:@"framework"]]; if([[NSFileManager defaultManager] fileExistsAtPath:check]) result=check; else { result=[[directory stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]; } } } return result; } +(NSBundle *)bundleWithModulePath:(NSString *)path { NSBundle *result; path=[self bundlePathFromModulePath:path]; result=[NSBundle bundleWithPath:path]; [result _setLoaded:YES]; return result; } +(void)registerFrameworks { unsigned i,count; const char **array=objc_copyImageNames(&count); for(i=0;i Frameworks/MyFramework.framework/ Bundles are organized like OS X with Contents/ */ -(NSString *)_findExecutable { NSString *type=[_path pathExtension]; NSString *name=[[self infoDictionary] objectForKey:@"CFBundleExecutable"]; NSString *checkDir; NSArray *contents; NSInteger i,count; if(name==nil) name=[[_path lastPathComponent] stringByDeletingPathExtension]; if([type isEqualToString:@"framework"]) checkDir=[[[_path stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Executables"]; else checkDir=[[_path stringByAppendingPathComponent:@"Contents"] stringByAppendingPathComponent:NSPlatformExecutableDirectory]; contents=[[NSFileManager defaultManager] directoryContentsAtPath:checkDir]; count=[contents count]; // Need to check for * versioning for(i=0;i", isa, self, _path, _resourcePath, (_isLoaded ? @"YES" : @"NO")]; } @end NSString *NSLocalizedString(NSString *key,NSString *comment) { return [[NSBundle mainBundle] localizedStringForKey:key value:nil table:nil]; } NSString *NSLocalizedStringFromTable(NSString *key,NSString *table,NSString *comment) { return [[NSBundle mainBundle] localizedStringForKey:key value:nil table:table]; } NSString *NSLocalizedStringFromTableInBundle(NSString *key,NSString *table,NSBundle *bundle,NSString *comment) { return [bundle localizedStringForKey:key value:nil table:table]; }