From 383c7fc20ad03ba483f7746055a72e966ed6ddf1 Mon Sep 17 00:00:00 2001 From: nico Date: Sat, 9 Feb 2002 01:06:05 +0000 Subject: [PATCH] Remove experimental +bundleForTool:, and modified +mainBundle to work for tools as well instaed git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@12459 72102866-910b-0410-8b05-ffd578937521 --- Source/NSBundle.m | 124 ++++++++++++++++++++++++++-------------------- 1 file changed, 71 insertions(+), 53 deletions(-) diff --git a/Source/NSBundle.m b/Source/NSBundle.m index 0324a9ca3..072462288 100644 --- a/Source/NSBundle.m +++ b/Source/NSBundle.m @@ -7,6 +7,8 @@ Author: Mirko Viviani Date: October 2000 Added frameworks support + Author: Nicola Pero + This file is part of the GNUstep Base Library. This library is free software; you can redistribute it and/or @@ -543,37 +545,96 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory) return array; } +/* For an application, returns the main bundle of the application. + For a tool, returns the main bundle associated with the tool (this + is experimental and not yet supported by gnustep-make, but will + soon be). + + For an application, the structure is as follows - + + The executable is Gomoku.app/ix86/linux-gnu/gnu-gnu-gnu/Gomoku + and the main bundle directory is Gomoku.app/. + + For a tool, the structure is as follows - + + The executable is xxx/Tools/ix86/linux-gnu/gnu-gnu-gnu/Control + and the main bundle directory is xxx/Tools/Resources/Control. + + (when the tool has not yet been installed, it's similar - + xxx/shared_obj/ix86/linux-gnu/gnu-gnu-gnu/Control + and the main bundle directory is xxx/Resources/Control). + + (For a flattened structure, the structure is the same without the + ix86/linux-gnu/gnu-gnu-gnu directories). */ + (NSBundle *)mainBundle { [load_lock lock]; - if ( !_mainBundle ) + if (!_mainBundle) { + /* We figure out the main bundle directory by examining the location + of the executable on disk. */ NSString *path, *s; - + + /* We don't know at the beginning if it's a tool or an application. */ + BOOL isApplication = YES; + + /* If it's a tool, we will need the tool name. Since we don't + know yet if it's a tool or an application, we always store + the executable name here - just in case it turns out it's a + tool. */ + NSString *toolName = [_executable_path lastPathComponent]; + /* Strip off the name of the program */ path = [_executable_path stringByDeletingLastPathComponent]; - /* The executable may not lie in the main bundle directory - so we need to chop off the extra subdirectories, the library - combo and the target cpu/os if they exist. The executable and - this library should match so that is why we can use the + /* We now need to chop off the extra subdirectories, the library + combo and the target cpu/os if they exist. The executable + and this library should match so that is why we can use the compiled-in settings. */ /* library combo */ s = [path lastPathComponent]; if ([s isEqual: library_combo]) - path = [path stringByDeletingLastPathComponent]; + { + path = [path stringByDeletingLastPathComponent]; + } /* target os */ s = [path lastPathComponent]; if ([s isEqual: gnustep_target_os]) - path = [path stringByDeletingLastPathComponent]; + { + path = [path stringByDeletingLastPathComponent]; + } /* target cpu */ s = [path lastPathComponent]; if ([s isEqual: gnustep_target_cpu]) - path = [path stringByDeletingLastPathComponent]; + { + path = [path stringByDeletingLastPathComponent]; + } /* object dir */ s = [path lastPathComponent]; if ([s hasSuffix: @"_obj"]) - path = [path stringByDeletingLastPathComponent]; + { + path = [path stringByDeletingLastPathComponent]; + /* if it has an object dir it can only be a + non-yet-installed tool. */ + isApplication = NO; + } + + if (isApplication == YES) + { + s = [path lastPathComponent]; + if (([s hasSuffix: @".app"] == NO) + && ([s hasSuffix: @".debug"] == NO) + && ([s hasSuffix: @".profile"] == NO)) + { + isApplication = NO; + } + } + + if (isApplication == NO) + { + path = [path stringByAppendingPathComponent: @"Resources"]; + path = [path stringByAppendingPathComponent: toolName]; + } NSDebugMLLog(@"NSBundle", @"Found main in %@\n", path); /* We do alloc and init separately so initWithPath: knows @@ -1239,10 +1300,6 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory) @implementation NSBundle (GNUstep) -/* These are convenience methods for searching for resource files - 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/ @@ -1282,45 +1339,6 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory) return nil; } -/** Return a bundle which accesses the first existing directory from the list - GNUSTEP_USER_ROOT/Libraries/Resources/toolName/ - GNUSTEP_NETWORK_ROOT/Libraries/Resources/toolName/ - GNUSTEP_LOCAL_ROOT/Libraries/Resources/toolName/ - GNUSTEP_SYSTEM_ROOT/Libraries/Resources/toolName/ - */ -+ (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;