Added +bundleForLibrary: and +bundleForTool:

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@11874 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Nicola Pero 2001-12-21 18:31:06 +00:00
parent cbc68d7c07
commit c23685096b

View file

@ -1318,6 +1318,84 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
within the GNUstep directory structure specified by the environment
variables. */
/* Return a bundle which accesses the first existing directory from the list
GNUSTEP_USER_ROOT/Libraries/Resources/libraryName/
GNUSTEP_NETWORK_ROOT/Libraries/Resources/libraryName/
GNUSTEP_LOCAL_ROOT/Libraries/Resources/libraryName/
GNUSTEP_SYSTEM_ROOT/Libraries/Resources/libraryName/
*/
+ (NSBundle *) bundleForLibrary: (NSString *)libraryName
{
NSArray *paths;
NSEnumerator *enumerator;
NSString *path;
NSString *tail;
NSFileManager *fm = [NSFileManager defaultManager];
if (libraryName == nil)
{
return nil;
}
tail = [@"Resources" stringByAppendingPathComponent: libraryName];
paths = NSSearchPathForDirectoriesInDomains (GSLibrariesDirectory,
NSAllDomainsMask, YES);
enumerator = [paths objectEnumerator];
while ((path = [enumerator nextObject]))
{
BOOL isDir;
path = [path stringByAppendingPathComponent: tail];
if ([fm fileExistsAtPath: path isDirectory: &isDir] && isDir)
{
return [NSBundle bundleWithPath: path];
}
}
return nil;
}
/* Return a bundle which accesses the first existing directory from the list
GNUSTEP_USER_ROOT/Tools/Resources/libraryName/
GNUSTEP_NETWORK_ROOT/Tools/Resources/libraryName/
GNUSTEP_LOCAL_ROOT/Tools/Resources/libraryName/
GNUSTEP_SYSTEM_ROOT/Tools/Resources/libraryName/
*/
+ (NSBundle *) bundleForTool: (NSString *)toolName
{
NSArray *paths;
NSEnumerator *enumerator;
NSString *path;
NSString *tail;
NSFileManager *fm = [NSFileManager defaultManager];
if (toolName == nil)
{
return nil;
}
tail = [@"Resources" stringByAppendingPathComponent: toolName];
paths = NSSearchPathForDirectoriesInDomains (GSLibrariesDirectory,
NSAllDomainsMask, YES);
enumerator = [paths objectEnumerator];
while ((path = [enumerator nextObject]))
{
BOOL isDir;
path = [path stringByAppendingPathComponent: tail];
if ([fm fileExistsAtPath: path isDirectory: &isDir] && isDir)
{
return [NSBundle bundleWithPath: path];
}
}
return nil;
}
+ (NSString *) _absolutePathOfExecutable: (NSString *)path
{
NSFileManager *mgr;