Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/appdir.c
| Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
| static char btempdir_session[FILE_MAX] = ""; /* volatile temporary directory */ | static char btempdir_session[FILE_MAX] = ""; /* volatile temporary directory */ | ||||
| /* This is now only used to really get the user's default document folder */ | /* This is now only used to really get the user's default document folder */ | ||||
| /* On Windows I chose the 'Users/<MyUserName>/Documents' since it's used | /* On Windows I chose the 'Users/<MyUserName>/Documents' since it's used | ||||
| * as default location to save documents */ | * as default location to save documents */ | ||||
| const char *BKE_appdir_folder_default(void) | const char *BKE_appdir_folder_default(void) | ||||
| { | { | ||||
| #ifndef WIN32 | #ifndef WIN32 | ||||
| const char * const xdg_documents_dir = getenv("XDG_DOCUMENTS_DIR"); | const char * const xdg_documents_dir = BLI_getenv("XDG_DOCUMENTS_DIR"); | ||||
| if (xdg_documents_dir) | if (xdg_documents_dir) | ||||
| return xdg_documents_dir; | return xdg_documents_dir; | ||||
| return getenv("HOME"); | return BLI_getenv("HOME"); | ||||
| #else /* Windows */ | #else /* Windows */ | ||||
| static char documentfolder[MAXPATHLEN]; | static char documentfolder[MAXPATHLEN]; | ||||
| HRESULT hResult; | HRESULT hResult; | ||||
| /* Check for %HOME% env var */ | /* Check for %HOME% env var */ | ||||
| if (uput_getenv("HOME", documentfolder, MAXPATHLEN)) { | if (uput_getenv("HOME", documentfolder, MAXPATHLEN)) { | ||||
| if (BLI_is_dir(documentfolder)) return documentfolder; | if (BLI_is_dir(documentfolder)) return documentfolder; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** | /** | ||||
| * Puts the value of the specified environment variable into *path if it exists | * Puts the value of the specified environment variable into *path if it exists | ||||
| * and points at a directory. Returns true if this was done. | * and points at a directory. Returns true if this was done. | ||||
| */ | */ | ||||
| static bool test_env_path(char *path, const char *envvar) | static bool test_env_path(char *path, const char *envvar) | ||||
| { | { | ||||
| const char *env = envvar ? getenv(envvar) : NULL; | const char *env = envvar ? BLI_getenv(envvar) : NULL; | ||||
| if (!env) return false; | if (!env) return false; | ||||
| if (BLI_is_dir(env)) { | if (BLI_is_dir(env)) { | ||||
| BLI_strncpy(path, env, FILE_MAX); | BLI_strncpy(path, env, FILE_MAX); | ||||
| #ifdef PATH_DEBUG | #ifdef PATH_DEBUG | ||||
| printf("\t%s env %s found: %s\n", __func__, envvar, env); | printf("\t%s env %s found: %s\n", __func__, envvar, env); | ||||
| #endif | #endif | ||||
| return true; | return true; | ||||
| ▲ Show 20 Lines • Show All 223 Lines • ▼ Show 20 Lines | const char *BKE_appdir_folder_id_ex( | ||||
| const int folder_id, const char *subfolder, | const int folder_id, const char *subfolder, | ||||
| char *path, size_t path_len) | char *path, size_t path_len) | ||||
| { | { | ||||
| const int ver = BLENDER_VERSION; | const int ver = BLENDER_VERSION; | ||||
| switch (folder_id) { | switch (folder_id) { | ||||
| case BLENDER_DATAFILES: /* general case */ | case BLENDER_DATAFILES: /* general case */ | ||||
| if (get_path_user(path, path_len, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break; | if (get_path_user(path, path_len, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break; | ||||
| if (get_path_local(path, path_len, "datafiles", subfolder, ver)) break; | |||||
| if (get_path_system(path, path_len, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES", ver)) break; | if (get_path_system(path, path_len, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES", ver)) break; | ||||
| if (get_path_local(path, path_len, "datafiles", subfolder, ver)) break; | |||||
| return NULL; | return NULL; | ||||
| case BLENDER_USER_DATAFILES: | case BLENDER_USER_DATAFILES: | ||||
| if (get_path_user(path, path_len, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break; | if (get_path_user(path, path_len, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break; | ||||
| return NULL; | return NULL; | ||||
| case BLENDER_SYSTEM_DATAFILES: | case BLENDER_SYSTEM_DATAFILES: | ||||
| if (get_path_local(path, path_len, "datafiles", subfolder, ver)) break; | |||||
| if (get_path_system(path, path_len, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES", ver)) break; | if (get_path_system(path, path_len, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES", ver)) break; | ||||
| if (get_path_local(path, path_len, "datafiles", subfolder, ver)) break; | |||||
| return NULL; | return NULL; | ||||
| case BLENDER_USER_AUTOSAVE: | case BLENDER_USER_AUTOSAVE: | ||||
| if (get_path_user(path, path_len, "autosave", subfolder, "BLENDER_USER_DATAFILES", ver)) break; | if (get_path_user(path, path_len, "autosave", subfolder, "BLENDER_USER_DATAFILES", ver)) break; | ||||
| return NULL; | return NULL; | ||||
| case BLENDER_USER_CONFIG: | case BLENDER_USER_CONFIG: | ||||
| if (get_path_user(path, path_len, "config", subfolder, "BLENDER_USER_CONFIG", ver)) break; | if (get_path_user(path, path_len, "config", subfolder, "BLENDER_USER_CONFIG", ver)) break; | ||||
| return NULL; | return NULL; | ||||
| case BLENDER_USER_SCRIPTS: | case BLENDER_USER_SCRIPTS: | ||||
| if (get_path_user(path, path_len, "scripts", subfolder, "BLENDER_USER_SCRIPTS", ver)) break; | if (get_path_user(path, path_len, "scripts", subfolder, "BLENDER_USER_SCRIPTS", ver)) break; | ||||
| return NULL; | return NULL; | ||||
| case BLENDER_SYSTEM_SCRIPTS: | case BLENDER_SYSTEM_SCRIPTS: | ||||
| if (get_path_local(path, path_len, "scripts", subfolder, ver)) break; | |||||
| if (get_path_system(path, path_len, "scripts", subfolder, "BLENDER_SYSTEM_SCRIPTS", ver)) break; | if (get_path_system(path, path_len, "scripts", subfolder, "BLENDER_SYSTEM_SCRIPTS", ver)) break; | ||||
| if (get_path_local(path, path_len, "scripts", subfolder, ver)) break; | |||||
| return NULL; | return NULL; | ||||
| case BLENDER_SYSTEM_PYTHON: | case BLENDER_SYSTEM_PYTHON: | ||||
| if (get_path_local(path, path_len, "python", subfolder, ver)) break; | |||||
| if (get_path_system(path, path_len, "python", subfolder, "BLENDER_SYSTEM_PYTHON", ver)) break; | if (get_path_system(path, path_len, "python", subfolder, "BLENDER_SYSTEM_PYTHON", ver)) break; | ||||
| if (get_path_local(path, path_len, "python", subfolder, ver)) break; | |||||
| return NULL; | return NULL; | ||||
| default: | default: | ||||
| BLI_assert(0); | BLI_assert(0); | ||||
| break; | break; | ||||
| } | } | ||||
| return path; | return path; | ||||
| ▲ Show 20 Lines • Show All 326 Lines • ▼ Show 20 Lines | static void where_is_temp(char *fullname, char *basename, const size_t maxlen, char *userdir) | ||||
| if (userdir && BLI_is_dir(userdir)) { | if (userdir && BLI_is_dir(userdir)) { | ||||
| BLI_strncpy(fullname, userdir, maxlen); | BLI_strncpy(fullname, userdir, maxlen); | ||||
| } | } | ||||
| #ifdef WIN32 | #ifdef WIN32 | ||||
| if (fullname[0] == '\0') { | if (fullname[0] == '\0') { | ||||
| const char *tmp = getenv("TEMP"); /* Windows */ | const char *tmp = BLI_getenv("TEMP"); /* Windows */ | ||||
| if (tmp && BLI_is_dir(tmp)) { | if (tmp && BLI_is_dir(tmp)) { | ||||
| BLI_strncpy(fullname, tmp, maxlen); | BLI_strncpy(fullname, tmp, maxlen); | ||||
| } | } | ||||
| } | } | ||||
| #else | #else | ||||
| /* Other OS's - Try TMP and TMPDIR */ | /* Other OS's - Try TMP and TMPDIR */ | ||||
| if (fullname[0] == '\0') { | if (fullname[0] == '\0') { | ||||
| const char *tmp = getenv("TMP"); | const char *tmp = BLI_getenv("TMP"); | ||||
| if (tmp && BLI_is_dir(tmp)) { | if (tmp && BLI_is_dir(tmp)) { | ||||
| BLI_strncpy(fullname, tmp, maxlen); | BLI_strncpy(fullname, tmp, maxlen); | ||||
| } | } | ||||
| } | } | ||||
| if (fullname[0] == '\0') { | if (fullname[0] == '\0') { | ||||
| const char *tmp = getenv("TMPDIR"); | const char *tmp = BLI_getenv("TMPDIR"); | ||||
| if (tmp && BLI_is_dir(tmp)) { | if (tmp && BLI_is_dir(tmp)) { | ||||
| BLI_strncpy(fullname, tmp, maxlen); | BLI_strncpy(fullname, tmp, maxlen); | ||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| if (fullname[0] == '\0') { | if (fullname[0] == '\0') { | ||||
| BLI_strncpy(fullname, "/tmp/", maxlen); | BLI_strncpy(fullname, "/tmp/", maxlen); | ||||
| ▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines | |||||