1996-05-28 21:25:46 +00:00
|
|
|
/* Implementation of login-related functions for GNUstep
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
|
|
|
Created: May 1996
|
|
|
|
|
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
1999-09-09 02:56:20 +00:00
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
1996-05-28 21:25:46 +00:00
|
|
|
*/
|
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
#include <config.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
#include <base/preface.h>
|
2000-10-31 16:17:33 +00:00
|
|
|
#include <Foundation/NSObjCRuntime.h>
|
1996-05-28 21:25:46 +00:00
|
|
|
#include <Foundation/NSString.h>
|
1996-09-02 13:23:43 +00:00
|
|
|
#include <Foundation/NSPathUtilities.h>
|
1999-02-20 21:19:15 +00:00
|
|
|
#include <Foundation/NSException.h>
|
1998-12-15 19:11:58 +00:00
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
#include <Foundation/NSFileManager.h>
|
1998-12-17 09:16:26 +00:00
|
|
|
#include <Foundation/NSProcessInfo.h>
|
2000-03-25 10:59:07 +00:00
|
|
|
#include <Foundation/NSString.h>
|
1998-12-15 19:11:58 +00:00
|
|
|
#include <Foundation/NSValue.h>
|
2000-05-04 18:10:02 +00:00
|
|
|
#include <Foundation/NSLock.h>
|
1999-02-20 21:19:15 +00:00
|
|
|
#include <Foundation/NSUserDefaults.h>
|
1998-12-15 19:11:58 +00:00
|
|
|
|
1996-05-28 21:25:46 +00:00
|
|
|
#include <stdlib.h> // for getenv()
|
1999-05-11 09:21:38 +00:00
|
|
|
#if !defined(__WIN32__)
|
1996-05-28 21:25:46 +00:00
|
|
|
#include <unistd.h> // for getlogin()
|
1999-04-13 20:37:04 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_PWD_H
|
1996-05-28 21:25:46 +00:00
|
|
|
#include <pwd.h> // for getpwnam()
|
1996-07-15 18:41:44 +00:00
|
|
|
#endif
|
1996-05-28 21:25:46 +00:00
|
|
|
#include <sys/types.h>
|
1999-06-29 11:54:03 +00:00
|
|
|
#include <stdio.h>
|
1996-05-28 21:25:46 +00:00
|
|
|
|
1999-02-20 21:19:15 +00:00
|
|
|
static NSString *theUserName = nil;
|
|
|
|
|
|
|
|
void
|
|
|
|
GSSetUserName(NSString* name)
|
|
|
|
{
|
|
|
|
if (theUserName == nil)
|
|
|
|
theUserName = RETAIN(name);
|
|
|
|
else if ([theUserName isEqualToString: name] == NO)
|
|
|
|
{
|
|
|
|
ASSIGN(theUserName, name);
|
|
|
|
[NSUserDefaults resetUserDefaults];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the caller's login name as an NSString object.
|
|
|
|
* The 'LOGNAME' environment variable is our primary source, but we use
|
|
|
|
* other system-dependent sources if LOGNAME is not set.
|
|
|
|
*/
|
1996-05-28 21:25:46 +00:00
|
|
|
NSString *
|
1999-07-13 15:59:50 +00:00
|
|
|
NSUserName(void)
|
1996-05-28 21:25:46 +00:00
|
|
|
{
|
1999-02-20 21:19:15 +00:00
|
|
|
if (theUserName == nil)
|
|
|
|
{
|
|
|
|
const char *login_name = 0;
|
1999-05-11 09:21:38 +00:00
|
|
|
#if defined(__WIN32__)
|
1999-02-20 21:19:15 +00:00
|
|
|
/* The GetUserName function returns the current user name */
|
|
|
|
char buf[1024];
|
|
|
|
DWORD n = 1024;
|
1997-01-09 16:24:07 +00:00
|
|
|
|
1999-03-03 06:04:33 +00:00
|
|
|
if (GetEnvironmentVariable("LOGNAME", buf, 1024))
|
1999-02-20 21:19:15 +00:00
|
|
|
login_name = buf;
|
|
|
|
else if (GetUserName(buf, &n))
|
|
|
|
login_name = buf;
|
1996-10-31 19:05:14 +00:00
|
|
|
#else
|
1999-02-20 21:19:15 +00:00
|
|
|
login_name = getenv("LOGNAME");
|
|
|
|
if (login_name == 0 || getpwnam(login_name) == 0)
|
|
|
|
{
|
|
|
|
# if __SOLARIS__ || defined(BSD)
|
|
|
|
int uid = geteuid(); // get the effective user id
|
|
|
|
struct passwd *pwent = getpwuid (uid);
|
|
|
|
login_name = pwent->pw_name;
|
|
|
|
# else
|
|
|
|
login_name = getlogin();
|
|
|
|
if (!login_name)
|
|
|
|
login_name = cuserid(NULL);
|
|
|
|
# endif
|
|
|
|
}
|
1996-10-31 19:05:14 +00:00
|
|
|
#endif
|
1999-02-20 21:19:15 +00:00
|
|
|
if (login_name)
|
|
|
|
GSSetUserName([NSString stringWithCString: login_name]);
|
|
|
|
else
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Unable to determine curren user name"];
|
|
|
|
}
|
|
|
|
return theUserName;
|
1996-05-28 21:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the caller's home directory as an NSString object. */
|
|
|
|
NSString *
|
1999-07-13 15:59:50 +00:00
|
|
|
NSHomeDirectory(void)
|
1996-05-28 21:25:46 +00:00
|
|
|
{
|
1996-09-02 13:20:20 +00:00
|
|
|
return NSHomeDirectoryForUser (NSUserName ());
|
1996-05-28 21:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return LOGIN_NAME's home directory as an NSString object. */
|
|
|
|
NSString *
|
1999-07-13 15:59:50 +00:00
|
|
|
NSHomeDirectoryForUser(NSString *login_name)
|
1996-05-28 21:25:46 +00:00
|
|
|
{
|
2000-06-12 05:17:41 +00:00
|
|
|
#if !defined(__MINGW__)
|
1996-05-28 21:25:46 +00:00
|
|
|
struct passwd *pw;
|
2000-05-04 18:10:02 +00:00
|
|
|
|
|
|
|
[gnustep_global_lock lock];
|
1998-09-30 07:42:38 +00:00
|
|
|
pw = getpwnam ([login_name cString]);
|
2000-05-04 18:10:02 +00:00
|
|
|
[gnustep_global_lock unlock];
|
1996-05-28 21:25:46 +00:00
|
|
|
return [NSString stringWithCString: pw->pw_dir];
|
1996-07-15 18:41:44 +00:00
|
|
|
#else
|
1997-01-09 16:24:07 +00:00
|
|
|
/* Then environment variable HOMEPATH holds the home directory
|
|
|
|
for the user on Windows NT; Win95 has no concept of home. */
|
|
|
|
char buf[1024], *nb;
|
|
|
|
DWORD n;
|
|
|
|
NSString *s;
|
|
|
|
|
2000-05-04 18:10:02 +00:00
|
|
|
[gnustep_global_lock lock];
|
1997-01-09 16:24:07 +00:00
|
|
|
n = GetEnvironmentVariable("HOMEPATH", buf, 1024);
|
|
|
|
if (n > 1024)
|
|
|
|
{
|
|
|
|
/* Buffer not big enough, so dynamically allocate it */
|
1999-09-28 11:10:34 +00:00
|
|
|
nb = (char *)NSZoneMalloc(NSDefaultMallocZone(), sizeof(char)*(n+1));
|
1997-01-09 16:24:07 +00:00
|
|
|
n = GetEnvironmentVariable("HOMEPATH", nb, n+1);
|
|
|
|
nb[n] = '\0';
|
|
|
|
s = [NSString stringWithCString: nb];
|
1999-09-28 11:10:34 +00:00
|
|
|
NSZoneFree(NSDefaultMallocZone(), nb);
|
1997-01-09 16:24:07 +00:00
|
|
|
}
|
2000-06-12 05:17:41 +00:00
|
|
|
else if (n > 0)
|
1997-01-09 16:24:07 +00:00
|
|
|
{
|
|
|
|
/* null terminate it and return the string */
|
|
|
|
buf[n] = '\0';
|
2000-05-04 18:10:02 +00:00
|
|
|
s = [NSString stringWithCString: buf];
|
1997-01-09 16:24:07 +00:00
|
|
|
}
|
2000-06-12 05:17:41 +00:00
|
|
|
else
|
2001-03-03 09:14:56 +00:00
|
|
|
{
|
|
|
|
s = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s != nil)
|
|
|
|
{
|
|
|
|
n = GetEnvironmentVariable("HOMEDRIVE", buf, 1024);
|
|
|
|
buf[n] = '\0';
|
|
|
|
s = [[NSString stringWithCString: buf] stringByAppendingString: s];
|
|
|
|
}
|
2000-05-04 18:10:02 +00:00
|
|
|
[gnustep_global_lock unlock];
|
|
|
|
return s;
|
1996-07-15 18:41:44 +00:00
|
|
|
#endif
|
1996-05-28 21:25:46 +00:00
|
|
|
}
|
1998-12-15 19:11:58 +00:00
|
|
|
|
1999-07-13 15:59:50 +00:00
|
|
|
NSString *
|
|
|
|
NSFullUserName(void)
|
1998-12-15 19:11:58 +00:00
|
|
|
{
|
1999-04-13 20:37:04 +00:00
|
|
|
#if HAVE_PWD_H
|
|
|
|
struct passwd *pw;
|
|
|
|
|
|
|
|
pw = getpwnam([NSUserName() cString]);
|
|
|
|
return [NSString stringWithCString: pw->pw_gecos];
|
|
|
|
#else
|
1998-12-15 19:11:58 +00:00
|
|
|
NSLog(@"Warning: NSFullUserName not implemented\n");
|
|
|
|
return NSUserName();
|
1999-04-13 20:37:04 +00:00
|
|
|
#endif
|
1998-12-15 19:11:58 +00:00
|
|
|
}
|
|
|
|
|
1999-07-13 15:59:50 +00:00
|
|
|
NSArray *
|
|
|
|
GSStandardPathPrefixes(void)
|
1998-12-15 19:11:58 +00:00
|
|
|
{
|
1999-07-13 15:59:50 +00:00
|
|
|
NSDictionary *env;
|
|
|
|
NSString *prefixes;
|
|
|
|
NSArray *prefixArray;
|
|
|
|
|
|
|
|
env = [[NSProcessInfo processInfo] environment];
|
|
|
|
prefixes = [env objectForKey: @"GNUSTEP_PATHPREFIX_LIST"];
|
|
|
|
if (prefixes)
|
|
|
|
{
|
|
|
|
#if defined(__WIN32__)
|
|
|
|
prefixArray = [prefixes componentsSeparatedByString: @";"];
|
|
|
|
#else
|
|
|
|
prefixArray = [prefixes componentsSeparatedByString: @":"];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-01-28 12:16:44 +00:00
|
|
|
NSString *strings[4];
|
1999-07-13 15:59:50 +00:00
|
|
|
NSString *str;
|
|
|
|
unsigned count = 0;
|
|
|
|
|
|
|
|
str = [env objectForKey: @"GNUSTEP_USER_ROOT"];
|
|
|
|
if (str != nil)
|
|
|
|
strings[count++] = str;
|
|
|
|
|
|
|
|
str = [env objectForKey: @"GNUSTEP_LOCAL_ROOT"];
|
|
|
|
if (str != nil)
|
|
|
|
strings[count++] = str;
|
|
|
|
|
2001-01-28 12:16:44 +00:00
|
|
|
str = [env objectForKey: @"GNUSTEP_NETWORK_ROOT"];
|
|
|
|
if (str != nil)
|
|
|
|
strings[count++] = str;
|
|
|
|
|
1999-07-13 15:59:50 +00:00
|
|
|
str = [env objectForKey: @"GNUSTEP_SYSTEM_ROOT"];
|
|
|
|
if (str != nil)
|
|
|
|
strings[count++] = str;
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
prefixArray = [NSArray arrayWithObjects: strings count: count];
|
|
|
|
else
|
|
|
|
prefixArray = [NSArray array];
|
|
|
|
}
|
|
|
|
return prefixArray;
|
1998-12-15 19:11:58 +00:00
|
|
|
}
|
|
|
|
|
1999-07-13 15:59:50 +00:00
|
|
|
NSArray *
|
|
|
|
NSStandardApplicationPaths(void)
|
1998-12-15 19:11:58 +00:00
|
|
|
{
|
1999-07-13 15:59:50 +00:00
|
|
|
NSArray *prefixArray = GSStandardPathPrefixes();
|
|
|
|
unsigned numPrefixes = [prefixArray count];
|
|
|
|
|
|
|
|
if (numPrefixes > 0)
|
|
|
|
{
|
|
|
|
NSString *paths[numPrefixes];
|
|
|
|
unsigned count;
|
|
|
|
|
|
|
|
[prefixArray getObjects: paths];
|
|
|
|
for (count = 0; count < numPrefixes; count++)
|
|
|
|
{
|
|
|
|
paths[count]
|
|
|
|
= [paths[count] stringByAppendingPathComponent: @"Apps"];
|
|
|
|
}
|
|
|
|
return [NSArray arrayWithObjects: paths count: count];
|
|
|
|
}
|
|
|
|
return prefixArray; /* An empty array */
|
|
|
|
}
|
|
|
|
|
|
|
|
NSArray *
|
|
|
|
NSStandardLibraryPaths(void)
|
|
|
|
{
|
|
|
|
NSArray *prefixArray = GSStandardPathPrefixes();
|
|
|
|
unsigned numPrefixes = [prefixArray count];
|
|
|
|
|
|
|
|
if (numPrefixes > 0)
|
|
|
|
{
|
|
|
|
NSString *paths[numPrefixes];
|
|
|
|
unsigned count;
|
|
|
|
|
|
|
|
[prefixArray getObjects: paths];
|
|
|
|
for (count = 0; count < numPrefixes; count++)
|
|
|
|
{
|
|
|
|
paths[count]
|
|
|
|
= [paths[count] stringByAppendingPathComponent: @"Library"];
|
|
|
|
}
|
|
|
|
return [NSArray arrayWithObjects: paths count: count];
|
|
|
|
}
|
|
|
|
return prefixArray; /* An empty array */
|
1998-12-15 19:11:58 +00:00
|
|
|
}
|
|
|
|
|
1999-07-13 15:59:50 +00:00
|
|
|
NSString *
|
|
|
|
NSTemporaryDirectory(void)
|
1998-12-15 19:11:58 +00:00
|
|
|
{
|
|
|
|
NSFileManager *manager;
|
|
|
|
NSString *tempDirName, *baseTempDirName;
|
1999-05-11 09:21:38 +00:00
|
|
|
#if defined(__WIN32__)
|
1998-12-15 19:11:58 +00:00
|
|
|
char buffer[1024];
|
|
|
|
if (GetTempPath(1024, buffer))
|
|
|
|
baseTempDirName = [NSString stringWithCString: buffer];
|
|
|
|
else
|
|
|
|
baseTempDirName = @"C:\\";
|
|
|
|
#else
|
|
|
|
baseTempDirName = @"/tmp";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
tempDirName = [baseTempDirName stringByAppendingPathComponent: NSUserName()];
|
|
|
|
manager = [NSFileManager defaultManager];
|
|
|
|
if ([manager fileExistsAtPath: tempDirName] == NO)
|
|
|
|
{
|
|
|
|
NSDictionary *attr;
|
2000-02-24 09:26:19 +00:00
|
|
|
|
1998-12-15 19:11:58 +00:00
|
|
|
attr = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: 0700]
|
2000-02-24 09:26:19 +00:00
|
|
|
forKey: NSFilePosixPermissions];
|
1998-12-15 19:11:58 +00:00
|
|
|
if ([manager createDirectoryAtPath: tempDirName attributes: attr] == NO)
|
|
|
|
tempDirName = baseTempDirName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tempDirName;
|
|
|
|
}
|
|
|
|
|
1999-07-13 15:59:50 +00:00
|
|
|
NSString *
|
|
|
|
NSOpenStepRootDirectory(void)
|
1998-12-15 19:11:58 +00:00
|
|
|
{
|
2000-02-24 09:26:19 +00:00
|
|
|
NSString *root = [[[NSProcessInfo processInfo] environment]
|
|
|
|
objectForKey: @"GNUSTEP_ROOT"];
|
1998-12-16 22:30:56 +00:00
|
|
|
|
2000-02-24 09:26:19 +00:00
|
|
|
if (root == nil)
|
2000-06-12 05:17:41 +00:00
|
|
|
#if defined(__MINGW__)
|
1998-12-16 22:30:56 +00:00
|
|
|
root = @"C:\\";
|
1998-12-15 19:11:58 +00:00
|
|
|
#else
|
1998-12-16 22:30:56 +00:00
|
|
|
root = @"/";
|
1998-12-15 19:11:58 +00:00
|
|
|
#endif
|
1998-12-16 22:30:56 +00:00
|
|
|
return root;
|
1998-12-15 19:11:58 +00:00
|
|
|
}
|
|
|
|
|
2000-03-25 10:59:07 +00:00
|
|
|
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;
|
2001-01-28 12:16:44 +00:00
|
|
|
NSString *adminDir = @"Administrator";
|
2000-03-25 10:59:07 +00:00
|
|
|
NSString *appsDir = @"Apps";
|
2001-01-28 12:16:44 +00:00
|
|
|
NSString *devDir = @"Developer";
|
2000-03-25 10:59:07 +00:00
|
|
|
NSString *libraryDir = @"Library";
|
2001-01-28 12:16:44 +00:00
|
|
|
NSString *libsDir = @"Libraries";
|
2000-03-25 10:59:07 +00:00
|
|
|
NSString *docDir = @"Documentation";
|
|
|
|
NSMutableArray *paths = [NSMutableArray new];
|
|
|
|
NSString *path;
|
|
|
|
NSFileManager *fm;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
env = [[NSProcessInfo processInfo] environment];
|
2000-03-28 13:02:01 +00:00
|
|
|
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"];
|
2000-03-25 10:59:07 +00:00
|
|
|
|
|
|
|
if (directoryKey == NSApplicationDirectory
|
2000-03-28 13:02:01 +00:00
|
|
|
|| directoryKey == NSAllApplicationsDirectory)
|
2000-03-25 10:59:07 +00:00
|
|
|
{
|
|
|
|
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
|
2000-03-28 13:02:01 +00:00
|
|
|
|| directoryKey == NSAllApplicationsDirectory);
|
2001-01-28 12:16:44 +00:00
|
|
|
*/
|
2000-03-25 10:59:07 +00:00
|
|
|
if (directoryKey == NSDeveloperApplicationDirectory
|
2001-01-28 12:16:44 +00:00
|
|
|
|| directoryKey == NSAllApplicationsDirectory)
|
|
|
|
{
|
|
|
|
if (domainMask & NSUserDomainMask);
|
|
|
|
if (domainMask & NSLocalDomainMask)
|
|
|
|
[paths addObject: [NSString pathWithComponents:
|
|
|
|
[NSArray arrayWithObjects: gnustep_local_root,
|
|
|
|
devDir, appsDir, nil]]];
|
|
|
|
if (domainMask & NSNetworkDomainMask)
|
|
|
|
[paths addObject: [NSString pathWithComponents:
|
|
|
|
[NSArray arrayWithObjects: gnustep_network_root,
|
|
|
|
devDir, appsDir, nil]]];
|
|
|
|
if (domainMask & NSSystemDomainMask)
|
|
|
|
[paths addObject: [NSString pathWithComponents:
|
|
|
|
[NSArray arrayWithObjects: gnustep_system_root,
|
|
|
|
devDir, appsDir, nil]]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (directoryKey == NSAdminApplicationDirectory
|
2001-01-28 12:16:44 +00:00
|
|
|
|| directoryKey == NSAllApplicationsDirectory)
|
|
|
|
{
|
|
|
|
if (domainMask & NSUserDomainMask);
|
|
|
|
/* users have no Administrator directory */
|
|
|
|
if (domainMask & NSLocalDomainMask)
|
|
|
|
[paths addObject: [NSString pathWithComponents:
|
|
|
|
[NSArray arrayWithObjects: gnustep_local_root,
|
|
|
|
devDir, adminDir, nil]]];
|
|
|
|
if (domainMask & NSNetworkDomainMask)
|
|
|
|
[paths addObject: [NSString pathWithComponents:
|
|
|
|
[NSArray arrayWithObjects: gnustep_network_root,
|
|
|
|
devDir, adminDir, nil]]];
|
|
|
|
if (domainMask & NSSystemDomainMask)
|
|
|
|
[paths addObject: [NSString pathWithComponents:
|
|
|
|
[NSArray arrayWithObjects: gnustep_system_root,
|
|
|
|
devDir, adminDir, nil]]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (directoryKey == NSLibraryDirectory
|
2000-03-28 13:02:01 +00:00
|
|
|
|| directoryKey == NSAllLibrariesDirectory)
|
2000-03-25 10:59:07 +00:00
|
|
|
{
|
|
|
|
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]];
|
|
|
|
}
|
2001-01-28 12:16:44 +00:00
|
|
|
if (directoryKey == NSDeveloperDirectory)
|
2000-03-25 10:59:07 +00:00
|
|
|
{
|
2001-01-28 12:16:44 +00:00
|
|
|
if (domainMask & NSUserDomainMask);
|
|
|
|
/* users have no Developer directory */
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSLocalDomainMask)
|
2001-01-28 12:16:44 +00:00
|
|
|
[paths addObject:
|
|
|
|
[gnustep_local_root stringByAppendingPathComponent: devDir]];
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSNetworkDomainMask)
|
2001-01-28 12:16:44 +00:00
|
|
|
[paths addObject:
|
|
|
|
[gnustep_network_root stringByAppendingPathComponent: devDir]];
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSSystemDomainMask)
|
2001-01-28 12:16:44 +00:00
|
|
|
[paths addObject:
|
|
|
|
[gnustep_system_root stringByAppendingPathComponent: devDir]];
|
2000-03-25 10:59:07 +00:00
|
|
|
}
|
|
|
|
if (directoryKey == NSUserDirectory)
|
|
|
|
{
|
|
|
|
if (domainMask & NSUserDomainMask)
|
2001-01-28 12:16:44 +00:00
|
|
|
[paths addObject: [NSHomeDirectory()
|
|
|
|
stringByAppendingPathComponent: @"GNUstep"]];
|
2000-03-25 10:59:07 +00:00
|
|
|
}
|
|
|
|
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]];
|
|
|
|
}
|
2001-01-28 12:16:44 +00:00
|
|
|
if (directoryKey == GSLibrariesDirectory)
|
|
|
|
{
|
|
|
|
if (domainMask & NSUserDomainMask)
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_user_root stringByAppendingPathComponent: libsDir]];
|
|
|
|
if (domainMask & NSLocalDomainMask)
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_local_root stringByAppendingPathComponent: libsDir]];
|
|
|
|
if (domainMask & NSNetworkDomainMask)
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_network_root stringByAppendingPathComponent: libsDir]];
|
|
|
|
if (domainMask & NSSystemDomainMask)
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_system_root stringByAppendingPathComponent: libsDir]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
|
|
|
|
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]];
|
|
|
|
}
|
1998-12-15 19:11:58 +00:00
|
|
|
|
2000-03-25 10:59:07 +00:00
|
|
|
return paths;
|
|
|
|
}
|