From e5e8db73df86ee04260c5f2bd2c61dfa8eb7943f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 29 Nov 2021 14:20:58 +0100 Subject: Refactor BKE_bpath module. The main goal of this refactor is to make BPath module use `IDTypeInfo`, and move each ID-specific part of the `foreach_path` looper into their own IDTypeInfo struct, using a new `foreach_path` callback. Additionally, following improvements/cleanups are included: * Attempt to get better, more consistent namings. ** In particular, move from `path_visitor` to more standard `foreach_path`. * Update and extend documentation. ** API doc was moved to header, according to recent discussions on this topic. * Remove `BKE_bpath_relocate_visitor` from API, this is specific callback that belongs in `lib_id.c` user code. NOTE: This commit is expected to be 100% non-behavioral-change. This implies that several potential further changes were only noted as comments (like using a more generic solution for `lib_id_library_local_paths`, addressing inconsistencies like path of packed libraries always being skipped, regardless of the `BKE_BPATH_FOREACH_PATH_SKIP_PACKED` `eBPathForeachFlag` flag value, etc.). NOTE: basic unittests were added to master already in rBdcc500e5a265093bc9cc. Reviewed By: brecht Differential Revision: https://developer.blender.org/D13381 --- source/blender/blenkernel/intern/library.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source/blender/blenkernel/intern/library.c') diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 74b1a612ccf..d7282b14734 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -36,6 +36,7 @@ #include "BLT_translation.h" +#include "BKE_bpath.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" @@ -60,6 +61,22 @@ static void library_foreach_id(ID *id, LibraryForeachIDData *data) BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, lib->parent, IDWALK_CB_NEVER_SELF); } +static void library_foreach_path(ID *id, BPathForeachPathData *bpath_data) +{ + Library *lib = (Library *)id; + + /* FIXME: Find if we should respect #BKE_BPATH_FOREACH_PATH_SKIP_PACKED here, and if not, explain + * why. */ + if (lib->packedfile != + NULL /*&& (bpath_data->flag & BKE_BPATH_FOREACH_PATH_SKIP_PACKED) != 0 */) { + return; + } + + if (BKE_bpath_foreach_path_fixed_process(bpath_data, lib->filepath)) { + BKE_library_filepath_set(bpath_data->bmain, lib, lib->filepath); + } +} + IDTypeInfo IDType_ID_LI = { .id_code = ID_LI, .id_filter = 0, @@ -77,6 +94,7 @@ IDTypeInfo IDType_ID_LI = { .make_local = NULL, .foreach_id = library_foreach_id, .foreach_cache = NULL, + .foreach_path = library_foreach_path, .owner_get = NULL, .blend_write = NULL, -- cgit v1.2.3