Fix T62736: Inconsistent behavior bpy.utils.user_resource()
If a subfolder was specified which didn't exist, logic would fallback to get_path_user (instead of get_path_environment). Now always use the from the environment variable if it's set and exists.
This commit is contained in:
parent
4e2aea5efe
commit
fe7c7d2820
Notes:
blender-bot
2023-02-14 03:19:07 +01:00
Referenced by issue #62736, Inconsistent behavior of bpy.utils.user_resource( ) function
|
@ -244,7 +244,7 @@ bool BKE_appdir_app_is_portable_install(void)
|
|||
* \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.
|
||||
* \return true if it was able to construct such a path and the path exists.
|
||||
*/
|
||||
static bool get_path_environment(
|
||||
char *targetpath,
|
||||
|
@ -271,6 +271,35 @@ static bool get_path_environment(
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_notest(
|
||||
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) {
|
||||
BLI_join_dirfile(targetpath, targetpath_len, user_path, subfolder_name);
|
||||
return true;
|
||||
}
|
||||
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
|
||||
|
@ -447,19 +476,19 @@ const char *BKE_appdir_folder_id_user_notest(const int folder_id, const char *su
|
|||
|
||||
switch (folder_id) {
|
||||
case BLENDER_USER_DATAFILES:
|
||||
if (get_path_environment(path, sizeof(path), subfolder, "BLENDER_USER_DATAFILES")) break;
|
||||
if (get_path_environment_notest(path, sizeof(path), subfolder, "BLENDER_USER_DATAFILES")) break;
|
||||
get_path_user(path, sizeof(path), "datafiles", subfolder, ver);
|
||||
break;
|
||||
case BLENDER_USER_CONFIG:
|
||||
if (get_path_environment(path, sizeof(path), subfolder, "BLENDER_USER_CONFIG")) break;
|
||||
if (get_path_environment_notest(path, sizeof(path), subfolder, "BLENDER_USER_CONFIG")) break;
|
||||
get_path_user(path, sizeof(path), "config", subfolder, ver);
|
||||
break;
|
||||
case BLENDER_USER_AUTOSAVE:
|
||||
if (get_path_environment(path, sizeof(path), subfolder, "BLENDER_USER_AUTOSAVE")) break;
|
||||
if (get_path_environment_notest(path, sizeof(path), subfolder, "BLENDER_USER_AUTOSAVE")) break;
|
||||
get_path_user(path, sizeof(path), "autosave", subfolder, ver);
|
||||
break;
|
||||
case BLENDER_USER_SCRIPTS:
|
||||
if (get_path_environment(path, sizeof(path), subfolder, "BLENDER_USER_SCRIPTS")) break;
|
||||
if (get_path_environment_notest(path, sizeof(path), subfolder, "BLENDER_USER_SCRIPTS")) break;
|
||||
get_path_user(path, sizeof(path), "scripts", subfolder, ver);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -167,10 +167,7 @@ static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObj
|
|||
}
|
||||
|
||||
/* same logic as BKE_appdir_folder_id_create(), but best leave it up to the script author to create */
|
||||
path = BKE_appdir_folder_id(folder_id, subdir);
|
||||
|
||||
if (!path)
|
||||
path = BKE_appdir_folder_id_user_notest(folder_id, subdir);
|
||||
path = BKE_appdir_folder_id_user_notest(folder_id, subdir);
|
||||
|
||||
return PyC_UnicodeFromByte(path ? path : "");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue