mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Add a few OSX compatibility methods
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33929 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a8bcdd81c1
commit
6efa3c983e
8 changed files with 111 additions and 27 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2011-10-02 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Headers/Foundation/NSFileManager.h
|
||||
* Source/NSFileManager.m
|
||||
* Tests/base/NSFileManager/general.m
|
||||
* Headers/Foundation/NSUserDefaults.h
|
||||
* Source/NSUserDefaults.m
|
||||
* Tests/base/NSUserDefaults/basic.m
|
||||
Add a few newer OSX methods for compatibility.
|
||||
|
||||
2011-10-01 Niels Grewe <niels.grewe@halbordnung.de>
|
||||
|
||||
* Source/NSXMLNode.m: Properly implement -initWithKind: initializer.
|
||||
|
|
|
@ -234,6 +234,18 @@ typedef uint32_t OSType;
|
|||
- (NSData*) contentsAtPath: (NSString*)path;
|
||||
- (BOOL) contentsEqualAtPath: (NSString*)path1
|
||||
andPath: (NSString*)path2;
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
|
||||
/**
|
||||
* Returns an array of the contents of the specified directory.<br />
|
||||
* The listing does <strong>not</strong> recursively list subdirectories.<br />
|
||||
* The special files '.' and '..' are not listed.<br />
|
||||
* Indicates an error by returning nil (eg. if path is not a directory or
|
||||
* it can't be read for some reason).
|
||||
*/
|
||||
- (NSArray*) contentsOfDirectoryAtPath: (NSString*)path error: (NSError**)error;
|
||||
#endif
|
||||
|
||||
- (BOOL) copyPath: (NSString*)source
|
||||
toPath: (NSString*)destination
|
||||
handler: (id)handler;
|
||||
|
|
|
@ -314,6 +314,14 @@ GS_EXPORT NSString* const GSLocale;
|
|||
*/
|
||||
- (NSDictionary*) dictionaryForKey: (NSString*)defaultName;
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
|
||||
/**
|
||||
* Looks up a value for a specified default using -objectForKey:
|
||||
* and checks that it is a double. Returns 0.0 if it is not.
|
||||
*/
|
||||
- (double) doubleForKey: (NSString*)defaultName;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Looks up a value for a specified default using -objectForKey:
|
||||
* and checks that it is a float. Returns 0.0 if it is not.
|
||||
|
@ -380,6 +388,15 @@ GS_EXPORT NSString* const GSLocale;
|
|||
*/
|
||||
- (void) setBool: (BOOL)value forKey: (NSString*)defaultName;
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
|
||||
/**
|
||||
* Sets a double value for defaultName in the application domain.<br />
|
||||
* Calls -setObject:forKey: to make the change by storing a double
|
||||
* [NSNumber] instance.
|
||||
*/
|
||||
- (void) setDouble: (double)value forKey: (NSString*)defaultName;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Sets a float value for defaultName in the application domain.<br />
|
||||
* Calls -setObject:forKey: to make the change by storing a float
|
||||
|
|
|
@ -691,6 +691,11 @@ static NSStringEncoding defaultEncoding;
|
|||
}
|
||||
}
|
||||
|
||||
- (NSArray*) contentsOfDirectoryAtPath: (NSString*)path error: (NSError**)error
|
||||
{
|
||||
return [self directoryContentsAtPath: path];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new directory and all intermediate directories
|
||||
* if flag is YES, creates only the last directory in the path
|
||||
|
|
|
@ -1063,6 +1063,18 @@ newLanguages(NSArray *oldNames)
|
|||
return nil;
|
||||
}
|
||||
|
||||
- (double) doubleForKey: (NSString*)defaultName
|
||||
{
|
||||
id obj = [self objectForKey: defaultName];
|
||||
|
||||
if (obj != nil && ([obj isKindOfClass: NSStringClass]
|
||||
|| [obj isKindOfClass: NSNumberClass]))
|
||||
{
|
||||
return [obj doubleValue];
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
- (float) floatForKey: (NSString*)defaultName
|
||||
{
|
||||
id obj = [self objectForKey: defaultName];
|
||||
|
@ -1177,6 +1189,13 @@ newLanguages(NSArray *oldNames)
|
|||
}
|
||||
}
|
||||
|
||||
- (void) setDouble: (double)value forKey: (NSString*)defaultName
|
||||
{
|
||||
NSNumber *n = [NSNumberClass numberWithDouble: value];
|
||||
|
||||
[self setObject: n forKey: defaultName];
|
||||
}
|
||||
|
||||
- (void) setFloat: (float)value forKey: (NSString*)defaultName
|
||||
{
|
||||
NSNumber *n = [NSNumberClass numberWithFloat: value];
|
||||
|
@ -1272,7 +1291,11 @@ static BOOL isPlistObject(id o)
|
|||
NS_DURING
|
||||
{
|
||||
obj = [_persDomains objectForKey: processName];
|
||||
if ([obj isKindOfClass: NSMutableDictionaryClass] == YES)
|
||||
if (nil == obj)
|
||||
{
|
||||
dict = [NSMutableDictionary new];
|
||||
}
|
||||
else if ([obj isKindOfClass: NSMutableDictionaryClass] == YES)
|
||||
{
|
||||
dict = obj;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,12 @@ int main()
|
|||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
NSString *dir = @"NSFileManagerTestDir";
|
||||
NSString *dirInDir = [@"TestDirectory" stringByAppendingPathComponent: @"WithinDirectory"];
|
||||
NSString *dirInDir;
|
||||
NSString *str1,*str2;
|
||||
|
||||
dirInDir
|
||||
= [@"TestDirectory" stringByAppendingPathComponent: @"WithinDirectory"];
|
||||
|
||||
PASS(mgr != nil && [mgr isKindOfClass: [NSFileManager class]],
|
||||
"NSFileManager understands +defaultManager");
|
||||
|
||||
|
@ -63,6 +67,14 @@ NSLog(@"'%@', '%@'", NSUserName(), [attr fileOwnerAccountName]);
|
|||
"NSFileManager creates a file");
|
||||
PASS([mgr fileExistsAtPath: @"NSFMFile"],"-fileExistsAtPath: agrees");
|
||||
|
||||
{
|
||||
NSArray *a;
|
||||
|
||||
a = [mgr contentsOfDirectoryAtPath: @"." error: 0];
|
||||
PASS(1 == [a count] && [[a lastObject] isEqual: @"NSFMFile"],
|
||||
"-contentsOfDirectoryAtPath: agrees");
|
||||
}
|
||||
|
||||
{
|
||||
NSData *dat1 = [mgr contentsAtPath: @"NSFMFile"];
|
||||
str2 = [[NSString alloc] initWithData: dat1 encoding: 1];
|
||||
|
|
|
@ -10,31 +10,32 @@ copyright 2004 Alexander Malmberg <alexander@malmberg.org>
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSFileManager *fm=[NSFileManager defaultManager];
|
||||
NSArray *files;
|
||||
int i;
|
||||
BOOL e,d;
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSArray *files;
|
||||
int i;
|
||||
BOOL e, d;
|
||||
|
||||
files=[fm directoryContentsAtPath: @"."];
|
||||
printf("%lu files\n", (unsigned long)[files count]);
|
||||
for (i=0;i<[files count];i++)
|
||||
{
|
||||
int j;
|
||||
NSString *f=[files objectAtIndex: i];
|
||||
e=[fm fileExistsAtPath: f
|
||||
isDirectory: &d];
|
||||
printf("%5i: %i %i %s\n",i,e,d, [f lossyCString]);
|
||||
for (j=0;j<[f length];j++)
|
||||
printf(" %3i: %04x\n",j,[f characterAtIndex: j]);
|
||||
}
|
||||
files = [fm directoryContentsAtPath: @"."];
|
||||
printf("%lu files\n", (unsigned long)[files count]);
|
||||
for (i = 0; i < [files count]; i++)
|
||||
{
|
||||
int j;
|
||||
NSString *f = [files objectAtIndex: i];
|
||||
|
||||
/* const char *test="hallå.txt";
|
||||
NSString *s=[NSString stringWithCString: test];
|
||||
printf("s=%s\n", [s lossyCString]);*/
|
||||
e = [fm fileExistsAtPath: f
|
||||
isDirectory: &d];
|
||||
printf("%5i: %i %i %s\n",i,e,d, [f lossyCString]);
|
||||
for (j = 0; j < [f length]; j++)
|
||||
printf(" %3i: %04x\n",j,[f characterAtIndex: j]);
|
||||
}
|
||||
|
||||
[arp release]; arp = nil;
|
||||
/* const char *test="hallå.txt";
|
||||
NSString *s=[NSString stringWithCString: test];
|
||||
printf("s=%s\n", [s lossyCString]);*/
|
||||
|
||||
return 0;
|
||||
[arp release]; arp = nil;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,11 +4,15 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSArray *testObj = [NSUserDefaults new];
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSUserDefaults *defs = [NSUserDefaults new];
|
||||
|
||||
test_NSObject(@"NSUserDefaults", [NSArray arrayWithObject:testObj]);
|
||||
test_NSObject(@"NSUserDefaults", [NSArray arrayWithObject: defs]);
|
||||
|
||||
defs = [NSUserDefaults standardUserDefaults];
|
||||
[defs setDouble: (double)42.42 forKey: @"aDouble"];
|
||||
PASS(EQ((double)42.42, [defs doubleForKey: @"aDouble"]),
|
||||
"can store double");
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue