Index: source/blender/windowmanager/intern/wm_files.c =================================================================== --- source/blender/windowmanager/intern/wm_files.c (revision 26096) +++ source/blender/windowmanager/intern/wm_files.c (working copy) @@ -304,17 +304,14 @@ { ListBase wmbase; char tstr[FILE_MAXDIR+FILE_MAXFILE], scestr[FILE_MAXDIR]; - char *home= BLI_gethome(); int from_memory= op?RNA_boolean_get(op->ptr, "factory"):0; int success; - BLI_clean(home); - free_ttfont(); /* still weird... what does it here? */ G.relbase_valid = 0; if (!from_memory) { - BLI_make_file_string(G.sce, tstr, home, ".B25.blend"); + BLI_make_file_string(G.sce, tstr, BLI_getconfig_folder(), "startup.blend"); } strcpy(scestr, G.sce); /* temporary store */ @@ -368,7 +365,7 @@ char *line; int num; - BLI_make_file_string("/", name, BLI_gethome(), ".Blog"); + BLI_make_file_string("/", name, BLI_getconfig_folder(), "file-history"); lines= BLI_read_file_as_lines(name); G.recent_files.first = G.recent_files.last = NULL; @@ -403,7 +400,7 @@ FILE *fp; int i; - BLI_make_file_string("/", name, BLI_gethome(), ".Blog"); + BLI_make_file_string("/", name, BLI_getconfig_folder(), "file-history"); recent = G.recent_files.first; /* refresh .Blog of recent opened files, when current file was changed */ @@ -535,7 +532,7 @@ if(win->screen->full == SCREENTEMP) wm_window_close(C, wm, win); - BLI_make_file_string("/", tstr, BLI_gethome(), ".B25.blend"); + BLI_make_file_string("/", tstr, BLI_getconfig_folder(), "startup.blend"); /* force save as regular blend file */ fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_LOCK | G_FILE_SIGN); Index: source/blender/blenlib/BLI_path_util.h =================================================================== --- source/blender/blenlib/BLI_path_util.h (revision 26096) +++ source/blender/blenlib/BLI_path_util.h (working copy) @@ -50,6 +50,8 @@ #define BLI_GETHOME_USER 1<<3 /* home folder ~/.blender */ #define BLI_GETHOME_ALL (BLI_GETHOME_SYSTEM|BLI_GETHOME_LOCAL|BLI_GETHOME_USER) +const char *BLI_getconfig_folder(); + void BLI_setenv(const char *env, const char *val); void BLI_setenv_if_new(const char *env, const char* val); @@ -143,8 +145,21 @@ * @return path to application bundle */ #ifdef __APPLE__ -char* BLI_getbundle(void); +const char* BLI_getbundle(void); + +#ifdef GHOST_COCOA +typedef enum { + BasePath_Temporary = 1, + BasePath_BlenderShared, + BasePath_BlenderUser +} basePathesTypes; +/** + * Gets the base path (with creation of .../blender if needed) + * Note that return string must be copied as its persistence is not guaranteed + */ +const char* BLI_cocoa_getBasePath(basePathesTypes pathType); #endif +#endif #ifdef WITH_ICONV void BLI_string_to_utf8(char *original, char *utf_8, const char *code); Index: source/blender/blenlib/CMakeLists.txt =================================================================== --- source/blender/blenlib/CMakeLists.txt (revision 26096) +++ source/blender/blenlib/CMakeLists.txt (working copy) @@ -26,6 +26,10 @@ FILE(GLOB SRC intern/*.c) +IF(WITH_COCOA) + SET(SRC ${SRC} intern/util_cocoa.m) +ENDIF(WITH_COCOA) + SET(INC . ../makesdna ../blenkernel ../../../intern/guardedalloc ../include ../gpu Index: source/blender/blenlib/SConscript =================================================================== --- source/blender/blenlib/SConscript (revision 26096) +++ source/blender/blenlib/SConscript (working copy) @@ -3,6 +3,9 @@ sources = env.Glob('intern/*.c') +if env['WITH_GHOST_COCOA']: + sources.append('intern/util_cocoa.m') + cflags='' incs = '. ../makesdna ../blenkernel #/intern/guardedalloc ../editors/include ../gpu' incs += ' ' + env['BF_FREETYPE_INC'] @@ -16,4 +19,8 @@ if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'): incs += ' ' + env['BF_PTHREADS_INC'] + +if env['WITH_GHOST_COCOA']: + defs += ' GHOST_COCOA' + env.BlenderLib ( 'bf_blenlib', sources, Split(incs), Split(defs), libtype=['core','player'], priority = [363,170], compileflags =cflags ) Index: source/blender/blenlib/intern/util_cocoa.m =================================================================== --- source/blender/blenlib/intern/util_cocoa.m (revision 0) +++ source/blender/blenlib/intern/util_cocoa.m (revision 0) @@ -0,0 +1,123 @@ +/* util_cocoa.m + * + * Functions specific to osx that use API available only in Objective-C + * + * + * $Id: util_cocoa.m 25007 2009-11-29 19:16:52Z kazanbas $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + * + */ + + +#import + +#include + +#include "BLI_path_util.h" + + +/** + * Gets the application bundle path + */ +const char* BLI_getbundle() +{ + static char bundlePath[512] = ""; + + NSAutoreleasePool *pool; + NSString *path; + + if (bundlePath[0]) + return bundlePath; //No need to re-retrieve cached path + + pool = [[NSAutoreleasePool alloc] init]; + + path = [[NSBundle mainBundle] bundlePath]; + + strcpy(bundlePath, [path cStringUsingEncoding:NSASCIIStringEncoding]); + + [pool drain]; + return bundlePath; +} + + +/** + * Gets the ~/Library/Application Data/Blender folder + * Creates it if needed + */ +const char* BLI_cocoa_getBasePath(basePathesTypes pathType) +{ + static char tempPath[512] = ""; + + NSAutoreleasePool *pool; + NSFileManager *fileManager; + NSString *basePath; + NSArray *paths; + + pool = [[NSAutoreleasePool alloc] init]; + + switch (pathType) { + /* Standard pathes */ + case BasePath_Temporary: + strcpy(tempPath, [NSTemporaryDirectory() cStringUsingEncoding:NSASCIIStringEncoding]); + [pool drain]; + return tempPath; + break; + + /* Blender specific pathes */ + case BasePath_BlenderShared: + 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"; + } + break; + case BasePath_BlenderUser: + 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"]; + } + break; + + default: + tempPath[0] = 0; + return tempPath; + } + + /* Ensure path exists, creates it if needed */ + fileManager = [NSFileManager defaultManager]; + if (![fileManager fileExistsAtPath:basePath isDirectory:NULL]) { + [fileManager createDirectoryAtPath:basePath attributes:nil]; + } + + strcpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]); + + [pool drain]; + return tempPath; +} \ No newline at end of file Index: source/blender/blenlib/intern/path_util.c =================================================================== --- source/blender/blenlib/intern/path_util.c (revision 26096) +++ source/blender/blenlib/intern/path_util.c (working copy) @@ -82,7 +82,7 @@ #include #endif -#ifdef __APPLE__ +#if defined(__APPLE__) && !defined(GHOST_COCOA) #include #include #endif @@ -859,7 +859,7 @@ /* #define PATH_DEBUG */ /* for testing paths that are checked */ -static int test_data_path(char *targetpath, char *path_base, char *path_sep, char *folder_name) +static int test_data_path(char *targetpath, const char *path_base, char *path_sep, char *folder_name) { char tmppath[FILE_MAXDIR]; @@ -901,6 +901,11 @@ i = s - bprogname + 1; BLI_strncpy(bprogdir, bprogname, i); +#if defined(__APPLE__) + if(test_data_path(targetpath, BLI_getbundle(), "/Contents/Resources", folder_name)) + return 1; +#endif + /* try release/folder_name (CWD relative) */ if(test_data_path(targetpath, BLI_getwdN(cwd), "release", folder_name)) return 1; @@ -917,14 +922,18 @@ static int gethome_path_user(char *targetpath, char *folder_name) { - char *home_path= BLI_gethome(); - #ifdef PATH_DEBUG printf("gethome_path_user...\n"); #endif - /* try $HOME/folder_name */ +#if defined(__APPLE__) && defined(GHOST_COCOA) + return test_data_path(targetpath, BLI_cocoa_getBasePath(BasePath_BlenderUser), "", folder_name); +#else + char *home_path= BLI_gethome(); + + /* try $BLENDERPATH/folder_name */ return test_data_path(targetpath, home_path, ".blender", folder_name); +#endif } static int gethome_path_system(char *targetpath, char *folder_name) @@ -967,6 +976,27 @@ return NULL; } +const char *BLI_getconfig_folder() +{ +#if defined(__APPLE__) && defined(GHOST_COCOA) + return BLI_cocoa_getBasePath(BasePath_BlenderUser); +#else + static char fulldir[FILE_MAXDIR] = ""; + +#ifdef WIN32 + strcpy(fulldir, BLI_gethome()); +#else + BLI_make_file_string("/", fulldir, BLI_gethome(), ".blender"); +#endif + + BLI_recurdir_fileops(fulldir); + + BLI_clean(fulldir); + + return fulldir; +#endif +} + #ifdef PATH_DEBUG #undef PATH_DEBUG #endif @@ -1532,10 +1562,10 @@ /* * returns absolute path to the app bundle - * only useful on OS X + * only useful on OS X - Carbon implementation */ -#ifdef __APPLE__ -char* BLI_getbundle(void) { +#if defined(__APPLE__) && !defined(GHOST_COCOA) +const char* BLI_getbundle(void) { CFURLRef bundleURL; CFStringRef pathStr; static char path[MAXPATHLEN]; Index: source/blender/blenloader/intern/writefile.c =================================================================== --- source/blender/blenloader/intern/writefile.c (revision 26096) +++ source/blender/blenloader/intern/writefile.c (working copy) @@ -2476,7 +2476,7 @@ } - BLI_make_file_string(G.sce, userfilename, BLI_gethome(), ".B25.blend"); + BLI_make_file_string(G.sce, userfilename, BLI_getconfig_folder(), "startup.blend"); write_user_block= BLI_streq(dir, userfilename); if(write_flags & G_FILE_RELATIVE_REMAP) Index: source/blender/blenfont/intern/blf_lang.c =================================================================== --- source/blender/blenfont/intern/blf_lang.c (revision 26096) +++ source/blender/blenfont/intern/blf_lang.c (working copy) @@ -60,39 +60,7 @@ char global_language[32]; char global_encoding_name[32]; -#if defined(__APPLE__) -void BLF_lang_init(void) /* Apple Only, todo - use BLI_gethome_folder */ -{ - char *bundlepath; - - strcpy(global_encoding_name, SYSTEM_ENCODING_DEFAULT); - - /* set messagepath directory */ -#ifndef LOCALEDIR -#define LOCALEDIR "/usr/share/locale" -#endif - - strcpy(global_messagepath, ".blender/locale"); - - if (!BLI_exist(global_messagepath)) { /* locale not in current dir */ - BLI_make_file_string("/", global_messagepath, BLI_gethome(), ".blender/locale"); - - if (!BLI_exist(global_messagepath)) { /* locale not in home dir */ - /* message catalogs are stored inside the application bundle */ - bundlepath= BLI_getbundle(); - strcpy(global_messagepath, bundlepath); - strcat(global_messagepath, "/Contents/Resources/locale"); - if (!BLI_exist(global_messagepath)) { /* locale not in bundle (now that's odd..) */ - strcpy(global_messagepath, LOCALEDIR); - - if (!BLI_exist(global_messagepath)) { /* locale not in LOCALEDIR */ - strcpy(global_messagepath, "message"); /* old compatibility as last */ - } - } - } - } -} -#elif defined(_WIN32) +#if defined(_WIN32) void BLF_lang_init(void) /* Windows Only, todo - use BLI_gethome_folder */ { strcpy(global_encoding_name, SYSTEM_ENCODING_DEFAULT); Index: source/blender/editors/space_file/file_ops.c =================================================================== --- source/blender/editors/space_file/file_ops.c (revision 26096) +++ source/blender/editors/space_file/file_ops.c (working copy) @@ -379,7 +379,7 @@ char name[FILE_MAX]; fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, 0, 1); - BLI_make_file_string("/", name, BLI_gethome(), ".Bfs"); + BLI_make_file_string("/", name, BLI_getconfig_folder(), "bookmarks"); fsmenu_write_file(fsmenu, name); } @@ -411,7 +411,7 @@ char name[FILE_MAX]; fsmenu_remove_entry(fsmenu, FS_CATEGORY_BOOKMARKS, index); - BLI_make_file_string("/", name, BLI_gethome(), ".Bfs"); + BLI_make_file_string("/", name, BLI_getconfig_folder(), "bookmarks"); fsmenu_write_file(fsmenu, name); ED_area_tag_redraw(sa); } @@ -614,7 +614,7 @@ folderlist_free(sfile->folders_next); fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir,0, 1); - BLI_make_file_string(G.sce, name, BLI_gethome(), ".Bfs"); + BLI_make_file_string(G.sce, name, BLI_getconfig_folder(), "bookmarks"); fsmenu_write_file(fsmenu_get(), name); WM_event_fileselect_event(C, op, EVT_FILESELECT_EXEC); Index: source/blender/editors/space_file/space_file.c =================================================================== --- source/blender/editors/space_file/space_file.c (revision 26096) +++ source/blender/editors/space_file/space_file.c (working copy) @@ -566,7 +566,7 @@ void ED_file_init(void) { char name[FILE_MAX]; - BLI_make_file_string("/", name, BLI_gethome(), ".Bfs"); + BLI_make_file_string("/", name, BLI_getconfig_folder(), "bookmarks"); fsmenu_read_file(fsmenu_get(), name); filelist_init_icons(); IMB_thumb_makedirs(); Index: source/blender/editors/interface/interface_icons.c =================================================================== --- source/blender/editors/interface/interface_icons.c (revision 26096) +++ source/blender/editors/interface/interface_icons.c (working copy) @@ -463,13 +463,9 @@ if ((btheme!=NULL) && (strlen(btheme->tui.iconfile) > 0)) { -#ifdef WIN32 sprintf(filenamestr, "icons/%s", btheme->tui.iconfile); -#else - sprintf(filenamestr, ".blender/icons/%s", btheme->tui.iconfile); -#endif - BLI_make_file_string("/", iconfilestr, BLI_gethome(), filenamestr); + BLI_make_file_string("/", iconfilestr, BLI_getconfig_folder(), filenamestr); if (BLI_exists(iconfilestr)) { bbuf = IMB_loadiffname(iconfilestr, IB_rect); @@ -557,11 +553,7 @@ list->first = list->last = NULL; -#ifdef WIN32 - BLI_make_file_string("/", icondirstr, BLI_gethome(), "icons"); -#else - BLI_make_file_string("/", icondirstr, BLI_gethome(), ".blender/icons"); -#endif + BLI_make_file_string("/", icondirstr, BLI_getconfig_folder(), "icons"); if(BLI_exists(icondirstr)==0) return;