diff options
Diffstat (limited to 'source/blender/blenkernel/intern/blender.c')
-rw-r--r-- | source/blender/blenkernel/intern/blender.c | 75 |
1 files changed, 57 insertions, 18 deletions
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index e1db35f50cb..252a11ccc7f 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -965,21 +965,25 @@ Main *BKE_undo_get_main(Scene **r_scene) /* -------------------------------------------------------------------- */ -/** \name Copy/Paste `.blend`, partial saves. +/** \name Partial `.blend` file save. * \{ */ -void BKE_copybuffer_begin(Main *bmain_src) +void BKE_blendfile_write_partial_begin(Main *bmain_src) { - /* set all id flags to zero; */ BKE_main_id_tag_all(bmain_src, LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT, false); } -void BKE_copybuffer_tag_ID(ID *id) +void BKE_blendfile_write_partial_tag_ID(ID *id, bool set) { - id->tag |= LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT; + if (set) { + id->tag |= LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT; + } + else { + id->tag &= ~(LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT); + } } -static void copybuffer_doit(void *UNUSED(handle), Main *UNUSED(bmain_src), void *vid) +static void blendfile_write_partial_cb(void *UNUSED(handle), Main *UNUSED(bmain), void *vid) { if (vid) { ID *id = vid; @@ -992,22 +996,23 @@ static void copybuffer_doit(void *UNUSED(handle), Main *UNUSED(bmain_src), void /** * \return Success. */ -bool BKE_copybuffer_save(Main *bmain_src, const char *filename, ReportList *reports) +bool BKE_blendfile_write_partial( + Main *bmain_src, const char *filepath, const int write_flags, ReportList *reports) { - /* frees main in end */ Main *bmain_dst = MEM_callocN(sizeof(Main), "copybuffer"); ListBase *lbarray_dst[MAX_LIBARRAY], *lbarray_src[MAX_LIBARRAY]; int a, retval; - - /* path backup/restore */ - void *path_list_backup; + + void *path_list_backup = NULL; const int path_list_flag = (BKE_BPATH_TRAVERSE_SKIP_LIBRARY | BKE_BPATH_TRAVERSE_SKIP_MULTIFILE); - path_list_backup = BKE_bpath_list_backup(bmain_src, path_list_flag); + if (write_flags & G_FILE_RELATIVE_REMAP) { + path_list_backup = BKE_bpath_list_backup(bmain_src, path_list_flag); + } - BLO_main_expander(copybuffer_doit); + BLO_main_expander(blendfile_write_partial_cb); BLO_expand_main(NULL, bmain_src); - + /* move over all tagged blocks */ set_listbasepointers(bmain_src, lbarray_src); a = set_listbasepointers(bmain_dst, lbarray_dst); @@ -1026,7 +1031,7 @@ bool BKE_copybuffer_save(Main *bmain_src, const char *filename, ReportList *repo /* save the buffer */ - retval = BLO_write_file(bmain_dst, filename, G_FILE_RELATIVE_REMAP, reports, NULL); + retval = BLO_write_file(bmain_dst, filepath, write_flags, reports, NULL); /* move back the main, now sorted again */ set_listbasepointers(bmain_src, lbarray_dst); @@ -1043,9 +1048,6 @@ bool BKE_copybuffer_save(Main *bmain_src, const char *filename, ReportList *repo MEM_freeN(bmain_dst); - /* set id flag to zero; */ - BKE_main_id_tag_all(bmain_src, LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT, false); - if (path_list_backup) { BKE_bpath_list_restore(bmain_src, path_list_flag, path_list_backup); BKE_bpath_list_free(path_list_backup); @@ -1054,6 +1056,43 @@ bool BKE_copybuffer_save(Main *bmain_src, const char *filename, ReportList *repo return retval; } +void BKE_blendfile_write_partial_end(Main *bmain_src) +{ + BKE_main_id_tag_all(bmain_src, LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT, false); +} + +/** \} */ + + +/* -------------------------------------------------------------------- */ + +/** \name Copy/Paste `.blend`, partial saves. + * \{ */ + +void BKE_copybuffer_begin(Main *bmain_src) +{ + BKE_blendfile_write_partial_begin(bmain_src); +} + +void BKE_copybuffer_tag_ID(ID *id) +{ + BKE_blendfile_write_partial_tag_ID(id, true); +} + +/** + * \return Success. + */ +bool BKE_copybuffer_save(Main *bmain_src, const char *filename, ReportList *reports) +{ + const int write_flags = G_FILE_RELATIVE_REMAP; + + bool retval = BKE_blendfile_write_partial(bmain_src, filename, write_flags, reports); + + BKE_blendfile_write_partial_end(bmain_src); + + return retval; +} + /** * \return Success. */ |