Blender
V3.3
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "BLI_fileops.h"
#include "BLI_fileops_types.h"
#include "BLI_listbase.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_string_utils.h"
#include "BLI_utildefines.h"
#include "BKE_appdir.h"
#include "BKE_blender_version.h"
#include "BLT_translation.h"
#include "GHOST_Path-api.h"
#include "MEM_guardedalloc.h"
#include "CLG_log.h"
#include <unistd.h>
Go to the source code of this file.
Macros | |
#define | STR_OR_FALLBACK(a) ((a) ? (a) : _str_null) |
Functions | |
Internal Utilities | |
static char * | blender_version_decimal (const int version) |
Default Directories | |
const char * | BKE_appdir_folder_default (void) |
const char * | BKE_appdir_folder_root (void) |
const char * | BKE_appdir_folder_default_or_root (void) |
const char * | BKE_appdir_folder_home (void) |
bool | BKE_appdir_folder_documents (char *dir) |
bool | BKE_appdir_folder_caches (char *r_path, const size_t path_len) |
bool | BKE_appdir_font_folder_default (char *dir) |
Path Presets (Internal Helpers) | |
static bool | test_path (char *targetpath, size_t targetpath_len, const bool check_is_dir, const char *path_base, const char *folder_name, const char *subfolder_name) |
static bool | test_env_path (char *path, const char *envvar, const bool check_is_dir) |
static bool | get_path_local_ex (char *targetpath, size_t targetpath_len, const char *folder_name, const char *subfolder_name, const int version, const bool check_is_dir) |
static bool | get_path_local (char *targetpath, size_t targetpath_len, const char *folder_name, const char *subfolder_name) |
bool | BKE_appdir_app_is_portable_install (void) |
static bool | get_path_environment_ex (char *targetpath, size_t targetpath_len, const char *subfolder_name, const char *envvar, const bool check_is_dir) |
static bool | get_path_environment (char *targetpath, size_t targetpath_len, const char *subfolder_name, const char *envvar) |
static bool | get_path_user_ex (char *targetpath, size_t targetpath_len, const char *folder_name, const char *subfolder_name, const int version, const bool check_is_dir) |
static bool | get_path_user (char *targetpath, size_t targetpath_len, const char *folder_name, const char *subfolder_name) |
static bool | get_path_system_ex (char *targetpath, size_t targetpath_len, const char *folder_name, const char *subfolder_name, const int version, const bool check_is_dir) |
static bool | get_path_system (char *targetpath, size_t targetpath_len, const char *folder_name, const char *subfolder_name) |
Path Presets API | |
bool | BKE_appdir_folder_id_ex (const int folder_id, const char *subfolder, char *path, size_t path_len) |
const char * | BKE_appdir_folder_id (const int folder_id, const char *subfolder) |
const char * | BKE_appdir_folder_id_user_notest (const int folder_id, const char *subfolder) |
const char * | BKE_appdir_folder_id_create (const int folder_id, const char *subfolder) |
const char * | BKE_appdir_folder_id_version (const int folder_id, const int version, const bool check_is_dir) |
Program Path Queries | |
Access locations of Blender & Python. | |
static void | where_am_i (char *fullname, const size_t maxlen, const char *name) |
void | BKE_appdir_program_path_init (const char *argv0) |
const char * | BKE_appdir_program_path (void) |
const char * | BKE_appdir_program_dir (void) |
bool | BKE_appdir_program_python_search (char *fullpath, const size_t fullpath_len, const int version_major, const int version_minor) |
Temporary Directories | |
static void | where_is_temp (char *tempdir, const size_t tempdir_len, const char *userdir) |
static void | tempdir_session_create (char *tempdir_session, const size_t tempdir_session_len, const char *tempdir) |
void | BKE_tempdir_init (const char *userdir) |
const char * | BKE_tempdir_session (void) |
const char * | BKE_tempdir_base (void) |
void | BKE_tempdir_session_purge (void) |
Variables | |
static const char | _str_null [] = "(null)" |
Local Variables | |
static CLG_LogRef | LOG = {"bke.appdir"} |
struct { | |
char program_filepath [FILE_MAX] | |
char program_dirname [FILE_MAX] | |
char temp_dirname_base [FILE_MAX] | |
char temp_dirname_session [FILE_MAX] | |
} | g_app |
Initialization | |
#define | ASSERT_IS_INIT() BLI_assert(is_appdir_init) |
static bool | is_appdir_init = false |
void | BKE_appdir_init (void) |
void | BKE_appdir_exit (void) |
Application Templates | |
static const char * | app_template_directory_search [2] |
static const int | app_template_directory_id [2] |
bool | BKE_appdir_app_template_any (void) |
bool | BKE_appdir_app_template_id_search (const char *app_template, char *path, size_t path_len) |
bool | BKE_appdir_app_template_has_userpref (const char *app_template) |
void | BKE_appdir_app_templates (ListBase *templates) |
Access to application level directories.
Definition in file appdir.c.
#define ASSERT_IS_INIT | ( | ) | BLI_assert(is_appdir_init) |
Check if this is an install with user files kept together with the Blender executable and its installation files.
Definition at line 404 of file appdir.c.
References FILE_MAX, get_path_local(), and NULL.
Referenced by BKE_studiolight_init(), and get_path_user_ex().
Return true if templates exist
Definition at line 966 of file appdir.c.
References app_template_directory_id, app_template_directory_search, ARRAY_SIZE, BKE_appdir_folder_id_ex(), and FILE_MAX.
Referenced by wm_file_read_post().
bool BKE_appdir_app_template_has_userpref | ( | const char * | app_template | ) |
Definition at line 992 of file appdir.c.
References app_template, BKE_appdir_app_template_id_search(), BLENDER_USERPREF_FILE, BLI_exists(), BLI_path_join(), FILE_MAX, and NULL.
Referenced by BKE_blendfile_userdef_write_all(), and wm_homefile_read_exec().
bool BKE_appdir_app_template_id_search | ( | const char * | app_template, |
char * | path, | ||
size_t | path_len | ||
) |
Definition at line 980 of file appdir.c.
References app_template, app_template_directory_id, app_template_directory_search, ARRAY_SIZE, BKE_appdir_folder_id_ex(), BLI_join_dirfile(), and FILE_MAX.
Referenced by BKE_appdir_app_template_has_userpref(), wm_block_splash_image(), wm_homefile_read_ex(), and workspace_system_file_read().
Definition at line 1012 of file appdir.c.
References app_template_directory_id, app_template_directory_search, ARRAY_SIZE, BKE_appdir_folder_id_ex(), BLI_addtail(), BLI_filelist_dir_contents(), BLI_filelist_free(), BLI_genericNodeN(), BLI_listbase_clear(), BLI_strdup(), FILE_MAX, FILENAME_IS_CURRPAR, direntry::relname, S_ISDIR, and type.
Referenced by workspace_add_invoke().
Definition at line 96 of file appdir.c.
References BLI_assert, and is_appdir_init.
Referenced by blender::bke::image::partial_update::ImagePartialUpdateTest::TearDown(), BlendfileLoadingBaseTest::TearDownTestCase(), blender::bke::tests::TEST(), WM_exit_ex(), and blender::bke::tests::Context< TestData >::~Context().
bool BKE_appdir_folder_caches | ( | char * | r_path, |
size_t | path_len | ||
) |
Get the user's cache directory, i.e.
$HOME/.cache/blender/
USERPROFILE%\AppData\Local\Blender Foundation\Blender\
/Library/Caches/Blender
blender
folder exists. It does check if the parent of the path exists. Definition at line 203 of file appdir.c.
References BKE_tempdir_base(), BLI_is_dir(), BLI_path_join(), GHOST_getUserSpecialDir(), GHOST_kUserSpecialDirCaches, NULL, and SEP_STR.
Referenced by blender::ed::asset::index::AssetLibraryIndex::init_indices_base_path().
const char* BKE_appdir_folder_default | ( | void | ) |
Get the folder that's the "natural" starting point for browsing files on an OS.
$HOME
userprofile%/Documents
Users/{MyUserName}/Documents
is used as it's the default location to save documents. Definition at line 127 of file appdir.c.
References BKE_appdir_folder_documents(), BLI_getenv(), MAXPATHLEN, and NULL.
Referenced by BKE_appdir_folder_default_or_root(), blo_update_defaults_screen(), and fileselect_initialize_params_common().
const char* BKE_appdir_folder_default_or_root | ( | void | ) |
Definition at line 153 of file appdir.c.
References BKE_appdir_folder_default(), BKE_appdir_folder_root(), and NULL.
Referenced by file_expand_directory().
bool BKE_appdir_folder_documents | ( | char * | dir | ) |
Get the user's document directory, i.e.
$HOME/Documents
userprofile%/Documents
If this can't be found using OS queries (via Ghost), try manually finding it.
Definition at line 173 of file appdir.c.
References BKE_appdir_folder_home(), BLI_is_dir(), BLI_path_join(), BLI_strncpy(), FILE_MAXDIR, GHOST_getUserSpecialDir(), GHOST_kUserSpecialDirDocuments, N_, and NULL.
Referenced by BKE_appdir_folder_default(), and BKE_preferences_asset_library_default_add().
const char* BKE_appdir_folder_home | ( | void | ) |
Get the user's home directory, i.e.
$HOME
userprofile%
Definition at line 162 of file appdir.c.
References BLI_expand_tilde(), and BLI_getenv().
Referenced by BKE_appdir_folder_documents().
const char* BKE_appdir_folder_id | ( | const int | folder_id, |
const char * | subfolder | ||
) |
Definition at line 672 of file appdir.c.
References BKE_appdir_folder_id_ex(), FILE_MAX, and NULL.
Referenced by BKE_appdir_folder_id_create(), BKE_appdir_program_python_search(), blf_load_font_default(), BLF_load_font_stack(), BLT_lang_init(), BPy_init_modules(), BPY_python_start(), bpy_script_paths(), bpy_system_resource(), colormanagement_init(), ED_file_read_bookmarks(), blender::io::usd::ensure_usd_plugin_path_registered(), Freestyle_Init(), icon_preview_imbuf_from_brush(), init_iconfile_list(), init_internal_icons(), Freestyle::Config::Path::Path(), studiolight_add_files_from_datafolder(), wm_block_create_splash(), wm_history_file_read(), wm_homefile_read_ex(), wm_platform_support_check_approval(), and workspace_config_file_read().
const char* BKE_appdir_folder_id_create | ( | int | folder_id, |
const char * | subfolder | ||
) |
Returns the path to a folder in the user area, creating it if it doesn't exist.
Definition at line 727 of file appdir.c.
References BKE_appdir_folder_id(), BKE_appdir_folder_id_user_notest(), BLENDER_USER_AUTOSAVE, BLENDER_USER_CONFIG, BLENDER_USER_DATAFILES, BLENDER_USER_SCRIPTS, BLI_dir_create_recursive(), ELEM, and NULL.
Referenced by BKE_blendfile_userdef_write_all(), bookmark_add_exec(), bookmark_cleanup_exec(), bookmark_delete_exec(), bookmark_move_exec(), ED_fsmenu_entry_set_name(), ED_fsmenu_entry_set_path(), file_execute(), reset_recent_exec(), wm_autosave_location(), wm_history_file_write(), and wm_homefile_write_exec().
bool BKE_appdir_folder_id_ex | ( | int | folder_id, |
const char * | subfolder, | ||
char * | path, | ||
size_t | path_len | ||
) |
Get a folder out of the folder_id presets for paths.
subfolder | The name of a directory to check for, this may contain path separators but must resolve to a directory, checked with BLI_is_dir. |
Definition at line 568 of file appdir.c.
References BLENDER_DATAFILES, BLENDER_SYSTEM_DATAFILES, BLENDER_SYSTEM_PYTHON, BLENDER_SYSTEM_SCRIPTS, BLENDER_USER_AUTOSAVE, BLENDER_USER_CONFIG, BLENDER_USER_DATAFILES, BLENDER_USER_SCRIPTS, BLI_assert_unreachable, get_path_environment(), get_path_local(), get_path_system(), and get_path_user().
Referenced by BKE_appdir_app_template_any(), BKE_appdir_app_template_id_search(), BKE_appdir_app_templates(), and BKE_appdir_folder_id().
const char* BKE_appdir_folder_id_user_notest | ( | int | folder_id, |
const char * | subfolder | ||
) |
Returns the path to a folder in the user area without checking that it actually exists first.
Definition at line 681 of file appdir.c.
References BLENDER_USER_AUTOSAVE, BLENDER_USER_CONFIG, BLENDER_USER_DATAFILES, BLENDER_USER_SCRIPTS, BLENDER_VERSION, BLI_assert_unreachable, FILE_MAX, get_path_environment_ex(), get_path_user_ex(), and NULL.
Referenced by BKE_appdir_folder_id_create(), and bpy_user_resource().
const char* BKE_appdir_folder_id_version | ( | int | folder_id, |
int | version, | ||
bool | check_is_dir | ||
) |
Returns the path of the top-level version-specific local, user or system directory. If check_is_dir, then the result will be NULL if the directory doesn't exist.
Definition at line 752 of file appdir.c.
References BLENDER_RESOURCE_PATH_LOCAL, BLENDER_RESOURCE_PATH_SYSTEM, BLENDER_RESOURCE_PATH_USER, BLI_assert_msg, FILE_MAX, get_path_local_ex(), get_path_system_ex(), get_path_user_ex(), and NULL.
Referenced by bpy_resource_path().
const char* BKE_appdir_folder_root | ( | void | ) |
Definition at line 142 of file appdir.c.
References BLI_windows_get_default_root_dir().
Referenced by BKE_appdir_folder_default_or_root().
bool BKE_appdir_font_folder_default | ( | char * | dir | ) |
Gets a good default directory for fonts.
Definition at line 227 of file appdir.c.
References BLI_exists(), BLI_expand_tilde(), BLI_path_slash_ensure(), BLI_strncpy(), BLI_strncpy_wchar_as_utf8(), FILE_MAXDIR, L, and STRNCPY.
Referenced by BKE_blendfile_userdef_from_defaults().
Sanity check to ensure correct API use in debug mode.
Run this once the first level of arguments has been passed so we can be sure --env-system-datafiles
, and other --env-*
arguments has been passed.
Without this any callers to this module that run early on, will miss out on changes from parsing arguments.
Definition at line 88 of file appdir.c.
References BLI_assert, and is_appdir_init.
Referenced by blender::bke::tests::Context< TestData >::Context(), main(), blender::bke::image::partial_update::ImagePartialUpdateTest::SetUp(), BlendfileLoadingBaseTest::SetUpTestCase(), and blender::bke::tests::TEST().
const char* BKE_appdir_program_dir | ( | void | ) |
Path to directory of executable
Definition at line 873 of file appdir.c.
References BLI_assert, and g_app.
const char* BKE_appdir_program_path | ( | void | ) |
Path to executable
Definition at line 867 of file appdir.c.
References BLI_assert, and g_app.
Referenced by BPY_python_start(), and make_app_info().
void BKE_appdir_program_path_init | ( | const char * | argv0 | ) |
Initialize path to program executable.
Definition at line 861 of file appdir.c.
References BLI_split_dir_part(), g_app, and where_am_i().
Referenced by main().
bool BKE_appdir_program_python_search | ( | char * | fullpath, |
size_t | fullpath_len, | ||
int | version_major, | ||
int | version_minor | ||
) |
Find Python executable.
Definition at line 879 of file appdir.c.
References ARRAY_SIZE, ASSERT_IS_INIT, basename(), BKE_appdir_folder_id(), BLENDER_SYSTEM_PYTHON, BLI_exists(), BLI_join_dirfile(), BLI_path_program_search(), SNPRINTF, and STRINGIFY.
Referenced by BPY_python_start().
const char* BKE_tempdir_base | ( | void | ) |
Path to persistent temporary directory (with trailing slash)
Definition at line 1154 of file appdir.c.
References g_app.
Referenced by BKE_appdir_folder_caches(), BKE_tempdir_session(), blender::io::obj::obj_mtl_parser_test::check_string(), blender::io::obj::obj_exporter_regression_test::compare_obj_export_to_golden(), outliner_id_copy_exec(), outliner_id_paste_exec(), pose_copy_exec(), pose_paste_exec(), render_result_exr_file_cache_path(), sig_handle_crash(), view3d_copybuffer_exec(), view3d_pastebuffer_exec(), wm_autosave_delete(), wm_autosave_location(), WM_exit_ex(), and WM_file_recover_last_session().
void BKE_tempdir_init | ( | const char * | userdir | ) |
Initialize path to temporary directory.
Definition at line 1133 of file appdir.c.
References BKE_tempdir_session_purge(), g_app, tempdir_session_create(), and where_is_temp().
Referenced by blender::io::obj::obj_mtl_parser_test::check_string(), blender::io::obj::obj_exporter_regression_test::compare_obj_export_to_golden(), blender::io::obj::ObjExporterWriterTest::SetUp(), blender::io::obj::TEST_F(), blender::bke::tests::AssetCatalogTest::use_temp_path(), blender::bke::tests::AssetLibraryServiceTest::use_temp_path(), and wm_init_userdef().
const char* BKE_tempdir_session | ( | void | ) |
Path to temporary directory (with trailing slash)
Definition at line 1149 of file appdir.c.
References BKE_tempdir_base(), and g_app.
Delete content of this instance's temp dir.
Definition at line 1159 of file appdir.c.
References BLI_delete(), BLI_is_dir(), and g_app.
Referenced by BKE_tempdir_init(), sig_handle_abort(), sig_handle_crash(), blender::io::obj::ObjExporterWriterTest::TearDown(), BlendfileLoadingBaseTest::TearDownTestCase(), and WM_exit_ex().
|
static |
Definition at line 113 of file appdir.c.
References BLI_assert, and BLI_snprintf().
Referenced by get_path_local_ex(), get_path_system_ex(), and get_path_user_ex().
|
static |
Definition at line 434 of file appdir.c.
References get_path_environment_ex().
Referenced by BKE_appdir_folder_id_ex().
|
static |
Returns the path of a folder from environment variables.
targetpath | String to return path. |
subfolder_name | optional name of sub-folder within folder. |
envvar | name of environment variable to check folder_name. |
check_is_dir | When false, return true even if the path doesn't exist. |
Definition at line 420 of file appdir.c.
References FILE_MAX, NULL, test_env_path(), and test_path().
Referenced by BKE_appdir_folder_id_user_notest(), and get_path_environment().
|
static |
Definition at line 393 of file appdir.c.
References BLENDER_VERSION, and get_path_local_ex().
Referenced by BKE_appdir_app_is_portable_install(), and BKE_appdir_folder_id_ex().
|
static |
Constructs in targetpath the name of a directory relative to a version-specific sub-directory in the parent directory of the Blender executable.
targetpath | String to return path. |
folder_name | Optional folder name within version-specific directory. |
subfolder_name | Optional sub-folder name within folder_name. |
version | To construct name of version-specific directory within #g_app.program_dirname. |
check_is_dir | When false, return true even if the path doesn't exist. |
Definition at line 352 of file appdir.c.
References blender_version_decimal(), BLI_path_join(), BLI_path_normalize(), BLI_snprintf(), CLOG_INFO, FILE_MAX, g_app, LOG, NULL, STR_OR_FALLBACK, and test_path().
Referenced by BKE_appdir_folder_id_version(), get_path_local(), and get_path_user_ex().
|
static |
Definition at line 551 of file appdir.c.
References BLENDER_VERSION, and get_path_system_ex().
Referenced by BKE_appdir_folder_id_ex().
|
static |
Returns the path of a folder within the Blender installation directory.
targetpath | String to return path. |
folder_name | default name of folder within installation area. |
subfolder_name | optional name of sub-folder within folder. |
version | Blender version, used to construct a sub-directory name. |
check_is_dir | When false, return true even if the path doesn't exist. |
Definition at line 511 of file appdir.c.
References blender_version_decimal(), BLI_path_join(), BLI_strncpy(), CLOG_INFO, FILE_MAX, GHOST_getSystemDir(), LOG, NULL, STR_OR_FALLBACK, and test_path().
Referenced by BKE_appdir_folder_id_version(), and get_path_system().
|
static |
Definition at line 490 of file appdir.c.
References BLENDER_VERSION, and get_path_user_ex().
Referenced by BKE_appdir_folder_id_ex().
|
static |
Returns the path of a folder within the user-files area.
targetpath | String to return path. |
folder_name | default name of folder within user area. |
subfolder_name | optional name of sub-folder within folder. |
version | Blender version, used to construct a sub-directory name. |
check_is_dir | When false, return true even if the path doesn't exist. |
Definition at line 453 of file appdir.c.
References BKE_appdir_app_is_portable_install(), blender_version_decimal(), BLI_strncpy(), CLOG_INFO, FILE_MAX, get_path_local_ex(), GHOST_getUserDir(), LOG, STR_OR_FALLBACK, and test_path().
Referenced by BKE_appdir_folder_id_user_notest(), BKE_appdir_folder_id_version(), and get_path_user().
|
static |
Definition at line 1093 of file appdir.c.
References BLI_dir_create_recursive(), BLI_is_dir(), BLI_path_slash_ensure(), BLI_string_join, BLI_strncpy(), CLOG_WARN, LOG, and NULL.
Referenced by BKE_tempdir_init().
Puts the value of the specified environment variable into path if it exists.
check_is_dir | When true, checks if it points at a directory. |
Definition at line 311 of file appdir.c.
References ASSERT_IS_INIT, BLI_getenv(), BLI_is_dir(), BLI_strncpy(), CLOG_INFO, FILE_MAX, LOG, and NULL.
Referenced by get_path_environment_ex().
|
static |
Concatenates paths into targetpath, returning true if result points to a directory.
path_base | Path base, never NULL. |
folder_name | First sub-directory (optional). |
subfolder_name | Second sub-directory (optional). |
check_is_dir | When false, return true even if the path doesn't exist. |
Definition at line 273 of file appdir.c.
References ASSERT_IS_INIT, BLI_assert, BLI_is_dir(), BLI_path_join(), CLOG_INFO, LOG, and NULL.
Referenced by get_path_environment_ex(), get_path_local_ex(), get_path_system_ex(), and get_path_user_ex().
|
static |
Checks if name is a fully qualified filename to an executable. If not it searches $PATH
for the file. On Windows it also adds the correct extension (.com
.exe
etc) from $PATHEXT
if necessary. Also on Windows it translates the name to its 8.3 version to prevent problems with spaces and stuff. Final result is returned in fullname.
fullname | The full path and full name of the executable (must be FILE_MAX minimum) |
name | The name of the executable (usually argv[0] ) to be checked |
Definition at line 797 of file appdir.c.
References BLI_exists(), BLI_path_abs_from_cwd(), BLI_path_normalize(), BLI_path_program_search(), BLI_path_slash_rfind(), BLI_strncpy(), CLOG_ERROR, CLOG_INFO, conv_utf_16_to_8(), free(), LOG, MEM_freeN, MEM_mallocN, NULL, and STREQ.
Referenced by BKE_appdir_program_path_init().
|
static |
Gets the temp directory when blender first runs. If the default path is not found, use try $TEMP
Also make sure the temp dir has a trailing slash
tempdir | The full path to the temporary temp directory. |
tempdir_len | The size of the tempdir buffer. |
userdir | Directory specified in user preferences (may be NULL). note that by default this is an empty string, only use when non-empty. |
Definition at line 1055 of file appdir.c.
References ARRAY_SIZE, BLI_getenv(), BLI_is_dir(), BLI_path_slash_ensure(), and BLI_strncpy().
Referenced by BKE_tempdir_init().
|
static |
Definition at line 959 of file appdir.c.
Referenced by BKE_appdir_app_template_any(), BKE_appdir_app_template_id_search(), and BKE_appdir_app_templates().
|
static |
Keep in sync with bpy.utils.app_template_paths()
Definition at line 954 of file appdir.c.
Referenced by BKE_appdir_app_template_any(), BKE_appdir_app_template_id_search(), and BKE_appdir_app_templates().
struct { ... } g_app |
Referenced by BKE_appdir_program_dir(), BKE_appdir_program_path(), BKE_appdir_program_path_init(), BKE_tempdir_base(), BKE_tempdir_init(), BKE_tempdir_session(), BKE_tempdir_session_purge(), and get_path_local_ex().
|
static |
Definition at line 82 of file appdir.c.
Referenced by BKE_appdir_exit(), and BKE_appdir_init().
|
static |
Definition at line 60 of file appdir.c.
Referenced by get_path_local_ex(), get_path_system_ex(), get_path_user_ex(), tempdir_session_create(), test_env_path(), test_path(), and where_am_i().
char program_dirname[FILE_MAX] |
char program_filepath[FILE_MAX] |
char temp_dirname_base[FILE_MAX] |