File/installation paths: osx (cocoa & carbon) update in ghost

This commit is contained in:
Damien Plisson
2010-07-05 19:59:37 +00:00
parent 78adaa6bc7
commit dd724f2826
3 changed files with 26 additions and 41 deletions

View File

@@ -45,8 +45,7 @@ extern const GHOST_TUns8* GHOST_getSystemDir();
/** /**
* Determine the base dir in which user configuration is stored, not including versioning. * 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 ~).
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/ */
extern const GHOST_TUns8* GHOST_getUserDir(); extern const GHOST_TUns8* GHOST_getUserDir();

View File

@@ -1238,5 +1238,15 @@ const GHOST_TUns8* GHOST_SystemCarbon::getUserDir() const
const GHOST_TUns8* GHOST_SystemCarbon::getBinaryDir() const const GHOST_TUns8* GHOST_SystemCarbon::getBinaryDir() const
{ {
return NULL; CFURLRef bundleURL;
CFStringRef pathStr;
static char path[256];
CFBundleRef mainBundle = CFBundleGetMainBundle();
bundleURL = CFBundleCopyBundleURL(mainBundle);
pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
CFStringGetCString(pathStr, path, 255, kCFStringEncodingASCII);
CFRelease(pathStr);
CFRelease(bundleURL);
return (GHOST_TUns8*)path;
} }

View File

@@ -1783,27 +1783,20 @@ void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
#pragma mark Base directories retrieval #pragma mark Base directories retrieval
// TODO: this should only return base path, remove the appending of Blender or .blender
const GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const const GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const
{ {
static GHOST_TUns8 tempPath[512] = ""; static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSFileManager *fileManager;
NSString *basePath; NSString *basePath;
NSArray *paths; NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSLocalDomainMask, YES); paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSLocalDomainMask, YES);
if ([paths count] > 0) if ([paths count] > 0)
basePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Blender"]; basePath = [paths objectAtIndex:0];
else { //Fall back to standard unix path in case of issue else {
basePath = @"/usr/share/blender"; [pool drain];
} return NULL;
/* 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]); strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
@@ -1812,27 +1805,20 @@ const GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const
return tempPath; return tempPath;
} }
// TODO: this should only return base path, remove the appending of Blenbder or .blender
const GHOST_TUns8* GHOST_SystemCocoa::getUserDir() const const GHOST_TUns8* GHOST_SystemCocoa::getUserDir() const
{ {
static GHOST_TUns8 tempPath[512] = ""; static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSFileManager *fileManager;
NSString *basePath; NSString *basePath;
NSArray *paths; NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
if ([paths count] > 0) if ([paths count] > 0)
basePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Blender"]; basePath = [paths objectAtIndex:0];
else { //Fall back to HOME in case of issue else {
basePath = [NSHomeDirectory() stringByAppendingPathComponent:@".blender"]; [pool drain];
} return NULL;
/* 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]); strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
@@ -1841,27 +1827,17 @@ const GHOST_TUns8* GHOST_SystemCocoa::getUserDir() const
return tempPath; return tempPath;
} }
// TODO: this is same as getUserDir for now
const GHOST_TUns8* GHOST_SystemCocoa::getBinaryDir() const const GHOST_TUns8* GHOST_SystemCocoa::getBinaryDir() const
{ {
static GHOST_TUns8 tempPath[512] = ""; static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSFileManager *fileManager;
NSString *basePath; NSString *basePath;
NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); basePath = [[NSBundle mainBundle] bundlePath];
if ([paths count] > 0) if (basePath == nil) {
basePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Blender"]; [pool drain];
else { //Fall back to HOME in case of issue return NULL;
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]); strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);