From e853a67efc13ab9c66528d3ea0e303eaf72551fc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 17 Mar 2023 16:44:03 +1100 Subject: [PATCH] Cleanup: use BKE_blendfile_* for functions defined in BKE_blendfile.h --- .../blender/asset_system/intern/asset_identifier.cc | 2 +- source/blender/blenkernel/BKE_blendfile.h | 7 +++++-- source/blender/blenkernel/intern/blendfile.cc | 9 ++++++--- .../editors/interface/interface_templates.cc | 2 +- source/blender/editors/space_file/file_draw.cc | 2 +- source/blender/editors/space_file/file_ops.c | 4 ++-- source/blender/editors/space_file/file_utils.c | 2 +- source/blender/editors/space_file/filelist.cc | 12 ++++++------ source/blender/editors/space_topbar/space_topbar.c | 2 +- source/blender/imbuf/intern/thumbs.c | 2 +- source/blender/windowmanager/intern/wm_files.cc | 2 +- source/blender/windowmanager/intern/wm_files_link.c | 13 +++++++------ source/creator/creator_args.c | 2 +- 13 files changed, 34 insertions(+), 27 deletions(-) diff --git a/source/blender/asset_system/intern/asset_identifier.cc b/source/blender/asset_system/intern/asset_identifier.cc index 7f36f2d7617..3509eb1e4aa 100644 --- a/source/blender/asset_system/intern/asset_identifier.cc +++ b/source/blender/asset_system/intern/asset_identifier.cc @@ -32,7 +32,7 @@ std::string AssetIdentifier::full_library_path() const std::string asset_path = full_path(); 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 {}; } diff --git a/source/blender/blenkernel/BKE_blendfile.h b/source/blender/blenkernel/BKE_blendfile.h index 839d28846a9..f216ff58ab3 100644 --- a/source/blender/blenkernel/BKE_blendfile.h +++ b/source/blender/blenkernel/BKE_blendfile.h @@ -26,7 +26,7 @@ struct bContext; * \param str: The path to check. * \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' * (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. * \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, diff --git a/source/blender/blenkernel/intern/blendfile.cc b/source/blender/blenkernel/intern/blendfile.cc index 18a0cd89051..0d12ddf152e 100644 --- a/source/blender/blenkernel/intern/blendfile.cc +++ b/source/blender/blenkernel/intern/blendfile.cc @@ -67,13 +67,16 @@ /** \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}; 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, * 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))) { char tc = *slash; *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; } if (STREQ(r_dir, BLO_EMBEDDED_STARTUP_BLEND)) { diff --git a/source/blender/editors/interface/interface_templates.cc b/source/blender/editors/interface/interface_templates.cc index 50a6a983fd8..625fe459758 100644 --- a/source/blender/editors/interface/interface_templates.cc +++ b/source/blender/editors/interface/interface_templates.cc @@ -6996,7 +6996,7 @@ int uiTemplateRecentFiles(uiLayout *layout, int rows) uiItemFullO(layout, "WM_OT_open_mainfile", filename, - BKE_has_bfile_extension(filename) ? ICON_FILE_BLEND : ICON_FILE_BACKUP, + BKE_blendfile_extension_check(filename) ? ICON_FILE_BLEND : ICON_FILE_BACKUP, nullptr, WM_OP_INVOKE_DEFAULT, 0, diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index eb6eadda607..4ecb9a52c6a 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -141,7 +141,7 @@ static void file_but_enable_drag(uiBut *but, else if (sfile->browse_mode == FILE_BROWSE_MODE_ASSETS && (file->typeflag & FILE_TYPE_ASSET) != 0) { 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); BLI_assert(import_method > -1); diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index c73d2eefd34..c3fef65c5ff 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -2538,7 +2538,7 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN BLI_split_dirfile( 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) { 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]; /* 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)); } else { diff --git a/source/blender/editors/space_file/file_utils.c b/source/blender/editors/space_file/file_utils.c index 141a7c26bee..97c228a7795 100644 --- a/source/blender/editors/space_file/file_utils.c +++ b/source/blender/editors/space_file/file_utils.c @@ -37,5 +37,5 @@ void file_path_to_ui_path(const char *path, char *r_path, int max_size) char tmp_path[PATH_MAX]; BLI_strncpy(tmp_path, path, sizeof(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); } diff --git a/source/blender/editors/space_file/filelist.cc b/source/blender/editors/space_file/filelist.cc index 0db08b99bee..f27238f4fe3 100644 --- a/source/blender/editors/space_file/filelist.cc +++ b/source/blender/editors/space_file/filelist.cc @@ -1353,7 +1353,7 @@ static bool filelist_checkdir_lib(FileList * /*filelist*/, char *r_dir, const bo char *name; 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)); if (do_change && !is_valid) { @@ -1950,7 +1950,7 @@ static const char *fileentry_uiname(const char *root, FileListInternEntry *entry char *group; 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) { 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 * using this may do `ELEM()`-like checks. */ - if (BKE_has_bfile_extension(path)) { + if (BKE_blendfile_extension_check(path)) { return FILE_TYPE_BLENDER; } if (file_is_blend_backup(path)) { @@ -2885,7 +2885,7 @@ bool filelist_islibrary(FileList *filelist, char *dir, char **r_group) if (filelist->asset_library) { 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) @@ -3041,7 +3041,7 @@ static int filelist_readjob_list_dir(FileListReadJob *job_params, } 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. */ entry->typeflag = FILE_TYPE_BLENDER; /* prevent current file being used as acceptable dir */ @@ -3234,7 +3234,7 @@ static std::optional filelist_readjob_list_lib(FileListReadJob *job_params, * 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 * 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) { return std::nullopt; } diff --git a/source/blender/editors/space_topbar/space_topbar.c b/source/blender/editors/space_topbar/space_topbar.c index a346dea6459..d527688c3b1 100644 --- a/source/blender/editors/space_topbar/space_topbar.c +++ b/source/blender/editors/space_topbar/space_topbar.c @@ -202,7 +202,7 @@ static void recent_files_menu_draw(const bContext *UNUSED(C), Menu *menu) if (!BLI_listbase_is_empty(&G.recent_files)) { for (recent = G.recent_files.first; (recent); recent = recent->next) { 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; uiItemFullO(layout, "WM_OT_open_mainfile", file, icon, NULL, WM_OP_INVOKE_DEFAULT, 0, &ptr); RNA_string_set(&ptr, "filepath", recent->filepath); diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index 53ce32ad0e9..3c4eef83b15 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -527,7 +527,7 @@ ImBuf *IMB_thumb_manage(const char *filepath, ThumbSize size, ThumbSource source path = file_path = filepath; 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_id) { /* No preview for blen groups */ diff --git a/source/blender/windowmanager/intern/wm_files.cc b/source/blender/windowmanager/intern/wm_files.cc index 8f9e8d81142..c873c511414 100644 --- a/source/blender/windowmanager/intern/wm_files.cc +++ b/source/blender/windowmanager/intern/wm_files.cc @@ -3261,7 +3261,7 @@ static bool wm_save_mainfile_check(bContext * /*C*/, wmOperator *op) { char filepath[FILE_MAX]; 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(), * we keep getting nitpicking bug reports about this - campbell */ BLI_path_extension_ensure(filepath, FILE_MAX, ".blend"); diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c index 9a3e35ef2c3..ee2b7455a0d 100644 --- a/source/blender/windowmanager/intern/wm_files_link.c +++ b/source/blender/windowmanager/intern/wm_files_link.c @@ -217,7 +217,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op) BLI_path_join(path, sizeof(path), root, relname); /* 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); 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); - 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)) { continue; } @@ -309,7 +309,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op) 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; 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) { - 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); 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, "filename", libname); - if (!BKE_has_bfile_extension(libname)) { + if (!BKE_blendfile_extension_check(libname)) { BKE_report(op->reports, RPT_ERROR, "Not a library"); 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); - 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; } diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c index 29c9be79661..8b11aa07b03 100644 --- a/source/creator/creator_args.c +++ b/source/creator/creator_args.c @@ -2070,7 +2070,7 @@ static int arg_handle_load_file(int UNUSED(argc), const char **argv, void *data) 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 * save at the filepath from the CLI. */ STRNCPY(G_MAIN->filepath, filepath);