Blender  V3.3
blendfile.c File Reference
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_workspace_types.h"
#include "BLI_listbase.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_system.h"
#include "BLI_utildefines.h"
#include "PIL_time.h"
#include "IMB_colormanagement.h"
#include "BKE_addon.h"
#include "BKE_appdir.h"
#include "BKE_blender.h"
#include "BKE_blender_version.h"
#include "BKE_blendfile.h"
#include "BKE_bpath.h"
#include "BKE_colorband.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_ipo.h"
#include "BKE_keyconfig.h"
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_lib_override.h"
#include "BKE_main.h"
#include "BKE_preferences.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_studiolight.h"
#include "BKE_undo_system.h"
#include "BKE_workspace.h"
#include "BLO_readfile.h"
#include "BLO_writefile.h"
#include "RNA_access.h"
#include "RE_pipeline.h"

Go to the source code of this file.

Functions

Blend/Library Paths
bool BKE_blendfile_is_readable (const char *path, ReportList *reports)
 
High Level <tt>.blend</tt> file read/write.
static bool blendfile_or_libraries_versions_atleast (Main *bmain, const short versionfile, const short subversionfile)
 
static bool foreach_path_clean_cb (BPathForeachPathData *UNUSED(bpath_data), char *path_dst, const char *path_src)
 
static void clean_paths (Main *bmain)
 
static bool wm_scene_is_visible (wmWindowManager *wm, Scene *scene)
 
static void setup_app_userdef (BlendFileData *bfd)
 
static void setup_app_data (bContext *C, BlendFileData *bfd, const struct BlendFileReadParams *params, BlendFileReadReport *reports)
 
static void setup_app_blend_file_data (bContext *C, BlendFileData *bfd, const struct BlendFileReadParams *params, BlendFileReadReport *reports)
 
static void handle_subversion_warning (Main *main, BlendFileReadReport *reports)
 
void BKE_blendfile_read_setup_ex (bContext *C, BlendFileData *bfd, const struct BlendFileReadParams *params, BlendFileReadReport *reports, const bool startup_update_defaults, const char *startup_app_template)
 
void BKE_blendfile_read_setup (bContext *C, BlendFileData *bfd, const struct BlendFileReadParams *params, BlendFileReadReport *reports)
 
struct BlendFileDataBKE_blendfile_read (const char *filepath, const struct BlendFileReadParams *params, BlendFileReadReport *reports)
 
struct BlendFileDataBKE_blendfile_read_from_memory (const void *filebuf, int filelength, const struct BlendFileReadParams *params, ReportList *reports)
 
struct BlendFileDataBKE_blendfile_read_from_memfile (Main *bmain, struct MemFile *memfile, const struct BlendFileReadParams *params, ReportList *reports)
 
void BKE_blendfile_read_make_empty (bContext *C)
 
UserDefBKE_blendfile_userdef_read (const char *filepath, ReportList *reports)
 
UserDefBKE_blendfile_userdef_read_from_memory (const void *filebuf, int filelength, ReportList *reports)
 
UserDefBKE_blendfile_userdef_from_defaults (void)
 
bool BKE_blendfile_userdef_write (const char *filepath, ReportList *reports)
 
bool BKE_blendfile_userdef_write_app_template (const char *filepath, ReportList *reports)
 
bool BKE_blendfile_userdef_write_all (ReportList *reports)
 
WorkspaceConfigFileDataBKE_blendfile_workspace_config_read (const char *filepath, const void *filebuf, int filelength, ReportList *reports)
 
bool BKE_blendfile_workspace_config_write (Main *bmain, const char *filepath, ReportList *reports)
 
void BKE_blendfile_workspace_config_data_free (WorkspaceConfigFileData *workspace_config)
 
Partial <tt>.blend</tt> file save.
void BKE_blendfile_write_partial_begin (Main *bmain_src)
 
void BKE_blendfile_write_partial_tag_ID (ID *id, bool set)
 
static void blendfile_write_partial_cb (void *UNUSED(handle), Main *UNUSED(bmain), void *vid)
 
bool BKE_blendfile_write_partial (Main *bmain_src, const char *filepath, const int write_flags, const int remap_mode, ReportList *reports)
 
void BKE_blendfile_write_partial_end (Main *bmain_src)
 

Detailed Description

High level .blend file read/write, and functions for writing partial files (only selected data-blocks).

Definition in file blendfile.c.

Function Documentation

◆ BKE_blendfile_is_readable()

bool BKE_blendfile_is_readable ( const char *  path,
struct ReportList reports 
)

Check whether a given path is actually a Blender-readable, valid .blend file.

Note
Currently does attempt to open and read (part of) the given file.

Definition at line 68 of file blendfile.c.

References BLO_blendhandle_close(), BLO_blendhandle_from_file(), NULL, and BlendFileReadReport::reports.

Referenced by file_draw_hint_if_invalid().

◆ BKE_blendfile_read()

struct BlendFileData* BKE_blendfile_read ( const char *  filepath,
const struct BlendFileReadParams params,
struct BlendFileReadReport reports 
)

◆ BKE_blendfile_read_from_memfile()

struct BlendFileData* BKE_blendfile_read_from_memfile ( struct Main bmain,
struct MemFile memfile,
const struct BlendFileReadParams params,
struct ReportList reports 
)

◆ BKE_blendfile_read_from_memory()

struct BlendFileData* BKE_blendfile_read_from_memory ( const void filebuf,
int  filelength,
const struct BlendFileReadParams params,
struct ReportList reports 
)
Returns
Blend file data, this must be passed to BKE_blendfile_read_setup when non-NULL.

Definition at line 537 of file blendfile.c.

References BKE_reports_prepend(), BLO_blendfiledata_free(), BLO_read_from_memory(), Main::is_read_invalid, BlendFileData::main, NULL, and params.

Referenced by wm_homefile_read_ex().

◆ BKE_blendfile_read_make_empty()

void BKE_blendfile_read_make_empty ( struct bContext C)

Utility to make a file 'empty' used for startup to optionally give an empty file. Handy for tests.

Definition at line 582 of file blendfile.c.

References BKE_id_delete(), C, CTX_data_main(), ELEM, FOREACH_MAIN_LISTBASE_BEGIN, FOREACH_MAIN_LISTBASE_END, FOREACH_MAIN_LISTBASE_ID_BEGIN, FOREACH_MAIN_LISTBASE_ID_END, GS, id, ID_SCE, ID_SCR, ID_WM, ID_WS, and ID::name.

Referenced by wm_homefile_read_ex().

◆ BKE_blendfile_read_setup()

void BKE_blendfile_read_setup ( bContext C,
BlendFileData bfd,
const struct BlendFileReadParams params,
BlendFileReadReport reports 
)

Definition at line 506 of file blendfile.c.

References BKE_blendfile_read_setup_ex(), C, NULL, and params.

Referenced by BKE_memfile_undo_decode(), and WM_file_read().

◆ BKE_blendfile_read_setup_ex()

void BKE_blendfile_read_setup_ex ( struct bContext C,
struct BlendFileData bfd,
const struct BlendFileReadParams params,
struct BlendFileReadReport reports,
bool  startup_update_defaults,
const char *  startup_app_template 
)

Shared setup function that makes the data from bfd into the current blend file, replacing the contents of #G.main. This uses the bfd BKE_blendfile_read and similarly named functions.

This is done in a separate step so the caller may perform actions after it is known the file loaded correctly but before the file replaces the existing blend file contents.

Definition at line 482 of file blendfile.c.

References BKE_reports_prepend(), BLO_blendfiledata_free(), BLO_READ_SKIP_DATA, BLO_update_defaults_startup_blend(), C, Main::is_read_invalid, BlendFileData::main, params, BlendFileReadReport::reports, and setup_app_blend_file_data().

Referenced by BKE_blendfile_read_setup(), and wm_homefile_read_ex().

◆ BKE_blendfile_userdef_from_defaults()

UserDef* BKE_blendfile_userdef_from_defaults ( void  )

◆ BKE_blendfile_userdef_read()

UserDef* BKE_blendfile_userdef_read ( const char *  filepath,
struct ReportList reports 
)

◆ BKE_blendfile_userdef_read_from_memory()

UserDef* BKE_blendfile_userdef_read_from_memory ( const void filebuf,
int  filelength,
ReportList reports 
)

◆ BKE_blendfile_userdef_write()

bool BKE_blendfile_userdef_write ( const char *  filepath,
struct ReportList reports 
)

Only write the UserDef in a .blend.

Returns
success.

Definition at line 712 of file blendfile.c.

References BLO_write_file(), BlendFileData::filepath, MEM_callocN, and MEM_freeN.

Referenced by BKE_blendfile_userdef_write_all(), and BKE_blendfile_userdef_write_app_template().

◆ BKE_blendfile_userdef_write_all()

bool BKE_blendfile_userdef_write_all ( ReportList reports)

◆ BKE_blendfile_userdef_write_app_template()

bool BKE_blendfile_userdef_write_app_template ( const char *  filepath,
struct ReportList reports 
)

Only write the UserDef in a .blend, merging with the existing blend file.

Returns
success.
Note
In the future we should re-evaluate user preferences, possibly splitting out system/hardware specific preferences.

Definition at line 732 of file blendfile.c.

References BKE_blender_userdef_app_template_data_swap(), BKE_blender_userdef_data_free(), BKE_blendfile_userdef_read(), BKE_blendfile_userdef_write(), BlendFileData::filepath, MEM_freeN, and NULL.

Referenced by BKE_blendfile_userdef_write_all().

◆ BKE_blendfile_workspace_config_data_free()

void BKE_blendfile_workspace_config_data_free ( WorkspaceConfigFileData workspace_config)

Definition at line 860 of file blendfile.c.

References BKE_main_free(), WorkspaceConfigFileData::main, and MEM_freeN.

Referenced by workspace_add_menu().

◆ BKE_blendfile_workspace_config_read()

WorkspaceConfigFileData* BKE_blendfile_workspace_config_read ( const char *  filepath,
const void filebuf,
int  filelength,
ReportList reports 
)

◆ BKE_blendfile_workspace_config_write()

bool BKE_blendfile_workspace_config_write ( Main bmain,
const char *  filepath,
ReportList reports 
)

◆ BKE_blendfile_write_partial()

bool BKE_blendfile_write_partial ( struct Main bmain_src,
const char *  filepath,
int  write_flags,
int  remap_mode,
struct ReportList reports 
)

◆ BKE_blendfile_write_partial_begin()

void BKE_blendfile_write_partial_begin ( Main bmain_src)

◆ BKE_blendfile_write_partial_end()

void BKE_blendfile_write_partial_end ( Main bmain_src)

◆ BKE_blendfile_write_partial_tag_ID()

void BKE_blendfile_write_partial_tag_ID ( ID id,
bool  set 
)

◆ blendfile_or_libraries_versions_atleast()

static bool blendfile_or_libraries_versions_atleast ( Main bmain,
const short  versionfile,
const short  subversionfile 
)
static

Definition at line 86 of file blendfile.c.

References Main::libraries, library, LISTBASE_FOREACH, and MAIN_VERSION_ATLEAST.

Referenced by setup_app_data().

◆ blendfile_write_partial_cb()

static void blendfile_write_partial_cb ( void UNUSEDhandle,
Main UNUSEDbmain,
void vid 
)
static

Definition at line 887 of file blendfile.c.

References id, Library::id, ID::lib, LIB_TAG_DOIT, LIB_TAG_NEED_EXPAND, and ID::tag.

Referenced by BKE_blendfile_write_partial().

◆ clean_paths()

static void clean_paths ( Main bmain)
static

◆ foreach_path_clean_cb()

static bool foreach_path_clean_cb ( BPathForeachPathData UNUSEDbpath_data,
char *  path_dst,
const char *  path_src 
)
static

Definition at line 103 of file blendfile.c.

References BLI_path_slash_native(), and STREQ.

Referenced by clean_paths().

◆ handle_subversion_warning()

static void handle_subversion_warning ( Main main,
BlendFileReadReport reports 
)
static

◆ setup_app_blend_file_data()

static void setup_app_blend_file_data ( bContext C,
BlendFileData bfd,
const struct BlendFileReadParams params,
BlendFileReadReport reports 
)
static

◆ setup_app_data()

static void setup_app_data ( bContext C,
BlendFileData bfd,
const struct BlendFileReadParams params,
BlendFileReadReport reports 
)
static

Context matching, handle no-UI case.

Note
this is called on Undo so any slow conversion functions here should be avoided or check (mode != LOAD_UNDO).
Parameters
bfdBlend file data, freed by this function on exit.

Definition at line 165 of file blendfile.c.

References BKE_blender_globals_clear(), BKE_lib_libblock_session_uuid_renew(), BKE_lib_override_library_main_hierarchy_root_ensure(), BKE_lib_override_library_main_operations_create(), BKE_lib_override_library_main_proxy_convert(), BKE_lib_override_library_main_resync(), BKE_main_id_refcount_recompute(), BKE_report(), BKE_scene_add(), BKE_scene_set_background(), BKE_screen_gizmo_tag_refresh(), BKE_screen_view3d_scene_sync(), BKE_view_layer_default_view(), blendfile_or_libraries_versions_atleast(), BLI_assert, blo_lib_link_restore(), BPY_context_update(), C, clean_paths(), CTX_data_main_set(), CTX_data_scene(), CTX_data_scene_set(), CTX_py_init_get(), CTX_wm_area_set(), CTX_wm_manager(), CTX_wm_manager_set(), CTX_wm_menu_set(), CTX_wm_region_set(), CTX_wm_screen(), CTX_wm_screen_set(), CTX_wm_window(), BlendFileData::cur_view_layer, BlendFileData::curscene, BlendFileData::curscreen, do_versions_ipos_to_animato(), BlendFileReadReport::duration, ELEM, BlendFileData::fileflags, Main::filepath, BlendFileData::filepath, ListBase::first, FOREACH_MAIN_LISTBASE_ID_BEGIN, FOREACH_MAIN_LISTBASE_ID_END, G, G_FILE_FLAG_ALL_RUNTIME, G_FILE_NO_UI, G_FILE_RECOVER_READ, G_FLAG_ALL_READFILE, G_FLAG_ALL_RUNTIME, G_MAIN, BlendFileData::globalf, id, IMB_colormanagement_check_file_config(), BlendFileReadReport::lib_overrides_resync, LISTBASE_FOREACH, BlendFileData::main, NULL, params, PIL_check_seconds_timer(), RE_FreeAllPersistentData(), RE_FreeAllRenderResults(), Main::recovered, BlendFileReadReport::reports, RPT_WARNING, wmWindow::scene, Main::scenes, Main::screens, STEP_INVALID, STRNCPY, SWAP, USER_EXPERIMENTAL_TEST, Main::versionfile, wmWindowManager::windows, Main::wm, wm_scene_is_visible(), and Main::workspaces.

Referenced by setup_app_blend_file_data().

◆ setup_app_userdef()

static void setup_app_userdef ( BlendFileData bfd)
static

◆ wm_scene_is_visible()

static bool wm_scene_is_visible ( wmWindowManager wm,
Scene scene 
)
static

Definition at line 127 of file blendfile.c.

References ListBase::first, wmWindow::next, scene, wmWindow::scene, and wmWindowManager::windows.

Referenced by setup_app_data().