diff options
author | Damien Plisson <damien.plisson@yahoo.fr> | 2010-02-16 11:36:33 +0300 |
---|---|---|
committer | Damien Plisson <damien.plisson@yahoo.fr> | 2010-02-16 11:36:33 +0300 |
commit | 1c0fa083b1f5f7231914e56eb005ed91dc7cc083 (patch) | |
tree | 95263096c6cf9dac36e593b25da127d7ec0ee33d /intern | |
parent | 1d914556f8ee9d8f22681f62033741d0e8b166ca (diff) |
Cocoa: user and system base dirs retrieval implementation
Diffstat (limited to 'intern')
-rw-r--r-- | intern/ghost/intern/GHOST_SystemCocoa.h | 4 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemCocoa.mm | 50 |
2 files changed, 51 insertions, 3 deletions
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.h b/intern/ghost/intern/GHOST_SystemCocoa.h index c533e551065..2f1a94fc8eb 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.h +++ b/intern/ghost/intern/GHOST_SystemCocoa.h @@ -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 diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 45438ec27c3..0a5445b4811 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -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; } |