diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-06-19 08:41:07 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-06-19 09:47:12 +0300 |
commit | fade37ff07ab3b62844068a1a5d60dd74ea787f6 (patch) | |
tree | a3d8903572491de4e00bbee91c9dbe0877fc10e3 /source/blender/blenloader/intern | |
parent | 5a77f643f45bdd52a70aecf7b09d8836d540b5a1 (diff) |
Writefile: move file flags to BlendFileWriteParams
This removes G_FILE_HISTORY, G_FILE_SAVE_COPY & G_FILE_USERPREFS.
Using file-flags made logic harder to follow since it's not so clear
which flags are expected to be in G.fileflags & which are meant to be
set and passed as arguments, these are shared between read & write
functions too.
Add BlendFileWriteParams so options which don't need to be stored
aren't mixed up with flags that are stored for reuse.
Diffstat (limited to 'source/blender/blenloader/intern')
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 1cda22de941..77c7410615e 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -4076,6 +4076,7 @@ static bool write_file_handle(Main *mainvar, MemFile *compare, MemFile *current, int write_flags, + bool use_userdef, const BlendThumbnail *thumb) { BHead bhead; @@ -4329,7 +4330,7 @@ static bool write_file_handle(Main *mainvar, /* So changes above don't cause a 'DNA1' to be detected as changed on undo. */ mywrite_flush(wd); - if (write_flags & G_FILE_USERPREFS) { + if (use_userdef) { write_userdef(&writer, &U); } @@ -4400,18 +4401,22 @@ static bool do_history(const char *name, ReportList *reports) /** * \return Success. */ -bool BLO_write_file_ex(Main *mainvar, - const char *filepath, - const int write_flags, - ReportList *reports, - /* Extra arguments. */ - eBLO_WritePathRemap remap_mode, - const BlendThumbnail *thumb) +bool BLO_write_file(Main *mainvar, + const char *filepath, + const int write_flags, + const struct BlendFileWriteParams *params, + ReportList *reports) { char tempname[FILE_MAX + 1]; eWriteWrapType ww_type; WriteWrap ww; + eBLO_WritePathRemap remap_mode = params->remap_mode; + const bool use_save_versions = params->use_save_versions; + const bool use_save_as_copy = params->use_save_as_copy; + const bool use_userdef = params->use_userdef; + const BlendThumbnail *thumb = params->thumb; + /* path backup/restore */ void *path_list_backup = NULL; const int path_list_flag = (BKE_BPATH_TRAVERSE_SKIP_LIBRARY | BKE_BPATH_TRAVERSE_SKIP_MULTIFILE); @@ -4476,7 +4481,7 @@ bool BLO_write_file_ex(Main *mainvar, if (remap_mode != BLO_WRITE_PATH_REMAP_NONE) { /* Check if we need to backup and restore paths. */ - if (UNLIKELY(G_FILE_SAVE_COPY & write_flags)) { + if (UNLIKELY(use_save_as_copy)) { path_list_backup = BKE_bpath_list_backup(mainvar, path_list_flag); } @@ -4501,7 +4506,7 @@ bool BLO_write_file_ex(Main *mainvar, } /* actual file writing */ - const bool err = write_file_handle(mainvar, &ww, NULL, NULL, write_flags, thumb); + const bool err = write_file_handle(mainvar, &ww, NULL, NULL, write_flags, use_userdef, thumb); ww.close(&ww); @@ -4519,7 +4524,7 @@ bool BLO_write_file_ex(Main *mainvar, /* file save to temporary file was successful */ /* now do reverse file history (move .blend1 -> .blend2, .blend -> .blend1) */ - if (write_flags & G_FILE_HISTORY) { + if (use_save_versions) { const bool err_hist = do_history(filepath, reports); if (err_hist) { BKE_report(reports, RPT_ERROR, "Version backup failed (file saved with @)"); @@ -4540,23 +4545,15 @@ bool BLO_write_file_ex(Main *mainvar, return 1; } -bool BLO_write_file(Main *mainvar, - const char *filepath, - const int write_flags, - ReportList *reports) -{ - return BLO_write_file_ex( - mainvar, filepath, write_flags, reports, BLO_WRITE_PATH_REMAP_NONE, NULL); -} - /** * \return Success. */ bool BLO_write_file_mem(Main *mainvar, MemFile *compare, MemFile *current, int write_flags) { - write_flags &= ~G_FILE_USERPREFS; + bool use_userdef = false; - const bool err = write_file_handle(mainvar, NULL, compare, current, write_flags, NULL); + const bool err = write_file_handle( + mainvar, NULL, compare, current, write_flags, use_userdef, NULL); return (err == 0); } |