Blender V5.0
readblenentry.cc File Reference
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include "MEM_guardedalloc.h"
#include "BLI_ghash.h"
#include "BLI_linklist.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "DNA_genfile.h"
#include "BKE_asset.hh"
#include "BKE_idtype.hh"
#include "BKE_main.hh"
#include "BKE_preview_image.hh"
#include "BLO_readfile.hh"
#include "readfile.hh"
#include "BLI_sys_types.h"

Go to the source code of this file.

Functions

void BLO_datablock_info_free (BLODataBlockInfo *datablock_info)
void BLO_datablock_info_linklist_free (LinkNode *datablock_infos)
BlendHandle * BLO_blendhandle_from_file (const char *filepath, BlendFileReadReport *reports)
BlendHandle * BLO_blendhandle_from_memory (const void *mem, int memsize, BlendFileReadReport *reports)
blender::int3 BLO_blendhandle_get_version (const BlendHandle *bh)
static bool blendhandle_load_id_data_and_validate (FileData *fd, BHead *bhead, bool use_assets_only, const char *&r_idname, short &r_idflag, AssetMetaData *&r_asset_meta_data)
LinkNodeBLO_blendhandle_get_datablock_names (BlendHandle *bh, int ofblocktype, const bool use_assets_only, int *r_tot_names)
LinkNodeBLO_blendhandle_get_datablock_info (BlendHandle *bh, int ofblocktype, const bool use_assets_only, int *r_tot_info_items)
static BHeadblo_blendhandle_read_preview_rects (FileData *fd, BHead *bhead, PreviewImage *result, const PreviewImage *preview_from_file)
PreviewImageBLO_blendhandle_get_preview_for_id (BlendHandle *bh, int ofblocktype, const char *name)
LinkNodeBLO_blendhandle_get_linkable_groups (BlendHandle *bh)
void BLO_blendhandle_close (BlendHandle *bh)
void BLO_read_invalidate_message (BlendHandle *bh, Main *bmain, const char *message)
BlendFileDataBLO_read_from_file (const char *filepath, eBLOReadSkip skip_flags, BlendFileReadReport *reports)
BlendFileDataBLO_read_from_memory (const void *mem, int memsize, eBLOReadSkip skip_flags, ReportList *reports)
BlendFileDataBLO_read_from_memfile (Main *oldmain, const char *filepath, MemFile *memfile, const BlendFileReadParams *params, ReportList *reports)
void BLO_blendfiledata_free (BlendFileData *bfd)
void BLO_read_do_version_after_setup (Main *new_bmain, BlendfileLinkAppendContext *lapp_context, BlendFileReadReport *reports)

Detailed Description

.blend file reading entry point.

Definition in file readblenentry.cc.

Function Documentation

◆ blendhandle_load_id_data_and_validate()

bool blendhandle_load_id_data_and_validate ( FileData * fd,
BHead * bhead,
bool use_assets_only,
const char *& r_idname,
short & r_idflag,
AssetMetaData *& r_asset_meta_data )
static

◆ BLO_blendfiledata_free()

void BLO_blendfiledata_free ( BlendFileData * bfd)

Frees a BlendFileData structure and all the data associated with it (the userdef data, and the main libblock data).

Parameters
bfdThe structure to free.

Definition at line 432 of file readblenentry.cc.

References BKE_main_free(), BlendFileData::main, MEM_freeN(), and BlendFileData::user.

Referenced by BKE_blendfile_read(), BKE_blendfile_read_from_memfile(), BKE_blendfile_read_from_memory(), BKE_blendfile_read_setup_readfile(), BlendfileLoadingBaseTest::blendfile_free(), and blender::ed::vse::sequencer_clipboard_paste_exec().

◆ BLO_blendhandle_close()

void BLO_blendhandle_close ( BlendHandle * bh)

Close and free a blendhandle. The handle becomes invalid after this call.

Parameters
bhThe handle to close.

Definition at line 321 of file readblenentry.cc.

References blo_filedata_free().

Referenced by BKE_blendfile_is_readable(), BLO_library_temp_load_id(), BLO_main_validate_libraries(), filelist_freelib(), filelist_readjob_list_lib(), imb_thumb_load_from_blend_id(), and link_append_context_library_blohandle_release().

◆ BLO_blendhandle_from_file()

BlendHandle * BLO_blendhandle_from_file ( const char * filepath,
BlendFileReadReport * reports )

Open a blendhandle from a file path.

Parameters
filepathThe file path to open.
reportsReport errors in opening the file (can be NULL).
Returns
A handle on success, or NULL on failure.

Definition at line 58 of file readblenentry.cc.

References blo_filedata_from_file().

Referenced by BKE_blendfile_is_readable(), BLO_library_temp_load_id(), BLO_main_validate_libraries(), bpy_lib_enter(), filelist_readjob_list_lib(), imb_thumb_load_from_blend_id(), and link_append_context_library_blohandle_ensure().

◆ BLO_blendhandle_from_memory()

BlendHandle * BLO_blendhandle_from_memory ( const void * mem,
int memsize,
BlendFileReadReport * reports )

Open a blendhandle from memory.

Parameters
memThe data to load from.
memsizeThe size of the data.
Returns
A handle on success, or NULL on failure.

Definition at line 67 of file readblenentry.cc.

References blo_filedata_from_memory().

Referenced by link_append_context_library_blohandle_ensure().

◆ BLO_blendhandle_get_datablock_info()

LinkNode * BLO_blendhandle_get_datablock_info ( BlendHandle * bh,
int ofblocktype,
bool use_assets_only,
int * r_tot_info_items )

Gets the names and asset-data (if ID is an asset) of data-blocks in a file of a certain type. The data-blocks can be limited to assets.

Parameters
bhThe blendhandle to access.
ofblocktypeThe type of names to get.
use_assets_onlyLimit the result to assets only.
r_tot_info_itemsThe length of the returned list.
Returns
A BLI_linklist of BLODataBlockInfo *.
Note
The links should be freed using BLO_datablock_info_free() or the entire list using BLO_datablock_info_linklist_free().

Definition at line 145 of file readblenentry.cc.

References BLODataBlockInfo::asset_data, blendhandle_load_id_data_and_validate(), BLI_linklist_prepend(), blo_bhead_first(), blo_bhead_next(), blo_bhead_prev(), BLO_CODE_DATA, BLO_CODE_ENDB, blo_read_asset_data_block(), BHead::code, DNA_struct_find_with_alias(), FileData::filesdna, BLODataBlockInfo::free_asset_data, MEM_mallocN(), BLODataBlockInfo::name, name, BLODataBlockInfo::no_preview_found, and STRNCPY().

Referenced by filelist_readjob_list_lib().

◆ BLO_blendhandle_get_datablock_names()

LinkNode * BLO_blendhandle_get_datablock_names ( BlendHandle * bh,
int ofblocktype,
bool use_assets_only,
int * r_tot_names )

Gets the names of all the data-blocks in a file of a certain type (e.g. all the scene names in a file).

Parameters
bhThe blendhandle to access.
ofblocktypeThe type of names to get.
use_assets_onlyOnly list IDs marked as assets.
r_tot_namesThe length of the returned list.
Returns
A BLI_linklist of strings. The string links should be freed with MEM_freeN().

Definition at line 112 of file readblenentry.cc.

References blendhandle_load_id_data_and_validate(), BLI_linklist_prepend(), BLI_strdup(), blo_bhead_first(), blo_bhead_next(), BLO_CODE_ENDB, and BHead::code.

Referenced by _bpy_names(), BKE_blendfile_link_append_context_item_idtypes_from_library_add(), and BLO_main_validate_libraries().

◆ BLO_blendhandle_get_linkable_groups()

LinkNode * BLO_blendhandle_get_linkable_groups ( BlendHandle * bh)

Gets the names of all the linkable data-block types available in a file. (e.g. "Scene", "Mesh", "Light", etc.).

Parameters
bhThe blendhandle to access.
Returns
A BLI_linklist of strings. The string links should be freed with MEM_freeN().

Definition at line 294 of file readblenentry.cc.

References BKE_idtype_idcode_is_linkable(), BKE_idtype_idcode_is_valid(), BKE_idtype_idcode_to_name(), BLI_gset_add(), BLI_gset_free(), BLI_gset_ptr_new(), BLI_linklist_prepend(), BLI_strdup(), blo_bhead_first(), blo_bhead_next(), BLO_CODE_ENDB, BHead::code, and str.

Referenced by filelist_readjob_list_lib().

◆ BLO_blendhandle_get_preview_for_id()

PreviewImage * BLO_blendhandle_get_preview_for_id ( BlendHandle * bh,
int ofblocktype,
const char * name )

Get the PreviewImage of a single data block in a file. (e.g. all the scene previews in a file).

Parameters
bhThe blendhandle to access.
ofblocktypeThe type of names to get.
nameName of the block without the ID_ prefix, to read the preview image from.
Returns
PreviewImage or NULL when no preview Images have been found. Caller owns the returned

Definition at line 253 of file readblenentry.cc.

References blo_bhead_first(), blo_bhead_id_name(), blo_bhead_next(), blo_blendhandle_read_preview_rects(), BLO_CODE_DATA, BLO_CODE_ENDB, BLO_library_read_struct(), DNA_struct_find_with_alias(), FileData::filesdna, MEM_dupallocN(), MEM_freeN(), name, result, and STREQ.

Referenced by imb_thumb_load_from_blend_id().

◆ BLO_blendhandle_get_version()

blender::int3 BLO_blendhandle_get_version ( const BlendHandle * bh)

Returns the major and minor version number of Blender used to create the file.

Definition at line 78 of file readblenentry.cc.

References FileData::filesubversion, and FileData::fileversion.

Referenced by bpy_lib_enter().

◆ blo_blendhandle_read_preview_rects()

BHead * blo_blendhandle_read_preview_rects ( FileData * fd,
BHead * bhead,
PreviewImage * result,
const PreviewImage * preview_from_file )
static

Read the preview rects and store in result.

bhead should point to the block that sourced the preview_from_file parameter. bhead parameter is consumed. The correct bhead pointing to the next bhead in the file after the preview rects is returned by this function.

Parameters
fdThe filedata to read the data from.
bheadshould point to the block that sourced the preview_from_file parameter. bhead is consumed. the new bhead is returned by this function.
resultthe Preview Image where the preview rect will be stored.
preview_from_fileThe read PreviewImage where the bhead points to. The rects of this
Returns
PreviewImage or nullptr when no preview Images have been found. Caller owns the returned

Definition at line 223 of file readblenentry.cc.

References BKE_previewimg_finish(), BLI_assert, blo_bhead_next(), BLO_library_read_struct(), PreviewImage::h, BHead::len, NUM_ICON_SIZES, PreviewImage::rect, result, and PreviewImage::w.

Referenced by BLO_blendhandle_get_preview_for_id().

◆ BLO_datablock_info_free()

void BLO_datablock_info_free ( BLODataBlockInfo * datablock_info)

Frees contained data, not datablock_info itself.

Definition at line 41 of file readblenentry.cc.

References BLODataBlockInfo::asset_data, BKE_asset_metadata_free(), and BLODataBlockInfo::free_asset_data.

Referenced by BLO_datablock_info_linklist_free().

◆ BLO_datablock_info_linklist_free()

void BLO_datablock_info_linklist_free ( LinkNode * datablock_infos)

Can be used to free the list returned by BLO_blendhandle_get_datablock_info().

Definition at line 49 of file readblenentry.cc.

References BLI_linklist_free(), BLO_datablock_info_free(), and MEM_freeN().

Referenced by filelist_readjob_list_lib().

◆ BLO_read_do_version_after_setup()

void BLO_read_do_version_after_setup ( Main * new_bmain,
BlendfileLinkAppendContext * lapp_context,
BlendFileReadReport * reports )

Does versioning code that requires the Main data-base to be fully loaded and valid.

readfile's do_versions does not allow to create (or delete) IDs, and only operates on a single library at a time.

Called at the end of #setup_add_data from BKE's blendfile.cc.

Parameters
new_bmainthe newly read Main data-base.

Definition at line 445 of file readblenentry.cc.

References do_versions_after_setup().

Referenced by BKE_blendfile_append(), BKE_blendfile_link(), and setup_app_data().

◆ BLO_read_from_file()

BlendFileData * BLO_read_from_file ( const char * filepath,
eBLOReadSkip skip_flags,
BlendFileReadReport * reports )

Open a blender file from a filepath. The function returns NULL and sets a report in the list if it cannot open the file.

Parameters
filepathThe path of the file to open.
reportsIf the return value is NULL, errors indicating the cause of the failure.
Returns
The data of the file.

Definition at line 337 of file readblenentry.cc.

References BLI_assert, BLI_path_is_abs_from_cwd(), BLI_path_is_rel(), blo_filedata_free(), blo_filedata_from_file(), blo_read_file_internal(), and FileData::skip_flags.

Referenced by BKE_blendfile_read(), BKE_blendfile_userdef_read(), BKE_blendfile_workspace_config_read(), and BlendfileLoadingBaseTest::blendfile_load().

◆ BLO_read_from_memfile()

BlendFileData * BLO_read_from_memfile ( Main * oldmain,
const char * filepath,
MemFile * memfile,
const BlendFileReadParams * params,
ReportList * reports )

Used for undo/redo, skips part of libraries reading (assuming their data are already loaded & valid).

Parameters
oldmainold main, from which we will keep libraries and other data-blocks that should not have changed.
filepathcurrent file, only for retrieving library data. Typically BKE_main_blendfile_path(oldmain).

Definition at line 377 of file readblenentry.cc.

References BLI_assert, blo_cache_storage_init(), blo_cache_storage_old_bmain_clear(), blo_filedata_free(), blo_filedata_from_memfile(), blo_join_main(), blo_make_old_idmap_from_main(), blo_read_file_internal(), blo_split_main(), FileData::old_bmain, params, FileData::relabase, BlendFileReadReport::reports, FileData::skip_flags, Main::split_mains, and STRNCPY().

Referenced by BKE_blendfile_read_from_memfile(), and BLO_memfile_main_get().

◆ BLO_read_from_memory()

BlendFileData * BLO_read_from_memory ( const void * mem,
int memsize,
eBLOReadSkip skip_flags,
ReportList * reports )

Open a blender file from memory. The function returns NULL and sets a report in the list if it cannot open the file.

Parameters
memThe file data.
memsizeThe length of mem.
reportsIf the return value is NULL, errors indicating the cause of the failure.
Returns
The data of the file.

Definition at line 357 of file readblenentry.cc.

References blo_filedata_free(), blo_filedata_from_memory(), blo_read_file_internal(), BlendFileReadReport::reports, and FileData::skip_flags.

Referenced by BKE_blendfile_read_from_memory(), BKE_blendfile_userdef_read_from_memory(), BKE_blendfile_workspace_config_read(), and load_main_from_memory().

◆ BLO_read_invalidate_message()

void BLO_read_invalidate_message ( BlendHandle * bh,
Main * bmain,
const char * message )

Mark the given Main (and the 'root' local one in case of lib-split Mains) as invalid, and generate an error report containing given message.

Definition at line 328 of file readblenentry.cc.

References blo_readfile_invalidate().