diff --git a/Foundation/CPBundle.j b/Foundation/CPBundle.j index 7c4fedf4a..9544ec98c 100644 --- a/Foundation/CPBundle.j +++ b/Foundation/CPBundle.j @@ -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 diff --git a/Objective-J/CFBundle.js b/Objective-J/CFBundle.js index 0faec4273..34c443670 100644 --- a/Objective-J/CFBundle.js +++ b/Objective-J/CFBundle.js @@ -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 + "\""));