diff options
author | Campbell Barton <campbell@blender.org> | 2022-10-04 05:54:09 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-10-04 05:54:09 +0300 |
commit | bf4926b30c6fc7b9f98dde508b7b644feaf21022 (patch) | |
tree | 6d79bbef18525e93dcf2ef7f9d9f1006d97e793a /source/blender/blenkernel | |
parent | 868ef9ec37a9dd4856a8a034f7e3865cf4252b1d (diff) |
Support environment variables to override USER & SYSTEM resource paths
Even though individual USER/SYSTEM paths could be set using environment variables,
it wasn't possible to override the USER or SYSTEM paths.
This meant the result of `bpy.utils.resource_path('USER')` &
`bpy.utils.resource_path('SYSTEM')` could still be used by scripts,
making the Blender session potentially the default USER directory
(even when `BLENDER_USER_CONFIG`, `BLENDER_USER_SCRIPTS` &
`BLENDER_USER_DATAFILES` all point elsewhere).
Resolve by adding environment variables:
- BLENDER_USER_RESOURCES
- BLENDER_SYSTEM_RESOURCES
These will be used for `bpy.utils.resource_path('USER')` &
`bpy.utils.resource_path('SYSTEM')`, as well as a basis for user &
system directories, unless those environment variables are
set (`BLENDER_USER_*` or `BLENDER_SYSTEM_*`).
Resolves issue raised by T101389.
Example usage & output:
{P3225}
Reviewed By: brecht
Ref D16111
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/appdir.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c index e3c42c8bb78..7c409f1095b 100644 --- a/source/blender/blenkernel/intern/appdir.c +++ b/source/blender/blenkernel/intern/appdir.c @@ -460,18 +460,22 @@ static bool get_path_user_ex(char *targetpath, const bool check_is_dir) { char user_path[FILE_MAX]; - const char *user_base_path; - /* for portable install, user path is always local */ - if (BKE_appdir_app_is_portable_install()) { - return get_path_local_ex( - targetpath, targetpath_len, folder_name, subfolder_name, version, check_is_dir); + if (test_env_path(user_path, "BLENDER_USER_RESOURCES", check_is_dir)) { + /* Pass. */ } - user_path[0] = '\0'; + else { + /* for portable install, user path is always local */ + if (BKE_appdir_app_is_portable_install()) { + return get_path_local_ex( + targetpath, targetpath_len, folder_name, subfolder_name, version, check_is_dir); + } + user_path[0] = '\0'; - user_base_path = GHOST_getUserDir(version, blender_version_decimal(version)); - if (user_base_path) { - BLI_strncpy(user_path, user_base_path, FILE_MAX); + const char *user_base_path = GHOST_getUserDir(version, blender_version_decimal(version)); + if (user_base_path) { + BLI_strncpy(user_path, user_base_path, FILE_MAX); + } } if (!user_path[0]) { @@ -518,7 +522,6 @@ static bool get_path_system_ex(char *targetpath, const bool check_is_dir) { char system_path[FILE_MAX]; - const char *system_base_path; char relfolder[FILE_MAX]; if (folder_name) { /* `subfolder_name` may be NULL. */ @@ -528,10 +531,15 @@ static bool get_path_system_ex(char *targetpath, relfolder[0] = '\0'; } - system_path[0] = '\0'; - system_base_path = GHOST_getSystemDir(version, blender_version_decimal(version)); - if (system_base_path) { - BLI_strncpy(system_path, system_base_path, FILE_MAX); + if (test_env_path(system_path, "BLENDER_SYSTEM_RESOURCES", check_is_dir)) { + /* Pass. */ + } + else { + system_path[0] = '\0'; + const char *system_base_path = GHOST_getSystemDir(version, blender_version_decimal(version)); + if (system_base_path) { + BLI_strncpy(system_path, system_base_path, FILE_MAX); + } } if (!system_path[0]) { |