* Start on integrating Sheldon Gills NSPathUtilities patches.

* Headers/Foundation/NSPathUtilities.h: Depreciate
GSSystemRootDirectory, GSStandardPathPrefixes. Add
GSPreferencesDirectory to NSSearchPathDirectory enum. Enumerate
NSSearchPathDomainMask values.
* Headers/Additions/GNUStepBase/Win32Support.h,
Headers/Additions/GNUStepBase/Win32_Utilites.h: New files.
* Source/GNUmakefile: Add NSPathUtilities.m
* Source/NSUser.m: Move everything in here...
* Source/NSPathUtilities.m: to here.
* Source/win32/GNUmakefile: Add Win32Support.m, Win32_Utilities.m
* Source/win32Win32Support.m, Win32_Utilities.m: New files
* Testing/nspathutilites.m: New file.
(Files and patches from Sheldon Gill with minor modifications).


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20837 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 2005-03-03 16:04:22 +00:00
parent 55b01ec39a
commit 26633b348b
12 changed files with 1700 additions and 1103 deletions

View file

@ -1,3 +1,20 @@
2005-03-03 Adam Fedor <fedor@gnu.org>
* Start on integrating Sheldon Gills NSPathUtilities patches.
* Headers/Foundation/NSPathUtilities.h: Depreciate
GSSystemRootDirectory, GSStandardPathPrefixes. Add
GSPreferencesDirectory to NSSearchPathDirectory enum. Enumerate
NSSearchPathDomainMask values.
* Headers/Additions/GNUStepBase/Win32Support.h,
Headers/Additions/GNUStepBase/Win32_Utilites.h: New files.
* Source/GNUmakefile: Add NSPathUtilities.m
* Source/NSUser.m: Move everything in here...
* Source/NSPathUtilities.m: to here.
* Source/win32/GNUmakefile: Add Win32Support.m, Win32_Utilities.m
* Source/win32Win32Support.m, Win32_Utilities.m: New files
* Testing/nspathutilites.m: New file.
(Files and patches from Sheldon Gill with minor modifications).
2005-03-02 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/Foundation/NSKeyValueCoding.h:

View file

@ -0,0 +1,37 @@
/* Useful support functions for GNUstep under MS-Windows
Copyright (C) 2004 Free Software Foundation, Inc.
Written by: Sheldon Gill <address@hidden>
Created: Dec 2003
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
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef __Win32Support_h_GNUSTEP_BASE_INCLUDE
#define __Win32Support_h_GNUSTEP_BASE_INCLUDE
#if defined(__WIN32__)
void Win32Initialise(void);
void Win32Finalise(void);
#else
#define Win32Initialise()
#define Win32Finalise()
#endif /* defined(__WIN32__) else */
#endif /* __WIN32Support_h_GNUSTEP_BASE_INCLUDE */

View file

@ -0,0 +1,59 @@
/** Win32 Utility support functions for GNUStep
Copyright (C) 2004 Free Software Foundation, Inc.
Written by: Sheldon Gill <address@hidden>
Date: 2004
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
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
AutogsdocSource: Win32_Utilities.m
*/
#ifndef __Win32_Utilities_h_GNUSTEP_BASE_INCLUDE
#define __Win32_Utilities_h_GNUSTEP_BASE_INCLUDE
/* TODO:
- Win32GetUserProfileDirectory()
Find profile directory for non-current user.
- Win32FindDirectory()
NOT IMPLEMENTED YET!
-Win32NSNumberFromRegistry()
NOT IMPLEMENTED YET!
-Win32NSDataFromRegistry()
NOT IMPLEMENTED YET!
*/
#if defined(__WIN32__)
/* ---- Init Functions ---- */
void Win32_Utilities_init(void);
void Win32_Utilities_fini(void);
/* ---- Environment Functions ---- */
NSString *Win32NSStringFromEnvironmentVariable(const char * envVar);
/* ---- Registry Functions ---- */
HKEY Win32OpenRegistry(DWORD hive, const char *key);
NSString *Win32NSStringFromRegistry(HKEY regkey, const char *regValue);
// NSNumber *Win32NSNumberFromRegistry(HKEY regkey, const char *regValue);
// NSData *Win32NSDataFromRegistry(HKEY regkey, const char *regValue);
/* ---- Path Functions ---- */
NSString *Win32GetUserProfileDirectory(NSString *userName);
NSString *Win32FindDirectory( DWORD DirCLSID );
#endif /* defined(__WIN32__) */
#endif /* */

View file

@ -20,7 +20,7 @@
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
AutogsdocSource: NSUser.m
AutogsdocSource: NSPathUtilities.m
*/
#ifndef __NSPathUtilities_h_GNUSTEP_BASE_INCLUDE
@ -34,15 +34,22 @@
* LOGNAME environment variable. Using it will almost certainly cause
* trouble if the process does not posess the file access priviliges of the
* new name. This is provided primarily for use by processes that run as
* system-manager and need to act as particular users. If uses the
* system-manager and need to act as particular users. It uses the
* [NSUserDefaults +resetUserDefaults] extension to reset the defaults system
* to use the defaults belonging to the new user.
*/
GS_EXPORT void GSSetUserName(NSString *name);
GS_EXPORT void GSSetUserName(NSString *name);
/**
* Try to locate file/directory (aName).(anExtension) in paths.
* Will return the first found or nil if nothing is found.
*/
//GS_EXPORT NSString *GSFindNamedFile(NSArray *paths, NSString *aName, NSString *anExtension);
GS_EXPORT NSString *GSDefaultsRootForUser(NSString *userName);
GS_EXPORT NSString *GSSystemRootDirectory(void);
GS_EXPORT NSArray *GSStandardPathPrefixes(void);
GS_EXPORT NSString *GSSystemRootDirectory(void) GS_ATTRIB_DEPRECATED;
GS_EXPORT NSArray *GSStandardPathPrefixes(void) GS_ATTRIB_DEPRECATED;
#endif
GS_EXPORT NSString *NSUserName(void);
GS_EXPORT NSString *NSHomeDirectory(void);
@ -82,24 +89,37 @@ typedef enum
NSDeveloperDirectory,
NSUserDirectory,
NSDocumentationDirectory,
/* Apple Reserved Directory Identifiers */
NSAllApplicationsDirectory,
NSAllLibrariesDirectory,
/* GNUstep Directory Identifiers */
//GSApplicationSupportDirectory = 150,
//GSFontsDirectory,
//GSFrameworksDirectory,
GSLibrariesDirectory,
GSToolsDirectory,
GSApplicationSupportDirectory,
} NSSearchPathDirectory;
GSPreferencesDirectory
} NSSearchPathDirectory;
/**
* Mask type for NSSearchPathForDirectoriesInDomains() function. A bitwise OR
* of one or more of <code>NSUserDomainMask, NSLocalDomainMask,
* NSNetworkDomainMask, NSSystemDomainMask, NSAllDomainsMask</code>.
*/
typedef unsigned int NSSearchPathDomainMask;
#define NSUserDomainMask 0x00000001
#define NSLocalDomainMask 0x00000002
#define NSNetworkDomainMask 0x00000004
#define NSSystemDomainMask 0x00000008
#define NSAllDomainsMask 0xffffffff
typedef enum
{
NSUserDomainMask = 1,
NSLocalDomainMask = 2,
NSNetworkDomainMask = 4,
NSSystemDomainMask = 8,
NSAllDomainsMask = 0xffffffff,
} NSSearchPathDomainMask;
GS_EXPORT NSArray *NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory directoryKey, NSSearchPathDomainMask domainMask, BOOL expandTilde);
GS_EXPORT NSString *NSFullUserName(void);

View file

@ -205,6 +205,7 @@ NSNumberFormatter.m \
NSObjCRuntime.m \
NSObject.m \
NSPage.m \
NSPathUtilities.m \
NSPipe.m \
NSPort.m \
NSPortCoder.m \
@ -239,6 +240,9 @@ externs.m \
objc-load.m
ifneq ($(GNUSTEP_TARGET_OS), mingw32)
ADD_HEADERS += \
Win32_Utilities.h
BASE_MFILES += \
NSMessagePort.m \
NSMessagePortNameServer.m

1116
Source/NSPathUtilities.m Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -32,7 +32,9 @@ SUBPROJECT_NAME = win32
win32_OBJC_FILES =\
GSRunLoopCtxt.m \
GSRunLoopWatcher.m \
NSRunLoopWin32.m
NSRunLoopWin33.m \
Win32Support.m \
Win32_Utilities.m
-include Makefile.preamble

View file

@ -0,0 +1,46 @@
/* Useful support functions for GNUstep under MS-Windows
Copyright (C) 2004-2005 Free Software Foundation, Inc.
Written by: Sheldon Gill <address@hidden>
Created: Dec 2003
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
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include "Win32_Utilities.h"
//#include "Win32_FileManagement.h"
/*
* Perform any and all necessary initialisation for supporting Win32
* Called after first part of library initialisation so some Obj-C is okay
*/
void Win32Initialise(void)
{
/* We call the initialisation routines of all support modules in turn */
Win32_Utilities_init();
// Win32_FileManagement_init();
}
/*
* Free and finalise all things for supporting Win32
*/
void Win32Finalise(void)
{
/* We call the finalisation routines of all support modules in turn */
Win32_Utilities_fini(void);
// Win32_FileManagement_fini();
}

View file

@ -0,0 +1,219 @@
/* Useful support functions for GNUstep under MS-Windows
Copyright (C) 2004-2005 Free Software Foundation, Inc.
Written by: Sheldon Gill <address@hidden>
Created: Dec 2003
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
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include <Foundation/NSString.h>
#include <Foundation/NSProcessInfo.h>
#include <Foundation/NSException.h>
#include "Win32_Utilities.h"
/* ------------------ */
/* Internal Variables */
/* ------------------ */
/* ------+---------+---------+---------+---------+---------+---------+---------+
#pragma mark -
#pragma mark -<Registry functions>-
---------+---------+---------+---------+---------+---------+---------+------- */
/**
* Returns a hive key or 0 if unable.
*/
HKEY
Win32OpenRegistry(DWORD hive, const char *key)
{
HKEY regkey;
if (ERROR_SUCCESS == RegOpenKeyEx(hive, key, 0, KEY_READ, &regkey))
{
return regkey;
}
return 0;
}
/**
* Returns an NSString as read from a registry STRING value.
*/
NSString *
Win32NSStringFromRegistry(HKEY regkey, const char *regValue)
{
char buf[MAX_PATH];
DWORD bufsize=MAX_PATH;
DWORD type;
if (ERROR_SUCCESS==RegQueryValueEx(regkey, regValue, 0, &type, buf, &bufsize))
{
// FIXME: Check type is correct!
bufsize=strlen(buf);
while (bufsize && isspace(buf[bufsize-1]))
{
bufsize--;
}
return [NSString stringWithCString:buf length:bufsize];
}
return nil;
}
// NSNumber *Win32NSNumberFromRegistry(HKEY regkey, const char *regValue);
// NSData *Win32NSDataFromRegistry(HKEY regkey, const char *regValue);
/* ------+---------+---------+---------+---------+---------+---------+---------+
#pragma mark -
#pragma mark -<Environment functions>-
---------+---------+---------+---------+---------+---------+---------+------- */
/**
* Obtains an NSString for the environment variable named envVar.
*/
NSString *
Win32NSStringFromEnvironmentVariable(const char * envVar)
{
char buf[1024], *nb;
DWORD n;
NSString *s = nil;
[gnustep_global_lock lock];
n = GetEnvironmentVariable(envVar, buf, 1024);
if (n > 1024)
{
/* Buffer not big enough, so dynamically allocate it */
nb = (char *)NSZoneMalloc(NSDefaultMallocZone(), sizeof(char)*(n+1));
if (nb != NULL)
{
n = GetEnvironmentVariable(envVar, nb, n+1);
nb[n] = '\0';
s = [NSString stringWithCString: nb];
NSZoneFree(NSDefaultMallocZone(), nb);
}
}
else if (n > 0)
{
/* null terminate it and return the string */
buf[n] = '\0';
s = [NSString stringWithCString: buf];
}
[gnustep_global_lock unlock];
return s;
}
/* ------+---------+---------+---------+---------+---------+---------+---------+
#pragma mark -
#pragma mark -<Path functions>-
---------+---------+---------+---------+---------+---------+---------+------- */
/**
* Locates the users profile directory, roughly equivalent to ~/ on unix
*/
NSString *
Win32GetUserProfileDirectory(NSString *userName)
{
if ([loginName isEqual: NSUserName()] == YES)
{
[gnustep_global_lock lock];
/*
* The environment variable HOMEPATH holds the home directory
* for the user on Windows NT;
* For OPENSTEP compatibility (and because USERPROFILE is usually
* unusable because it contains spaces), we use HOMEPATH in
* preference to USERPROFILE.
*/
s = Win32NSStringFromEnvironmentVariable("HOMEPATH");
if (s != nil && ([s length] < 2 || [s characterAtIndex: 1] != ':'))
{
s = [Win32NSStringFromEnvironmentVariable("HOMEDRIVE")
stringByAppendingString: s];
}
if (s == nil)
{
s = Win32NSStringFromEnvironmentVariable("USERPROFILE");
}
if (s == nil)
{
; // FIXME: Talk to the NET API and get the profile path
}
[gnustep_global_lock unlock];
}
else
{
s = nil;
NSLog(@"Not implemented! Can't determine other user home directories in Win32.");
}
if ([s length] == 0 && [loginName length] != 1)
{
s = nil;
NSLog(@"NSHomeDirectoryForUser(%@) failed", loginName);
}
return s;
}
/**
* Locates specified directory on Win32 systems
*/
NSString *
Win32FindDirectory( int DirCSIDL)
{
[NSException raise: NSInternalInconsistencyException
format: @"Not implemented! Can't find directories in Win32."];
}
/**
* Initialises resources required by utilities
*/
void Win32_Utilities_init(void)
{
/*
* Initialise the COM sub-system for this application
*/
CoCreateInstance();
/*
* Look for the libraries we need
*/
// GetDLLVersion
/*
* Get pointers to the Explorer Shell memory functions
*/
// IShellMalloc, IShellFree
// SHGetFolder
;
}
/**
* Closes down and releases resources
*/
void Win32_Utilities_fini(void)
{
/*
* Release the pointers for Explorer Shell functions
*/
;
}
#endif // defined(__WIN32)
// EOF

View file

@ -57,6 +57,7 @@ CHECKABLE_TOOLS = \
nsmaptable \
nsmethodsignature \
nsnotification \
nspathutilities \
nsprocessinfo \
nsscanner \
nsset \
@ -115,6 +116,7 @@ nsinvocation_OBJC_FILES = nsinvocation.m
nsmaptable_OBJC_FILES = nsmaptable.m
nsmethodsignature_OBJC_FILES = nsmethodsignature.m
nsnotification_OBJC_FILES = nsnotification.m
nspathutilities_OBJC_FILES = nspathutilities.m
nsprocessinfo_OBJC_FILES = nsprocessinfo.m
nsscanner_OBJC_FILES = nsscanner.m
nsset_OBJC_FILES = nsset.m

165
Testing/nspathutilities.m Normal file
View file

@ -0,0 +1,165 @@
/* TESTING: NSPathUtilities.h ************************************************
* *
* Author: Sheldon Gill *
* Date: 20-Dec-2003 *
* *
* Lists all search paths *
* *
**************************************************************************** */
#include <Foundation/NSString.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSFileManager.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSPathUtilities.h>
#include <Foundation/NSException.h>
/* Define any unknown directory keys */
#ifndef NSDocumentDirectory
#define NSDocumentDirectory 155
#endif
#ifndef GSFrameworksDirectory
#define GSFrameworksDirectory 153
#endif
#ifndef GSFontsDirectory
#define GSFontsDirectory 154
#endif
void print_paths(NSArray *paths)
{
int i, count;
count = [paths count];
if (count==1)
{
printf("%s\n", [[paths objectAtIndex:0] cString]);
}
else
{
printf("<list>\n");
for ( i = 0; i < count; i++ )
{
printf(" %s\n", [[paths objectAtIndex:i] cString]);
}
}
}
int main( int argc, char *argv[] )
{
NSAutoreleasePool *arp;
NSArray *domain_names;
NSArray *directory_key_names;
NSArray *paths;
int i, j, k;
BOOL tilde_expansion = YES;
#define DIR_KEYS 16
#define DOMAIN_MASKS 5
NSSearchPathDomainMask domain_masks[DOMAIN_MASKS] = {
NSUserDomainMask,
NSLocalDomainMask,
NSNetworkDomainMask,
NSSystemDomainMask,
NSAllDomainsMask
};
NSSearchPathDirectory directory_keys[DIR_KEYS] = {
NSApplicationDirectory,
NSDemoApplicationDirectory,
NSDeveloperApplicationDirectory,
NSAdminApplicationDirectory,
NSLibraryDirectory,
NSDeveloperDirectory,
NSUserDirectory,
NSDocumentationDirectory,
NSDocumentDirectory,
NSAllApplicationsDirectory,
NSAllLibrariesDirectory,
GSLibrariesDirectory,
GSToolsDirectory,
GSApplicationSupportDirectory,
GSFrameworksDirectory,
GSFontsDirectory
};
NSSearchPathDirectory key;
NSSearchPathDomainMask domain;
printf("TESTING: NSPathUtilities.h\n");
arp = [NSAutoreleasePool new];
if (argc > 1)
tilde_expansion = NO;
printf("Begin...\n");
domain_names = [NSArray arrayWithObjects:
@"NSUserDomainMask",
@"NSLocalDomainMask",
@"NSNetworkDomainMask",
@"NSSystemDomainMask",
@"NSAllDomainsMask",
nil
];
directory_key_names = [NSArray arrayWithObjects:
@"NSApplicationDirectory",
@"NSDemoApplicationDirectory",
@"NSDeveloperApplicationDirectory",
@"NSAdminApplicationDirectory",
@"NSLibraryDirectory",
@"NSDeveloperDirectory",
@"NSUserDirectory",
@"NSDocumentationDirectory",
@"NSDocumentDirectory",
@"NSAllApplicationsDirectory",
@"NSAllLibrariesDirectory",
@"GSLibrariesDirectory",
@"GSToolsDirectory",
@"GSApplicationSupportDirectory",
@"GSFrameworksDirectory",
@"GSFontsDirectory",
nil
];
printf("NSSearchPathForDirectoriesInDomains()\n");
for ( i = 0 ; i < DOMAIN_MASKS ; i++ )
{
printf("Domain: %s\n",[[domain_names objectAtIndex: i] cString]);
domain = domain_masks[i];
for ( j = 0 ; j < DIR_KEYS ; j++ )
{
printf(" %s = ",[[directory_key_names objectAtIndex: j] cString]);
key = directory_keys[j];
paths = NSSearchPathForDirectoriesInDomains( key, domain, tilde_expansion );
if ([paths count] == 0)
{
printf("<Empty>\n");
}
else
{
print_paths(paths);
}
}
}
printf("End NSSearchPathForDirectoriesInDomains\n\n");
printf("Begin NSUser functions...\n");
GSPrintf(stdout,@"User name is '%@'\n",NSUserName());
GSPrintf(stdout,@"Home directory is '%@'\n",NSHomeDirectory());
GSPrintf(stdout,@"GSDefaultsRoot for user is '%@'\n",GSDefaultsRootForUser(NSUserName()));
GSPrintf(stdout,@"Temp for user is '%@'\n",NSTemporaryDirectory());
printf("End NSUser functions\n\n");
[arp release];
printf("End Testing!\n");
return 0;
}