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:
authorRay Molenkamp <github@lazydodo.com>2018-09-05 07:31:10 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-09-05 07:32:19 +0300
commitc13b2a2504393371e32a4fb4c01cfad8d7cc929e (patch)
treea07973eeff324519187c23cd6b52f61da10d83a3
parentbb6a94fa7b28390ea8c22a6026562b0ab6685f92 (diff)
Fix T54152: --env-system-scripts fails on win32
-rw-r--r--source/blender/blenkernel/intern/appdir.c117
-rw-r--r--source/blender/blenlib/BLI_path_util.h1
-rw-r--r--source/blender/blenlib/intern/path_util.c23
-rw-r--r--source/blender/blenlib/intern/storage.c2
-rw-r--r--source/blender/blentranslation/intern/blt_lang.c2
-rw-r--r--source/blender/editors/physics/physics_fluid.c5
-rw-r--r--source/blender/editors/space_file/fsmenu.c2
-rw-r--r--source/blender/imbuf/intern/colormanagement.c2
-rw-r--r--source/blender/imbuf/intern/thumbs.c6
-rw-r--r--source/blender/modifiers/intern/MOD_fluidsim_util.c4
10 files changed, 103 insertions, 61 deletions
diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c
index 317994d4ed9..8d6c34222d7 100644
--- a/source/blender/blenkernel/intern/appdir.c
+++ b/source/blender/blenkernel/intern/appdir.c
@@ -69,12 +69,12 @@ static char btempdir_session[FILE_MAX] = ""; /* volatile temporary directory */
const char *BKE_appdir_folder_default(void)
{
#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)
return xdg_documents_dir;
- return getenv("HOME");
+ return BLI_getenv("HOME");
#else /* Windows */
static char documentfolder[MAXPATHLEN];
HRESULT hResult;
@@ -159,7 +159,7 @@ static bool test_path(
*/
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 (BLI_is_dir(env)) {
@@ -237,19 +237,51 @@ static bool is_portable_install(void)
}
/**
+ * Returns the path of a folder from environment variables
+ *
+ * \param targetpath: String to return path.
+ * \param subfolder_name: optional name of subfolder within folder.
+ * \param envvar: name of environment variable to check folder_name.
+ * \return true if it was able to construct such a path.
+ */
+static bool get_path_environment(
+ char *targetpath,
+ size_t targetpath_len,
+ const char *subfolder_name,
+ const char *envvar)
+{
+ char user_path[FILE_MAX];
+
+ if (test_env_path(user_path, envvar)) {
+ if (subfolder_name) {
+ return test_path(
+ targetpath,
+ targetpath_len,
+ user_path,
+ NULL,
+ subfolder_name);
+ }
+ else {
+ BLI_strncpy(targetpath, user_path, FILE_MAX);
+ return true;
+ }
+ }
+ return false;
+}
+
+/**
* Returns the path of a folder within the user-files area.
*
*
* \param targetpath String to return path
* \param folder_name default name of folder within user area
* \param subfolder_name optional name of subfolder within folder
- * \param envvar name of environment variable which, if defined, overrides folder_name
- * \param ver Blender version, used to construct a subdirectory name
+ * \param ver Blender version, used to construct a subdirectory name
* \return true if it was able to construct such a path.
*/
static bool get_path_user(
char *targetpath, size_t targetpath_len, const char *folder_name, const char *subfolder_name,
- const char *envvar, const int ver)
+ const int ver)
{
char user_path[FILE_MAX];
const char *user_base_path;
@@ -260,16 +292,6 @@ static bool get_path_user(
}
user_path[0] = '\0';
- if (test_env_path(user_path, envvar)) {
- if (subfolder_name) {
- return test_path(targetpath, targetpath_len, user_path, NULL, subfolder_name);
- }
- else {
- BLI_strncpy(targetpath, user_path, FILE_MAX);
- return true;
- }
- }
-
user_base_path = (const char *)GHOST_getUserDir(ver, blender_version_decimal(ver));
if (user_base_path)
BLI_strncpy(user_path, user_base_path, FILE_MAX);
@@ -295,13 +317,12 @@ static bool get_path_user(
* \param targetpath String to return path
* \param folder_name default name of folder within installation area
* \param subfolder_name optional name of subfolder within folder
- * \param envvar name of environment variable which, if defined, overrides folder_name
* \param ver Blender version, used to construct a subdirectory name
* \return true if it was able to construct such a path.
*/
static bool get_path_system(
char *targetpath, size_t targetpath_len, const char *folder_name, const char *subfolder_name,
- const char *envvar, const int ver)
+ const int ver)
{
char system_path[FILE_MAX];
const char *system_base_path;
@@ -320,17 +341,6 @@ static bool get_path_system(
}
system_path[0] = '\0';
-
- if (test_env_path(system_path, envvar)) {
- if (subfolder_name) {
- return test_path(targetpath, targetpath_len, system_path, NULL, subfolder_name);
- }
- else {
- BLI_strncpy(targetpath, system_path, FILE_MAX);
- return true;
- }
- }
-
system_base_path = (const char *)GHOST_getSystemDir(ver, blender_version_decimal(ver));
if (system_base_path)
BLI_strncpy(system_path, system_base_path, FILE_MAX);
@@ -367,40 +377,49 @@ const char *BKE_appdir_folder_id_ex(
switch (folder_id) {
case BLENDER_DATAFILES: /* general case */
- if (get_path_user(path, path_len, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break;
+ if (get_path_environment(path, path_len, subfolder, "BLENDER_USER_DATAFILES")) break;
+ if (get_path_user(path, path_len, "datafiles", subfolder, ver)) break;
+ if (get_path_environment(path, path_len, subfolder, "BLENDER_SYSTEM_DATAFILES")) 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, ver)) break;
return NULL;
case BLENDER_USER_DATAFILES:
- if (get_path_user(path, path_len, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break;
+ if (get_path_environment(path, path_len, subfolder, "BLENDER_USER_DATAFILES")) break;
+ if (get_path_user(path, path_len, "datafiles", subfolder, ver)) break;
return NULL;
case BLENDER_SYSTEM_DATAFILES:
+ if (get_path_environment(path, path_len, subfolder, "BLENDER_SYSTEM_DATAFILES")) break;
+ if (get_path_system(path, path_len, "datafiles", subfolder, 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;
return NULL;
case BLENDER_USER_AUTOSAVE:
- if (get_path_user(path, path_len, "autosave", subfolder, "BLENDER_USER_DATAFILES", ver)) break;
+ if (get_path_environment(path, path_len, subfolder, "BLENDER_USER_DATAFILES")) break;
+ if (get_path_user(path, path_len, "autosave", subfolder, ver)) break;
return NULL;
case BLENDER_USER_CONFIG:
- if (get_path_user(path, path_len, "config", subfolder, "BLENDER_USER_CONFIG", ver)) break;
+ if (get_path_environment(path, path_len, subfolder, "BLENDER_USER_CONFIG")) break;
+ if (get_path_user(path, path_len, "config", subfolder, ver)) break;
return NULL;
case BLENDER_USER_SCRIPTS:
- if (get_path_user(path, path_len, "scripts", subfolder, "BLENDER_USER_SCRIPTS", ver)) break;
+ if (get_path_environment(path, path_len, subfolder, "BLENDER_USER_SCRIPTS")) break;
+ if (get_path_user(path, path_len, "scripts", subfolder, ver)) break;
return NULL;
case BLENDER_SYSTEM_SCRIPTS:
+ if (get_path_environment(path, path_len, subfolder, "BLENDER_SYSTEM_SCRIPTS")) break;
+ if (get_path_system(path, path_len, "scripts", subfolder, ver)) break;
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;
return NULL;
case BLENDER_SYSTEM_PYTHON:
+ if (get_path_environment(path, path_len, subfolder, "BLENDER_SYSTEM_PYTHON")) break;
+ if (get_path_system(path, path_len, "python", subfolder, ver)) break;
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;
return NULL;
default:
@@ -428,16 +447,20 @@ const char *BKE_appdir_folder_id_user_notest(const int folder_id, const char *su
switch (folder_id) {
case BLENDER_USER_DATAFILES:
- get_path_user(path, sizeof(path), "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver);
+ if (get_path_environment(path, sizeof(path), subfolder, "BLENDER_USER_DATAFILES")) break;
+ get_path_user(path, sizeof(path), "datafiles", subfolder, ver);
break;
case BLENDER_USER_CONFIG:
- get_path_user(path, sizeof(path), "config", subfolder, "BLENDER_USER_CONFIG", ver);
+ if (get_path_environment(path, sizeof(path), subfolder, "BLENDER_USER_CONFIG")) break;
+ get_path_user(path, sizeof(path), "config", subfolder, ver);
break;
case BLENDER_USER_AUTOSAVE:
- get_path_user(path, sizeof(path), "autosave", subfolder, "BLENDER_USER_AUTOSAVE", ver);
+ if (get_path_environment(path, sizeof(path), subfolder, "BLENDER_USER_AUTOSAVE")) break;
+ get_path_user(path, sizeof(path), "autosave", subfolder, ver);
break;
case BLENDER_USER_SCRIPTS:
- get_path_user(path, sizeof(path), "scripts", subfolder, "BLENDER_USER_SCRIPTS", ver);
+ if (get_path_environment(path, sizeof(path), subfolder, "BLENDER_USER_SCRIPTS")) break;
+ get_path_user(path, sizeof(path), "scripts", subfolder, ver);
break;
default:
BLI_assert(0);
@@ -481,13 +504,13 @@ const char *BKE_appdir_folder_id_version(const int folder_id, const int ver, con
bool ok;
switch (folder_id) {
case BLENDER_RESOURCE_PATH_USER:
- ok = get_path_user(path, sizeof(path), NULL, NULL, NULL, ver);
+ ok = get_path_user(path, sizeof(path), NULL, NULL, ver);
break;
case BLENDER_RESOURCE_PATH_LOCAL:
ok = get_path_local(path, sizeof(path), NULL, NULL, ver);
break;
case BLENDER_RESOURCE_PATH_SYSTEM:
- ok = get_path_system(path, sizeof(path), NULL, NULL, NULL, ver);
+ ok = get_path_system(path, sizeof(path), NULL, NULL, ver);
break;
default:
path[0] = '\0'; /* in case do_check is false */
@@ -743,7 +766,7 @@ static void where_is_temp(char *fullname, char *basename, const size_t maxlen, c
#ifdef WIN32
if (fullname[0] == '\0') {
- const char *tmp = getenv("TEMP"); /* Windows */
+ const char *tmp = BLI_getenv("TEMP"); /* Windows */
if (tmp && BLI_is_dir(tmp)) {
BLI_strncpy(fullname, tmp, maxlen);
}
@@ -751,14 +774,14 @@ static void where_is_temp(char *fullname, char *basename, const size_t maxlen, c
#else
/* Other OS's - Try TMP and TMPDIR */
if (fullname[0] == '\0') {
- const char *tmp = getenv("TMP");
+ const char *tmp = BLI_getenv("TMP");
if (tmp && BLI_is_dir(tmp)) {
BLI_strncpy(fullname, tmp, maxlen);
}
}
if (fullname[0] == '\0') {
- const char *tmp = getenv("TMPDIR");
+ const char *tmp = BLI_getenv("TMPDIR");
if (tmp && BLI_is_dir(tmp)) {
BLI_strncpy(fullname, tmp, maxlen);
}
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index b4329bf81ac..e434e83416b 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -41,6 +41,7 @@ struct ListBase;
void BLI_setenv(const char *env, const char *val) ATTR_NONNULL(1);
void BLI_setenv_if_new(const char *env, const char *val) ATTR_NONNULL(1);
+const char *BLI_getenv(const char *env) ATTR_NONNULL(1);
void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
void BLI_make_exist(char *dir);
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 6272f2109d2..b28579febaf 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1095,7 +1095,7 @@ bool BLI_path_program_extensions_add_win32(char *name, const size_t maxlen)
if ((type == 0) || S_ISDIR(type)) {
/* typically 3-5, ".EXE", ".BAT"... etc */
const int ext_max = 12;
- const char *ext = getenv("PATHEXT");
+ const char *ext = BLI_getenv("PATHEXT");
if (ext) {
const int name_len = strlen(name);
char *filename = alloca(name_len + ext_max);
@@ -1152,7 +1152,7 @@ bool BLI_path_program_search(
const char separator = ':';
#endif
- path = getenv("PATH");
+ path = BLI_getenv("PATH");
if (path) {
char filename[FILE_MAX];
const char *temp;
@@ -1220,11 +1220,28 @@ void BLI_setenv(const char *env, const char *val)
*/
void BLI_setenv_if_new(const char *env, const char *val)
{
- if (getenv(env) == NULL)
+ if (BLI_getenv(env) == NULL)
BLI_setenv(env, val);
}
/**
+* get an env var, result has to be used immediately
+*/
+const char* BLI_getenv(const char *env)
+{
+#ifdef _MSC_VER
+ static char buffer[32767]; /* 32767 is the total size of the environment block on windows*/
+ if (GetEnvironmentVariableA(env, buffer, sizeof(buffer)))
+ return buffer;
+ else
+ return NULL;
+#else
+ return getenv(env);
+#endif
+}
+
+
+/**
* Strips off nonexistent (or non-accessible) subdirectories from the end of *dir, leaving the path of
* the lowest-level directory that does exist and we can read.
*/
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index f69b35ce5a9..cfcc2bc4390 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -85,7 +85,7 @@
*/
char *BLI_current_working_dir(char *dir, const size_t maxncpy)
{
- const char *pwd = getenv("PWD");
+ const char *pwd = BLI_getenv("PWD");
if (pwd) {
size_t srclen = BLI_strnlen(pwd, maxncpy);
if (srclen != maxncpy) {
diff --git a/source/blender/blentranslation/intern/blt_lang.c b/source/blender/blentranslation/intern/blt_lang.c
index 916de3a5d20..f373ca24861 100644
--- a/source/blender/blentranslation/intern/blt_lang.c
+++ b/source/blender/blentranslation/intern/blt_lang.c
@@ -214,7 +214,7 @@ void BLT_lang_init(void)
*
* Would also be good to find nicer way to check if LANG is correct.
*/
- const char *lang = getenv("LANG");
+ const char *lang = BLI_getenv("LANG");
if (lang != NULL) {
char *old_locale = setlocale(LC_ALL, NULL);
/* Make a copy so subsequenct setlocale() doesn't interfere. */
diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c
index 1cd2528b3ca..f960d6ed97b 100644
--- a/source/blender/editors/physics/physics_fluid.c
+++ b/source/blender/editors/physics/physics_fluid.c
@@ -42,6 +42,7 @@
#include "DNA_object_fluidsim_types.h"
#include "BLI_blenlib.h"
+#include "BLI_path_util.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
@@ -868,8 +869,8 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, shor
fb= MEM_callocN(sizeof(FluidBakeJob), "fluid bake job");
- if (getenv(strEnvName)) {
- int dlevel = atoi(getenv(strEnvName));
+ if (BLI_getenv(strEnvName)) {
+ int dlevel = atoi(BLI_getenv(strEnvName));
elbeemSetDebugLevel(dlevel);
BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer), "fluidsimBake::msg: Debug messages activated due to envvar '%s'\n", strEnvName);
elbeemDebugOut(debugStrBuffer);
diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c
index baa8e78572a..70df086b32d 100644
--- a/source/blender/editors/space_file/fsmenu.c
+++ b/source/blender/editors/space_file/fsmenu.c
@@ -577,7 +577,7 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
#else
/* unix */
{
- const char *home = getenv("HOME");
+ const char *home = BLI_getenv("HOME");
if (read_bookmarks && home) {
BLI_snprintf(line, sizeof(line), "%s/", home);
diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c
index 86c0dd69930..1d287025a4e 100644
--- a/source/blender/imbuf/intern/colormanagement.c
+++ b/source/blender/imbuf/intern/colormanagement.c
@@ -624,7 +624,7 @@ void colormanagement_init(void)
OCIO_init();
- ocio_env = getenv("OCIO");
+ ocio_env = BLI_getenv("OCIO");
if (ocio_env && ocio_env[0] != '\0') {
config = OCIO_configCreateFromEnv();
diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c
index bfb7a041802..9d2b635bd7b 100644
--- a/source/blender/imbuf/intern/thumbs.c
+++ b/source/blender/imbuf/intern/thumbs.c
@@ -99,10 +99,10 @@ static bool get_thumb_dir(char *dir, ThumbSize size)
s += strlen(dir);
#else
#if defined(USE_FREEDESKTOP)
- const char *home_cache = getenv("XDG_CACHE_HOME");
- const char *home = home_cache ? home_cache : getenv("HOME");
+ const char *home_cache = BLI_getenv("XDG_CACHE_HOME");
+ const char *home = home_cache ? home_cache : BLI_getenv("HOME");
#else
- const char *home = getenv("HOME");
+ const char *home = BLI_getenv("HOME");
#endif
if (!home) return 0;
s += BLI_strncpy_rlen(s, home, FILE_MAX);
diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c
index e366116a5fb..8dd4e289503 100644
--- a/source/blender/modifiers/intern/MOD_fluidsim_util.c
+++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c
@@ -481,8 +481,8 @@ static DerivedMesh *fluidsim_read_cache(
const char *strEnvName2 = "BLENDER_ELBEEMBOBJABORT"; // from blendercall.cpp
if (G.background == 1) {
- if (getenv(strEnvName2)) {
- int elevel = atoi(getenv(strEnvName2));
+ if (BLI_getenv(strEnvName2)) {
+ int elevel = atoi(BLI_getenv(strEnvName2));
if (elevel > 0) {
printf("Env. var %s set, fluid sim mesh '%s' not found, aborting render...\n",
strEnvName2, targetFile);