main sync #3

Merged
Patrick Busch merged 318 commits from blender/blender:main into main 2023-03-17 15:52:21 +01:00
13 changed files with 34 additions and 27 deletions
Showing only changes of commit e853a67efc - Show all commits

View File

@ -32,7 +32,7 @@ std::string AssetIdentifier::full_library_path() const
std::string asset_path = full_path(); std::string asset_path = full_path();
char blend_path[1090 /*FILE_MAX_LIBEXTRA*/]; char blend_path[1090 /*FILE_MAX_LIBEXTRA*/];
if (!BKE_library_path_explode(asset_path.c_str(), blend_path, nullptr, nullptr)) { if (!BKE_blendfile_library_path_explode(asset_path.c_str(), blend_path, nullptr, nullptr)) {
return {}; return {};
} }

View File

@ -26,7 +26,7 @@ struct bContext;
* \param str: The path to check. * \param str: The path to check.
* \return true is this path ends with a blender file extension. * \return true is this path ends with a blender file extension.
*/ */
bool BKE_has_bfile_extension(const char *str); bool BKE_blendfile_extension_check(const char *str);
/** /**
* Try to explode given path into its 'library components' * Try to explode given path into its 'library components'
* (i.e. a .blend file, id type/group, and data-block itself). * (i.e. a .blend file, id type/group, and data-block itself).
@ -40,7 +40,10 @@ bool BKE_has_bfile_extension(const char *str);
* NULL. * NULL.
* \return true if path contains a blend file. * \return true if path contains a blend file.
*/ */
bool BKE_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name); bool BKE_blendfile_library_path_explode(const char *path,
char *r_dir,
char **r_group,
char **r_name);
/** /**
* Shared setup function that makes the data from `bfd` into the current blend file, * Shared setup function that makes the data from `bfd` into the current blend file,

View File

@ -67,13 +67,16 @@
/** \name Blend/Library Paths /** \name Blend/Library Paths
* \{ */ * \{ */
bool BKE_has_bfile_extension(const char *str) bool BKE_blendfile_extension_check(const char *str)
{ {
const char *ext_test[4] = {".blend", ".ble", ".blend.gz", nullptr}; const char *ext_test[4] = {".blend", ".ble", ".blend.gz", nullptr};
return BLI_path_extension_check_array(str, ext_test); return BLI_path_extension_check_array(str, ext_test);
} }
bool BKE_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name) bool BKE_blendfile_library_path_explode(const char *path,
char *r_dir,
char **r_group,
char **r_name)
{ {
/* We might get some data names with slashes, /* We might get some data names with slashes,
* so we have to go up in path until we find blend file itself, * so we have to go up in path until we find blend file itself,
@ -98,7 +101,7 @@ bool BKE_library_path_explode(const char *path, char *r_dir, char **r_group, cha
while ((slash = (char *)BLI_path_slash_rfind(r_dir))) { while ((slash = (char *)BLI_path_slash_rfind(r_dir))) {
char tc = *slash; char tc = *slash;
*slash = '\0'; *slash = '\0';
if (BKE_has_bfile_extension(r_dir) && BLI_is_file(r_dir)) { if (BKE_blendfile_extension_check(r_dir) && BLI_is_file(r_dir)) {
break; break;
} }
if (STREQ(r_dir, BLO_EMBEDDED_STARTUP_BLEND)) { if (STREQ(r_dir, BLO_EMBEDDED_STARTUP_BLEND)) {

View File

@ -6996,7 +6996,7 @@ int uiTemplateRecentFiles(uiLayout *layout, int rows)
uiItemFullO(layout, uiItemFullO(layout,
"WM_OT_open_mainfile", "WM_OT_open_mainfile",
filename, filename,
BKE_has_bfile_extension(filename) ? ICON_FILE_BLEND : ICON_FILE_BACKUP, BKE_blendfile_extension_check(filename) ? ICON_FILE_BLEND : ICON_FILE_BACKUP,
nullptr, nullptr,
WM_OP_INVOKE_DEFAULT, WM_OP_INVOKE_DEFAULT,
0, 0,

View File

@ -141,7 +141,7 @@ static void file_but_enable_drag(uiBut *but,
else if (sfile->browse_mode == FILE_BROWSE_MODE_ASSETS && else if (sfile->browse_mode == FILE_BROWSE_MODE_ASSETS &&
(file->typeflag & FILE_TYPE_ASSET) != 0) { (file->typeflag & FILE_TYPE_ASSET) != 0) {
char blend_path[FILE_MAX_LIBEXTRA]; char blend_path[FILE_MAX_LIBEXTRA];
if (BKE_library_path_explode(path, blend_path, nullptr, nullptr)) { if (BKE_blendfile_library_path_explode(path, blend_path, nullptr, nullptr)) {
const int import_method = ED_fileselect_asset_import_method_get(sfile, file); const int import_method = ED_fileselect_asset_import_method_get(sfile, file);
BLI_assert(import_method > -1); BLI_assert(import_method > -1);

View File

@ -2538,7 +2538,7 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN
BLI_split_dirfile( BLI_split_dirfile(
path, params->dir, params->file, sizeof(params->dir), sizeof(params->file)); path, params->dir, params->file, sizeof(params->dir), sizeof(params->file));
} }
else if (BKE_library_path_explode(params->dir, tdir, &group, &name)) { else if (BKE_blendfile_library_path_explode(params->dir, tdir, &group, &name)) {
if (group) { if (group) {
BLI_path_append(tdir, sizeof(tdir), group); BLI_path_append(tdir, sizeof(tdir), group);
} }
@ -2577,7 +2577,7 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN
char tdir[FILE_MAX_LIBEXTRA]; char tdir[FILE_MAX_LIBEXTRA];
/* If we are 'inside' a blend library, we cannot do anything... */ /* If we are 'inside' a blend library, we cannot do anything... */
if (lastdir && BKE_library_path_explode(lastdir, tdir, NULL, NULL)) { if (lastdir && BKE_blendfile_library_path_explode(lastdir, tdir, NULL, NULL)) {
BLI_strncpy(params->dir, lastdir, sizeof(params->dir)); BLI_strncpy(params->dir, lastdir, sizeof(params->dir));
} }
else { else {

View File

@ -37,5 +37,5 @@ void file_path_to_ui_path(const char *path, char *r_path, int max_size)
char tmp_path[PATH_MAX]; char tmp_path[PATH_MAX];
BLI_strncpy(tmp_path, path, sizeof(tmp_path)); BLI_strncpy(tmp_path, path, sizeof(tmp_path));
BLI_path_slash_rstrip(tmp_path); BLI_path_slash_rstrip(tmp_path);
BLI_strncpy(r_path, BKE_has_bfile_extension(tmp_path) ? tmp_path : path, max_size); BLI_strncpy(r_path, BKE_blendfile_extension_check(tmp_path) ? tmp_path : path, max_size);
} }

View File

@ -1353,7 +1353,7 @@ static bool filelist_checkdir_lib(FileList * /*filelist*/, char *r_dir, const bo
char *name; char *name;
const bool is_valid = (BLI_is_dir(r_dir) || const bool is_valid = (BLI_is_dir(r_dir) ||
(BKE_library_path_explode(r_dir, tdir, nullptr, &name) && (BKE_blendfile_library_path_explode(r_dir, tdir, nullptr, &name) &&
BLI_is_file(tdir) && !name)); BLI_is_file(tdir) && !name));
if (do_change && !is_valid) { if (do_change && !is_valid) {
@ -1950,7 +1950,7 @@ static const char *fileentry_uiname(const char *root, FileListInternEntry *entry
char *group; char *group;
BLI_path_join(abspath, sizeof(abspath), root, relpath); BLI_path_join(abspath, sizeof(abspath), root, relpath);
BKE_library_path_explode(abspath, buff, &group, &name); BKE_blendfile_library_path_explode(abspath, buff, &group, &name);
if (!name) { if (!name) {
name = group; name = group;
} }
@ -2623,7 +2623,7 @@ int ED_path_extension_type(const char *path)
/* ATTENTION: Never return OR'ed bit-flags here, always return a single enum value! Some code /* ATTENTION: Never return OR'ed bit-flags here, always return a single enum value! Some code
* using this may do `ELEM()`-like checks. */ * using this may do `ELEM()`-like checks. */
if (BKE_has_bfile_extension(path)) { if (BKE_blendfile_extension_check(path)) {
return FILE_TYPE_BLENDER; return FILE_TYPE_BLENDER;
} }
if (file_is_blend_backup(path)) { if (file_is_blend_backup(path)) {
@ -2885,7 +2885,7 @@ bool filelist_islibrary(FileList *filelist, char *dir, char **r_group)
if (filelist->asset_library) { if (filelist->asset_library) {
return true; return true;
} }
return BKE_library_path_explode(filelist->filelist.root, dir, r_group, nullptr); return BKE_blendfile_library_path_explode(filelist->filelist.root, dir, r_group, nullptr);
} }
static int groupname_to_code(const char *group) static int groupname_to_code(const char *group)
@ -3041,7 +3041,7 @@ static int filelist_readjob_list_dir(FileListReadJob *job_params,
} }
if (!(entry->typeflag & FILE_TYPE_DIR)) { if (!(entry->typeflag & FILE_TYPE_DIR)) {
if (do_lib && BKE_has_bfile_extension(target)) { if (do_lib && BKE_blendfile_extension_check(target)) {
/* If we are considering .blend files as libraries, promote them to directory status. */ /* If we are considering .blend files as libraries, promote them to directory status. */
entry->typeflag = FILE_TYPE_BLENDER; entry->typeflag = FILE_TYPE_BLENDER;
/* prevent current file being used as acceptable dir */ /* prevent current file being used as acceptable dir */
@ -3234,7 +3234,7 @@ static std::optional<int> filelist_readjob_list_lib(FileListReadJob *job_params,
* will do a dir listing only when this function does not return any entries. */ * will do a dir listing only when this function does not return any entries. */
/* TODO(jbakker): We should consider introducing its own function to detect if it is a lib and /* TODO(jbakker): We should consider introducing its own function to detect if it is a lib and
* call it directly from `filelist_readjob_do` to increase readability. */ * call it directly from `filelist_readjob_do` to increase readability. */
const bool is_lib = BKE_library_path_explode(root, dir, &group, nullptr); const bool is_lib = BKE_blendfile_library_path_explode(root, dir, &group, nullptr);
if (!is_lib) { if (!is_lib) {
return std::nullopt; return std::nullopt;
} }

View File

@ -202,7 +202,7 @@ static void recent_files_menu_draw(const bContext *UNUSED(C), Menu *menu)
if (!BLI_listbase_is_empty(&G.recent_files)) { if (!BLI_listbase_is_empty(&G.recent_files)) {
for (recent = G.recent_files.first; (recent); recent = recent->next) { for (recent = G.recent_files.first; (recent); recent = recent->next) {
const char *file = BLI_path_basename(recent->filepath); const char *file = BLI_path_basename(recent->filepath);
const int icon = BKE_has_bfile_extension(file) ? ICON_FILE_BLEND : ICON_FILE_BACKUP; const int icon = BKE_blendfile_extension_check(file) ? ICON_FILE_BLEND : ICON_FILE_BACKUP;
PointerRNA ptr; PointerRNA ptr;
uiItemFullO(layout, "WM_OT_open_mainfile", file, icon, NULL, WM_OP_INVOKE_DEFAULT, 0, &ptr); uiItemFullO(layout, "WM_OT_open_mainfile", file, icon, NULL, WM_OP_INVOKE_DEFAULT, 0, &ptr);
RNA_string_set(&ptr, "filepath", recent->filepath); RNA_string_set(&ptr, "filepath", recent->filepath);

View File

@ -527,7 +527,7 @@ ImBuf *IMB_thumb_manage(const char *filepath, ThumbSize size, ThumbSource source
path = file_path = filepath; path = file_path = filepath;
if (source == THB_SOURCE_BLEND) { if (source == THB_SOURCE_BLEND) {
if (BKE_library_path_explode(path, path_buff, &blen_group, &blen_id)) { if (BKE_blendfile_library_path_explode(path, path_buff, &blen_group, &blen_id)) {
if (blen_group) { if (blen_group) {
if (!blen_id) { if (!blen_id) {
/* No preview for blen groups */ /* No preview for blen groups */

View File

@ -3261,7 +3261,7 @@ static bool wm_save_mainfile_check(bContext * /*C*/, wmOperator *op)
{ {
char filepath[FILE_MAX]; char filepath[FILE_MAX];
RNA_string_get(op->ptr, "filepath", filepath); RNA_string_get(op->ptr, "filepath", filepath);
if (!BKE_has_bfile_extension(filepath)) { if (!BKE_blendfile_extension_check(filepath)) {
/* some users would prefer BLI_path_extension_replace(), /* some users would prefer BLI_path_extension_replace(),
* we keep getting nitpicking bug reports about this - campbell */ * we keep getting nitpicking bug reports about this - campbell */
BLI_path_extension_ensure(filepath, FILE_MAX, ".blend"); BLI_path_extension_ensure(filepath, FILE_MAX, ".blend");

View File

@ -217,7 +217,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
BLI_path_join(path, sizeof(path), root, relname); BLI_path_join(path, sizeof(path), root, relname);
/* test if we have a valid data */ /* test if we have a valid data */
if (!BKE_library_path_explode(path, libname, &group, &name)) { if (!BKE_blendfile_library_path_explode(path, libname, &group, &name)) {
BKE_reportf(op->reports, RPT_ERROR, "'%s': not a library", path); BKE_reportf(op->reports, RPT_ERROR, "'%s': not a library", path);
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
} }
@ -290,7 +290,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
BLI_path_join(path, sizeof(path), root, relname); BLI_path_join(path, sizeof(path), root, relname);
if (BKE_library_path_explode(path, libname, &group, &name)) { if (BKE_blendfile_library_path_explode(path, libname, &group, &name)) {
if (!wm_link_append_item_poll(NULL, path, group, name, do_append)) { if (!wm_link_append_item_poll(NULL, path, group, name, do_append)) {
continue; continue;
} }
@ -309,7 +309,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
BLI_path_join(path, sizeof(path), root, relname); BLI_path_join(path, sizeof(path), root, relname);
if (BKE_library_path_explode(path, libname, &group, &name)) { if (BKE_blendfile_library_path_explode(path, libname, &group, &name)) {
BlendfileLinkAppendContextItem *item; BlendfileLinkAppendContextItem *item;
if (!wm_link_append_item_poll(op->reports, path, group, name, do_append)) { if (!wm_link_append_item_poll(op->reports, path, group, name, do_append)) {
@ -611,7 +611,7 @@ static int wm_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEvent *UN
void WM_lib_reload(Library *lib, bContext *C, ReportList *reports) void WM_lib_reload(Library *lib, bContext *C, ReportList *reports)
{ {
if (!BKE_has_bfile_extension(lib->filepath_abs)) { if (!BKE_blendfile_extension_check(lib->filepath_abs)) {
BKE_reportf(reports, RPT_ERROR, "'%s' is not a valid library filepath", lib->filepath_abs); BKE_reportf(reports, RPT_ERROR, "'%s' is not a valid library filepath", lib->filepath_abs);
return; return;
} }
@ -688,7 +688,7 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
RNA_string_get(op->ptr, "directory", root); RNA_string_get(op->ptr, "directory", root);
RNA_string_get(op->ptr, "filename", libname); RNA_string_get(op->ptr, "filename", libname);
if (!BKE_has_bfile_extension(libname)) { if (!BKE_blendfile_extension_check(libname)) {
BKE_report(op->reports, RPT_ERROR, "Not a library"); BKE_report(op->reports, RPT_ERROR, "Not a library");
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
} }
@ -751,7 +751,8 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
BLI_path_join(path, sizeof(path), root, relname); BLI_path_join(path, sizeof(path), root, relname);
if (BLI_path_cmp(path, lib->filepath_abs) == 0 || !BKE_has_bfile_extension(relname)) { if (BLI_path_cmp(path, lib->filepath_abs) == 0 ||
!BKE_blendfile_extension_check(relname)) {
continue; continue;
} }

View File

@ -2070,7 +2070,7 @@ static int arg_handle_load_file(int UNUSED(argc), const char **argv, void *data)
return -1; return -1;
} }
if (BKE_has_bfile_extension(filepath)) { if (BKE_blendfile_extension_check(filepath)) {
/* Just pretend a file was loaded, so the user can press Save and it'll /* Just pretend a file was loaded, so the user can press Save and it'll
* save at the filepath from the CLI. */ * save at the filepath from the CLI. */
STRNCPY(G_MAIN->filepath, filepath); STRNCPY(G_MAIN->filepath, filepath);