New: CFBundle.identifier, CFBundle.bundleWithIdentifier, CPBundle -bundleWithIdentifier.

Finding a bundle by identifier is theoretically better than using a class.
This commit is contained in:
Aparajita Fishman committed 2013-04-05 23:16:05 -04:00
1 parent 90e11039a1
commit a3730812bc
2 files changed
+38 -6

No files matched your search

+12 -2
View File
@@ -51,6 +51,16 @@ var CPBundlesForURLStrings = { };
return [self bundleWithURL:aPath];
}
+ (CPBundle)bundleWithIdentifier:(CPString)anIdentifier
{
var bundle = CFBundle.bundleWithIdentifier(anIdentifier);
if (bundle)
bundle = CPBundlesForURLStrings[bundle.bundleURL().absoluteString()] || nil;
return bundle;
}
+ (CPBundle)bundleForClass:(Class)aClass
{
return [self bundleWithURL:CFBundle.bundleForClass(aClass).bundleURL()];
@@ -118,12 +128,12 @@ var CPBundlesForURLStrings = { };
//[self load];
return className ? CPClassFromString(className) : Nil;
return className ? CPClassFromString(className) : nil;
}
- (CPString)bundleIdentifier
{
return [self objectForInfoDictionaryKey:@"CPBundleIdentifier"];
return _bundle.identifier();
}
- (BOOL)isLoaded
+26 -4
View File
@@ -27,8 +27,9 @@ var CFBundleUnloaded = 0,
CFBundleLoadingSpritedImages = 1 << 3,
CFBundleLoaded = 1 << 4;
var CFBundlesForURLStrings = { },
CFBundlesForClasses = { },
var CFBundlesForURLStrings = { },
CFBundlesForClasses = { },
CFBundlesWithIdentifiers = { },
CFCacheBuster = new Date().getTime(),
CFTotalBytesLoaded = 0,
CPApplicationSizeInBytes = 0;
@@ -108,8 +109,9 @@ function addClassToBundle(aClass, aBundle)
function resetBundle()
{
CFBundlesForURLStrings = { };
CFBundlesForClasses = { };
CFBundlesForURLStrings = { };
CFBundlesForClasses = { };
CFBundlesWithIdentifiers = { };
//CFCacheBuster = new Date().getTime(),
CFTotalBytesLoaded = 0;
CPApplicationSizeInBytes = 0;
@@ -122,6 +124,12 @@ CFBundle.bundleForClass = function(/*Class*/ aClass)
DISPLAY_NAME(CFBundle.bundleForClass);
CFBundle.bundleWithIdentifier = function(/*String*/ bundleID)
{
return CFBundlesWithIdentifiers[bundleID] || NULL;
};
DISPLAY_NAME(CFBundle.bundleContainingURL);
CFBundle.prototype.bundleURL = function()
{
return this._bundleURL;
@@ -192,6 +200,13 @@ CFBundle.prototype.valueForInfoDictionaryKey = function(/*String*/ aKey)
DISPLAY_NAME(CFBundle.prototype.valueForInfoDictionaryKey);
CFBundle.prototype.identifier = function()
{
return this._infoDictionary.valueForKey("CPBundleIdentifier");
};
DISPLAY_NAME(CFBundle.prototype.identifier);
CFBundle.prototype.hasSpritedImages = function()
{
var environments = this._infoDictionary.valueForKey("CPBundleEnvironmentsWithImageSprites") || [],
@@ -283,8 +298,15 @@ CFBundle.prototype.load = function(/*BOOL*/ shouldExecute)
self._isValid = !!infoDictionary || CFBundle.mainBundle() === self;
if (infoDictionary)
{
self._infoDictionary = infoDictionary;
var identifier = self._infoDictionary.valueForKey("CPBundleIdentifier");
if (identifier)
CFBundlesWithIdentifiers[identifier] = self;
}
if (!self._infoDictionary)
{
finishBundleLoadingWithError(self, new Error("Could not load bundle at \"" + path + "\""));