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 | |
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')
-rw-r--r-- | source/blender/blenloader/BLO_writefile.h | 27 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 41 |
2 files changed, 35 insertions, 33 deletions
diff --git a/source/blender/blenloader/BLO_writefile.h b/source/blender/blenloader/BLO_writefile.h index 18783474392..32cb6633c12 100644 --- a/source/blender/blenloader/BLO_writefile.h +++ b/source/blender/blenloader/BLO_writefile.h @@ -35,25 +35,30 @@ struct ReportList; */ typedef enum eBLO_WritePathRemap { /** No path manipulation. */ - BLO_WRITE_PATH_REMAP_NONE = 1, + BLO_WRITE_PATH_REMAP_NONE = 0, /** Remap existing relative paths (default). */ - BLO_WRITE_PATH_REMAP_RELATIVE = 2, + BLO_WRITE_PATH_REMAP_RELATIVE = 1, /** Remap paths making all paths relative to the new location. */ - BLO_WRITE_PATH_REMAP_RELATIVE_ALL = 3, + BLO_WRITE_PATH_REMAP_RELATIVE_ALL = 2, /** Make all paths absolute. */ - BLO_WRITE_PATH_REMAP_ABSOLUTE = 4, + BLO_WRITE_PATH_REMAP_ABSOLUTE = 3, } eBLO_WritePathRemap; -extern bool BLO_write_file_ex(struct Main *mainvar, - const char *filepath, - const int write_flags, - struct ReportList *reports, - /* Extra arguments. */ - eBLO_WritePathRemap remap_mode, - const struct BlendThumbnail *thumb); +/** Similar to #BlendFileReadParams. */ +struct BlendFileWriteParams { + eBLO_WritePathRemap remap_mode; + /** Save `.blend1`, `.blend2`... etc. */ + uint use_save_versions : 1; + /** On write, restore paths after editing them (see #BLO_WRITE_PATH_REMAP_RELATIVE). */ + uint use_save_as_copy : 1; + uint use_userdef : 1; + const struct BlendThumbnail *thumb; +}; + extern bool BLO_write_file(struct Main *mainvar, const char *filepath, const int write_flags, + const struct BlendFileWriteParams *params, struct ReportList *reports); extern bool BLO_write_file_mem(struct Main *mainvar, 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); } |