Blender  V2.93
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 "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

High Level <tt>.blend</tt> file read/write.
static bool clean_paths_visit_cb (void *UNUSED(userdata), char *path_dst, const char *path_src)
 
static void clean_paths (Main *main)
 
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, ReportList *reports)
 
static void setup_app_blend_file_data (bContext *C, BlendFileData *bfd, const struct BlendFileReadParams *params, ReportList *reports)
 
static void handle_subversion_warning (Main *main, ReportList *reports)
 
void BKE_blendfile_read_setup_ex (bContext *C, BlendFileData *bfd, const struct BlendFileReadParams *params, ReportList *reports, const bool startup_update_defaults, const char *startup_app_template)
 
void BKE_blendfile_read_setup (bContext *C, BlendFileData *bfd, const struct BlendFileReadParams *params, ReportList *reports)
 
struct BlendFileDataBKE_blendfile_read (const char *filepath, const struct BlendFileReadParams *params, ReportList *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_read()

struct BlendFileData* BKE_blendfile_read ( const char *  filepath,
const struct BlendFileReadParams params,
ReportList reports 
)
Returns
Blend file data, this must be passed to BKE_blendfile_read_setup when non-NULL.

Definition at line 470 of file blendfile.c.

References BKE_reports_prependf(), BLO_read_from_file(), handle_subversion_warning(), BlendFileData::main, and params.

Referenced by BKE_memfile_undo_decode(), WM_file_read(), and wm_homefile_read().

◆ BKE_blendfile_read_from_memfile()

struct BlendFileData* BKE_blendfile_read_from_memfile ( Main bmain,
struct MemFile memfile,
const struct BlendFileReadParams params,
ReportList reports 
)
Returns
Blend file data, this must be passed to BKE_blendfile_read_setup when non-NULL.
Note
memfile is the undo buffer.

Definition at line 511 of file blendfile.c.

References BKE_main_blendfile_path(), BKE_reports_prepend(), BLI_assert, BLI_listbase_is_empty(), BLO_read_from_memfile(), BlendFileData::main, params, Main::screens, Main::wm, and Main::workspaces.

Referenced by BKE_memfile_undo_decode().

◆ BKE_blendfile_read_from_memory()

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

Definition at line 492 of file blendfile.c.

References BKE_reports_prepend(), BLO_read_from_memory(), and params.

Referenced by wm_homefile_read().

◆ BKE_blendfile_read_make_empty()

void BKE_blendfile_read_make_empty ( bContext C)

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

Definition at line 537 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().

◆ BKE_blendfile_read_setup()

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

Definition at line 459 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 ( bContext C,
BlendFileData bfd,
const struct BlendFileReadParams params,
ReportList reports,
const 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 442 of file blendfile.c.

References BLO_blendfiledata_free(), BLO_READ_SKIP_DATA, BLO_update_defaults_startup_blend(), C, BlendFileData::main, params, and setup_app_blend_file_data().

Referenced by BKE_blendfile_read_setup(), and wm_homefile_read().

◆ BKE_blendfile_userdef_from_defaults()

UserDef* BKE_blendfile_userdef_from_defaults ( void  )

◆ BKE_blendfile_userdef_read()

UserDef* BKE_blendfile_userdef_read ( const char *  filepath,
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,
ReportList reports 
)

Only write the userdef in a .blend

Returns
success

Definition at line 673 of file blendfile.c.

References BLO_write_file(), 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,
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 prefs.

Definition at line 700 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(), 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 825 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 ( Main bmain_src,
const char *  filepath,
const int  write_flags,
const int  remap_mode,
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_write_partial_cb()

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

Definition at line 852 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 main)
static

◆ clean_paths_visit_cb()

static bool clean_paths_visit_cb ( void *  UNUSEDuserdata,
char *  path_dst,
const char *  path_src 
)
static

Definition at line 79 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,
ReportList reports 
)
static

Definition at line 421 of file blendfile.c.

References BKE_reportf(), BLENDER_FILE_SUBVERSION, BLENDER_FILE_VERSION, main(), and RPT_ERROR.

Referenced by BKE_blendfile_read().

◆ setup_app_blend_file_data()

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

◆ setup_app_data()

static void setup_app_data ( bContext C,
BlendFileData bfd,
const struct BlendFileReadParams params,
ReportList 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 136 of file blendfile.c.

References BKE_blender_globals_clear(), BKE_lib_libblock_session_uuid_renew(), BKE_lib_override_library_main_operations_create(), 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(), BLI_assert, BLI_strncpy(), 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(), ELEM, FILE_MAX, BlendFileData::fileflags, BlendFileData::filename, 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(), LISTBASE_FOREACH, BlendFileData::main, Main::name, NULL, params, RE_FreeAllPersistentData(), RE_FreeAllRenderResults(), Main::recovered, RPT_WARNING, wmWindow::scene, Main::scenes, Main::screens, STEP_INVALID, 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 98 of file blendfile.c.

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

Referenced by setup_app_data().