Implement keyed coding for NSURL.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@30853 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2010-06-25 13:38:06 +00:00
parent 9b72ce7cd0
commit 48a9a7cfab
3 changed files with 78 additions and 32 deletions

View file

@ -1,3 +1,10 @@
2010-06-25 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSURL.m: Implement keyed coding
* Source/NSBundle.m: When fetching a localised resource for a specific
language, ignore the language list in the user preferences, and just
look for that language asn for unlocalised data.
2010-06-25 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSKeyedArchiver.m:

View file

@ -1646,33 +1646,53 @@ IF_NO_GC(
<rootPath>/<bundlePath>
<rootPath>/<bundlePath>/<language.lproj>
*/
+ (NSArray *) _bundleResourcePathsWithRootPath: (NSString *)rootPath
subPath: (NSString *)subPath
+ (NSArray *) _bundleResourcePathsWithRootPath: (NSString*)rootPath
subPath: (NSString*)subPath
localization: (NSString*)localization
{
NSString* primary;
NSString* language;
NSArray* languages;
NSMutableArray* array;
NSEnumerator* enumerate;
NSString *primary;
NSString *language;
NSArray *languages;
NSMutableArray *array;
NSEnumerator *enumerate;
array = [NSMutableArray arrayWithCapacity: 8];
languages = [NSUserDefaults userLanguages];
primary = [rootPath stringByAppendingPathComponent: @"Resources"];
[array addObject: _bundle_resource_path(primary, subPath, nil)];
/* This matches OS X behavior, which only searches languages that
are in the user's preference. Don't use -preferredLocalizations -
that would cause a recursive loop. */
enumerate = [languages objectEnumerator];
while ((language = [enumerate nextObject]))
[array addObject: _bundle_resource_path(primary, subPath, language)];
/* If we have been asked for a specific localization, we add it.
*/
if (localization != nil)
{
[array addObject: _bundle_resource_path(primary, subPath, localization)];
}
else
{
/* This matches OS X behavior, which only searches languages that
* are in the user's preference. Don't use -preferredLocalizations -
* that would cause a recursive loop.
*/
enumerate = [languages objectEnumerator];
while ((language = [enumerate nextObject]))
{
[array addObject: _bundle_resource_path(primary, subPath, language)];
}
}
primary = rootPath;
[array addObject: _bundle_resource_path(primary, subPath, nil)];
enumerate = [languages objectEnumerator];
while ((language = [enumerate nextObject]))
[array addObject: _bundle_resource_path(primary, subPath, language)];
if (localization != nil)
{
[array addObject: _bundle_resource_path(primary, subPath, localization)];
}
else
{
enumerate = [languages objectEnumerator];
while ((language = [enumerate nextObject]))
{
[array addObject: _bundle_resource_path(primary, subPath, language)];
}
}
return array;
}
@ -1695,7 +1715,7 @@ IF_NO_GC(
}
pathlist = [[self _bundleResourcePathsWithRootPath: rootPath
subPath: subPath] objectEnumerator];
subPath: subPath localization: nil] objectEnumerator];
while ((path = [pathlist nextObject]) != nil)
{
if (bundle_directory_readable(path))
@ -1767,7 +1787,8 @@ IF_NO_GC(
+ (NSArray*) _pathsForResourcesOfType: (NSString*)extension
inRootDirectory: (NSString*)bundlePath
inSubDirectory: (NSString *)subPath
inSubDirectory: (NSString*)subPath
localization: (NSString*)localization
{
BOOL allfiles;
NSString *path;
@ -1776,7 +1797,7 @@ IF_NO_GC(
NSFileManager *mgr = manager();
pathlist = [[NSBundle _bundleResourcePathsWithRootPath: bundlePath
subPath: subPath] objectEnumerator];
subPath: subPath localization: localization] objectEnumerator];
resources = [NSMutableArray arrayWithCapacity: 2];
allfiles = (extension == nil || [extension length] == 0);
@ -1801,15 +1822,17 @@ IF_NO_GC(
{
return [self _pathsForResourcesOfType: extension
inRootDirectory: bundlePath
inSubDirectory: nil];
inSubDirectory: nil
localization: nil];
}
- (NSArray *) pathsForResourcesOfType: (NSString *)extension
inDirectory: (NSString *)subPath
{
return [[self class] _pathsForResourcesOfType: extension
inRootDirectory: [self bundlePath]
inSubDirectory: subPath];
inRootDirectory: [self bundlePath]
inSubDirectory: subPath
localization: nil];
}
- (NSArray*) pathsForResourcesOfType: (NSString*)extension
@ -1822,8 +1845,10 @@ IF_NO_GC(
NSString *path = nil;
result = [NSMutableArray array];
paths = [self pathsForResourcesOfType: extension
inDirectory: subPath];
paths = [[self class] _pathsForResourcesOfType: extension
inRootDirectory: [self bundlePath]
inSubDirectory: subPath
localization: localizationName];
enumerator = [paths objectEnumerator];
while ((path = [enumerator nextObject]) != nil)

View file

@ -1149,8 +1149,16 @@ static unsigned urlAlign;
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[aCoder encodeObject: _urlString];
[aCoder encodeObject: _baseURL];
if ([aCoder allowsKeyedCoding])
{
[aCoder encodeObject: _baseURL forKey: @"NS.base"];
[aCoder encodeObject: _urlString forKey: @"NS.relative"];
}
else
{
[aCoder encodeObject: _urlString];
[aCoder encodeObject: _baseURL];
}
}
- (NSUInteger) hash
@ -1163,15 +1171,21 @@ static unsigned urlAlign;
NSURL *base;
NSString *rel;
[aCoder decodeValueOfObjCType: @encode(id) at: &rel];
[aCoder decodeValueOfObjCType: @encode(id) at: &base];
if ([aCoder allowsKeyedCoding])
{
base = [aCoder decodeObjectForKey: @"NS.base"];
rel = [aCoder decodeObjectForKey: @"NS.relative"];
}
else
{
rel = [aCoder decodeObject];
base = [aCoder decodeObject];
}
if (nil == rel)
{
rel = @"";
}
self = [self initWithString: rel relativeToURL: base];
RELEASE(rel);
RELEASE(base);
return self;
}