diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-03-03 13:11:22 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-03-03 13:11:22 +0300 |
commit | b02b8a3c003be496fc685a05f5c469b65743006a (patch) | |
tree | 2fe095f32094ed1cfbe3f9c9943d4635b881b396 /source | |
parent | 82cf78dfe87d1d1b12f5b6ba383fb0248508ebf2 (diff) |
Refactor BKE_copybuffer for general partial saving
Move to re-usable BKE_blendfile_write_partial API
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_blender.h | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_library.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/blender.c | 75 |
3 files changed, 67 insertions, 20 deletions
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 0a35d0aba57..fdb34743f36 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -103,7 +103,15 @@ extern const char *BKE_undo_get_name(int nr, bool *r_active); extern bool BKE_undo_save_file(const char *filename); extern struct Main *BKE_undo_get_main(struct Scene **r_scene); -/* copybuffer */ +/* partial blend file writing */ +void BKE_blendfile_write_partial_tag_ID(struct ID *id, bool set); +void BKE_blendfile_write_partial_begin(struct Main *bmain_src); +bool BKE_blendfile_write_partial( + struct Main *bmain_src, const char *filepath, const int write_flags, struct ReportList *reports); +void BKE_blendfile_write_partial_end(struct Main *bmain_src); + + +/* copybuffer (wrapper for BKE_blendfile_write_partial) */ void BKE_copybuffer_begin(struct Main *bmain_src); void BKE_copybuffer_tag_ID(struct ID *id); bool BKE_copybuffer_save(struct Main *bmain_src, const char *filename, struct ReportList *reports); diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 9cfc0373952..606edd9cc3a 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -108,7 +108,7 @@ void BKE_main_id_tag_idcode(struct Main *mainvar, const short type, const int ta void BKE_main_id_tag_listbase(struct ListBase *lb, const int tag, const bool value); void BKE_main_id_tag_all(struct Main *mainvar, const int tag, const bool value); -void BKE_main_id_flag_listbase(ListBase *lb, const int flag, const bool value); +void BKE_main_id_flag_listbase(struct ListBase *lb, const int flag, const bool value); void BKE_main_id_flag_all(struct Main *bmain, const int flag, const bool value); void BKE_main_id_clear_newpoins(struct Main *bmain); 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. */ |