Update CPBundle to better support CPURLs.

Reviewed by me.
This commit is contained in:
Francisco Ryan Tolmasky I committed 2010-03-05 22:44:59 -08:00
1 parent d7f0bf6a24
commit 8f08c33bcc
1 file changed
+26 -15
+26 -15
View File
@@ -23,15 +23,13 @@
@import "CPObject.j"
@import "CPDictionary.j"
@import "CPURLRequest.j"
/*!
@class CPBundle
@ingroup foundation
@brief Groups information about an application's code & resources.
*/
var CPBundlesForPaths = { };
var CPBundlesForURLStrings = { };
@implementation CPBundle : CPObject
{
@@ -39,24 +37,32 @@ var CPBundlesForPaths = { };
id _delegate;
}
+ (CPBundle)bundleWithURL:(CPURL)aURL
{
return [[self alloc] initWithURL:aURL];
}
+ (CPBundle)bundleWithPath:(CPString)aPath
{
return [[self alloc] initWithPath:aPath];
return [self bundleWithURL:aPath];
}
+ (CPBundle)bundleForClass:(Class)aClass
{
return [self bundleWithPath:CFBundle.bundleForClass(aClass).path()];
return [self bundleWithURL:CFBundle.bundleForClass(aClass).bundleURL()];
}
+ (CPBundle)mainBundle
{
return [CPBundle bundleWithPath:CFBundle.mainBundle().path()];
return [CPBundle bundleWithPath:CFBundle.mainBundle().bundleURL()];
}
- (id)initWithPath:(CPString)aPath
- (id)initWithURL:(CPURL)aURL
{
var existingBundle = CPBundlesForPaths[aPath];
aURL = new CFURL(aURL);
var URLString = aURL.absoluteString(),
existingBundle = CPBundlesForURLStrings[URLString];
if (existingBundle)
return existingBundle;
@@ -65,13 +71,18 @@ var CPBundlesForPaths = { };
if (self)
{
_bundle = new CFBundle(aPath);
CPBundlesForPaths[aPath] = self;
_bundle = new CFBundle(aURL);
CPBundlesForURLStrings[URLString] = self;
}
return self;
}
- (id)initWithPath:(CPString)aPath
{
return [self initWithURL:aPath];
}
- (Class)classNamed:(CPString)aString
{
// ???
@@ -89,12 +100,12 @@ var CPBundlesForPaths = { };
- (CPString)resourcePath
{
var resourcePath = [self bundlePath];
return [[self resourceURL] path];
}
if (resourcePath.length)
resourcePath += '/';
return resourcePath + "Resources";
- (CPURL)resourceURL
{
return _bundle.resourcesDirectoryURL();
}
- (Class)principalClass