[Bf-blender-cvs] [fade37ff07a] master: Writefile: move file flags to BlendFileWriteParams
Campbell Barton
noreply at git.blender.org
Fri Jun 19 08:51:48 CEST 2020
Commit: fade37ff07ab3b62844068a1a5d60dd74ea787f6
Author: Campbell Barton
Date: Fri Jun 19 15:41:07 2020 +1000
Branches: master
https://developer.blender.org/rBfade37ff07ab3b62844068a1a5d60dd74ea787f6
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.
===================================================================
M source/blender/blenkernel/BKE_global.h
M source/blender/blenkernel/intern/blender_undo.c
M source/blender/blenkernel/intern/blendfile.c
M source/blender/blenloader/BLO_writefile.h
M source/blender/blenloader/intern/writefile.c
M source/blender/windowmanager/intern/wm_files.c
M source/blender/windowmanager/intern/wm_init_exit.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h
index a134f29228f..61c270202f1 100644
--- a/source/blender/blenkernel/BKE_global.h
+++ b/source/blender/blenkernel/BKE_global.h
@@ -169,7 +169,7 @@ enum {
G_FILE_AUTOPACK = (1 << 0),
G_FILE_COMPRESS = (1 << 1),
- G_FILE_USERPREFS = (1 << 9),
+ // G_FILE_DEPRECATED_9 = (1 << 9),
G_FILE_NO_UI = (1 << 10),
/* Bits 11 to 22 (inclusive) are deprecated & need to be cleared */
@@ -177,12 +177,8 @@ enum {
/** On read, use #FileGlobal.filename instead of the real location on-disk,
* needed for recovering temp files so relative paths resolve */
G_FILE_RECOVER = (1 << 23),
- /** On write, make backup `.blend1`, `.blend2` ... files, when the users preference is enabled */
- G_FILE_HISTORY = (1 << 25),
/** BMesh option to save as older mesh format */
/* #define G_FILE_MESH_COMPAT (1 << 26) */
- /** On write, restore paths after editing them (see #BLO_WRITE_PATH_REMAP_RELATIVE). */
- G_FILE_SAVE_COPY = (1 << 27),
/* #define G_FILE_GLSL_NO_ENV_LIGHTING (1 << 28) */ /* deprecated */
};
@@ -190,7 +186,7 @@ enum {
* Run-time only #G.fileflags which are never read or written to/from Blend files.
* This means we can change the values without worrying about do-versions.
*/
-#define G_FILE_FLAG_ALL_RUNTIME (G_FILE_NO_UI | G_FILE_HISTORY | G_FILE_SAVE_COPY)
+#define G_FILE_FLAG_ALL_RUNTIME (G_FILE_NO_UI)
/** ENDIAN_ORDER: indicates what endianness the platform where the file was written had. */
#if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
diff --git a/source/blender/blenkernel/intern/blender_undo.c b/source/blender/blenkernel/intern/blender_undo.c
index e19a4935698..a6f84f3c3a4 100644
--- a/source/blender/blenkernel/intern/blender_undo.c
+++ b/source/blender/blenkernel/intern/blender_undo.c
@@ -109,8 +109,6 @@ MemFileUndoData *BKE_memfile_undo_encode(Main *bmain, MemFileUndoData *mfu_prev)
static int counter = 0;
char filename[FILE_MAX];
char numstr[32];
- /* Don't do file history on undo. */
- const int fileflags = G.fileflags & ~G_FILE_HISTORY;
/* Calculate current filename. */
counter++;
@@ -119,7 +117,8 @@ MemFileUndoData *BKE_memfile_undo_encode(Main *bmain, MemFileUndoData *mfu_prev)
BLI_snprintf(numstr, sizeof(numstr), "%d.blend", counter);
BLI_join_dirfile(filename, sizeof(filename), BKE_tempdir_session(), numstr);
- /* success = */ /* UNUSED */ BLO_write_file(bmain, filename, fileflags, NULL);
+ /* success = */ /* UNUSED */ BLO_write_file(
+ bmain, filename, G.fileflags, &(const struct BlendFileWriteParams){0}, NULL);
BLI_strncpy(mfu->filename, filename, sizeof(mfu->filename));
}
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index a3031e9047f..c6af21c6b4e 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -646,7 +646,13 @@ bool BKE_blendfile_userdef_write(const char *filepath, ReportList *reports)
Main *mainb = MEM_callocN(sizeof(Main), "empty main");
bool ok = false;
- if (BLO_write_file(mainb, filepath, G_FILE_USERPREFS, reports)) {
+ if (BLO_write_file(mainb,
+ filepath,
+ 0,
+ &(const struct BlendFileWriteParams){
+ .use_userdef = true,
+ },
+ reports)) {
ok = true;
}
@@ -768,7 +774,7 @@ WorkspaceConfigFileData *BKE_blendfile_workspace_config_read(const char *filepat
bool BKE_blendfile_workspace_config_write(Main *bmain, const char *filepath, ReportList *reports)
{
- int fileflags = G.fileflags & ~(G_FILE_NO_UI | G_FILE_HISTORY);
+ const int fileflags = G.fileflags & ~G_FILE_NO_UI;
bool retval = false;
BKE_blendfile_write_partial_begin(bmain);
@@ -883,7 +889,13 @@ bool BKE_blendfile_write_partial(Main *bmain_src,
}
/* save the buffer */
- retval = BLO_write_file_ex(bmain_dst, filepath, write_flags, reports, remap_mode, NULL);
+ retval = BLO_write_file(bmain_dst,
+ filepath,
+ write_flags,
+ &(const struct BlendFileWriteParams){
+ .remap_mode = remap_mode,
+ },
+ reports);
if (path_list_backup) {
BKE_bpath_list_restore(bmain_dst, path_list_flag, path_list_backup);
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,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list