Blender  V3.3
Classes
BKE_bpath.h File Reference

Go to the source code of this file.

Classes

struct  BPathForeachPathData
 

Functions

Helpers to handle common cases from <tt>IDTypeInfo</tt>'s <tt>foreach_path</tt> functions.
bool BKE_bpath_foreach_path_fixed_process (struct BPathForeachPathData *bpath_data, char *path)
 
bool BKE_bpath_foreach_path_dirfile_fixed_process (struct BPathForeachPathData *bpath_data, char *path_dir, char *path_file)
 
bool BKE_bpath_foreach_path_allocated_process (struct BPathForeachPathData *bpath_data, char **path)
 
High level features.
void BKE_bpath_missing_files_check (struct Main *bmain, struct ReportList *reports)
 
void BKE_bpath_missing_files_find (struct Main *bmain, const char *searchpath, struct ReportList *reports, bool find_all)
 
void BKE_bpath_relative_rebase (struct Main *bmain, const char *basedir_src, const char *basedir_dst, struct ReportList *reports)
 
void BKE_bpath_relative_convert (struct Main *bmain, const char *basedir, struct ReportList *reports)
 
void BKE_bpath_absolute_convert (struct Main *bmain, const char *basedir, struct ReportList *reports)
 
voidBKE_bpath_list_backup (struct Main *bmain, eBPathForeachFlag flag)
 
void BKE_bpath_list_restore (struct Main *bmain, eBPathForeachFlag flag, void *path_list_handle)
 
void BKE_bpath_list_free (void *path_list_handle)
 

Core <tt>foreach_path</tt> API.

enum  eBPathForeachFlag {
  BKE_BPATH_FOREACH_PATH_ABSOLUTE = (1 << 0) , BKE_BPATH_FOREACH_PATH_SKIP_LINKED = (1 << 1) , BKE_BPATH_FOREACH_PATH_SKIP_PACKED = (1 << 2) , BKE_BPATH_FOREACH_PATH_RESOLVE_TOKEN = (1 << 3) ,
  BKE_BPATH_TRAVERSE_SKIP_WEAK_REFERENCES = (1 << 5) , BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE = (1 << 8) , BKE_BPATH_FOREACH_PATH_RELOAD_EDITED = (1 << 9)
}
 
typedef enum eBPathForeachFlag eBPathForeachFlag
 
typedef bool(* BPathForeachPathFunctionCallback) (struct BPathForeachPathData *bpath_data, char *r_path_dst, const char *path_src)
 
typedef struct BPathForeachPathData BPathForeachPathData
 
void BKE_bpath_foreach_path_id (BPathForeachPathData *bpath_data, struct ID *id)
 
void BKE_bpath_foreach_path_main (BPathForeachPathData *bpath_data)
 

Detailed Description

Warning
All paths manipulated by this API are assumed to be either constant char buffers of FILE_MAX size, or allocated char buffers not bigger than FILE_MAX.

Definition in file BKE_bpath.h.

Typedef Documentation

◆ BPathForeachPathData

Storage for common data needed across the BPath 'foreach_path' code.

◆ BPathForeachPathFunctionCallback

typedef bool(* BPathForeachPathFunctionCallback) (struct BPathForeachPathData *bpath_data, char *r_path_dst, const char *path_src)

Callback used to iterate over an ID's file paths.

Note
paths parameters should be considered as having a maximal FILE_MAX string length.
Returns
true if the path has been changed, and in that case, result should be written into r_path_dst.

Definition at line 69 of file BKE_bpath.h.

◆ eBPathForeachFlag

Enumeration Type Documentation

◆ eBPathForeachFlag

Enumerator
BKE_BPATH_FOREACH_PATH_ABSOLUTE 

Flags controlling the behavior of the generic BPath API. Ensures the absolute_base_path member of BPathForeachPathData is initialized properly with the path of the current .blend file. This can be used by the callbacks to convert relative paths to absolute ones.

BKE_BPATH_FOREACH_PATH_SKIP_LINKED 

Skip paths of linked IDs.

BKE_BPATH_FOREACH_PATH_SKIP_PACKED 

Skip paths when their matching data is packed.

BKE_BPATH_FOREACH_PATH_RESOLVE_TOKEN 

Resolve tokens within a virtual filepath to a single, concrete, filepath.

BKE_BPATH_TRAVERSE_SKIP_WEAK_REFERENCES 
BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE 

Flags not affecting the generic BPath API. Those may be used by specific IDTypeInfo foreach_path implementations and/or callbacks to implement specific behaviors. Skip paths where a single dir is used with an array of files, eg. sequence strip images or point-caches. In this case only use the first file path is processed.

This is needed for directory manipulation callbacks which might otherwise modify the same directory multiple times.

BKE_BPATH_FOREACH_PATH_RELOAD_EDITED 

Reload data (when the path is edited).

Note
Only used by Image IDType currently.

Definition at line 27 of file BKE_bpath.h.

Function Documentation

◆ BKE_bpath_absolute_convert()

void BKE_bpath_absolute_convert ( struct Main bmain,
const char *  basedir,
struct ReportList reports 
)

Make all relative file paths in given bmain absolute, using given basedir as root.

Definition at line 564 of file bpath.c.

References absolute_convert_foreach_path_cb(), and bpath_absolute_relative_convert().

Referenced by BLO_write_file(), make_paths_absolute_exec(), and blender::bke::tests::TEST_F().

◆ BKE_bpath_foreach_path_allocated_process()

bool BKE_bpath_foreach_path_allocated_process ( struct BPathForeachPathData bpath_data,
char **  path 
)

Run the callback on a path, replacing the content of the string as needed.

Parameters
pathA pointer to a MEM-allocated string. If modified, it will be freed and replaced by a new allocated string.
Note
path is expected to be FILE_MAX size or smaller.
Returns
true is path was modified and re-allocated, false otherwise.

Definition at line 175 of file bpath.c.

References BPathForeachPathData::absolute_base_path, BLI_path_abs(), BLI_strdup(), BLI_strncpy(), BPathForeachPathData::callback_function, FILE_MAX, and MEM_freeN.

Referenced by text_foreach_path().

◆ BKE_bpath_foreach_path_dirfile_fixed_process()

bool BKE_bpath_foreach_path_dirfile_fixed_process ( struct BPathForeachPathData bpath_data,
char *  path_dir,
char *  path_file 
)

Run the callback on a (directory + file) path, replacing the content of the two strings as needed.

Parameters
path_dirA fixed, FILE_MAXDIR-sized char buffer.
path_fileA fixed, FILE_MAXFILE-sized char buffer.
Returns
true is path_dir and/or path_file were modified, false otherwise.

Definition at line 149 of file bpath.c.

References BPathForeachPathData::absolute_base_path, BLI_join_dirfile(), BLI_path_abs(), BLI_split_dirfile(), BLI_strncpy(), BPathForeachPathData::callback_function, FILE_MAX, FILE_MAXDIR, and FILE_MAXFILE.

Referenced by seq_foreach_path_callback().

◆ BKE_bpath_foreach_path_fixed_process()

bool BKE_bpath_foreach_path_fixed_process ( struct BPathForeachPathData bpath_data,
char *  path 
)

◆ BKE_bpath_foreach_path_id()

void BKE_bpath_foreach_path_id ( BPathForeachPathData bpath_data,
struct ID id 
)

◆ BKE_bpath_foreach_path_main()

void BKE_bpath_foreach_path_main ( BPathForeachPathData bpath_data)

◆ BKE_bpath_list_backup()

void* BKE_bpath_list_backup ( struct Main bmain,
eBPathForeachFlag  flag 
)

Temp backup of paths from all IDs in given bmain.

Returns
An opaque handle to pass to BKE_bpath_list_restore and BKE_bpath_list_free.

Definition at line 619 of file bpath.c.

References BKE_bpath_foreach_path_main(), bpath_list_append(), and MEM_callocN.

Referenced by BKE_blendfile_write_partial(), BLO_write_file(), and blender::bke::tests::TEST_F().

◆ BKE_bpath_list_free()

void BKE_bpath_list_free ( void path_list_handle)

Free the temp backup of paths in path_list_handle.

Note
This function assumes that the path list has already been restored with a call to BKE_bpath_list_restore, and is therefore empty.

Definition at line 641 of file bpath.c.

References BLI_assert, BLI_freelistN(), BLI_listbase_is_empty(), and MEM_freeN.

Referenced by BKE_blendfile_write_partial(), BLO_write_file(), and blender::bke::tests::TEST_F().

◆ BKE_bpath_list_restore()

void BKE_bpath_list_restore ( struct Main bmain,
eBPathForeachFlag  flag,
void path_list_handle 
)

Restore the temp backup of paths from path_list_handle into all IDs in given bmain.

Note
This function assumes that the data in given Main did not change (no addition/deletion/re-ordering of IDs, or their file paths) since the call to BKE_bpath_list_backup that generated the given path_list_handle.

Definition at line 631 of file bpath.c.

References BKE_bpath_foreach_path_main(), and bpath_list_restore().

Referenced by BKE_blendfile_write_partial(), BLO_write_file(), and blender::bke::tests::TEST_F().

◆ BKE_bpath_missing_files_check()

void BKE_bpath_missing_files_check ( struct Main bmain,
struct ReportList reports 
)

◆ BKE_bpath_missing_files_find()

void BKE_bpath_missing_files_find ( struct Main bmain,
const char *  searchpath,
struct ReportList reports,
bool  find_all 
)

Recursively search into given search directory, for all file paths of all IDs in given bmain, and replace existing paths as needed.

Note
The search will happen into the whole search directory tree recursively (with a limit of MAX_DIR_RECURSE), if several files are found matching a searched filename, the biggest one will be used. This is so that things like thumbnails don't get selected instead of the actual image e.g.
Parameters
searchpathThe root directory in which the new filepaths should be searched for.
find_allIf true, also search for files which current path is still valid, if false skip those still valid paths.

Definition at line 368 of file bpath.c.

References BKE_BPATH_FOREACH_PATH_ABSOLUTE, BKE_bpath_foreach_path_main(), BKE_BPATH_FOREACH_PATH_RELOAD_EDITED, BKE_BPATH_FOREACH_PATH_RESOLVE_TOKEN, BKE_main_blendfile_path(), data, BPathFind_Data::find_all, missing_files_find_foreach_path_cb(), NULL, and BPathFind_Data::reports.

Referenced by find_missing_files_exec().

◆ BKE_bpath_relative_convert()

void BKE_bpath_relative_convert ( struct Main bmain,
const char *  basedir,
struct ReportList reports 
)

Make all absolute file paths in given bmain relative to given basedir.

Definition at line 559 of file bpath.c.

References bpath_absolute_relative_convert(), and relative_convert_foreach_path_cb().

Referenced by BLO_write_file(), make_paths_relative_exec(), and blender::bke::tests::TEST_F().

◆ BKE_bpath_relative_rebase()

void BKE_bpath_relative_rebase ( struct Main bmain,
const char *  basedir_src,
const char *  basedir_dst,
struct ReportList reports 
)

Rebase all relative file paths in given bmain from basedir_src to basedir_dst.

Definition at line 439 of file bpath.c.

References BKE_bpath_foreach_path_main(), BKE_BPATH_FOREACH_PATH_SKIP_LINKED, BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE, BKE_reportf(), BLI_assert, data, NULL, relative_rebase_foreach_path_cb(), RPT_INFO, and RPT_WARNING.

Referenced by BLO_write_file(), and blender::bke::tests::TEST_F().