93f913a920
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@86 127b21dd-08f5-0310-b4b7-95ae10353056
53 lines
1.2 KiB
Objective-C
53 lines
1.2 KiB
Objective-C
//
|
|
// Created for the Oolite-Linux project
|
|
//
|
|
// Dylan Smith, 2005-07-02
|
|
//
|
|
// This extends NSFileManager and adds some methods to insulate the
|
|
// main oolite code from the gory details of creating/chdiring to the
|
|
// commander save directory.
|
|
//
|
|
// oolite: (c) 2004 Giles C Williams.
|
|
// This work is licensed under the Creative Commons Attribution NonCommercial
|
|
// ShareAlike license.
|
|
//
|
|
#include <stdlib.h>
|
|
#import "OOFileManager.h"
|
|
|
|
@implementation NSFileManager ( OOFileManager )
|
|
|
|
- (NSArray *)commanderContents
|
|
{
|
|
if([self chdirToDefaultCommanderPath])
|
|
{
|
|
NSArray *contents=[self directoryContentsAtPath: @"."];
|
|
return contents;
|
|
}
|
|
return nil;
|
|
}
|
|
|
|
- (BOOL)chdirToDefaultCommanderPath
|
|
{
|
|
NSString *savedir=
|
|
[NSHomeDirectory() stringByAppendingPathComponent:@SAVEDIR];
|
|
if(![self changeCurrentDirectoryPath: savedir])
|
|
{
|
|
// it probably doesn't exist.
|
|
if(![self createDirectoryAtPath: savedir attributes: nil])
|
|
{
|
|
NSLog(@"Unable to create: %@", savedir);
|
|
return NO;
|
|
}
|
|
if(![self changeCurrentDirectoryPath: savedir])
|
|
{
|
|
NSLog(@"Created %@ but couldn't chdir to it", savedir);
|
|
return NO;
|
|
}
|
|
}
|
|
NSLog(@"CWD is %@", savedir);
|
|
|
|
return YES;
|
|
}
|
|
|
|
@end
|