2005-03-15 04:24:26 +00:00
|
|
|
/* Implementation of filesystem & path-related functions for GNUstep
|
|
|
|
Copyright (C) 1996-2004 Free Software Foundation, Inc.
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
Written by: Andrew Kachites McCallum <address@hidden>
|
2005-03-03 16:04:22 +00:00
|
|
|
Created: May 1996
|
2005-03-15 04:24:26 +00:00
|
|
|
Rewrite by: Sheldon Gill
|
|
|
|
Date: Jan 2004
|
2005-10-13 10:11:56 +00:00
|
|
|
Rewrites by: Richard Frith-Macdonald
|
|
|
|
Date: 2004-2005
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-03-03 16:04:22 +00:00
|
|
|
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.
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-03-03 16:04:22 +00:00
|
|
|
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.
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-03-03 16:04:22 +00:00
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
2005-05-22 03:32:16 +00:00
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
2005-03-03 16:04:22 +00:00
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
<title>NSPathUtilities function reference</title>
|
2005-03-03 16:04:22 +00:00
|
|
|
$Date$ $Revision$
|
|
|
|
*/
|
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
/**
|
|
|
|
<unit>
|
|
|
|
<heading>Path Utility Functions</heading>
|
|
|
|
<p>
|
|
|
|
Path utilities provides functions to dynamically discover paths
|
|
|
|
for the platform the application is running on.
|
|
|
|
This avoids the need for hard coding paths, making porting easier
|
|
|
|
and also allowing for places to change without breaking
|
|
|
|
applications.
|
|
|
|
(why do this? Well imagine we're running GNUstep 1 and the new
|
|
|
|
wonderful GNUstep 2 becomes available but we're not sure of it
|
|
|
|
yet. You could install /GNUstep/System2/ and have applications
|
|
|
|
use which ever System you wanted at the time...)
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
On unix systems, the paths are initialised by reading a configuration
|
|
|
|
file. Something like "/etc/GNUstep/GNUstep.conf". This provides the basic
|
|
|
|
information required by the library to establish all locations required.
|
|
|
|
</p>
|
|
|
|
<p>
|
2005-10-13 10:11:56 +00:00
|
|
|
On windows, the paths may also (as a fallback) be initialised by
|
|
|
|
reading information from the windows registry.
|
2005-03-15 04:24:26 +00:00
|
|
|
HKEY_LOCAL_MACHINE\Software\GNU\GNUstep contains the machine wide
|
|
|
|
definititions for system paths.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
See <REF "filesystem.pdf">GNUstep File System Heirarchy</REF> document
|
|
|
|
for more information and detailed descriptions.</p>
|
|
|
|
</unit>
|
|
|
|
*/
|
|
|
|
|
2005-03-03 16:04:22 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "GNUstepBase/preface.h"
|
|
|
|
#include "Foundation/NSObjCRuntime.h"
|
|
|
|
#include "Foundation/NSString.h"
|
|
|
|
#include "Foundation/NSPathUtilities.h"
|
|
|
|
#include "Foundation/NSException.h"
|
|
|
|
#include "Foundation/NSArray.h"
|
2005-03-15 04:24:26 +00:00
|
|
|
#include "Foundation/NSDebug.h"
|
2005-03-03 16:04:22 +00:00
|
|
|
#include "Foundation/NSDictionary.h"
|
|
|
|
#include "Foundation/NSFileManager.h"
|
|
|
|
#include "Foundation/NSProcessInfo.h"
|
|
|
|
#include "Foundation/NSString.h"
|
|
|
|
#include "Foundation/NSValue.h"
|
|
|
|
#include "Foundation/NSLock.h"
|
|
|
|
#include "Foundation/NSUserDefaults.h"
|
|
|
|
#include "GNUstepBase/GSCategories.h"
|
2005-03-15 04:24:26 +00:00
|
|
|
#if defined(__WIN32__)
|
|
|
|
#include "GNUstepBase/Win32_Utilities.h"
|
|
|
|
#endif
|
2005-03-03 16:04:22 +00:00
|
|
|
|
|
|
|
#include "GSPrivate.h"
|
2005-03-15 04:24:26 +00:00
|
|
|
#include "GNUstepBase/Win32Support.h"
|
2005-03-03 16:04:22 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2005-03-15 04:24:26 +00:00
|
|
|
#include <unistd.h> // for getuid()
|
2005-03-03 16:04:22 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
#include <pwd.h> // for getpwnam()
|
|
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
/* Defines used to highlight design decisions. It's possible these could
|
|
|
|
be made compile time or even user configurable.
|
|
|
|
*/
|
|
|
|
#define OPTION_PLATFORM_SUPPORT // To find platform specific things
|
|
|
|
|
2005-03-03 16:04:22 +00:00
|
|
|
#define lowlevelstringify(X) #X
|
|
|
|
#define stringify(X) lowlevelstringify(X)
|
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
/* The global configuration file. The real value is read from config.h */
|
|
|
|
#ifndef GNUSTEP_CONFIGURATION_FILE
|
2005-10-12 17:40:40 +00:00
|
|
|
# define GNUSTEP_CONFIGURATION_FILE /etc/GNUstep/GNUstep.conf
|
2005-03-15 04:24:26 +00:00
|
|
|
#endif
|
2005-03-15 06:36:21 +00:00
|
|
|
/* The name of the user-specific configuration file */
|
2005-03-15 04:24:26 +00:00
|
|
|
#define DEFAULT_STEPRC_FILE @".GNUsteprc"
|
2005-03-15 06:36:21 +00:00
|
|
|
/* The standard path for user Defaults files */
|
2005-03-15 04:24:26 +00:00
|
|
|
#define DEFAULT_DEFAULTS_PATH @"Defaults"
|
|
|
|
/* The standard path to user GNUstep resources */
|
|
|
|
#define DEFAULT_USER_ROOT @"GNUstep"
|
|
|
|
|
2005-03-17 14:48:32 +00:00
|
|
|
|
2005-07-31 08:18:19 +00:00
|
|
|
static NSString *gnustep_target_cpu =
|
|
|
|
#ifdef GNUSTEP_TARGET_CPU
|
|
|
|
@GNUSTEP_TARGET_CPU;
|
|
|
|
#else
|
|
|
|
nil;
|
|
|
|
#endif
|
|
|
|
static NSString *gnustep_target_os =
|
|
|
|
#ifdef GNUSTEP_TARGET_OS
|
|
|
|
@GNUSTEP_TARGET_OS;
|
|
|
|
#else
|
|
|
|
nil;
|
|
|
|
#endif
|
|
|
|
static NSString *library_combo =
|
|
|
|
#ifdef LIBRARY_COMBO
|
|
|
|
@LIBRARY_COMBO;
|
|
|
|
#else
|
|
|
|
nil;
|
|
|
|
#endif
|
|
|
|
static NSString *gnustep_flattened =
|
|
|
|
#ifdef GNUSTEP_FLATTENED
|
|
|
|
@GNUSTEP_FLATTENED;
|
|
|
|
#else
|
|
|
|
nil;
|
|
|
|
#endif
|
|
|
|
|
2005-03-17 14:48:32 +00:00
|
|
|
#define MGR() [NSFileManager defaultManager]
|
|
|
|
|
2005-03-18 09:42:54 +00:00
|
|
|
/*
|
|
|
|
* NB. use fprintf() rather than NSLog() to avoid possibility of recursion
|
|
|
|
* when features of NSLog() cause patrh utilities to be used.
|
|
|
|
*/
|
|
|
|
#define PrintOnce(format, args...) \
|
|
|
|
do { static BOOL beenHere = NO; if (beenHere == NO) {\
|
|
|
|
beenHere = YES; \
|
|
|
|
fprintf(stderr, format, ## args); }} while (0)
|
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
/* ------------------ */
|
|
|
|
/* Internal variables */
|
|
|
|
/* ------------------ */
|
2005-03-17 14:48:32 +00:00
|
|
|
|
|
|
|
static NSString *configFile;
|
2005-03-15 04:24:26 +00:00
|
|
|
|
|
|
|
/* We read these four paths only once */
|
2005-03-17 14:48:32 +00:00
|
|
|
static NSString *gnustepUserRoot = nil; /* GNUSTEP_USER_ROOT path */
|
|
|
|
static NSString *gnustepLocalRoot = nil; /* GNUSTEP_LOCAL_ROOT path */
|
|
|
|
static NSString *gnustepNetworkRoot = nil; /* GNUSTEP_NETWORK_ROOT path */
|
|
|
|
static NSString *gnustepSystemRoot = nil; /* GNUSTEP_SYSTEM_ROOT path */
|
2005-03-15 04:24:26 +00:00
|
|
|
|
2005-10-12 17:40:40 +00:00
|
|
|
static NSString *gnustepRcFileName = nil;
|
|
|
|
static NSString *gnustepDefaultsPath = nil;
|
|
|
|
static NSString *gnustepUserPath = nil;
|
2005-03-15 04:24:26 +00:00
|
|
|
|
|
|
|
static NSString *theUserName = nil; /* The user's login name */
|
|
|
|
static NSString *tempDir = nil; /* user's temporary directory */
|
|
|
|
|
|
|
|
#ifdef OPTION_PLATFORM_SUPPORT
|
2005-03-17 14:48:32 +00:00
|
|
|
static NSString *osSysPrefs = nil;
|
|
|
|
static NSString *osSysApps = nil;
|
|
|
|
static NSString *osSysLibs = nil;
|
|
|
|
static NSString *osSysAdmin = nil;
|
2005-03-15 04:24:26 +00:00
|
|
|
|
2005-03-17 14:48:32 +00:00
|
|
|
static NSString *platformResources = nil;
|
|
|
|
static NSString *platformApps = nil;
|
|
|
|
static NSString *platformLibs = nil;
|
|
|
|
static NSString *platformAdmin = nil;
|
2005-03-15 04:24:26 +00:00
|
|
|
|
2005-03-17 14:48:32 +00:00
|
|
|
static NSString *localResources = nil;
|
|
|
|
static NSString *localApps = nil;
|
|
|
|
static NSString *localLibs = nil;
|
2005-03-15 04:24:26 +00:00
|
|
|
|
|
|
|
/* Keys for Platform support in conf-file. */
|
|
|
|
#define SYS_APPS @"SYS_APPS"
|
|
|
|
#define SYS_LIBS @"SYS_LIBS"
|
|
|
|
#define SYS_PREFS @"SYS_PREFS"
|
|
|
|
#define SYS_ADMIN @"SYS_ADMIN"
|
|
|
|
#define SYS_RESOURCES @"SYS_RESOURCES"
|
|
|
|
|
|
|
|
#define PLATFORM_APPS @"PLATFORM_APPS"
|
|
|
|
#define PLATFORM_LIBS @"PLATFORM_LIBS"
|
|
|
|
#define PLATFORM_ADMIN @"PLATFORM_ADMIN"
|
|
|
|
#define PLATFORM_RESOURCES @"PLATFORM_RESOURCES"
|
|
|
|
|
|
|
|
#define PLATFORM_LOCAL_APPS @"PLATFORM_LOCAL_APPS"
|
|
|
|
#define PLATFORM_LOCAL_LIBS @"PLATFORM_LOCAL_LIBS"
|
|
|
|
#define PLATFORM_LOCAL_ADMIN @"PLATFORM_LOCAL_ADMIN"
|
|
|
|
#define PLATFORM_LOCAL_RESOURCES @"PLATFORM_LOCAL_RESOURCES"
|
|
|
|
#endif /* OPTION_PLATFORM_SUPPORT */
|
|
|
|
|
|
|
|
/* ============================= */
|
|
|
|
/* Internal function prototypes. */
|
|
|
|
/* ============================= */
|
|
|
|
|
2005-03-17 14:48:32 +00:00
|
|
|
static NSString *setUserGNUstepPath(NSString *userName,
|
|
|
|
NSString **defaultsPath,
|
|
|
|
NSString **userPath);
|
2005-03-15 04:24:26 +00:00
|
|
|
|
2005-03-15 06:36:21 +00:00
|
|
|
static NSDictionary *GSReadStepConfFile(NSString *name);
|
2005-03-15 04:24:26 +00:00
|
|
|
|
2005-03-17 15:27:52 +00:00
|
|
|
static void InitialisePathUtilities(void);
|
|
|
|
static void ShutdownPathUtilities(void);
|
2005-03-15 04:24:26 +00:00
|
|
|
|
2005-10-13 10:11:56 +00:00
|
|
|
/* Convenience MACRO to ease legibility and coding */
|
|
|
|
/* Conditionally assign lval to var */
|
|
|
|
#define ASSIGN_IF_SET(var, dictionary, key) ({\
|
|
|
|
id val = [dictionary objectForKey: key];\
|
|
|
|
if (val != nil) { RELEASE(var); var = RETAIN(val); }\
|
|
|
|
})
|
2005-03-03 16:04:22 +00:00
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
/* Convenience MACRO to ease legibility and coding */
|
|
|
|
/* Conditionally assign lval to var */
|
2005-03-17 14:48:32 +00:00
|
|
|
#define TEST_ASSIGN(var, lval) \
|
2005-03-15 04:24:26 +00:00
|
|
|
if ((var == nil)&&(lval != nil)) \
|
|
|
|
{ \
|
|
|
|
var = lval; \
|
|
|
|
}
|
2005-03-03 16:04:22 +00:00
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
/* Get a path string from a dictionary */
|
|
|
|
static inline NSString *
|
2005-03-17 14:48:32 +00:00
|
|
|
getPathConfig(NSDictionary *dict, NSString *key)
|
2005-03-03 16:04:22 +00:00
|
|
|
{
|
2005-03-15 04:24:26 +00:00
|
|
|
NSString *path;
|
|
|
|
|
|
|
|
NSCParameterAssert(dict!=nil);
|
2005-03-03 16:04:22 +00:00
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
path = [dict objectForKey: key];
|
|
|
|
TEST_RETAIN(path);
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read .GNUsteprc file for user and set paths accordingly
|
|
|
|
*/
|
2005-03-17 14:48:32 +00:00
|
|
|
static NSString *setUserGNUstepPath(NSString *userName,
|
|
|
|
NSString **defaultsPath,
|
|
|
|
NSString **userPath)
|
2005-03-15 04:24:26 +00:00
|
|
|
{
|
2005-10-12 06:15:15 +00:00
|
|
|
NSDictionary *dict;
|
|
|
|
NSString *home;
|
|
|
|
NSString *path;
|
|
|
|
NSString *steprcFile;
|
|
|
|
NSString *userRoot;
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
/* Look for rc file (".GNUsteprc") file in user's home directory */
|
|
|
|
home = NSHomeDirectoryForUser(userName);
|
|
|
|
if (home == nil)
|
|
|
|
{
|
|
|
|
/* It's OK if path is nil. We're might be running as user nobody in
|
2005-10-12 06:15:15 +00:00
|
|
|
* which case we don't want to access user stuff. Possibly it's a
|
|
|
|
* misconfigured Windows environment, though...
|
|
|
|
*/
|
2005-03-15 04:24:26 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2005-03-17 14:48:32 +00:00
|
|
|
if ([gnustepRcFileName length] > 0)
|
2005-03-15 04:24:26 +00:00
|
|
|
{
|
2005-03-17 14:48:32 +00:00
|
|
|
steprcFile = [home stringByAppendingPathComponent: gnustepRcFileName];
|
|
|
|
|
|
|
|
dict = GSReadStepConfFile(steprcFile);
|
2005-03-15 04:24:26 +00:00
|
|
|
if (dict != nil)
|
2005-03-17 14:48:32 +00:00
|
|
|
{
|
|
|
|
path = [dict objectForKey: @"GNUSTEP_DEFAULTS_ROOT"];
|
|
|
|
if (path != nil)
|
|
|
|
{
|
2005-10-12 06:15:15 +00:00
|
|
|
/*
|
|
|
|
* Special case for defaults root ... expand leading '~'
|
|
|
|
*/
|
|
|
|
if ([path hasPrefix: @"~"])
|
|
|
|
{
|
|
|
|
GSOnceFLog(@"Use of '~' in GNUSTEP_DEFAULTS_ROOT is deprecated");
|
|
|
|
path = [path substringFromIndex: 1];
|
|
|
|
while ([path hasPrefix: @"/"] || [path hasPrefix: @"\\"])
|
|
|
|
{
|
|
|
|
path = [path substringFromIndex: 1];
|
|
|
|
}
|
|
|
|
path = [home stringByAppendingPathComponent: path];
|
|
|
|
}
|
|
|
|
ASSIGN(*defaultsPath, path);
|
2005-03-17 14:48:32 +00:00
|
|
|
}
|
|
|
|
path = [dict objectForKey: @"GNUSTEP_USER_ROOT"];
|
|
|
|
if (path != nil)
|
|
|
|
{
|
2005-10-12 06:15:15 +00:00
|
|
|
/*
|
|
|
|
* For backward compatibility, remove leading '~' component
|
|
|
|
* we will prepend the home directory later.
|
|
|
|
*/
|
|
|
|
if ([path hasPrefix: @"~"])
|
|
|
|
{
|
|
|
|
GSOnceFLog(@"Use of '~' in GNUSTEP_USER_ROOT is deprecated");
|
|
|
|
path = [path substringFromIndex: 1];
|
|
|
|
while ([path hasPrefix: @"/"] || [path hasPrefix: @"\\"])
|
|
|
|
{
|
|
|
|
path = [path substringFromIndex: 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSIGN(*userPath, path);
|
2005-03-17 14:48:32 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-15 04:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set the user path and defaults directory to default values if needed */
|
2005-03-17 14:48:32 +00:00
|
|
|
TEST_ASSIGN(*defaultsPath, DEFAULT_DEFAULTS_PATH);
|
|
|
|
TEST_ASSIGN(*userPath, DEFAULT_USER_ROOT);
|
|
|
|
|
|
|
|
/* Now we set the user's root path for the gnustep files. */
|
|
|
|
if ([*userPath isAbsolutePath])
|
|
|
|
userRoot = *userPath;
|
2005-03-15 04:24:26 +00:00
|
|
|
else
|
2005-03-17 14:48:32 +00:00
|
|
|
userRoot = [home stringByAppendingPathComponent: *userPath];
|
|
|
|
return userRoot;
|
2005-03-15 04:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialise all things required by this module */
|
2005-03-17 15:27:52 +00:00
|
|
|
static void InitialisePathUtilities(void)
|
2005-03-15 04:24:26 +00:00
|
|
|
{
|
2005-10-12 08:40:48 +00:00
|
|
|
if (gnustepSystemRoot != nil)
|
2005-03-15 04:24:26 +00:00
|
|
|
{
|
2005-10-12 08:40:48 +00:00
|
|
|
return; // Protect from multiple calls
|
|
|
|
}
|
2005-10-12 07:03:18 +00:00
|
|
|
|
2005-10-12 08:40:48 +00:00
|
|
|
/* Set up our root paths */
|
|
|
|
NS_DURING
|
|
|
|
{
|
2005-10-12 17:40:40 +00:00
|
|
|
NSDictionary *env = [[NSProcessInfo processInfo] environment];
|
2005-03-15 04:24:26 +00:00
|
|
|
#if defined(__WIN32__)
|
2005-10-12 08:40:48 +00:00
|
|
|
HKEY regkey;
|
2005-03-15 04:24:26 +00:00
|
|
|
#endif
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-10-12 08:40:48 +00:00
|
|
|
/* Initialise Win32 things if on that platform */
|
|
|
|
Win32Initialise(); // should be called by DLL_PROCESS_ATTACH
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-10-12 08:40:48 +00:00
|
|
|
[gnustep_global_lock lock];
|
2005-03-15 04:24:26 +00:00
|
|
|
|
|
|
|
#ifndef OPTION_NO_ENVIRONMENT
|
2005-10-12 08:40:48 +00:00
|
|
|
/* First we look at the environment */
|
2005-10-12 17:40:40 +00:00
|
|
|
TEST_ASSIGN(gnustepSystemRoot,
|
|
|
|
[env objectForKey: @"GNUSTEP_SYSTEM_ROOT"]);
|
|
|
|
TEST_ASSIGN(gnustepNetworkRoot,
|
|
|
|
[env objectForKey: @"GNUSTEP_NETWORK_ROOT"]);
|
|
|
|
TEST_ASSIGN(gnustepLocalRoot,
|
|
|
|
[env objectForKey: @"GNUSTEP_LOCAL_ROOT"]);
|
2005-03-15 04:24:26 +00:00
|
|
|
#endif /* !OPTION_NO_ENVIRONMENT */
|
2005-10-12 17:40:40 +00:00
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
#if defined(__WIN32__)
|
2005-10-12 08:40:48 +00:00
|
|
|
regkey = Win32OpenRegistry(HKEY_LOCAL_MACHINE,
|
|
|
|
"\\Software\\GNU\\GNUstep");
|
|
|
|
if (regkey != (HKEY)NULL)
|
|
|
|
{
|
|
|
|
TEST_ASSIGN(gnustepSystemRoot,
|
2005-10-12 17:40:40 +00:00
|
|
|
Win32NSStringFromRegistry(regkey, @"GNUSTEP_SYSTEM_ROOT"));
|
2005-10-12 08:40:48 +00:00
|
|
|
TEST_ASSIGN(gnustepNetworkRoot,
|
2005-10-12 17:40:40 +00:00
|
|
|
Win32NSStringFromRegistry(regkey, @"GNUSTEP_NETWORK_ROOT"));
|
2005-10-12 08:40:48 +00:00
|
|
|
TEST_ASSIGN(gnustepLocalRoot,
|
2005-10-12 17:40:40 +00:00
|
|
|
Win32NSStringFromRegistry(regkey, @"GNUSTEP_LOCAL_ROOT"));
|
2005-10-12 08:40:48 +00:00
|
|
|
RegCloseKey(regkey);
|
|
|
|
}
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
#if 0
|
2005-10-12 08:40:48 +00:00
|
|
|
// Not implemented yet
|
|
|
|
platformApps = Win32FindDirectory(CLSID_APPS);
|
|
|
|
platformLibs = Win32FindDirectory(CLSID_LIBS);
|
2005-03-15 04:24:26 +00:00
|
|
|
#endif
|
|
|
|
#else
|
2005-10-12 08:40:48 +00:00
|
|
|
/* Now we source the configuration file if it exists */
|
2005-10-12 17:40:40 +00:00
|
|
|
configFile = [env objectForKey: @"GNUSTEP_CONFIGURATION_FILE"];
|
|
|
|
if (configFile == nil)
|
|
|
|
{
|
|
|
|
configFile
|
|
|
|
= [NSString stringWithCString:
|
|
|
|
stringify(GNUSTEP_CONFIGURATION_FILE)];
|
|
|
|
}
|
2005-10-12 08:40:48 +00:00
|
|
|
configFile = RETAIN([configFile stringByStandardizingPath]);
|
|
|
|
if ([MGR() fileExistsAtPath: configFile])
|
|
|
|
{
|
|
|
|
NSDictionary *d = GSReadStepConfFile(configFile);
|
2005-03-17 14:48:32 +00:00
|
|
|
|
2005-10-12 08:40:48 +00:00
|
|
|
if (d != nil)
|
|
|
|
{
|
2005-10-13 10:11:56 +00:00
|
|
|
ASSIGN_IF_SET(gnustepSystemRoot, d, @"GNUSTEP_SYSTEM_ROOT");
|
|
|
|
ASSIGN_IF_SET(gnustepNetworkRoot, d, @"GNUSTEP_NETWORK_ROOT");
|
|
|
|
ASSIGN_IF_SET(gnustepLocalRoot, d, @"GNUSTEP_LOCAL_ROOT");
|
2005-10-12 07:03:18 +00:00
|
|
|
|
2005-10-13 10:11:56 +00:00
|
|
|
ASSIGN_IF_SET(gnustepRcFileName, d, @"USER_GNUSTEP_RC");
|
|
|
|
ASSIGN_IF_SET(gnustepDefaultsPath, d, @"USER_GNUSTEP_DEFAULTS");
|
|
|
|
ASSIGN_IF_SET(gnustepUserPath, d, @"USER_GNUSTEP_DIR");
|
2005-03-17 14:48:32 +00:00
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
#ifdef OPTION_PLATFORM_SUPPORT
|
2005-10-13 10:11:56 +00:00
|
|
|
ASSIGN_IF_SET(osSysPrefs, d, SYS_PREFS);
|
|
|
|
ASSIGN_IF_SET(osSysApps, d, SYS_APPS);
|
|
|
|
ASSIGN_IF_SET(osSysLibs, d, SYS_LIBS);
|
|
|
|
ASSIGN_IF_SET(osSysAdmin, d, SYS_ADMIN);
|
|
|
|
|
|
|
|
ASSIGN_IF_SET(platformResources, d, PLATFORM_RESOURCES);
|
|
|
|
ASSIGN_IF_SET(platformApps, d, PLATFORM_APPS);
|
|
|
|
ASSIGN_IF_SET(platformLibs, d, PLATFORM_LIBS);
|
|
|
|
ASSIGN_IF_SET(platformAdmin, d, PLATFORM_ADMIN);
|
|
|
|
|
|
|
|
ASSIGN_IF_SET(localResources, d, PLATFORM_LOCAL_RESOURCES);
|
|
|
|
ASSIGN_IF_SET(localApps, d, PLATFORM_LOCAL_APPS);
|
|
|
|
ASSIGN_IF_SET(localLibs, d, PLATFORM_LOCAL_LIBS);
|
2005-03-15 04:24:26 +00:00
|
|
|
#endif /* OPTION_PLATFORM SUPPORT */
|
2005-03-17 14:48:32 +00:00
|
|
|
}
|
2005-10-12 08:40:48 +00:00
|
|
|
}
|
2005-03-17 15:27:52 +00:00
|
|
|
#endif
|
2005-03-15 04:24:26 +00:00
|
|
|
|
2005-10-12 08:40:48 +00:00
|
|
|
/* System admins may force the user and defaults paths by
|
|
|
|
* setting USER_GNUSTEP_RC to be an empty string.
|
|
|
|
* If they simply don't define it at all, we assign a default
|
|
|
|
* value here.
|
|
|
|
*/
|
|
|
|
TEST_ASSIGN(gnustepRcFileName, DEFAULT_STEPRC_FILE);
|
2005-10-12 07:03:18 +00:00
|
|
|
|
2005-10-12 08:40:48 +00:00
|
|
|
/* If the user has an rc file we need to source it */
|
|
|
|
gnustepUserRoot = setUserGNUstepPath(NSUserName(),
|
|
|
|
&gnustepDefaultsPath, &gnustepUserPath);
|
2005-10-12 07:03:18 +00:00
|
|
|
|
2005-10-12 08:40:48 +00:00
|
|
|
/* Finally we check and report problems... */
|
|
|
|
if (gnustepSystemRoot == nil)
|
|
|
|
{
|
2005-10-13 10:11:56 +00:00
|
|
|
gnustepSystemRoot = [NSString stringWithCString:\
|
|
|
|
STRINGIFY(GNUSTEP_INSTALL_PREFIX)];
|
2005-10-12 08:40:48 +00:00
|
|
|
fprintf (stderr, "Warning - GNUSTEP_SYSTEM_ROOT is not set " \
|
|
|
|
"- using %s\n", [gnustepSystemRoot lossyCString]);
|
|
|
|
}
|
|
|
|
if (gnustepNetworkRoot == nil)
|
|
|
|
{
|
2005-10-13 10:11:56 +00:00
|
|
|
gnustepNetworkRoot = [NSString stringWithCString:\
|
|
|
|
STRINGIFY(GNUSTEP_NETWORK_ROOT)];
|
2005-10-12 08:40:48 +00:00
|
|
|
fprintf (stderr, "Warning - GNUSTEP_NETWORK_ROOT is not set " \
|
|
|
|
"- using %s\n", [gnustepNetworkRoot lossyCString]);
|
2005-10-12 07:03:18 +00:00
|
|
|
}
|
2005-10-12 08:40:48 +00:00
|
|
|
if (gnustepLocalRoot == nil)
|
2005-10-12 07:03:18 +00:00
|
|
|
{
|
2005-10-13 10:11:56 +00:00
|
|
|
gnustepLocalRoot = [NSString stringWithCString:\
|
|
|
|
STRINGIFY(GNUSTEP_LOCAL_ROOT)];
|
2005-10-12 08:40:48 +00:00
|
|
|
fprintf (stderr, "Warning - GNUSTEP_LOCAL_ROOT is not set " \
|
|
|
|
"- using %s\n", [gnustepLocalRoot lossyCString]);
|
2005-10-12 07:03:18 +00:00
|
|
|
}
|
2005-10-12 08:40:48 +00:00
|
|
|
|
|
|
|
[gnustep_global_lock unlock];
|
2005-03-15 04:24:26 +00:00
|
|
|
}
|
2005-10-12 08:40:48 +00:00
|
|
|
NS_HANDLER
|
|
|
|
{
|
|
|
|
/* unlock then re-raise the exception */
|
|
|
|
[gnustep_global_lock unlock];
|
|
|
|
[localException raise];
|
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
2005-03-15 04:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close down and release all things allocated.
|
|
|
|
*/
|
2005-03-17 15:27:52 +00:00
|
|
|
static void ShutdownPathUtilities(void)
|
2005-03-15 04:24:26 +00:00
|
|
|
{
|
2005-10-12 07:03:18 +00:00
|
|
|
DESTROY(gnustepSystemRoot);
|
|
|
|
DESTROY(gnustepNetworkRoot);
|
|
|
|
DESTROY(gnustepLocalRoot);
|
|
|
|
DESTROY(gnustepUserRoot);
|
2005-03-15 04:24:26 +00:00
|
|
|
|
2005-10-12 07:03:18 +00:00
|
|
|
DESTROY(gnustepRcFileName);
|
|
|
|
DESTROY(gnustepDefaultsPath);
|
|
|
|
DESTROY(gnustepUserPath);
|
2005-03-15 04:24:26 +00:00
|
|
|
|
|
|
|
#ifdef OPTION_PLATFORM_SUPPORT
|
2005-10-12 07:03:18 +00:00
|
|
|
DESTROY(osSysPrefs);
|
|
|
|
DESTROY(osSysApps);
|
|
|
|
DESTROY(osSysLibs);
|
|
|
|
DESTROY(osSysAdmin);
|
|
|
|
|
|
|
|
DESTROY(platformResources);
|
|
|
|
DESTROY(platformApps);
|
|
|
|
DESTROY(platformLibs);
|
|
|
|
DESTROY(platformAdmin);
|
|
|
|
|
|
|
|
DESTROY(localResources);
|
|
|
|
DESTROY(localApps);
|
|
|
|
DESTROY(localLibs);
|
2005-03-15 04:24:26 +00:00
|
|
|
#endif /* OPTION_PLATFORM SUPPORT */
|
|
|
|
|
2005-10-12 07:03:18 +00:00
|
|
|
DESTROY(tempDir);
|
2005-03-15 04:24:26 +00:00
|
|
|
|
|
|
|
/* Shutdown Win32 support */
|
|
|
|
Win32Finalise();
|
2005-03-03 16:04:22 +00:00
|
|
|
}
|
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
|
2005-03-03 16:04:22 +00:00
|
|
|
/**
|
2005-03-15 04:24:26 +00:00
|
|
|
* Reads a file and expects it to be in basic unix "conf" style format with
|
2005-10-13 10:11:56 +00:00
|
|
|
* one key = value per line (the format a unix shell can 'source' in order
|
|
|
|
* to define shell variables).<br />
|
|
|
|
* The key must be an unquoted string containing only alphanumerics and
|
|
|
|
* the underscore character. It may not begin with a digit, though it may
|
|
|
|
* be preceeded by whitespace (which is ignored).<br />
|
|
|
|
* The '=' must appear <em>immediately after the key.<br />
|
|
|
|
* The value may be any quoted string ... any leading or trailing whitespace
|
|
|
|
* (except inside a quoted string) is removed.<br />
|
2005-03-15 04:24:26 +00:00
|
|
|
* Lines beginning with a hash '#' are deemed comment lines and ignored.<br/ >
|
2005-10-13 10:11:56 +00:00
|
|
|
* The backslash character may be used as an escape character anywhere
|
|
|
|
* in the file except within a singly quoted string
|
|
|
|
* (where it is taken literally) ... in particular it may be used at
|
|
|
|
* the end of a line to join two lines together.
|
|
|
|
* However, in contrast to normal shell usage,
|
|
|
|
* we do not allow newline characters within a quoted string.<br />
|
|
|
|
* NB. Since windows uses backslash characters in paths, it is a good
|
|
|
|
* idea to specify path values in the config file as singly quoted
|
|
|
|
* strings to avoid having to double all occurrances of the backslash.<br />
|
|
|
|
* Creates a dictionary of the (key,value) pairs.<br/ >
|
2005-03-03 16:04:22 +00:00
|
|
|
*/
|
2005-03-15 06:36:21 +00:00
|
|
|
static NSDictionary *
|
|
|
|
GSReadStepConfFile(NSString *fileName)
|
2005-03-03 16:04:22 +00:00
|
|
|
{
|
2005-03-15 04:24:26 +00:00
|
|
|
NSMutableDictionary *dict;
|
2005-03-17 14:48:32 +00:00
|
|
|
NSDictionary *attributes;
|
2005-03-15 04:24:26 +00:00
|
|
|
NSString *file;
|
|
|
|
NSArray *lines;
|
2005-10-13 10:11:56 +00:00
|
|
|
NSRange r;
|
2005-03-15 04:24:26 +00:00
|
|
|
unsigned count;
|
|
|
|
|
2005-03-17 14:48:32 +00:00
|
|
|
if ([MGR() isReadableFileAtPath: fileName] == NO)
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
attributes = [MGR() fileAttributesAtPath: fileName traverseLink: YES];
|
|
|
|
if (([attributes filePosixPermissions] & 022) != 0)
|
|
|
|
{
|
2005-10-09 10:41:53 +00:00
|
|
|
#if defined(__WIN32__)
|
|
|
|
fprintf(stderr, "The file '%S' is writable by someone other than"
|
|
|
|
" its owner.\nIgnoring it.\n",
|
|
|
|
(const unichar*)[fileName fileSystemRepresentation]);
|
|
|
|
#else
|
2005-03-17 14:48:32 +00:00
|
|
|
fprintf(stderr, "The file '%s' is writable by someone other than"
|
|
|
|
" its owner.\nIgnoring it.\n", [fileName fileSystemRepresentation]);
|
2005-10-09 10:41:53 +00:00
|
|
|
#endif
|
2005-03-17 14:48:32 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2005-10-13 10:11:56 +00:00
|
|
|
dict = [NSMutableDictionary dictionaryWithCapacity: 16];
|
2005-03-15 04:24:26 +00:00
|
|
|
if (dict == nil)
|
|
|
|
{
|
|
|
|
return nil; // should throw an exception??
|
|
|
|
}
|
|
|
|
|
|
|
|
file = [NSString stringWithContentsOfFile: fileName];
|
2005-10-13 10:11:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow DOS (CRLF) and Mac (CR) line termination as well as the normal LF
|
|
|
|
*/
|
|
|
|
r = [file rangeOfString: @"\r\n"];
|
|
|
|
if (r.length > 0)
|
|
|
|
{
|
|
|
|
file = [file stringByReplacingString: @"\r\n" withString: @"\n"];
|
|
|
|
}
|
|
|
|
r = [file rangeOfString: @"\r"];
|
|
|
|
if (r.length > 0)
|
|
|
|
{
|
|
|
|
file = [file stringByReplacingString: @"\r" withString: @"\n"];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove any escaped newline characters.
|
|
|
|
*/
|
|
|
|
r = [file rangeOfString: @"\\\n"];
|
|
|
|
if (r.length > 0)
|
|
|
|
{
|
|
|
|
file = [file stringByReplacingString: @"\\\n" withString: @""];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Split files into lines
|
|
|
|
*/
|
2005-03-15 04:24:26 +00:00
|
|
|
lines = [file componentsSeparatedByString: @"\n"];
|
|
|
|
count = [lines count];
|
|
|
|
|
|
|
|
while (count-- > 0)
|
2005-03-03 16:04:22 +00:00
|
|
|
{
|
2005-03-15 04:24:26 +00:00
|
|
|
NSString *line;
|
|
|
|
NSString *key;
|
|
|
|
NSString *val;
|
|
|
|
|
|
|
|
line = [[lines objectAtIndex: count] stringByTrimmingSpaces];
|
|
|
|
|
2005-10-13 10:11:56 +00:00
|
|
|
if (([line length] > 0) && ([line characterAtIndex: 0] != '#'))
|
2005-03-17 14:48:32 +00:00
|
|
|
{
|
|
|
|
r = [line rangeOfString: @"="];
|
|
|
|
if (r.length == 1)
|
|
|
|
{
|
2005-10-13 10:11:56 +00:00
|
|
|
unsigned length;
|
|
|
|
|
2005-03-17 14:48:32 +00:00
|
|
|
key = [line substringToIndex: r.location];
|
|
|
|
val = [line substringFromIndex: NSMaxRange(r)];
|
|
|
|
|
|
|
|
key = [key stringByTrimmingSpaces];
|
|
|
|
val = [val stringByTrimmingSpaces];
|
|
|
|
|
2005-10-13 10:11:56 +00:00
|
|
|
if ((length = [val length]) > 0)
|
|
|
|
{
|
|
|
|
unichar c = [val characterAtIndex: 0];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Strip quotes from the value if necessary.
|
|
|
|
*/
|
|
|
|
if (c == '\'' || c == '"')
|
|
|
|
{
|
|
|
|
if (length > 1 && [val characterAtIndex: length-1] == c)
|
|
|
|
{
|
|
|
|
r = NSMakeRange(1, length-2);
|
|
|
|
val = [val substringWithRange: r];
|
|
|
|
length -= 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val = [val substringFromIndex: 1];
|
|
|
|
length -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle backslash quotes (except in a singly quoted string).
|
|
|
|
*/
|
|
|
|
if (c != '\'')
|
|
|
|
{
|
|
|
|
r = [val rangeOfString: @"\\"];
|
|
|
|
if (r.length > 0)
|
|
|
|
{
|
|
|
|
unichar buf[length];
|
|
|
|
unsigned pos;
|
|
|
|
|
|
|
|
[val getCharacters: buf];
|
|
|
|
for (pos = 0; pos < length; pos++)
|
|
|
|
{
|
|
|
|
if (buf[pos] == '\\')
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = pos + 1; i < length; i++)
|
|
|
|
{
|
|
|
|
buf[i-1] = buf[i];
|
|
|
|
}
|
|
|
|
length--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val = [NSString stringWithCharacters: buf
|
|
|
|
length: length];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-03-17 14:48:32 +00:00
|
|
|
if ([key length] > 0)
|
2005-10-12 08:40:48 +00:00
|
|
|
{
|
|
|
|
[dict setObject: val forKey: key];
|
|
|
|
}
|
2005-03-17 14:48:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
key = [line stringByTrimmingSpaces];
|
|
|
|
val = nil;
|
|
|
|
}
|
|
|
|
}
|
2005-03-03 16:04:22 +00:00
|
|
|
}
|
2005-03-15 04:24:26 +00:00
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See NSPathUtilities.h for description */
|
|
|
|
void
|
|
|
|
GSSetUserName(NSString *aName)
|
|
|
|
{
|
|
|
|
NSCParameterAssert([aName length] > 0);
|
|
|
|
|
2005-03-03 16:04:22 +00:00
|
|
|
/*
|
2005-03-15 04:24:26 +00:00
|
|
|
* Do nothing if it's not a different user.
|
2005-03-03 16:04:22 +00:00
|
|
|
*/
|
2005-03-15 04:24:26 +00:00
|
|
|
if ([theUserName isEqualToString: aName])
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release the memory
|
2005-03-15 06:36:21 +00:00
|
|
|
*/
|
2005-03-15 04:24:26 +00:00
|
|
|
[gnustep_global_lock lock];
|
|
|
|
ShutdownPathUtilities();
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-03-03 16:04:22 +00:00
|
|
|
/*
|
2005-03-15 04:24:26 +00:00
|
|
|
* Reset things as new user
|
2005-03-03 16:04:22 +00:00
|
|
|
*/
|
2005-03-15 04:24:26 +00:00
|
|
|
ASSIGN(theUserName, aName);
|
|
|
|
InitialisePathUtilities();
|
2005-03-03 16:04:22 +00:00
|
|
|
[NSUserDefaults resetStandardUserDefaults];
|
2005-03-15 04:24:26 +00:00
|
|
|
|
|
|
|
[gnustep_global_lock unlock];
|
2005-03-03 16:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-03-15 04:24:26 +00:00
|
|
|
* Return the caller's login name as an NSString object.<br/ >
|
2005-03-03 16:04:22 +00:00
|
|
|
* Under unix-like systems, the name associated with the current
|
2005-03-15 04:24:26 +00:00
|
|
|
* effective user ID is used.<br/ >
|
|
|
|
* Under ms-windows, the 'LOGNAME' environemnt is used, or if that fails, the
|
|
|
|
* GetUserName() call is used to find the user name.
|
2005-03-03 16:04:22 +00:00
|
|
|
*/
|
|
|
|
/* NOTE FOR DEVELOPERS.
|
|
|
|
* If you change the behavior of this method you must also change
|
|
|
|
* user_home.c in the makefiles package to match.
|
|
|
|
*/
|
|
|
|
NSString *
|
|
|
|
NSUserName(void)
|
|
|
|
{
|
|
|
|
#if defined(__WIN32__)
|
|
|
|
if (theUserName == nil)
|
|
|
|
{
|
|
|
|
const char *loginName = 0;
|
|
|
|
/* The GetUserName function returns the current user name */
|
|
|
|
char buf[1024];
|
|
|
|
DWORD n = 1024;
|
|
|
|
|
|
|
|
if (GetEnvironmentVariable("LOGNAME", buf, 1024) != 0 && buf[0] != '\0')
|
|
|
|
loginName = buf;
|
|
|
|
else if (GetUserName(buf, &n) != 0 && buf[0] != '\0')
|
|
|
|
loginName = buf;
|
|
|
|
if (loginName)
|
|
|
|
theUserName = [[NSString alloc] initWithCString: loginName];
|
|
|
|
else
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Unable to determine current user name"];
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* Set olduid to some invalid uid that we could never start off running
|
|
|
|
as. */
|
|
|
|
static int olduid = -1;
|
|
|
|
#ifdef HAVE_GETEUID
|
|
|
|
int uid = geteuid();
|
|
|
|
#else
|
|
|
|
int uid = getuid();
|
|
|
|
#endif /* HAVE_GETEUID */
|
|
|
|
|
|
|
|
if (theUserName == nil || uid != olduid)
|
|
|
|
{
|
|
|
|
const char *loginName = 0;
|
|
|
|
#ifdef HAVE_GETPWUID
|
|
|
|
struct passwd *pwent = getpwuid (uid);
|
|
|
|
loginName = pwent->pw_name;
|
|
|
|
#endif /* HAVE_GETPWUID */
|
|
|
|
olduid = uid;
|
|
|
|
if (loginName)
|
|
|
|
theUserName = [[NSString alloc] initWithCString: loginName];
|
|
|
|
else
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Unable to determine current user name"];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return theUserName;
|
|
|
|
}
|
|
|
|
|
2005-03-15 04:24:26 +00:00
|
|
|
|
2005-03-03 16:04:22 +00:00
|
|
|
/**
|
|
|
|
* Return the caller's home directory as an NSString object.
|
|
|
|
* Calls NSHomeDirectoryForUser() to do this.
|
|
|
|
*/
|
|
|
|
NSString *
|
|
|
|
NSHomeDirectory(void)
|
|
|
|
{
|
|
|
|
return NSHomeDirectoryForUser (NSUserName ());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns loginName's home directory as an NSString object.
|
|
|
|
*/
|
|
|
|
/* NOTE FOR DEVELOPERS.
|
|
|
|
* If you change the behavior of this method you must also change
|
|
|
|
* user_home.c in the makefiles package to match.
|
|
|
|
*/
|
|
|
|
NSString *
|
|
|
|
NSHomeDirectoryForUser(NSString *loginName)
|
|
|
|
{
|
|
|
|
NSString *s = nil;
|
2005-10-11 19:09:26 +00:00
|
|
|
#if !defined(__MINGW32__)
|
2005-03-03 16:04:22 +00:00
|
|
|
struct passwd *pw;
|
|
|
|
|
|
|
|
[gnustep_global_lock lock];
|
|
|
|
pw = getpwnam ([loginName cString]);
|
2005-03-15 04:24:26 +00:00
|
|
|
if (pw != 0 && pw->pw_dir != NULL)
|
2005-03-03 16:04:22 +00:00
|
|
|
{
|
|
|
|
s = [NSString stringWithCString: pw->pw_dir];
|
|
|
|
}
|
|
|
|
[gnustep_global_lock unlock];
|
|
|
|
#else
|
2005-03-15 04:24:26 +00:00
|
|
|
s = Win32GetUserProfileDirectory(loginName);
|
2005-03-03 16:04:22 +00:00
|
|
|
#endif
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the full username of the current user.
|
|
|
|
* If unable to determine this, returns the standard user name.
|
|
|
|
*/
|
|
|
|
NSString *
|
|
|
|
NSFullUserName(void)
|
|
|
|
{
|
2005-03-15 04:24:26 +00:00
|
|
|
#if defined(__WIN32__)
|
|
|
|
/* FIXME: Win32 way to get full user name via Net API */
|
|
|
|
return NSUserName();
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_PWD_H
|
2005-03-03 16:04:22 +00:00
|
|
|
struct passwd *pw;
|
|
|
|
|
|
|
|
pw = getpwnam([NSUserName() cString]);
|
|
|
|
return [NSString stringWithCString: pw->pw_gecos];
|
|
|
|
#else
|
|
|
|
NSLog(@"Warning: NSFullUserName not implemented\n");
|
|
|
|
return NSUserName();
|
2005-03-15 04:24:26 +00:00
|
|
|
#endif /* HAVE_PWD_H */
|
|
|
|
#endif /* defined(__Win32__) else */
|
2005-03-03 16:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-03-15 04:24:26 +00:00
|
|
|
* Return the path of the defaults directory for userName.<br />
|
2005-03-03 16:04:22 +00:00
|
|
|
* This examines the .GNUsteprc file in the home directory of the
|
|
|
|
* user for the GNUSTEP_DEFAULTS_ROOT or the GNUSTEP_USER_ROOT
|
2005-03-15 04:24:26 +00:00
|
|
|
* directory definitions, over-riding those in GNUstep.conf.
|
2005-03-03 16:04:22 +00:00
|
|
|
*/
|
2005-03-15 04:24:26 +00:00
|
|
|
NSString *
|
2005-03-03 16:04:22 +00:00
|
|
|
GSDefaultsRootForUser(NSString *userName)
|
|
|
|
{
|
2005-03-15 04:24:26 +00:00
|
|
|
NSString *home;
|
2005-03-17 14:48:32 +00:00
|
|
|
NSString *defaultsPath = nil;
|
|
|
|
NSString *userPath = nil;
|
2005-03-03 16:04:22 +00:00
|
|
|
|
2005-03-17 15:27:52 +00:00
|
|
|
if ([userName length] == 0)
|
|
|
|
{
|
|
|
|
userName = NSUserName();
|
|
|
|
}
|
2005-10-12 07:03:18 +00:00
|
|
|
InitialisePathUtilities();
|
2005-03-15 04:24:26 +00:00
|
|
|
if ([userName isEqual: NSUserName()])
|
2005-03-03 16:04:22 +00:00
|
|
|
{
|
2005-03-17 14:48:32 +00:00
|
|
|
home = gnustepUserRoot;
|
|
|
|
defaultsPath = gnustepDefaultsPath;
|
2005-03-03 16:04:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-17 14:48:32 +00:00
|
|
|
home = setUserGNUstepPath(userName, &defaultsPath, &userPath);
|
2005-03-03 16:04:22 +00:00
|
|
|
}
|
|
|
|
|
2005-03-17 14:48:32 +00:00
|
|
|
if ([defaultsPath isAbsolutePath])
|
2005-03-03 16:04:22 +00:00
|
|
|
{
|
2005-03-17 14:48:32 +00:00
|
|
|
home = defaultsPath;
|
2005-03-03 16:04:22 +00:00
|
|
|
}
|
2005-03-15 04:24:26 +00:00
|
|
|
else if (home != nil)
|
|
|
|
{
|
2005-03-17 14:48:32 +00:00
|
|
|
home = [home stringByAppendingPathComponent: defaultsPath];
|
2005-03-15 04:24:26 +00:00
|
|
|
}
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-10-13 10:11:56 +00:00
|
|
|
return home;
|
2005-03-03 16:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the standard paths in which applications are stored and
|
2005-03-15 04:24:26 +00:00
|
|
|
* should be searched for. Calls NSSearchPathForDirectoriesInDomains()<br/ >
|
|
|
|
* Refer to the GNUstep File System Heirarchy documentation for more info.
|
2005-03-03 16:04:22 +00:00
|
|
|
*/
|
|
|
|
NSArray *
|
|
|
|
NSStandardApplicationPaths(void)
|
|
|
|
{
|
|
|
|
return NSSearchPathForDirectoriesInDomains(NSAllApplicationsDirectory,
|
|
|
|
NSAllDomainsMask, YES);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-03-15 04:24:26 +00:00
|
|
|
* Returns the standard paths in which resources are stored and
|
|
|
|
* should be searched for. Calls NSSearchPathForDirectoriesInDomains()<br/ >
|
|
|
|
* Refer to the GNUstep File System Heirarchy documentation for more info.
|
2005-03-03 16:04:22 +00:00
|
|
|
*/
|
|
|
|
NSArray *
|
|
|
|
NSStandardLibraryPaths(void)
|
|
|
|
{
|
|
|
|
return NSSearchPathForDirectoriesInDomains(NSAllLibrariesDirectory,
|
|
|
|
NSAllDomainsMask, YES);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the name of a directory in which temporary files can be stored.
|
|
|
|
* Under GNUstep this is a location which is not readable by other users.
|
|
|
|
* <br />
|
|
|
|
* If a suitable directory can't be found or created, this function raises an
|
|
|
|
* NSGenericException.
|
|
|
|
*/
|
|
|
|
NSString *
|
|
|
|
NSTemporaryDirectory(void)
|
|
|
|
{
|
|
|
|
NSFileManager *manager;
|
|
|
|
NSString *tempDirName;
|
|
|
|
NSString *baseTempDirName = nil;
|
|
|
|
NSDictionary *attr;
|
|
|
|
int perm;
|
|
|
|
int owner;
|
|
|
|
BOOL flag;
|
|
|
|
#if !defined(__WIN32__)
|
|
|
|
int uid;
|
|
|
|
#else
|
|
|
|
char buffer[1024];
|
|
|
|
|
|
|
|
if (GetTempPath(1024, buffer))
|
|
|
|
{
|
2005-10-13 10:11:56 +00:00
|
|
|
baseTempDirName = [NSString stringWithCString: buffer];
|
2005-03-03 16:04:22 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user has supplied a directory name in the TEMP or TMP
|
|
|
|
* environment variable, attempt to use that unless we already
|
2005-04-12 17:01:30 +00:00
|
|
|
* have a temporary directory specified.
|
2005-03-03 16:04:22 +00:00
|
|
|
*/
|
|
|
|
if (baseTempDirName == nil)
|
|
|
|
{
|
|
|
|
NSDictionary *env = [[NSProcessInfo processInfo] environment];
|
|
|
|
|
|
|
|
baseTempDirName = [env objectForKey: @"TEMP"];
|
|
|
|
if (baseTempDirName == nil)
|
|
|
|
{
|
|
|
|
baseTempDirName = [env objectForKey: @"TMP"];
|
|
|
|
if (baseTempDirName == nil)
|
|
|
|
{
|
2005-10-11 19:09:26 +00:00
|
|
|
#if defined(__MINGW32__)
|
2005-03-03 16:04:22 +00:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
baseTempDirName = @"/cygdrive/c/";
|
|
|
|
#else
|
|
|
|
baseTempDirName = @"/c/";
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
baseTempDirName = @"/tmp";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that the base directory exists ... if it doesn't we can't
|
|
|
|
* go any further.
|
|
|
|
*/
|
|
|
|
tempDirName = baseTempDirName;
|
|
|
|
manager = [NSFileManager defaultManager];
|
|
|
|
if ([manager fileExistsAtPath: tempDirName isDirectory: &flag] == NO
|
|
|
|
|| flag == NO)
|
|
|
|
{
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
format: @"Temporary directory (%@) does not exist",
|
|
|
|
tempDirName];
|
|
|
|
return nil; /* Not reached. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that we are the directory owner, and that we, and nobody else,
|
|
|
|
* have access to it. If other people have access, try to create a secure
|
|
|
|
* subdirectory.
|
|
|
|
*/
|
|
|
|
attr = [manager fileAttributesAtPath: tempDirName traverseLink: YES];
|
|
|
|
owner = [[attr objectForKey: NSFileOwnerAccountID] intValue];
|
|
|
|
perm = [[attr objectForKey: NSFilePosixPermissions] intValue];
|
|
|
|
perm = perm & 0777;
|
|
|
|
|
|
|
|
// Mateu Batle: secure temporary directories don't work in MinGW
|
2005-10-11 19:09:26 +00:00
|
|
|
#ifndef __MINGW32__
|
2005-03-03 16:04:22 +00:00
|
|
|
|
2005-10-11 19:09:26 +00:00
|
|
|
#if defined(__MINGW32__)
|
2005-03-03 16:04:22 +00:00
|
|
|
uid = owner;
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_GETEUID
|
|
|
|
uid = geteuid();
|
|
|
|
#else
|
|
|
|
uid = getuid();
|
|
|
|
#endif /* HAVE_GETEUID */
|
|
|
|
#endif
|
|
|
|
if ((perm != 0700 && perm != 0600) || owner != uid)
|
|
|
|
{
|
2005-04-12 17:01:30 +00:00
|
|
|
NSString *secure;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The name of the secure subdirectory reflects the user ID rather
|
|
|
|
* than the user name, since it is possible to have an account with
|
|
|
|
* lots of names on a unix system (ie multiple entries in the password
|
|
|
|
* file but a single userid). The private directory is secure within
|
|
|
|
* the account, not to a particular user name.
|
|
|
|
*/
|
|
|
|
secure = [NSString stringWithFormat: @"GNUstepSecure%d", uid];
|
|
|
|
tempDirName
|
|
|
|
= [baseTempDirName stringByAppendingPathComponent: secure];
|
2005-03-03 16:04:22 +00:00
|
|
|
/*
|
|
|
|
NSLog(@"Temporary directory (%@) may be insecure ... attempting to "
|
|
|
|
@"add secure subdirectory", tempDirName);
|
|
|
|
*/
|
|
|
|
if ([manager fileExistsAtPath: tempDirName] == NO)
|
|
|
|
{
|
|
|
|
NSNumber *p = [NSNumber numberWithInt: 0700];
|
|
|
|
|
|
|
|
attr = [NSDictionary dictionaryWithObject: p
|
|
|
|
forKey: NSFilePosixPermissions];
|
|
|
|
if ([manager createDirectoryAtPath: tempDirName
|
|
|
|
attributes: attr] == NO)
|
|
|
|
{
|
|
|
|
[NSException raise: NSGenericException
|
2005-04-12 17:01:30 +00:00
|
|
|
format:
|
|
|
|
@"Attempt to create a secure temporary directory (%@) failed.",
|
2005-03-03 16:04:22 +00:00
|
|
|
tempDirName];
|
|
|
|
return nil; /* Not reached. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that the new directory is really secure.
|
|
|
|
*/
|
|
|
|
attr = [manager fileAttributesAtPath: tempDirName traverseLink: YES];
|
|
|
|
owner = [[attr objectForKey: NSFileOwnerAccountID] intValue];
|
|
|
|
perm = [[attr objectForKey: NSFilePosixPermissions] intValue];
|
|
|
|
perm = perm & 0777;
|
|
|
|
if ((perm != 0700 && perm != 0600) || owner != uid)
|
|
|
|
{
|
|
|
|
[NSException raise: NSGenericException
|
2005-04-12 17:01:30 +00:00
|
|
|
format:
|
|
|
|
@"Attempt to create a secure temporary directory (%@) failed.",
|
2005-03-03 16:04:22 +00:00
|
|
|
tempDirName];
|
|
|
|
return nil; /* Not reached. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ([manager isWritableFileAtPath: tempDirName] == NO)
|
|
|
|
{
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
format: @"Temporary directory (%@) is not writable",
|
|
|
|
tempDirName];
|
|
|
|
return nil; /* Not reached. */
|
|
|
|
}
|
|
|
|
return tempDirName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-03-15 04:24:26 +00:00
|
|
|
* Deprecated function. Returns the location of the <em>root</em>
|
2005-03-15 06:36:21 +00:00
|
|
|
* directory of the GNUstep file heirarchy. Don't assume that /System,
|
2005-03-15 04:24:26 +00:00
|
|
|
* /Network etc exist in this path! Use other path utility functions for that.
|
|
|
|
* Refer to the GNUstep File System Heirarchy documentation for more info.
|
2005-03-03 16:04:22 +00:00
|
|
|
*/
|
|
|
|
NSString *
|
|
|
|
NSOpenStepRootDirectory(void)
|
|
|
|
{
|
|
|
|
NSString *root;
|
|
|
|
|
|
|
|
root = [[[NSProcessInfo processInfo] environment]
|
|
|
|
objectForKey: @"GNUSTEP_ROOT"];
|
|
|
|
if (root == nil)
|
|
|
|
{
|
2005-10-11 19:09:26 +00:00
|
|
|
#if defined(__MINGW32__)
|
2005-03-03 16:04:22 +00:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
root = @"/cygdrive/c/";
|
|
|
|
#else
|
|
|
|
root = @"~c/";
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
root = @"/";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-03-15 04:24:26 +00:00
|
|
|
* Returns an array of search paths to look at for resources.<br/ >
|
2005-07-25 05:18:19 +00:00
|
|
|
* The paths are returned in domain order: USER, LOCAL, NETWORK then SYSTEM.
|
2005-03-03 16:04:22 +00:00
|
|
|
*/
|
|
|
|
NSArray *
|
2005-03-15 06:36:21 +00:00
|
|
|
NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory directoryKey,
|
2005-03-03 16:04:22 +00:00
|
|
|
NSSearchPathDomainMask domainMask, BOOL expandTilde)
|
|
|
|
{
|
2005-03-15 04:24:26 +00:00
|
|
|
static NSString *adminDir = @"Administrator";
|
|
|
|
static NSString *appsDir = @"Applications";
|
|
|
|
static NSString *devDir = @"Developer";
|
|
|
|
static NSString *demosDir = @"Demos";
|
|
|
|
static NSString *libraryDir = @"Library";
|
|
|
|
static NSString *supportDir = @"ApplicationSupport";
|
2005-03-15 06:36:21 +00:00
|
|
|
static NSString *docDir = @"Documentation";
|
2005-03-15 04:24:26 +00:00
|
|
|
static NSString *fontsDir = @"Fonts";
|
|
|
|
static NSString *frameworkDir = @"Frameworks";
|
|
|
|
static NSString *libsDir = @"Libraries";
|
|
|
|
static NSString *toolsDir = @"Tools";
|
|
|
|
NSMutableArray *paths = [NSMutableArray new];
|
|
|
|
NSString *path;
|
|
|
|
unsigned i;
|
|
|
|
unsigned count;
|
2005-03-03 16:04:22 +00:00
|
|
|
|
2005-10-12 07:03:18 +00:00
|
|
|
InitialisePathUtilities();
|
|
|
|
|
2005-03-17 14:48:32 +00:00
|
|
|
NSCAssert(gnustepSystemRoot!=nil,@"Path utilities without initialisation!");
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-03-03 16:04:22 +00:00
|
|
|
/*
|
|
|
|
* The order in which we return paths is important - user must come
|
|
|
|
* first, followed by local, followed by network, followed by system.
|
|
|
|
* The calling code can then loop on the returned paths, and stop as
|
|
|
|
* soon as it finds something. So things in user automatically
|
|
|
|
* override things in system etc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ADD_PATH(mask, base_dir, add_dir) \
|
|
|
|
if (domainMask & mask) \
|
|
|
|
{ \
|
|
|
|
path = [base_dir stringByAppendingPathComponent: add_dir]; \
|
2005-07-25 05:18:19 +00:00
|
|
|
if (path != nil && [paths containsObject: path] == NO) \
|
2005-03-03 16:04:22 +00:00
|
|
|
[paths addObject: path]; \
|
|
|
|
}
|
2005-03-15 04:24:26 +00:00
|
|
|
#ifdef OPTION_PLATFORM_SUPPORT
|
|
|
|
#define ADD_PLATFORM_PATH(mask, add_dir) \
|
|
|
|
if (domainMask & mask) \
|
|
|
|
{ \
|
2005-07-25 05:18:19 +00:00
|
|
|
if (add_dir != nil && [paths containsObject: add_dir] == NO) \
|
2005-03-15 04:24:26 +00:00
|
|
|
[paths addObject: add_dir]; \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define ADD_PLATFORM_PATH(mask, add_dir)
|
|
|
|
#endif /* OPTION_PLATFORM_SUPPORT */
|
2005-03-03 16:04:22 +00:00
|
|
|
|
2005-07-25 05:18:19 +00:00
|
|
|
switch (directoryKey)
|
2005-03-03 16:04:22 +00:00
|
|
|
{
|
2005-07-25 05:18:19 +00:00
|
|
|
case NSAllApplicationsDirectory:
|
|
|
|
{
|
|
|
|
NSString *devDemosDir;
|
|
|
|
NSString *devAppsDir;
|
|
|
|
NSString *devAdminDir;
|
2005-03-03 16:04:22 +00:00
|
|
|
|
2005-07-25 05:18:19 +00:00
|
|
|
devDemosDir = [devDir stringByAppendingPathComponent: demosDir];
|
|
|
|
devAppsDir = [devDir stringByAppendingPathComponent: appsDir];
|
|
|
|
devAdminDir = [devDir stringByAppendingPathComponent: adminDir];
|
2005-03-03 16:04:22 +00:00
|
|
|
|
2005-07-25 05:18:19 +00:00
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserRoot, appsDir);
|
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserRoot, devAppsDir);
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-07-25 05:18:19 +00:00
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, appsDir);
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, devAppsDir);
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, devAdminDir);
|
2005-03-15 04:24:26 +00:00
|
|
|
|
2005-07-25 05:18:19 +00:00
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, appsDir);
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, devAppsDir);
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, devAdminDir);
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-07-25 05:18:19 +00:00
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, appsDir);
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, devAppsDir);
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, devAdminDir);
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-07-25 05:18:19 +00:00
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, devDemosDir);
|
2005-03-15 06:36:21 +00:00
|
|
|
|
2005-07-25 05:18:19 +00:00
|
|
|
ADD_PLATFORM_PATH(NSLocalDomainMask, localApps);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, platformApps);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, osSysApps);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, osSysAdmin);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, platformAdmin);
|
|
|
|
}
|
|
|
|
break;
|
2005-03-15 04:24:26 +00:00
|
|
|
|
2005-07-25 05:18:19 +00:00
|
|
|
case NSApplicationDirectory:
|
|
|
|
{
|
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserRoot, appsDir);
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, appsDir);
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, appsDir);
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, appsDir);
|
|
|
|
|
|
|
|
ADD_PLATFORM_PATH(NSLocalDomainMask, localApps);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, platformApps);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, osSysApps);
|
|
|
|
}
|
|
|
|
break;
|
2005-03-15 04:24:26 +00:00
|
|
|
|
2005-07-25 05:18:19 +00:00
|
|
|
case NSDemoApplicationDirectory:
|
|
|
|
{
|
|
|
|
NSString *devDemosDir;
|
2005-03-17 14:48:32 +00:00
|
|
|
|
2005-07-25 05:18:19 +00:00
|
|
|
devDemosDir = [devDir stringByAppendingPathComponent: demosDir];
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, devDemosDir);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSDeveloperApplicationDirectory:
|
|
|
|
{
|
|
|
|
NSString *devAppsDir;
|
|
|
|
|
|
|
|
devAppsDir = [devDir stringByAppendingPathComponent: appsDir];
|
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserRoot, devAppsDir);
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, devAppsDir);
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, devAppsDir);
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, devAppsDir);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSAdminApplicationDirectory:
|
|
|
|
{
|
|
|
|
NSString *devAdminDir;
|
|
|
|
|
|
|
|
devAdminDir = [devDir stringByAppendingPathComponent: adminDir];
|
|
|
|
/* NSUserDomainMask - users have no Administrator directory */
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, devAdminDir);
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, devAdminDir);
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, devAdminDir);
|
|
|
|
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, osSysAdmin);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, platformAdmin);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSAllLibrariesDirectory:
|
|
|
|
{
|
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserRoot, libraryDir);
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, libraryDir);
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, libraryDir);
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, libraryDir);
|
|
|
|
|
|
|
|
ADD_PLATFORM_PATH(NSLocalDomainMask, localResources);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, platformResources);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSLibraryDirectory:
|
|
|
|
{
|
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserRoot, libraryDir);
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, libraryDir);
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, libraryDir);
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, libraryDir);
|
|
|
|
|
|
|
|
ADD_PLATFORM_PATH(NSLocalDomainMask, localResources);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, platformResources);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSDeveloperDirectory:
|
|
|
|
{
|
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserRoot, devDir);
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, devDir);
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, devDir);
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, devDir);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSUserDirectory:
|
|
|
|
{
|
|
|
|
if (domainMask & NSUserDomainMask)
|
|
|
|
{
|
|
|
|
[paths addObject: gnustepUserRoot];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSDocumentationDirectory:
|
|
|
|
{
|
|
|
|
NSString *gsdocDir;
|
|
|
|
|
|
|
|
gsdocDir = [libraryDir stringByAppendingPathComponent: docDir];
|
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserRoot, gsdocDir);
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, gsdocDir);
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, gsdocDir);
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, gsdocDir);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Now the GNUstep additions */
|
|
|
|
case GSApplicationSupportDirectory:
|
|
|
|
{
|
|
|
|
NSString *appSupDir;
|
|
|
|
|
|
|
|
appSupDir = [libraryDir stringByAppendingPathComponent: supportDir];
|
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserRoot, appSupDir);
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, appSupDir);
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, appSupDir);
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, appSupDir);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSFrameworksDirectory:
|
|
|
|
{
|
|
|
|
NSString *frameDir;
|
|
|
|
|
|
|
|
frameDir = [libraryDir stringByAppendingPathComponent: frameworkDir];
|
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserRoot, frameDir);
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, frameDir);
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, frameDir);
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, frameDir);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSFontsDirectory:
|
|
|
|
{
|
|
|
|
NSString *fontDir;
|
|
|
|
|
|
|
|
fontDir = [libraryDir stringByAppendingPathComponent: fontsDir];
|
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserRoot, fontDir);
|
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, fontDir);
|
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, fontDir);
|
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, fontDir);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSLibrariesDirectory:
|
|
|
|
{
|
|
|
|
NSString *gslibsDir;
|
2005-07-31 08:18:19 +00:00
|
|
|
NSString *full = nil;
|
|
|
|
NSString *part = nil;
|
2005-07-25 05:18:19 +00:00
|
|
|
|
|
|
|
gslibsDir = [libraryDir stringByAppendingPathComponent: libsDir];
|
2005-07-31 08:18:19 +00:00
|
|
|
if ([gnustep_flattened boolValue] == NO
|
|
|
|
&& gnustep_target_cpu != nil && gnustep_target_os != nil)
|
|
|
|
{
|
|
|
|
part = [gnustep_target_cpu stringByAppendingPathComponent:
|
|
|
|
gnustep_target_os];
|
|
|
|
if (library_combo != nil)
|
|
|
|
{
|
|
|
|
full = [part stringByAppendingPathComponent: library_combo];
|
|
|
|
full = [gslibsDir stringByAppendingPathComponent: full];
|
|
|
|
}
|
|
|
|
part = [gslibsDir stringByAppendingPathComponent: part];
|
|
|
|
}
|
|
|
|
|
2005-07-25 05:18:19 +00:00
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserRoot, gslibsDir);
|
2005-07-31 08:18:19 +00:00
|
|
|
if (full) ADD_PATH(NSUserDomainMask, gnustepUserRoot, full);
|
|
|
|
if (part) ADD_PATH(NSUserDomainMask, gnustepUserRoot, part);
|
2005-07-25 05:18:19 +00:00
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, gslibsDir);
|
2005-07-31 08:18:19 +00:00
|
|
|
if (full) ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, full);
|
|
|
|
if (part) ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, part);
|
2005-07-25 05:18:19 +00:00
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, gslibsDir);
|
2005-07-31 08:18:19 +00:00
|
|
|
if (full) ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, full);
|
|
|
|
if (part) ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, part);
|
2005-07-25 05:18:19 +00:00
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, gslibsDir);
|
2005-07-31 08:18:19 +00:00
|
|
|
if (full) ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, full);
|
|
|
|
if (part) ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, part);
|
2005-07-25 05:18:19 +00:00
|
|
|
|
|
|
|
ADD_PLATFORM_PATH(NSLocalDomainMask, localLibs);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, platformLibs);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, osSysLibs);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSToolsDirectory:
|
|
|
|
{
|
2005-07-31 08:18:19 +00:00
|
|
|
NSString *full = nil;
|
|
|
|
NSString *part = nil;
|
|
|
|
|
|
|
|
if ([gnustep_flattened boolValue] == NO
|
|
|
|
&& gnustep_target_cpu != nil && gnustep_target_os != nil)
|
|
|
|
{
|
|
|
|
part = [gnustep_target_cpu stringByAppendingPathComponent:
|
|
|
|
gnustep_target_os];
|
|
|
|
if (library_combo != nil)
|
|
|
|
{
|
|
|
|
full = [part stringByAppendingPathComponent: library_combo];
|
|
|
|
full = [toolsDir stringByAppendingPathComponent: full];
|
|
|
|
}
|
|
|
|
part = [toolsDir stringByAppendingPathComponent: part];
|
|
|
|
}
|
|
|
|
|
2005-07-25 05:18:19 +00:00
|
|
|
ADD_PATH(NSUserDomainMask, gnustepUserRoot, toolsDir);
|
2005-07-31 08:18:19 +00:00
|
|
|
if (full) ADD_PATH(NSUserDomainMask, gnustepUserRoot, full);
|
|
|
|
if (part) ADD_PATH(NSUserDomainMask, gnustepUserRoot, part);
|
2005-07-25 05:18:19 +00:00
|
|
|
ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, toolsDir);
|
2005-07-31 08:18:19 +00:00
|
|
|
if (full) ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, full);
|
|
|
|
if (part) ADD_PATH(NSLocalDomainMask, gnustepLocalRoot, part);
|
2005-07-25 05:18:19 +00:00
|
|
|
ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, toolsDir);
|
2005-07-31 08:18:19 +00:00
|
|
|
if (full) ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, full);
|
|
|
|
if (part) ADD_PATH(NSNetworkDomainMask, gnustepNetworkRoot, part);
|
2005-07-25 05:18:19 +00:00
|
|
|
ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, toolsDir);
|
2005-07-31 08:18:19 +00:00
|
|
|
if (full) ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, full);
|
|
|
|
if (part) ADD_PATH(NSSystemDomainMask, gnustepSystemRoot, part);
|
2005-07-25 05:18:19 +00:00
|
|
|
|
|
|
|
ADD_PLATFORM_PATH(NSLocalDomainMask, localApps);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, platformApps);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, osSysApps);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, platformAdmin);
|
|
|
|
ADD_PLATFORM_PATH(NSSystemDomainMask, osSysAdmin);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSPreferencesDirectory:
|
|
|
|
{
|
|
|
|
// Not used
|
|
|
|
}
|
|
|
|
break;
|
2005-03-03 16:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef ADD_PATH
|
2005-03-15 04:24:26 +00:00
|
|
|
#undef ADD_PLATFORM_PATH
|
2005-03-03 16:04:22 +00:00
|
|
|
|
|
|
|
count = [paths count];
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
path = [paths objectAtIndex: i];
|
2005-03-15 04:24:26 +00:00
|
|
|
|
|
|
|
/* remove paths which don't exist on this system */
|
2005-03-17 14:48:32 +00:00
|
|
|
if ([MGR() fileExistsAtPath: path] == NO)
|
2005-03-03 16:04:22 +00:00
|
|
|
{
|
|
|
|
[paths removeObjectAtIndex: i];
|
2005-03-15 04:24:26 +00:00
|
|
|
i--;
|
|
|
|
count--;
|
2005-03-03 16:04:22 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* 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 == YES)
|
2005-03-15 04:24:26 +00:00
|
|
|
{
|
|
|
|
[paths replaceObjectAtIndex: i
|
|
|
|
withObject: [path stringByExpandingTildeInPath]];
|
|
|
|
}
|
2005-03-03 16:04:22 +00:00
|
|
|
else
|
2005-03-15 04:24:26 +00:00
|
|
|
{
|
|
|
|
[paths replaceObjectAtIndex: i
|
|
|
|
withObject: [path stringByAbbreviatingWithTildeInPath]];
|
|
|
|
}
|
2005-03-03 16:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AUTORELEASE (paths);
|
|
|
|
return paths;
|
|
|
|
}
|