Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Weikert <elubie@gmx.net>2010-07-04 19:35:23 +0400
committerAndrea Weikert <elubie@gmx.net>2010-07-04 19:35:23 +0400
commitca81aa704e958a73a55e79654f70eaa9a0fad85a (patch)
tree8b40e3a7613df4e707fcc8efb3a099f9445ac350 /source/blender/blenlib
parent3ca7b160a664e74c6815056a4a8596bb4c2b70be (diff)
Patch [#22339] File/installation paths changes
Patch Tracker: http://projects.blender.org/tracker/?func=detail&aid=22339&group_id=9&atid=127 This patch implements the proposal outlined here: http://wiki.blender.org/index.php/Dev:2.5/Source/Installation/Proposal Original patch by Matt Ebb. Contributions by Nathan Letwory, Damien Plisson and Andrea Weikert NOTE: This is a work in progress commit, some work still needs to be done on the SCons and CMake files for this to work properly, but at least should compile and the files should be created in the right directory. Commit discussed on IRC with Ton and Campbell.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_path_util.h61
-rw-r--r--source/blender/blenlib/CMakeLists.txt4
-rw-r--r--source/blender/blenlib/intern/BLI_bfile.c223
-rw-r--r--source/blender/blenlib/intern/path_util.c334
-rw-r--r--source/blender/blenlib/intern/path_util_cocoa.mm96
5 files changed, 459 insertions, 259 deletions
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index fb30e991200..24b74b40a37 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -45,6 +45,58 @@ char *BLI_gethome_folder(char *folder_name, int flag);
#define BLI_GETHOME_USER 1<<3 /* home folder ~/.blender */
#define BLI_GETHOME_ALL (BLI_GETHOME_SYSTEM|BLI_GETHOME_LOCAL|BLI_GETHOME_USER)
+
+#ifdef __APPLE__
+typedef enum {
+ BasePath_Temporary = 1,
+ BasePath_BlenderShared,
+ BasePath_BlenderUser,
+ BasePath_ApplicationBundle
+} basePathesTypes;
+
+/**
+ * Gets the base path. The path may not exist.
+ * Note that return string must be copied as its persistence is not guaranteed
+ *
+ * @return base path of pathType
+ */
+const char* BLI_osx_getBasePath(basePathesTypes pathType);
+#endif
+
+char *BLI_get_folder(int folder_id, char *subfolder);
+char *BLI_get_folder_create(int folder_id, char *subfolder);
+
+/* folder_id */
+
+/* general, will find baserd on user/local/system priority */
+#define BLENDER_CONFIG 1
+#define BLENDER_DATAFILES 2
+#define BLENDER_SCRIPTS 3
+#define BLENDER_PLUGINS 4
+#define BLENDER_PYTHON 5
+
+/* user-specific */
+#define BLENDER_USER_CONFIG 31
+#define BLENDER_USER_DATAFILES 32
+#define BLENDER_USER_SCRIPTS 33
+#define BLENDER_USER_PLUGINS 34
+
+/* system */
+#define BLENDER_SYSTEM_CONFIG 51 /* optional */
+#define BLENDER_SYSTEM_DATAFILES 52
+#define BLENDER_SYSTEM_SCRIPTS 53
+#define BLENDER_SYSTEM_PLUGINS 54
+#define BLENDER_SYSTEM_PYTHON 54
+
+#define BLENDER_TEMP 80
+
+#define BLENDER_USERFOLDER(id) (id >= BLENDER_USER_CONFIG && id <= BLENDER_USER_PLUGINS)
+
+#define BLENDER_STARTUP_FILE "startup.blend"
+#define BLENDER_BOOKMARK_FILE "bookmarks.txt"
+#define BLENDER_HISTORY_FILE "recent-files.txt"
+
+
void BLI_setenv(const char *env, const char *val);
void BLI_setenv_if_new(const char *env, const char* val);
@@ -135,15 +187,6 @@ char *get_install_dir(void);
void BLI_where_is_temp(char *fullname, int usertemp);
- /**
- * determines the full path to the application bundle on OS X
- *
- * @return path to application bundle
- */
-#ifdef __APPLE__
-char* BLI_getbundle(void);
-#endif
-
#ifdef WITH_ICONV
void BLI_string_to_utf8(char *original, char *utf_8, const char *code);
#endif
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 628c2dc43a5..185e1c9c960 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -33,6 +33,10 @@ SET(INC
${ZLIB_INC}
)
+IF(APPLE)
+ SET(SRC ${SRC} intern/path_util_cocoa.m)
+ENDIF(APPLE)
+
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
SET(INC
${INC}
diff --git a/source/blender/blenlib/intern/BLI_bfile.c b/source/blender/blenlib/intern/BLI_bfile.c
index 2330beb618d..b9ac6875b20 100644
--- a/source/blender/blenlib/intern/BLI_bfile.c
+++ b/source/blender/blenlib/intern/BLI_bfile.c
@@ -48,8 +48,6 @@
#include "BLI_storage.h"
#include "BLI_bfile.h"
-#include "GHOST_C-api.h"
-
/* Internal bfile classification flags */
#define BCF_OPEN (0)
#define BCF_FOPEN (1<<0)
@@ -64,12 +62,8 @@
/* Declaration of internal functions */
-static void chomp(char* line);
-static void expand_envvars(char* src, char* dst);
static void fill_paths(BFILE *bfile, const char *path, const char *relpath);
-static void init_vars_from_file(const char* path);
static void free_paths(BFILE* bfile);
-static void setup_temp();
/*** Exported functions ***/
@@ -274,205 +268,9 @@ void BLI_bfile_set_error(BFILE *bfile, int error) {
}
-void BLI_bfile_init_vars() {
- char file[MAXPATHLEN];
- char temp[MAXPATHLEN];
- extern char bprogname[];
- FILE* fp;
-
- /* This one is unconditional */
- sprintf(temp, "%d", BLENDER_VERSION);
- BLI_setenv("BLENDER_VERSION", temp);
-
- /* Is this unpack&run? */
- sprintf(temp, "%s/%d/environment", dirname(bprogname), BLENDER_VERSION);
- if (BLI_exist(temp)) {
- BLI_setenv_if_new("BLENDER_SHARE", dirname(bprogname));
- } else {
- BLI_setenv_if_new("BLENDER_SHARE", (const char*)GHOST_getSystemDir());
- }
-
- strcpy(file, (const char*)GHOST_getUserDir());
- BLI_add_slash(file);
- strcat(file, LAST_SESSION_FILE);
- fp = fopen(file, "r");
- /* 1st line, read previous version */
- if (fp && (fscanf(fp, "%3c\n", temp) == 1)) {
- temp[3] = '\0';
- BLI_setenv("BLENDER_VERSION_PREV", temp);
- /* 2nd line, read previous session path if needed */
- if (!getenv("BLENDER_TEMP")) {
- if ((fgets(temp, MAXPATHLEN, fp) != NULL)) {
- /* Clean any \n */
- chomp(temp);
- /* Check the dir is still there or generate new one */
- if (!BLI_exist(temp)) {
- setup_temp();
- }
- } else {
- /* We have to generate it for sure */
- setup_temp();
- }
- }
- } else {
- /* Probably new user, or only <=249 before */
- BLI_setenv("BLENDER_VERSION_PREV", "0");
- setup_temp();
- }
-
- if (fp) {
- fclose(fp);
- }
-
- /* Loaded session info (or created), so time to store current data */
- // TODO use own fuctions to get safe saving
- fp = fopen(file, "w");
- if (fp) {
- fprintf(fp, "%s\n%s\n", getenv("BLENDER_VERSION"), getenv("BLENDER_TEMP"));
- fclose(fp);
- }
-
- /* Load vars from user and system files */
- strcpy(file, (const char *)GHOST_getUserDir());
- BLI_add_slash(file);
- strcat(file, ENVIRONMENT_FILE);
- init_vars_from_file(file);
- sprintf(temp, "/%d/environment", BLENDER_VERSION);
- BLI_make_file_string("/", file, getenv("BLENDER_SHARE"), temp);
- init_vars_from_file(file);
-}
-
-
/*** Internal functions ***/
/**
- Eliminate trailing EOL by writing a \0 over it.
- Name taken from Perl.
- */
-static void chomp(char* line) {
- int len = strlen(line);
-#ifndef WIN32
- if (line[len - 1] == '\n') {
- line[len - 1] = '\0';
- }
-#else
- if ((line[len - 2] == '\r' ) && ((line[len - 1] == '\n'))) {
- line[len - 2] = '\0';
- }
-#endif /* WIN32 */
-}
-
-
-/**
- Parse a file with lines like FOO=bar (comment lines have # as first
- character) assigning to envvar FOO the value bar if FOO does not
- exist yet.
- Any white space before FOO, around the = or trailing will be used,
- so beware.
- */
-#define MAX_LINE 4096
-#define ENV_VAR 256
-#define VAR_LEN 8192
-static void init_vars_from_file(const char* path) {
- char line[MAX_LINE];
- char name[ENV_VAR];
- FILE *fp;
- char* separator;
- char expanded[VAR_LEN];
-
- fp = fopen(path, "r");
- if (!fp) return;
-
- while (fgets(line, MAX_LINE, fp) != NULL) {
- /* Ignore comment lines */
- if (line[0] == '#')
- continue;
-
- /* Split into envvar name and contents */
- separator = strchr(line, '=');
- if (separator && ((separator - line) < ENV_VAR)) {
- /* First remove EOL */
- chomp(line);
- strncpy(name, line, separator - line);
- name[separator - line] = '\0';
- expand_envvars(separator + 1, expanded);
- BLI_setenv_if_new(name, expanded);
- }
- }
- fclose(fp);
-}
-
-
-/**
- Look for ${} (or %%) env vars in src and expand if the var
- exists (even if empty value). If not exist, the name is left as is.
- The process is done all over src, and nested ${${}} is not supported.
- src must be \0 terminated, and dst must be big enough.
-*/
-#ifndef WIN32
- #define ENVVAR_PREFFIX "${"
- #define ENVVAR_P_SIZE 2
- #define ENVVAR_SUFFIX "}"
- #define ENVVAR_S_SIZE 1
-#else
- #define ENVVAR_PREFFIX "%"
- #define ENVVAR_P_SIZE 1
- #define ENVVAR_SUFFIX "%"
- #define ENVVAR_S_SIZE 1
-#endif /* WIN32 */
-static void expand_envvars(char* src, char* dst) {
- char* hit1;
- char* hit2;
- char name[ENV_VAR];
- char* value;
- int prevlen;
- int done = 0;
- char* source = src;
-
- dst[0] = '\0';
- while (!done) {
- hit1 = strstr(source, ENVVAR_PREFFIX);
- if (hit1) {
- hit2 = strstr(hit1 + ENVVAR_P_SIZE, ENVVAR_SUFFIX);
- if (hit2) {
- /* "Copy" the leading part, if any */
- if (hit1 != source) {
- prevlen = strlen(dst);
- strncat(dst, source, hit1 - source);
- dst[prevlen + (hit1 - source)] = '\0';
- }
- /* Figure the name of the env var we just found */
- strncpy(name, hit1 + ENVVAR_P_SIZE,
- hit2 - (hit1 + ENVVAR_P_SIZE));
- name[hit2 - (hit1 + ENVVAR_P_SIZE)] = '\0';
- /* See if we can get something with that name */
- value = getenv(name);
- if (value) {
- /* Push the var value */
- strcat(dst, value);
- } else {
- /* Leave the var name, so it is clear that it failed */
- strcat(dst, ENVVAR_PREFFIX);
- strcat(dst, name);
- strcat(dst, ENVVAR_SUFFIX);
- }
- /* Continue after closing mark, like a new string */
- source = hit2 + ENVVAR_S_SIZE;
- } else {
- /* Non terminated var so "copy as is" and finish */
- strcat(dst, source);
- done = 1;
- }
- } else {
- /* "Copy" whatever is left */
- strcat(dst, source);
- done = 1;
- }
- }
-}
-
-
-/**
Return a full path if the filename exists when combined
with any item from pathlist. Or NULL otherwise.
*/
@@ -572,24 +370,3 @@ static void free_paths(BFILE* bfile) {
MEM_freeN(bfile->tpath);
}
}
-
-
-/**
- Create a temp directory in safe and multiuser way.
- */
-static void setup_temp() {
- char template[MAXPATHLEN];
- char* tempdir;
-
- if (getenv("TMPDIR")) {
- sprintf(template, "%s/blender-XXXXXX", getenv("TMPDIR"));
- } else {
- sprintf(template, "/tmp/blender-XXXXXX");
-// MacOSX NSTemporaryDirectory and WIN32 ???
-// https://bugs.launchpad.net/cuneiform-linux/+bug/267136
-// https://svn.r-project.org/R/trunk/src/main/mkdtemp.c
- }
- tempdir = mkdtemp(template);
- BLI_setenv("BLENDER_TEMP", tempdir);
-}
-
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 2d5234aee34..b43da1cf9bd 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -44,6 +44,7 @@
#include "BLI_storage_types.h"
#include "BKE_utildefines.h"
+#include "BKE_blender.h" // BLENDER_VERSION
@@ -63,11 +64,6 @@
#else /* non windows */
-#ifdef __APPLE__
-#include <sys/param.h>
-#include <CoreFoundation/CoreFoundation.h>
-#endif
-
#ifdef __linux__
#include "binreloc.h"
#endif
@@ -759,7 +755,11 @@ char *BLI_gethome(void) {
}
- /* add user profile support for WIN 2K / NT */
+ /* add user profile support for WIN 2K / NT.
+ * This is %APPDATA%, which translates to either
+ * %USERPROFILE%\Application Data or since Vista
+ * to %USERPROFILE%\AppData\Roaming
+ */
hResult = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appdatapath);
if (hResult == S_OK)
@@ -794,7 +794,7 @@ char *BLI_gethome(void) {
/* this function returns the path to a blender folder, if it exists
* utility functions for BLI_gethome_folder */
-/* #define PATH_DEBUG */ /* for testing paths that are checked */
+// #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)
{
@@ -905,6 +905,303 @@ char *BLI_gethome_folder(char *folder_name, int flag)
return NULL;
}
+
+/* NEW stuff, to be cleaned up when fully migrated */
+/* ************************************************************* */
+/* ************************************************************* */
+
+#define PATH_DEBUG2
+
+static char *blender_version_decimal(void)
+{
+ static char version_str[5];
+ sprintf(version_str, "%d.%02d", BLENDER_VERSION/100, BLENDER_VERSION%100);
+ return version_str;
+}
+
+static int test_path(char *targetpath, char *path_base, char *path_sep, char *folder_name)
+{
+ char tmppath[FILE_MAX];
+
+ if(path_sep) BLI_join_dirfile(tmppath, path_base, path_sep);
+ else BLI_strncpy(tmppath, path_base, sizeof(tmppath));
+
+ BLI_make_file_string("/", targetpath, tmppath, folder_name);
+
+ if (BLI_exists(targetpath)) {
+#ifdef PATH_DEBUG2
+ printf("\tpath found: %s\n", targetpath);
+#endif
+ return 1;
+ }
+ else {
+#ifdef PATH_DEBUG2
+ printf("\tpath missing: %s\n", targetpath);
+#endif
+ //targetpath[0] = '\0';
+ return 0;
+ }
+}
+
+static int test_env_path(char *path, char *envvar)
+{
+ char *env = envvar?getenv(envvar):NULL;
+ if (!env) return 0;
+
+ if (BLI_exists(env)) {
+ BLI_strncpy(path, env, FILE_MAX);
+ return 1;
+ } else {
+ path[0] = '\0';
+ return 0;
+ }
+}
+
+static int get_path_local(char *targetpath, char *folder_name)
+{
+ extern char bprogname[]; /* argv[0] from creator.c */
+ char bprogdir[FILE_MAX];
+ char cwd[FILE_MAX];
+ char *s;
+ int i;
+
+#ifdef PATH_DEBUG2
+ printf("get_path_local...\n");
+#endif
+
+
+ /* use argv[0] (bprogname) to get the path to the executable */
+ s = BLI_last_slash(bprogname);
+ i = s - bprogname + 1;
+ BLI_strncpy(bprogdir, bprogname, i);
+
+ /* try EXECUTABLE_DIR/folder_name */
+ if(test_path(targetpath, bprogdir, "", folder_name))
+ return 1;
+
+ /* try CWD/release/folder_name */
+ if(test_path(targetpath, BLI_getwdN(cwd), "release", folder_name))
+ return 1;
+
+ /* try EXECUTABLE_DIR/release/folder_name */
+ if(test_path(targetpath, bprogdir, "release", folder_name))
+ return 1;
+
+ /* try EXECUTABLE_DIR/2.5/folder_name - new default directory for local blender installed files */
+ if(test_path(targetpath, bprogdir, blender_version_decimal(), folder_name))
+ return 1;
+
+ /* try ./.blender/folder_name -- DEPRECATED, need to update build systems */
+ if(test_path(targetpath, bprogdir, ".blender", folder_name))
+ return 1;
+
+ return 0;
+}
+
+#ifdef WIN32
+static int get_knownfolder_path(char *path, int folder)
+{
+ static char knownpath[MAXPATHLEN];
+ HRESULT hResult = SHGetFolderPath(NULL, folder, NULL, SHGFP_TYPE_CURRENT, knownpath);
+
+ if (hResult == S_OK)
+ {
+ if (BLI_exists(knownpath)) { /* from fop, also below... */
+ BLI_strncpy(path, knownpath, FILE_MAX);
+ return 1;
+ }
+ }
+ return 0;
+}
+#endif
+
+static int get_path_user(char *targetpath, char *folder_name, char *envvar)
+{
+ char user_path[FILE_MAX];
+#if defined(WIN32)
+ char appdata[FILE_MAX];
+#endif
+
+ user_path[0] = '\0';
+
+ if (test_env_path(targetpath, envvar))
+ return 1;
+
+#if defined(__APPLE__)
+ BLI_snprintf(user_path, FILE_MAX, "%s/%s", BLI_osx_getBasePath(BasePath_BlenderUser), blender_version_decimal());
+#elif defined(WIN32)
+ if (get_knownfolder_path(appdata, CSIDL_APPDATA)) {
+ BLI_snprintf(user_path, FILE_MAX, "%s\\Blender Foundation\\Blender\\%s", appdata, blender_version_decimal());
+ }
+#else /* UNIX */
+ /* XXX example below - replace with OS API */
+ BLI_snprintf(user_path, FILE_MAX, "%s/.blender/%s", BLI_gethome(), blender_version_decimal());
+#endif
+
+ if(!user_path[0])
+ return 0;
+
+#ifdef PATH_DEBUG2
+ printf("get_path_user: %s\n", user_path);
+#endif
+
+ /* try $HOME/folder_name */
+ return test_path(targetpath, user_path, NULL, folder_name);
+}
+
+static int get_path_system(char *targetpath, char *folder_name, char *envvar)
+{
+ char system_path[FILE_MAX];
+#if defined(WIN32)
+ char appdata[FILE_MAX];
+#endif
+
+ if (test_env_path(targetpath, envvar))
+ return 1;
+
+#if defined(__APPLE__)
+ BLI_snprintf(system_path, FILE_MAX, "%s/%s", BLI_osx_getBasePath(BasePath_ApplicationBundle), blender_version_decimal());
+#elif defined(WIN32)
+ if (get_knownfolder_path(appdata, CSIDL_COMMON_APPDATA)) {
+ BLI_snprintf(system_path, FILE_MAX, "%s\\Blender Foundation\\Blender\\%s", appdata, blender_version_decimal());
+ }
+#else /* UNIX */
+ /* XXX example below - replace with OS API */
+ BLI_snprintf(system_path, FILE_MAX, "/usr/share/blender/%s", blender_version_decimal());
+#endif
+
+ if(!system_path[0])
+ return 0;
+
+#ifdef PATH_DEBUG2
+ printf("get_path_system: %s\n", system_path);
+#endif
+
+ /* try $BLENDERPATH/folder_name */
+ return test_path(targetpath, system_path, NULL, folder_name);
+}
+
+/* get a folder out of the 'folder_id' presets for paths */
+/* returns the path if found, NULL string if not */
+char *BLI_get_folder(int folder_id, char *subfolder)
+{
+ static char path[FILE_MAX] = "";
+ char search_path[FILE_MAX];
+
+ switch (folder_id) {
+ case BLENDER_DATAFILES: /* general case */
+ BLI_join_dirfile(search_path, "datafiles", subfolder);
+ if (get_path_user(path, search_path, "BLENDER_USER_DATAFILES")) break;
+ if (get_path_local(path, search_path)) break;
+ if (get_path_system(path, search_path, "BLENDER_SYSTEM_DATAFILES")) break;
+ return NULL;
+
+ case BLENDER_USER_DATAFILES:
+ BLI_join_dirfile(search_path, "datafiles", subfolder);
+ if (get_path_user(path, search_path, "BLENDER_USER_DATAFILES")) break;
+ return NULL;
+
+ case BLENDER_SYSTEM_DATAFILES:
+ BLI_join_dirfile(search_path, "datafiles", subfolder);
+ if (get_path_system(path, search_path, "BLENDER_SYSTEM_DATAFILES")) break;
+ return NULL;
+
+ case BLENDER_CONFIG: /* general case */
+ BLI_join_dirfile(search_path, "config", subfolder);
+ if (get_path_user(path, search_path, "BLENDER_USER_CONFIG")) break;
+ if (get_path_local(path, search_path)) break;
+ if (get_path_system(path, search_path, "BLENDER_SYSTEM_CONFIG")) break;
+ return NULL;
+
+ case BLENDER_USER_CONFIG:
+ BLI_join_dirfile(search_path, "config", subfolder);
+ if (get_path_user(path, search_path, "BLENDER_USER_CONFIG")) break;
+ return NULL;
+
+ case BLENDER_SYSTEM_CONFIG:
+ BLI_join_dirfile(search_path, "config", subfolder);
+ if (get_path_system(path, search_path, "BLENDER_SYSTEM_CONFIG")) break;
+ return NULL;
+
+ case BLENDER_SCRIPTS: /* general case */
+ BLI_join_dirfile(search_path, "scripts", subfolder);
+ if (get_path_user(path, search_path, "BLENDER_USER_SCRIPTS")) break;
+ if (get_path_local(path, search_path)) break;
+ if (get_path_system(path, search_path, "BLENDER_SYSTEM_SCRIPTS")) break;
+ return NULL;
+
+ case BLENDER_USER_SCRIPTS:
+ BLI_join_dirfile(search_path, "scripts", subfolder);
+ if (get_path_user(path, search_path, "BLENDER_USER_SCRIPTS")) break;
+ return NULL;
+
+ case BLENDER_SYSTEM_SCRIPTS:
+ BLI_join_dirfile(search_path, "scripts", subfolder);
+ if (get_path_system(path, search_path, "BLENDER_SYSTEM_SCRIPTS")) break;
+ return NULL;
+
+ case BLENDER_PYTHON: /* general case */
+ BLI_join_dirfile(search_path, "python", subfolder);
+ if (get_path_local(path, search_path)) break;
+ if (get_path_system(path, search_path, "BLENDER_SYSTEM_PYTHON")) break;
+ return NULL;
+
+ case BLENDER_SYSTEM_PYTHON:
+ BLI_join_dirfile(search_path, "scripts", subfolder);
+
+ if (get_path_system(path, search_path, "BLENDER_SYSTEM_PYTHON")) break;
+ return NULL;
+ }
+
+ return path;
+}
+
+static char *BLI_get_user_folder_notest(int folder_id, char *subfolder)
+{
+ static char path[FILE_MAX] = "";
+ char search_path[FILE_MAX];
+
+ switch (folder_id) {
+ case BLENDER_USER_DATAFILES:
+ BLI_join_dirfile(search_path, "datafiles", subfolder);
+ get_path_user(path, search_path, "BLENDER_USER_DATAFILES");
+ break;
+ case BLENDER_USER_CONFIG:
+ BLI_join_dirfile(search_path, "config", subfolder);
+ get_path_user(path, search_path, "BLENDER_USER_CONFIG");
+ break;
+ }
+ if ('\0' == path[0]) {
+ return NULL;
+ }
+ return path;
+}
+
+char *BLI_get_folder_create(int folder_id, char *subfolder)
+{
+ char *path;
+
+ /* only for user folders */
+ if (!ELEM(folder_id, BLENDER_USER_DATAFILES, BLENDER_USER_CONFIG))
+ return NULL;
+
+ path = BLI_get_folder(folder_id, subfolder);
+
+ if (!path) {
+ path = BLI_get_user_folder_notest(folder_id, subfolder);
+ if (path) BLI_recurdir_fileops(path);
+ }
+
+ return path;
+}
+
+
+/* End new stuff */
+/* ************************************************************* */
+/* ************************************************************* */
+
+
+
#ifdef PATH_DEBUG
#undef PATH_DEBUG
#endif
@@ -1158,6 +1455,9 @@ void BLI_join_dirfile(char *string, const char *dir, const char *file)
if(string != dir) /* compare pointers */
BLI_strncpy(string, dir, FILE_MAX);
+
+ if (!file)
+ return;
sl_dir= BLI_add_slash(string);
@@ -1465,26 +1765,6 @@ char *get_install_dir(void) {
}
}
-/*
- * returns absolute path to the app bundle
- * only useful on OS X
- */
-#ifdef __APPLE__
-char* BLI_getbundle(void) {
- CFURLRef bundleURL;
- CFStringRef pathStr;
- static char path[MAXPATHLEN];
- CFBundleRef mainBundle = CFBundleGetMainBundle();
-
- bundleURL = CFBundleCopyBundleURL(mainBundle);
- pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
- CFStringGetCString(pathStr, path, MAXPATHLEN, kCFStringEncodingASCII);
- CFRelease(pathStr);
- CFRelease(bundleURL);
- return path;
-}
-#endif
-
#ifdef WITH_ICONV
void BLI_string_to_utf8(char *original, char *utf_8, const char *code)
diff --git a/source/blender/blenlib/intern/path_util_cocoa.mm b/source/blender/blenlib/intern/path_util_cocoa.mm
new file mode 100644
index 00000000000..00593afcd0c
--- /dev/null
+++ b/source/blender/blenlib/intern/path_util_cocoa.mm
@@ -0,0 +1,96 @@
+/* path_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): Damien Plisson 2010
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ */
+
+
+#import <Cocoa/Cocoa.h>
+
+#include <string.h>
+
+#include "BLI_path_util.h"
+
+
+
+/**
+ * Gets the ~/Library/Application Data/Blender folder
+ */
+const char* BLI_osx_getBasePath(basePathesTypes pathType)
+{
+ static char tempPath[512] = "";
+
+ NSAutoreleasePool *pool;
+ 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 { //Error
+ basePath = @"";
+ }
+ break;
+ case BasePath_BlenderUser:
+ paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
+ if ([paths count] > 0)
+ basePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Blender"];
+ else { //Error
+ basePath = @"";
+ }
+ break;
+ case BasePath_ApplicationBundle:
+ basePath = [[NSBundle mainBundle] bundlePath];
+ break;
+
+ default:
+ tempPath[0] = 0;
+ [pool drain];
+ return tempPath;
+ }
+
+ strcpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
+
+ [pool drain];
+ return tempPath;
+} \ No newline at end of file