[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26948] trunk/blender/intern/ghost/intern: Cocoa: user and system base dirs retrieval implementation

Damien Plisson damien.plisson at yahoo.fr
Tue Feb 16 09:36:33 CET 2010


Revision: 26948
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26948
Author:   damien78
Date:     2010-02-16 09:36:33 +0100 (Tue, 16 Feb 2010)

Log Message:
-----------
Cocoa: user and system base dirs retrieval implementation

Modified Paths:
--------------
    trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h
    trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h	2010-02-16 02:10:27 UTC (rev 26947)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h	2010-02-16 08:36:33 UTC (rev 26948)
@@ -218,14 +218,14 @@
 	 * "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

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2010-02-16 02:10:27 UTC (rev 26947)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2010-02-16 08:36:33 UTC (rev 26948)
@@ -1737,12 +1737,60 @@
 	[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;
 }





More information about the Bf-blender-cvs mailing list