mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
* Source/NSBundle.m (+pathsForResourcesOfType:inDirectory:,
-pathsForResourcesOfType:inDirectory:forLocalization:): Implement. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21850 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3dcf0943ca
commit
7a2eeb1de4
3 changed files with 88 additions and 37 deletions
|
@ -1,3 +1,9 @@
|
|||
2005-10-20 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Source/NSBundle.m (+pathsForResourcesOfType:inDirectory:,
|
||||
-pathsForResourcesOfType:inDirectory:forLocalization:):
|
||||
Implement.
|
||||
|
||||
2005-10-18 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSUserDefaults.m: Begin applying registry patch.
|
||||
|
|
|
@ -206,8 +206,15 @@ GS_EXPORT NSString* const NSLoadedClasses;
|
|||
- (Class) principalClass;
|
||||
|
||||
/**
|
||||
* Not implemented. Create an instance and call the corresponding instance
|
||||
* method instead.
|
||||
<p> Returns an array of paths for all resources with the specified
|
||||
extension and residing in the bundlePath directory. bundlePath can
|
||||
be any type of directory structure, but typically it is used to
|
||||
search for resources in a application or framework. For example,
|
||||
one could search for tiff files in the MyApp.app application using [NSBundle
|
||||
pathsForResourcesOfType: @"tiff" inDirectory: @"MyApp.app"]. It
|
||||
will search in any Resources subdirectory inside bundlePath as well
|
||||
as the main directory for resource files. If extension is nil or
|
||||
empty, all resources are returned. </p>
|
||||
*/
|
||||
+ (NSArray*) pathsForResourcesOfType: (NSString*)extension
|
||||
inDirectory: (NSString*)bundlePath;
|
||||
|
@ -220,7 +227,7 @@ GS_EXPORT NSString* const NSLoadedClasses;
|
|||
</p>
|
||||
*/
|
||||
- (NSArray*) pathsForResourcesOfType: (NSString*)extension
|
||||
inDirectory: (NSString*)bundlePath;
|
||||
inDirectory: (NSString*)subPath;
|
||||
|
||||
/**
|
||||
<p>
|
||||
|
@ -229,10 +236,10 @@ GS_EXPORT NSString* const NSLoadedClasses;
|
|||
in the following order:
|
||||
</p>
|
||||
<example>
|
||||
root path/Resources/bundlePath
|
||||
root path/Resources/bundlePath/"language.lproj"
|
||||
root path/bundlePath
|
||||
root path/bundlePath/"language.lproj"
|
||||
root path/Resources/subPath
|
||||
root path/Resources/subPath/"language.lproj"
|
||||
root path/subPath
|
||||
root path/subPath/"language.lproj"
|
||||
</example>
|
||||
<p>
|
||||
where language.lproj can be any localized language directory inside
|
||||
|
@ -245,7 +252,7 @@ GS_EXPORT NSString* const NSLoadedClasses;
|
|||
*/
|
||||
- (NSString*) pathForResource: (NSString*)name
|
||||
ofType: (NSString*)ext
|
||||
inDirectory: (NSString*)bundlePath;
|
||||
inDirectory: (NSString*)subPath;
|
||||
|
||||
/**
|
||||
Returns an absolute path for a resource name with the extension ext
|
||||
|
@ -299,18 +306,22 @@ GS_EXPORT NSString* const NSLoadedClasses;
|
|||
forPreferences: (NSArray *)preferencesArray;
|
||||
|
||||
- (BOOL) isLoaded;
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
This method returns the same information as
|
||||
-pathsForResourcesOfType:inDirectory: except that only non-localized
|
||||
resources and resources that match the localization localizationName
|
||||
are returned.
|
||||
*/
|
||||
- (NSArray*) pathsForResourcesOfType: (NSString*)extension
|
||||
inDirectory: (NSString*)bundlePath
|
||||
inDirectory: (NSString*)subPath
|
||||
forLocalization: (NSString*)localizationName;
|
||||
/**
|
||||
* Not implemented.
|
||||
*/
|
||||
- (NSString*) pathForResource: (NSString*)name
|
||||
ofType: (NSString*)ext
|
||||
inDirectory: (NSString*)bundlePath
|
||||
inDirectory: (NSString*)subPath
|
||||
forLocalization: (NSString*)localizationName;
|
||||
|
||||
/** Returns the info property list associated with the bundle. */
|
||||
|
|
|
@ -1184,7 +1184,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
|||
<rootPath>/<bundlePath>/<language.lproj>
|
||||
*/
|
||||
+ (NSArray *) _bundleResourcePathsWithRootPath: (NSString *)rootPath
|
||||
subPath: (NSString *)bundlePath
|
||||
subPath: (NSString *)subPath
|
||||
{
|
||||
NSString* primary;
|
||||
NSString* language;
|
||||
|
@ -1196,16 +1196,19 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
|||
languages = [NSUserDefaults userLanguages];
|
||||
|
||||
primary = [rootPath stringByAppendingPathComponent: @"Resources"];
|
||||
[array addObject: _bundle_resource_path(primary, bundlePath, nil)];
|
||||
[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, bundlePath, language)];
|
||||
[array addObject: _bundle_resource_path(primary, subPath, language)];
|
||||
|
||||
primary = rootPath;
|
||||
[array addObject: _bundle_resource_path(primary, bundlePath, nil)];
|
||||
[array addObject: _bundle_resource_path(primary, subPath, nil)];
|
||||
enumerate = [languages objectEnumerator];
|
||||
while ((language = [enumerate nextObject]))
|
||||
[array addObject: _bundle_resource_path(primary, bundlePath, language)];
|
||||
[array addObject: _bundle_resource_path(primary, subPath, language)];
|
||||
|
||||
return array;
|
||||
}
|
||||
|
@ -1213,7 +1216,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
|||
+ (NSString *) pathForResource: (NSString *)name
|
||||
ofType: (NSString *)ext
|
||||
inRootPath: (NSString *)rootPath
|
||||
inDirectory: (NSString *)bundlePath
|
||||
inDirectory: (NSString *)subPath
|
||||
withVersion: (int)version
|
||||
{
|
||||
NSString *path, *fullpath;
|
||||
|
@ -1227,7 +1230,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
|||
}
|
||||
|
||||
pathlist = [[self _bundleResourcePathsWithRootPath: rootPath
|
||||
subPath: bundlePath] objectEnumerator];
|
||||
subPath: subPath] objectEnumerator];
|
||||
fullpath = nil;
|
||||
while ((path = [pathlist nextObject]))
|
||||
{
|
||||
|
@ -1307,7 +1310,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
|||
|
||||
- (NSString *) pathForResource: (NSString *)name
|
||||
ofType: (NSString *)ext
|
||||
inDirectory: (NSString *)bundlePath
|
||||
inDirectory: (NSString *)subPath
|
||||
{
|
||||
NSString *rootPath;
|
||||
|
||||
|
@ -1320,19 +1323,13 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
|||
return [NSBundle pathForResource: name
|
||||
ofType: ext
|
||||
inRootPath: rootPath
|
||||
inDirectory: bundlePath
|
||||
inDirectory: subPath
|
||||
withVersion: _version];
|
||||
}
|
||||
|
||||
+ (NSArray*) pathsForResourcesOfType: (NSString*)extension
|
||||
inDirectory: (NSString*)bundlePath
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSArray *) pathsForResourcesOfType: (NSString *)extension
|
||||
inDirectory: (NSString *)bundlePath
|
||||
+ (NSArray*) _pathsForResourcesOfType: (NSString*)extension
|
||||
inRootDirectory: (NSString*)bundlePath
|
||||
inSubDirectory: (NSString *)subPath
|
||||
{
|
||||
BOOL allfiles;
|
||||
NSString *path;
|
||||
|
@ -1340,10 +1337,8 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
|||
NSEnumerator *pathlist;
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
|
||||
/* Not sure if this is correct since it will only search in
|
||||
lprojs that are user preferences. FIXME. */
|
||||
pathlist = [[NSBundle _bundleResourcePathsWithRootPath: [self bundlePath]
|
||||
subPath: bundlePath] objectEnumerator];
|
||||
pathlist = [[NSBundle _bundleResourcePathsWithRootPath: bundlePath
|
||||
subPath: subPath] objectEnumerator];
|
||||
resources = [NSMutableArray arrayWithCapacity: 2];
|
||||
allfiles = (extension == nil || [extension length] == 0);
|
||||
|
||||
|
@ -1363,17 +1358,56 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
|||
return resources;
|
||||
}
|
||||
|
||||
- (NSArray*) pathsForResourcesOfType: (NSString*)extension
|
||||
+ (NSArray*) pathsForResourcesOfType: (NSString*)extension
|
||||
inDirectory: (NSString*)bundlePath
|
||||
{
|
||||
return [self _pathsForResourcesOfType: extension
|
||||
inRootDirectory: bundlePath
|
||||
inSubDirectory: nil];
|
||||
}
|
||||
|
||||
- (NSArray *) pathsForResourcesOfType: (NSString *)extension
|
||||
inDirectory: (NSString *)subPath
|
||||
{
|
||||
return [[self class] _pathsForResourcesOfType: extension
|
||||
inRootDirectory: [self bundlePath]
|
||||
inSubDirectory: subPath];
|
||||
}
|
||||
|
||||
- (NSArray*) pathsForResourcesOfType: (NSString*)extension
|
||||
inDirectory: (NSString*)subPath
|
||||
forLocalization: (NSString*)localizationName
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
NSArray *paths = nil;
|
||||
NSMutableArray *result = nil;
|
||||
NSEnumerator *enumerator = nil;
|
||||
NSString *path = nil;
|
||||
|
||||
result = [NSMutableArray array];
|
||||
paths = [self pathsForResourcesOfType: extension
|
||||
inDirectory: subPath];
|
||||
|
||||
enumerator = [paths objectEnumerator];
|
||||
while( (path = [enumerator nextObject]) )
|
||||
{
|
||||
/* Add all non-localized paths, plus ones in the particular localization
|
||||
(if there is one). */
|
||||
NSString *theDir = [path stringByDeletingLastPathComponent];
|
||||
if ([[theDir pathExtension] isEqual: @"lproj"] == NO
|
||||
|| (localizationName != nil
|
||||
&& [localizationName length] != 0
|
||||
&& [[theDir lastPathComponent] hasPrefix: localizationName]) )
|
||||
{
|
||||
[result addObject: path];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSString*) pathForResource: (NSString*)name
|
||||
ofType: (NSString*)ext
|
||||
inDirectory: (NSString*)bundlePath
|
||||
inDirectory: (NSString*)subPath
|
||||
forLocalization: (NSString*)localizationName
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
|
|
Loading…
Reference in a new issue