mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-12 17:11:12 +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
377a757e54
commit
cbf54ac301
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>
|
2011-10-01 Niels Grewe <niels.grewe@halbordnung.de>
|
||||||
|
|
||||||
* Source/NSXMLNode.m: Properly implement -initWithKind: initializer.
|
* Source/NSXMLNode.m: Properly implement -initWithKind: initializer.
|
||||||
|
|
|
@ -234,6 +234,18 @@ typedef uint32_t OSType;
|
||||||
- (NSData*) contentsAtPath: (NSString*)path;
|
- (NSData*) contentsAtPath: (NSString*)path;
|
||||||
- (BOOL) contentsEqualAtPath: (NSString*)path1
|
- (BOOL) contentsEqualAtPath: (NSString*)path1
|
||||||
andPath: (NSString*)path2;
|
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
|
- (BOOL) copyPath: (NSString*)source
|
||||||
toPath: (NSString*)destination
|
toPath: (NSString*)destination
|
||||||
handler: (id)handler;
|
handler: (id)handler;
|
||||||
|
|
|
@ -314,6 +314,14 @@ GS_EXPORT NSString* const GSLocale;
|
||||||
*/
|
*/
|
||||||
- (NSDictionary*) dictionaryForKey: (NSString*)defaultName;
|
- (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:
|
* Looks up a value for a specified default using -objectForKey:
|
||||||
* and checks that it is a float. Returns 0.0 if it is not.
|
* 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;
|
- (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 />
|
* Sets a float value for defaultName in the application domain.<br />
|
||||||
* Calls -setObject:forKey: to make the change by storing a float
|
* 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
|
* Creates a new directory and all intermediate directories
|
||||||
* if flag is YES, creates only the last directory in the path
|
* if flag is YES, creates only the last directory in the path
|
||||||
|
|
|
@ -1063,6 +1063,18 @@ newLanguages(NSArray *oldNames)
|
||||||
return nil;
|
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
|
- (float) floatForKey: (NSString*)defaultName
|
||||||
{
|
{
|
||||||
id obj = [self objectForKey: 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
|
- (void) setFloat: (float)value forKey: (NSString*)defaultName
|
||||||
{
|
{
|
||||||
NSNumber *n = [NSNumberClass numberWithFloat: value];
|
NSNumber *n = [NSNumberClass numberWithFloat: value];
|
||||||
|
@ -1272,7 +1291,11 @@ static BOOL isPlistObject(id o)
|
||||||
NS_DURING
|
NS_DURING
|
||||||
{
|
{
|
||||||
obj = [_persDomains objectForKey: processName];
|
obj = [_persDomains objectForKey: processName];
|
||||||
if ([obj isKindOfClass: NSMutableDictionaryClass] == YES)
|
if (nil == obj)
|
||||||
|
{
|
||||||
|
dict = [NSMutableDictionary new];
|
||||||
|
}
|
||||||
|
else if ([obj isKindOfClass: NSMutableDictionaryClass] == YES)
|
||||||
{
|
{
|
||||||
dict = obj;
|
dict = obj;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,12 @@ int main()
|
||||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||||
NSString *dir = @"NSFileManagerTestDir";
|
NSString *dir = @"NSFileManagerTestDir";
|
||||||
NSString *dirInDir = [@"TestDirectory" stringByAppendingPathComponent: @"WithinDirectory"];
|
NSString *dirInDir;
|
||||||
NSString *str1,*str2;
|
NSString *str1,*str2;
|
||||||
|
|
||||||
|
dirInDir
|
||||||
|
= [@"TestDirectory" stringByAppendingPathComponent: @"WithinDirectory"];
|
||||||
|
|
||||||
PASS(mgr != nil && [mgr isKindOfClass: [NSFileManager class]],
|
PASS(mgr != nil && [mgr isKindOfClass: [NSFileManager class]],
|
||||||
"NSFileManager understands +defaultManager");
|
"NSFileManager understands +defaultManager");
|
||||||
|
|
||||||
|
@ -63,6 +67,14 @@ NSLog(@"'%@', '%@'", NSUserName(), [attr fileOwnerAccountName]);
|
||||||
"NSFileManager creates a file");
|
"NSFileManager creates a file");
|
||||||
PASS([mgr fileExistsAtPath: @"NSFMFile"],"-fileExistsAtPath: agrees");
|
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"];
|
NSData *dat1 = [mgr contentsAtPath: @"NSFMFile"];
|
||||||
str2 = [[NSString alloc] initWithData: dat1 encoding: 1];
|
str2 = [[NSString alloc] initWithData: dat1 encoding: 1];
|
||||||
|
|
|
@ -22,6 +22,7 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
NSString *f = [files objectAtIndex: i];
|
NSString *f = [files objectAtIndex: i];
|
||||||
|
|
||||||
e = [fm fileExistsAtPath: f
|
e = [fm fileExistsAtPath: f
|
||||||
isDirectory: &d];
|
isDirectory: &d];
|
||||||
printf("%5i: %i %i %s\n",i,e,d, [f lossyCString]);
|
printf("%5i: %i %i %s\n",i,e,d, [f lossyCString]);
|
||||||
|
|
|
@ -5,10 +5,14 @@
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||||
NSArray *testObj = [NSUserDefaults 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;
|
[arp release]; arp = nil;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue