diff --git a/scripts/modules/bpy/utils/__init__.py b/scripts/modules/bpy/utils/__init__.py index f345998bfad..5ba9fef622a 100644 --- a/scripts/modules/bpy/utils/__init__.py +++ b/scripts/modules/bpy/utils/__init__.py @@ -739,7 +739,7 @@ def user_resource(resource_type, *, path="", create=False): """ Return a user resource path (normally from the users home directory). - :arg type: Resource type in ['DATAFILES', 'CONFIG', 'SCRIPTS']. + :arg type: Resource type in ['DATAFILES', 'CONFIG', 'SCRIPTS', 'EXTENSIONS']. :type type: string :arg path: Optional subdirectory. :type path: string diff --git a/scripts/modules/sys_info.py b/scripts/modules/sys_info.py index 1d151fef13b..d6aa437ee4c 100644 --- a/scripts/modules/sys_info.py +++ b/scripts/modules/sys_info.py @@ -96,6 +96,7 @@ def write_sysinfo(filepath): output.write("datafiles: %r\n" % (bpy.utils.user_resource('DATAFILES'))) output.write("config: %r\n" % (bpy.utils.user_resource('CONFIG'))) output.write("scripts: %r\n" % (bpy.utils.user_resource('SCRIPTS'))) + output.write("extensions: %r\n" % (bpy.utils.user_resource('EXTENSIONS'))) output.write("tempdir: %r\n" % (bpy.app.tempdir)) output.write(title("FFmpeg")) diff --git a/source/blender/blenkernel/BKE_appdir.hh b/source/blender/blenkernel/BKE_appdir.hh index 6102e56f35e..b30afdc6040 100644 --- a/source/blender/blenkernel/BKE_appdir.hh +++ b/source/blender/blenkernel/BKE_appdir.hh @@ -168,6 +168,7 @@ enum { BLENDER_USER_CONFIG = 31, BLENDER_USER_DATAFILES = 32, BLENDER_USER_SCRIPTS = 33, + BLENDER_USER_EXTENSIONS = 34, /* system */ BLENDER_SYSTEM_DATAFILES = 52, diff --git a/source/blender/blenkernel/intern/appdir.cc b/source/blender/blenkernel/intern/appdir.cc index 8b57c2027f9..c206b68f8d6 100644 --- a/source/blender/blenkernel/intern/appdir.cc +++ b/source/blender/blenkernel/intern/appdir.cc @@ -656,6 +656,15 @@ bool BKE_appdir_folder_id_ex(const int folder_id, } return false; + case BLENDER_USER_EXTENSIONS: + if (get_path_environment(path, path_maxncpy, subfolder, "BLENDER_USER_EXTENSIONS")) { + break; + } + if (get_path_user(path, path_maxncpy, "extensions", subfolder)) { + break; + } + return false; + case BLENDER_SYSTEM_PYTHON: if (get_path_environment(path, path_maxncpy, subfolder, "BLENDER_SYSTEM_PYTHON")) { break; @@ -717,6 +726,14 @@ std::optional BKE_appdir_folder_id_user_notest(const int folder_id, } get_path_user_ex(path, sizeof(path), "scripts", subfolder, version, check_is_dir); break; + case BLENDER_USER_EXTENSIONS: + if (get_path_environment_ex( + path, sizeof(path), subfolder, "BLENDER_USER_EXTENSIONS", check_is_dir)) + { + break; + } + get_path_user_ex(path, sizeof(path), "extensions", subfolder, version, check_is_dir); + break; default: BLI_assert_unreachable(); break; @@ -731,7 +748,12 @@ std::optional BKE_appdir_folder_id_user_notest(const int folder_id, std::optional BKE_appdir_folder_id_create(const int folder_id, const char *subfolder) { /* Only for user folders. */ - if (!ELEM(folder_id, BLENDER_USER_DATAFILES, BLENDER_USER_CONFIG, BLENDER_USER_SCRIPTS)) { + if (!ELEM(folder_id, + BLENDER_USER_DATAFILES, + BLENDER_USER_CONFIG, + BLENDER_USER_SCRIPTS, + BLENDER_USER_EXTENSIONS)) + { BLI_assert_unreachable(); return std::nullopt; } diff --git a/source/blender/blenkernel/intern/preferences.cc b/source/blender/blenkernel/intern/preferences.cc index 62f820dd22e..14d8b784893 100644 --- a/source/blender/blenkernel/intern/preferences.cc +++ b/source/blender/blenkernel/intern/preferences.cc @@ -255,14 +255,14 @@ size_t BKE_preferences_extension_repo_dirpath_get(const bUserExtensionRepo *repo return BLI_strncpy_rlen(dirpath, repo->custom_dirpath, dirpath_maxncpy); } - /* TODO: support `BLENDER_USER_EXTENSIONS`, until then add to user resource. */ - std::optional path = BKE_appdir_resource_path_id(BLENDER_RESOURCE_PATH_USER, false); + std::optional path = BKE_appdir_folder_id_user_notest(BLENDER_USER_EXTENSIONS, + nullptr); /* Highly unlikely to fail as the directory doesn't have to exist. */ if (!path) { dirpath[0] = '\0'; return 0; } - return BLI_path_join(dirpath, dirpath_maxncpy, path.value().c_str(), "extensions", repo->module); + return BLI_path_join(dirpath, dirpath_maxncpy, path.value().c_str(), repo->module); } bUserExtensionRepo *BKE_preferences_extension_repo_find_index(const UserDef *userdef, int index) diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 0daa2b2585f..f40444f8ff9 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -625,7 +625,7 @@ typedef struct bUserExtensionRepo { /** * The "local" directory where extensions are stored. - * When unset, use `{BLENDER_RESOURCE_PATH_USER}/extensions/{bUserExtensionRepo::module}`. + * When unset, use `{BLENDER_USER_EXTENSIONS}/{bUserExtensionRepo::module}`. */ char custom_dirpath[1024]; /* FILE_MAX */ char remote_path[1024]; /* FILE_MAX */ diff --git a/source/blender/python/intern/bpy.cc b/source/blender/python/intern/bpy.cc index 5feb1d9b19a..547350df270 100644 --- a/source/blender/python/intern/bpy.cc +++ b/source/blender/python/intern/bpy.cc @@ -223,6 +223,7 @@ static PyObject *bpy_user_resource(PyObject * /*self*/, PyObject *args, PyObject {BLENDER_USER_DATAFILES, "DATAFILES"}, {BLENDER_USER_CONFIG, "CONFIG"}, {BLENDER_USER_SCRIPTS, "SCRIPTS"}, + {BLENDER_USER_EXTENSIONS, "EXTENSIONS"}, {0, nullptr}, }; PyC_StringEnum type = {type_items}; diff --git a/source/creator/creator_args.cc b/source/creator/creator_args.cc index f923a9eb68c..833ee8be0a6 100644 --- a/source/creator/creator_args.cc +++ b/source/creator/creator_args.cc @@ -755,6 +755,7 @@ static void print_help(bArgs *ba, bool all) PRINT(" (other 'BLENDER_USER_*' variables override when set).\n"); PRINT(" $BLENDER_USER_CONFIG Directory for user configuration files.\n"); PRINT(" $BLENDER_USER_SCRIPTS Directory for user scripts.\n"); + PRINT(" $BLENDER_USER_EXTENSIONS Directory for user extensions.\n"); PRINT(" $BLENDER_USER_DATAFILES Directory for user data files (icons, translations, ..).\n"); PRINT("\n"); PRINT(" $BLENDER_SYSTEM_RESOURCES Top level directory for system files.\n");