Blender  V3.3
Functions
readblenentry.c File Reference
#include <stddef.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_ghash.h"
#include "BLI_linklist.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "DNA_genfile.h"
#include "DNA_sdna_types.h"
#include "BKE_icons.h"
#include "BKE_idtype.h"
#include "BKE_main.h"
#include "BLO_blend_defs.h"
#include "BLO_readfile.h"
#include "BLO_undofile.h"
#include "readfile.h"
#include "BLI_sys_types.h"

Go to the source code of this file.

Functions

void BLO_blendhandle_print_sizes (BlendHandle *bh, void *fp)
 
BlendHandleBLO_blendhandle_from_file (const char *filepath, BlendFileReadReport *reports)
 
BlendHandleBLO_blendhandle_from_memory (const void *mem, int memsize, BlendFileReadReport *reports)
 
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_previews (BlendHandle *bh, int ofblocktype, int *r_tot_prev)
 
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 struct BlendFileReadParams *params, ReportList *reports)
 
void BLO_blendfiledata_free (BlendFileData *bfd)
 

Detailed Description

.blend file reading entry point.

Definition in file readblenentry.c.

Function Documentation

◆ 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 449 of file readblenentry.c.

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_ex(), and BlendfileLoadingBaseTest::blendfile_free().

◆ 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 345 of file readblenentry.c.

References blo_filedata_free().

Referenced by BKE_blendfile_is_readable(), BLO_library_temp_free(), BLO_main_validate_libraries(), bpy_lib_exit(), 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,
struct 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 48 of file readblenentry.c.

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,
struct 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 57 of file readblenentry.c.

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 *. The links and BLODataBlockInfo.asset_data should be freed with MEM_freeN.

Definition at line 132 of file readblenentry.c.

References BLODataBlockInfo::asset_data, BLI_linklist_prepend(), blo_bhead_first(), blo_bhead_id_asset_data_address(), blo_bhead_id_name(), blo_bhead_next(), blo_bhead_prev(), blo_read_asset_data_block(), BHead::code, ENDB, MEM_mallocN, BLODataBlockInfo::name, NULL, 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 103 of file readblenentry.c.

References BLI_linklist_prepend(), BLI_strdup(), blo_bhead_first(), blo_bhead_id_asset_data_address(), blo_bhead_id_name(), blo_bhead_next(), BHead::code, ENDB, names, and NULL.

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 318 of file readblenentry.c.

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(), BHead::code, ENDB, names, NULL, 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 219 of file readblenentry.c.

References blo_bhead_first(), blo_bhead_id_name(), blo_bhead_next(), blo_blendhandle_read_preview_rects(), BLO_library_read_struct(), DATA, DNA_struct_find_nr(), ENDB, FileData::filesdna, MEM_dupallocN, MEM_freeN, BLODataBlockInfo::name, NULL, result, and STREQ.

Referenced by imb_thumb_load_from_blend_id().

◆ BLO_blendhandle_get_previews()

LinkNode* BLO_blendhandle_get_previews ( BlendHandle bh,
int  ofblocktype,
int *  r_tot_prev 
)

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

Parameters
bhThe blendhandle to access.
ofblocktypeThe type of names to get.
r_tot_prevThe length of the returned list.
Returns
A BLI_linklist of PreviewImage. The PreviewImage links should be freed with malloc.

Definition at line 258 of file readblenentry.c.

References BLI_linklist_prepend(), blo_bhead_first(), blo_bhead_id_name(), blo_bhead_next(), blo_blendhandle_read_preview_rects(), BLO_library_read_struct(), BHead::code, DATA, DNA_struct_find_nr(), ENDB, FileData::filesdna, GS, ID_AC, ID_GR, ID_IM, ID_LA, ID_MA, ID_NT, ID_OB, ID_SCE, ID_TE, ID_WO, MEM_callocN, MEM_freeN, NULL, and BHead::SDNAnr.

◆ BLO_blendhandle_print_sizes()

void BLO_blendhandle_print_sizes ( BlendHandle bh,
void fp 
)

◆ blo_blendhandle_read_preview_rects()

static 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 NULL when no preview Images have been found. Caller owns the returned

Definition at line 191 of file readblenentry.c.

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

Referenced by BLO_blendhandle_get_preview_for_id(), and BLO_blendhandle_get_previews().

◆ BLO_read_from_file()

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

Open a blender file from a pathname. 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 361 of file readblenentry.c.

References blo_filedata_free(), blo_filedata_from_file(), blo_read_file_internal(), NULL, 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 ( struct Main oldmain,
const char *  filepath,
struct MemFile memfile,
const struct BlendFileReadParams params,
struct 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 397 of file readblenentry.c.

References BLI_assert, BLI_strncpy(), blo_add_library_pointer_map(), 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_READ_SKIP_UNDO_OLD_MAIN, blo_split_main(), ListBase::first, NULL, params, FileData::relabase, BlendFileReadReport::reports, and FileData::skip_flags.

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,
struct 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 378 of file readblenentry.c.

References blo_filedata_free(), blo_filedata_from_memory(), blo_read_file_internal(), NULL, 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,
struct 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 352 of file readblenentry.c.

References blo_readfile_invalidate().