Extensions: add BLENDER_USER_EXTENSIONS user directory
Replace: `{BLENDER_RESOURCE_PATH_USER}/extensions`
With: `{BLENDER_USER_EXTENSIONS}`
This follows BLENDER_USER_CONFIG & BLENDER_USER_SCRIPTS conventions.
Reading the environment variable and accessible via
`bpy.utils.user_resource('SCRIPTS')`
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<std::string> 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<std::string> BKE_appdir_folder_id_user_notest(const int folder_id,
|
||||
std::optional<std::string> 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;
|
||||
}
|
||||
|
||||
@@ -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<std::string> path = BKE_appdir_resource_path_id(BLENDER_RESOURCE_PATH_USER, false);
|
||||
std::optional<std::string> 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)
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user