From 939e4b2efcb3d8a2d4481341866ef0fb2e6d4aa6 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 5 Jun 2024 18:36:13 +0200 Subject: [PATCH] Core: Change portable install folder to portable/ There is a mechanism to store config files in the same folder as the Blender executable. The typical use case is putting Blender on a USB drive and taking the config with you. However the problem is that this is using the 4.2/ folder, which is fine for config/ but with e.g. addons, studiolights and now extensions this is mixing user and system files. This requires exceptions, doesn't work well in some cases and is just generally not great design. Instead use a folder named portable/ that is separate. Pull Request: https://projects.blender.org/blender/blender/pulls/122778 --- source/blender/blenkernel/BKE_appdir.hh | 5 ---- source/blender/blenkernel/intern/appdir.cc | 21 ++++++---------- .../blender/blenkernel/intern/studiolight.cc | 24 ++++++++----------- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/source/blender/blenkernel/BKE_appdir.hh b/source/blender/blenkernel/BKE_appdir.hh index b30afdc6040..6002e3fcebc 100644 --- a/source/blender/blenkernel/BKE_appdir.hh +++ b/source/blender/blenkernel/BKE_appdir.hh @@ -100,11 +100,6 @@ std::optional BKE_appdir_resource_path_id_with_version(int folder_i int version); std::optional BKE_appdir_resource_path_id(int folder_id, bool check_is_dir); -/** - * Check if this is an install with user files kept together - * with the Blender executable and its installation files. - */ -bool BKE_appdir_app_is_portable_install(); /** * Return true if templates exist */ diff --git a/source/blender/blenkernel/intern/appdir.cc b/source/blender/blenkernel/intern/appdir.cc index c206b68f8d6..eb006ffbd06 100644 --- a/source/blender/blenkernel/intern/appdir.cc +++ b/source/blender/blenkernel/intern/appdir.cc @@ -391,8 +391,8 @@ static bool get_path_local_ex(char *targetpath, targetpath_maxncpy, check_is_dir, path_base, - blender_version_decimal(version), - relfolder); + (version) ? blender_version_decimal(version) : relfolder, + (version) ? relfolder : nullptr); } static bool get_path_local(char *targetpath, size_t targetpath_maxncpy, @@ -405,13 +405,6 @@ static bool get_path_local(char *targetpath, targetpath, targetpath_maxncpy, folder_name, subfolder_name, version, check_is_dir); } -bool BKE_appdir_app_is_portable_install() -{ - /* Detect portable install by the existence of `config` folder. */ - char dirpath[FILE_MAX]; - return get_path_local(dirpath, sizeof(dirpath), "config", nullptr); -} - /** * Returns the path of a folder from environment variables. * @@ -465,15 +458,15 @@ static bool get_path_user_ex(char *targetpath, { char user_path[FILE_MAX]; + /* Environment variable override. */ if (test_env_path(user_path, "BLENDER_USER_RESOURCES", check_is_dir)) { /* Pass. */ } + /* Portable install, to store user files next to Blender executable. */ + else if (get_path_local_ex(user_path, sizeof(user_path), "portable", nullptr, 0, true)) { + /* Pass. */ + } else { - /* for portable install, user path is always local */ - if (BKE_appdir_app_is_portable_install()) { - return get_path_local_ex( - targetpath, targetpath_maxncpy, folder_name, subfolder_name, version, check_is_dir); - } user_path[0] = '\0'; const char *user_base_path = GHOST_getUserDir(version, blender_version_decimal(version)); diff --git a/source/blender/blenkernel/intern/studiolight.cc b/source/blender/blenkernel/intern/studiolight.cc index b6c988e7b79..fa47514213d 100644 --- a/source/blender/blenkernel/intern/studiolight.cc +++ b/source/blender/blenkernel/intern/studiolight.cc @@ -840,21 +840,17 @@ void BKE_studiolight_init() BLI_addtail(&studiolights, sl); /* Go over the preset folder and add a studio-light for every image with its path. */ - /* For portable installs (where USER and SYSTEM paths are the same), - * only go over LOCAL data-files once. */ /* Also reserve icon space for it. */ - if (!BKE_appdir_app_is_portable_install()) { - studiolight_add_files_from_datafolder(BLENDER_USER_DATAFILES, - STUDIOLIGHT_LIGHTS_FOLDER, - STUDIOLIGHT_TYPE_STUDIO | STUDIOLIGHT_USER_DEFINED | - STUDIOLIGHT_SPECULAR_HIGHLIGHT_PASS); - studiolight_add_files_from_datafolder(BLENDER_USER_DATAFILES, - STUDIOLIGHT_WORLD_FOLDER, - STUDIOLIGHT_TYPE_WORLD | STUDIOLIGHT_USER_DEFINED); - studiolight_add_files_from_datafolder(BLENDER_USER_DATAFILES, - STUDIOLIGHT_MATCAP_FOLDER, - STUDIOLIGHT_TYPE_MATCAP | STUDIOLIGHT_USER_DEFINED); - } + studiolight_add_files_from_datafolder(BLENDER_USER_DATAFILES, + STUDIOLIGHT_LIGHTS_FOLDER, + STUDIOLIGHT_TYPE_STUDIO | STUDIOLIGHT_USER_DEFINED | + STUDIOLIGHT_SPECULAR_HIGHLIGHT_PASS); + studiolight_add_files_from_datafolder(BLENDER_USER_DATAFILES, + STUDIOLIGHT_WORLD_FOLDER, + STUDIOLIGHT_TYPE_WORLD | STUDIOLIGHT_USER_DEFINED); + studiolight_add_files_from_datafolder(BLENDER_USER_DATAFILES, + STUDIOLIGHT_MATCAP_FOLDER, + STUDIOLIGHT_TYPE_MATCAP | STUDIOLIGHT_USER_DEFINED); studiolight_add_files_from_datafolder(BLENDER_SYSTEM_DATAFILES, STUDIOLIGHT_LIGHTS_FOLDER, STUDIOLIGHT_TYPE_STUDIO |