mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Added implementation of NSSearchPathForDirectoriesInDomains()
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6379 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d7192f1ffd
commit
de8d46b01f
3 changed files with 149 additions and 0 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2000-03-25 Jonathan Gapen <jagapen@whitewater.chem.wisc.edu>
|
||||||
|
|
||||||
|
* Source/NSUser.m: Added new MacOS X function,
|
||||||
|
NSSearchPathForDirectoriesInDomains()
|
||||||
|
* Headers/gnustep/base/NSPathUtilities.h: Added prototype and
|
||||||
|
argument definitions for the above function.
|
||||||
|
|
||||||
2000-03-23 Adam Fedor <fedor@gnu.org>
|
2000-03-23 Adam Fedor <fedor@gnu.org>
|
||||||
|
|
||||||
* Source/....m: include config.h
|
* Source/....m: include config.h
|
||||||
|
|
|
@ -45,6 +45,28 @@ extern NSString *NSHomeDirectory();
|
||||||
extern NSString *NSHomeDirectoryForUser(NSString *userName);
|
extern NSString *NSHomeDirectoryForUser(NSString *userName);
|
||||||
|
|
||||||
#ifndef STRICT_OPENSTEP
|
#ifndef STRICT_OPENSTEP
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
NSApplicationDirectory,
|
||||||
|
NSDemoApplicationDirectory,
|
||||||
|
NSDeveloperApplicationDirectory,
|
||||||
|
NSAdminApplicationDirectory,
|
||||||
|
NSLibraryDirectory,
|
||||||
|
NSDeveloperDirectory,
|
||||||
|
NSUserDirectory,
|
||||||
|
NSDocumentationDirectory,
|
||||||
|
NSAllApplicationsDirectory,
|
||||||
|
NSAllLibrariesDirectory
|
||||||
|
} NSSearchPathDirectory;
|
||||||
|
|
||||||
|
typedef unsigned int NSSearchPathDomainMask;
|
||||||
|
#define NSUserDomainMask 0x00000001
|
||||||
|
#define NSLocalDomainMask 0x00000002
|
||||||
|
#define NSNetworkDomainMask 0x00000004
|
||||||
|
#define NSSystemDomainMask 0x00000008
|
||||||
|
#define NSAllDomainsMask 0xffffffff
|
||||||
|
|
||||||
|
extern NSArray *NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory directory, NSSearchPathDomainMask domainMask, BOOL expandTilde);
|
||||||
extern NSString *NSFullUserName(void);
|
extern NSString *NSFullUserName(void);
|
||||||
extern NSArray *NSStandardApplicationPaths(void);
|
extern NSArray *NSStandardApplicationPaths(void);
|
||||||
extern NSArray *NSStandardLibraryPaths(void);
|
extern NSArray *NSStandardLibraryPaths(void);
|
||||||
|
|
120
Source/NSUser.m
120
Source/NSUser.m
|
@ -31,6 +31,7 @@
|
||||||
#include <Foundation/NSDictionary.h>
|
#include <Foundation/NSDictionary.h>
|
||||||
#include <Foundation/NSFileManager.h>
|
#include <Foundation/NSFileManager.h>
|
||||||
#include <Foundation/NSProcessInfo.h>
|
#include <Foundation/NSProcessInfo.h>
|
||||||
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSValue.h>
|
#include <Foundation/NSValue.h>
|
||||||
#include <Foundation/NSUserDefaults.h>
|
#include <Foundation/NSUserDefaults.h>
|
||||||
|
|
||||||
|
@ -290,4 +291,123 @@ NSOpenStepRootDirectory(void)
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSArray *
|
||||||
|
NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory directoryKey,
|
||||||
|
NSSearchPathDomainMask domainMask,
|
||||||
|
BOOL expandTilde)
|
||||||
|
{
|
||||||
|
NSDictionary *env;
|
||||||
|
NSString *gnustep_user_root;
|
||||||
|
NSString *gnustep_local_root;
|
||||||
|
NSString *gnustep_network_root;
|
||||||
|
NSString *gnustep_system_root;
|
||||||
|
NSString *appsDir = @"Apps";
|
||||||
|
NSString *libraryDir = @"Library";
|
||||||
|
NSString *docDir = @"Documentation";
|
||||||
|
NSMutableArray *paths = [NSMutableArray new];
|
||||||
|
NSString *path;
|
||||||
|
NSFileManager *fm;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
env = [[NSProcessInfo processInfo] environment];
|
||||||
|
gnustep_user_root = [env objectForKey:@"GNUSTEP_USER_ROOT"];
|
||||||
|
gnustep_local_root = [env objectForKey:@"GNUSTEP_LOCAL_ROOT"];
|
||||||
|
gnustep_network_root = [env objectForKey:@"GNUSTEP_NETWORK_ROOT"];
|
||||||
|
gnustep_system_root = [env objectForKey:@"GNUSTEP_SYSTEM_ROOT"];
|
||||||
|
|
||||||
|
if (directoryKey == NSApplicationDirectory
|
||||||
|
|| directoryKey == NSAllApplicationsDirectory)
|
||||||
|
{
|
||||||
|
if (domainMask & NSUserDomainMask)
|
||||||
|
[paths addObject:
|
||||||
|
[gnustep_user_root stringByAppendingPathComponent: appsDir]];
|
||||||
|
if (domainMask & NSLocalDomainMask)
|
||||||
|
[paths addObject:
|
||||||
|
[gnustep_local_root stringByAppendingPathComponent: appsDir]];
|
||||||
|
if (domainMask & NSNetworkDomainMask)
|
||||||
|
[paths addObject:
|
||||||
|
[gnustep_network_root stringByAppendingPathComponent: appsDir]];
|
||||||
|
if (domainMask & NSSystemDomainMask)
|
||||||
|
[paths addObject:
|
||||||
|
[gnustep_system_root stringByAppendingPathComponent: appsDir]];
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if (directoryKey == NSDemoApplicationDirectory
|
||||||
|
|| directoryKey == NSAllApplicationsDirectory);
|
||||||
|
if (directoryKey == NSDeveloperApplicationDirectory
|
||||||
|
|| directoryKey == NSAllApplicationsDirectory);
|
||||||
|
if (directoryKey == NSAdminApplicationDirectory
|
||||||
|
|| directoryKey == NSAllApplicationsDirectory);
|
||||||
|
*/
|
||||||
|
if (directoryKey == NSLibraryDirectory
|
||||||
|
|| directoryKey == NSAllLibrariesDirectory)
|
||||||
|
{
|
||||||
|
if (domainMask & NSUserDomainMask)
|
||||||
|
[paths addObject:
|
||||||
|
[gnustep_user_root stringByAppendingPathComponent: libraryDir]];
|
||||||
|
if (domainMask & NSLocalDomainMask)
|
||||||
|
[paths addObject:
|
||||||
|
[gnustep_local_root stringByAppendingPathComponent: libraryDir]];
|
||||||
|
if (domainMask & NSNetworkDomainMask)
|
||||||
|
[paths addObject:
|
||||||
|
[gnustep_network_root stringByAppendingPathComponent: libraryDir]];
|
||||||
|
if (domainMask & NSSystemDomainMask)
|
||||||
|
[paths addObject:
|
||||||
|
[gnustep_system_root stringByAppendingPathComponent: libraryDir]];
|
||||||
|
}
|
||||||
|
if (directoryKey == NSDeveloperDirectory
|
||||||
|
|| directoryKey == NSAllLibrariesDirectory)
|
||||||
|
{
|
||||||
|
// GNUstep doesn't have a 'Developer' subdirectory (yet?)
|
||||||
|
if (domainMask & NSUserDomainMask)
|
||||||
|
[paths addObject: gnustep_user_root];
|
||||||
|
if (domainMask & NSLocalDomainMask)
|
||||||
|
[paths addObject: gnustep_local_root];
|
||||||
|
if (domainMask & NSNetworkDomainMask)
|
||||||
|
[paths addObject: gnustep_network_root];
|
||||||
|
if (domainMask & NSSystemDomainMask)
|
||||||
|
[paths addObject: gnustep_system_root];
|
||||||
|
}
|
||||||
|
if (directoryKey == NSUserDirectory)
|
||||||
|
{
|
||||||
|
if (domainMask & NSUserDomainMask)
|
||||||
|
[paths addObject: NSHomeDirectory()];
|
||||||
|
}
|
||||||
|
if (directoryKey == NSDocumentationDirectory)
|
||||||
|
{
|
||||||
|
if (domainMask & NSUserDomainMask)
|
||||||
|
[paths addObject:
|
||||||
|
[gnustep_user_root stringByAppendingPathComponent: docDir]];
|
||||||
|
if (domainMask & NSLocalDomainMask)
|
||||||
|
[paths addObject:
|
||||||
|
[gnustep_local_root stringByAppendingPathComponent: docDir]];
|
||||||
|
if (domainMask & NSNetworkDomainMask)
|
||||||
|
[paths addObject:
|
||||||
|
[gnustep_network_root stringByAppendingPathComponent: docDir]];
|
||||||
|
if (domainMask & NSSystemDomainMask)
|
||||||
|
[paths addObject:
|
||||||
|
[gnustep_system_root stringByAppendingPathComponent: docDir]];
|
||||||
|
}
|
||||||
|
|
||||||
|
fm = [NSFileManager defaultManager];
|
||||||
|
for (i = 0; i < [paths count]; i++)
|
||||||
|
{
|
||||||
|
path = [paths objectAtIndex: i];
|
||||||
|
// remove bad paths
|
||||||
|
if (![fm fileExistsAtPath: path])
|
||||||
|
{
|
||||||
|
[paths removeObject: path];
|
||||||
|
i--; // mutable arrays move objects up a slot when you remove one
|
||||||
|
}
|
||||||
|
// this may look like a performance hit at first glance, but if these
|
||||||
|
// string methods don't alter the string, they return the receiver
|
||||||
|
else if (expandTilde)
|
||||||
|
[paths replaceObjectAtIndex: i
|
||||||
|
withObject: [path stringByExpandingTildeInPath]];
|
||||||
|
else
|
||||||
|
[paths replaceObjectAtIndex: i
|
||||||
|
withObject: [path stringByAbbreviatingWithTildeInPath]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue