Add a few 10.6 NSURL methods to NSBundle.

Based on patch by julian.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33367 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2011-06-22 23:01:01 +00:00
parent bbc480f958
commit dbd9d19e8f
3 changed files with 86 additions and 0 deletions

View file

@ -1,3 +1,9 @@
2011-06-23 Fred Kiefer <FredKiefer@gmx.de>
* Headers/Foundation/NSBundle.h,
* Source/NSBundle.m: Add a few 10.6 NSURL methods.
Based on patch by julian.
2011-06-20 Sebastian Reitenbach <sebastia@l00-bugdead-prods.de>
* SSL/GSSSLHandle.m:

View file

@ -184,6 +184,9 @@ GS_EXPORT NSString* const NSLoadedClasses;
* not readable, return nil. If you want the main bundle of an
* application or a tool, it's better if you use +mainBundle. */
+ (NSBundle*) bundleWithPath: (NSString*)path;
#if OS_API_VERSION(100600,GS_API_LATEST)
+ (NSBundle*) bundleWithURL: (NSURL*)url;
#endif
/**
Returns an absolute path for a resource name with the extension
@ -204,6 +207,13 @@ GS_EXPORT NSString* const NSLoadedClasses;
inDirectory: (NSString*)bundlePath
withVersion: (int)version;
#if OS_API_VERSION(100600,GS_API_LATEST)
+ (NSURL*) URLForResource: (NSString*)name
withExtension: (NSString*)ext
subdirectory: (NSString*)subpath
inBundleWithURL: (NSURL*)bundleURL;
#endif
/** <init />
* Init the bundle for reading resources from path.<br />
* The MacOS-X documentation says that the path must be a full path to
@ -226,6 +236,10 @@ GS_EXPORT NSString* const NSLoadedClasses;
*/
- (id) initWithPath: (NSString*)path;
#if OS_API_VERSION(100600,GS_API_LATEST)
- (id) initWithURL: (NSURL*)url;
#endif
/** Return the path to the bundle - an absolute path. */
- (NSString*) bundlePath;
@ -299,6 +313,18 @@ GS_EXPORT NSString* const NSLoadedClasses;
- (NSString*) pathForResource: (NSString*)name
ofType: (NSString*)ext;
#if OS_API_VERSION(100600,GS_API_LATEST)
- (NSURL*) URLForResource: (NSString*)name
withExtension: (NSString*)extension;
- (NSURL*) URLForResource: (NSString*)name
withExtension: (NSString*)extension
subdirectory: (NSString*)subpath;
- (NSURL*) URLForResource: (NSString*)name
withExtension: (NSString*)extension
subdirectory: (NSString*)subpath
localization: (NSString*)localizationName;
#endif
/**
<p>Returns the value for the key found in the strings file tableName, or
Localizable.strings if tableName is nil.</p>

View file

@ -48,6 +48,7 @@
#import "Foundation/NSFileManager.h"
#import "Foundation/NSPathUtilities.h"
#import "Foundation/NSData.h"
#import "Foundation/NSURL.h"
#import "Foundation/NSValue.h"
#import "GNUstepBase/NSObject+GNUstepBase.h"
#import "GNUstepBase/NSString+GNUstepBase.h"
@ -1296,6 +1297,11 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
return AUTORELEASE([[self alloc] initWithPath: path]);
}
+ (NSBundle*) bundleWithURL: (NSURL*)url
{
return AUTORELEASE([[self alloc] initWithURL: url]);
}
+ (NSBundle*) bundleWithIdentifier: (NSString*)identifier
{
NSBundle *bundle = nil;
@ -1464,6 +1470,12 @@ IF_NO_GC(
return self;
}
- (id) initWithURL: (NSURL*)url
{
// FIXME
return [self initWithPath: [url path]];
}
- (void) dealloc
{
if ([self isLoaded] == YES && self != _mainBundle
@ -1823,6 +1835,18 @@ IF_NO_GC(
inDirectory: nil];
}
+ (NSURL*) URLForResource: (NSString*)name
withExtension: (NSString*)ext
subdirectory: (NSString*)subpath
inBundleWithURL: (NSURL*)bundleURL
{
NSBundle *root = [self bundleWithURL: bundleURL];
return [root URLForResource: name
withExtension: ext
subdirectory: subpath];
}
- (NSString *) pathForResource: (NSString *)name
ofType: (NSString *)ext
{
@ -1851,6 +1875,36 @@ IF_NO_GC(
inDirectory: subPath];
}
- (NSURL *) URLForResource: (NSString *)name
withExtension: (NSString *)ext
{
return [self URLForResource: name
withExtension: ext
subdirectory: nil
localization: nil];
}
- (NSURL *) URLForResource: (NSString *)name
withExtension: (NSString *)ext
subdirectory: (NSString *)subpath
{
return [self URLForResource: name
withExtension: ext
subdirectory: subpath
localization: nil];
}
- (NSURL *) URLForResource: (NSString *)name
withExtension: (NSString *)ext
subdirectory: (NSString *)subpath
localization: (NSString *)localizationName
{
return [NSURL fileURLWithPath: [self pathForResource: name
ofType: ext
inDirectory: subpath
forLocalization: localizationName]];
}
+ (NSArray*) _pathsForResourcesOfType: (NSString*)extension
inRootDirectory: (NSString*)bundlePath
inSubDirectory: (NSString*)subPath