Cocoa: user and system base dirs retrieval implementation

This commit is contained in:
Damien Plisson 2010-02-16 08:36:33 +00:00
parent 1d914556f8
commit 1c0fa083b1
2 changed files with 51 additions and 3 deletions

@ -218,14 +218,14 @@ public:
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual GHOST_TUns8* getSystemDir() const = 0;
virtual GHOST_TUns8* getSystemDir() const;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
virtual GHOST_TUns8* getUserDir() const = 0;
virtual GHOST_TUns8* getUserDir() const;
/**
* Handles a window event. Called by GHOST_WindowCocoa window delegate

@ -1737,12 +1737,60 @@ void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
[pool drain];
}
#pragma mark Base directories retrieval
GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSFileManager *fileManager;
NSString *basePath;
NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSLocalDomainMask, YES);
if ([paths count] > 0)
basePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Blender"];
else { //Fall back to standard unix path in case of issue
basePath = @"/usr/share/blender";
}
/* Ensure path exists, creates it if needed */
fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:basePath isDirectory:NULL]) {
[fileManager createDirectoryAtPath:basePath attributes:nil];
}
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}
GHOST_TUns8* GHOST_SystemCocoa::getUserDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSFileManager *fileManager;
NSString *basePath;
NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
if ([paths count] > 0)
basePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Blender"];
else { //Fall back to HOME in case of issue
basePath = [NSHomeDirectory() stringByAppendingPathComponent:@".blender"];
}
/* Ensure path exists, creates it if needed */
fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:basePath isDirectory:NULL]) {
[fileManager createDirectoryAtPath:basePath attributes:nil];
}
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}