[Bf-blender-cvs] [cd3b313d5f4] blender2.8: Prevent G.fileflags changes when WM_OT_save_mainfile() is called from script

Sybren A. Stüvel noreply at git.blender.org
Fri Oct 12 10:27:15 CEST 2018


Commit: cd3b313d5f44a10a1150bf1ddb560775d1bcd827
Author: Sybren A. Stüvel
Date:   Fri Oct 12 10:24:07 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBcd3b313d5f44a10a1150bf1ddb560775d1bcd827

Prevent G.fileflags changes when WM_OT_save_mainfile() is called from script

This is to solve an issue where a blend file could be compressed
unbeknownst to the artist. This happened in the following situtation:

- Artist edits an uncompressed blend file.
- Some script saves a compressed blendfile to a separate location.
- When the artist saves the file (s)he is editing (File>Save, or Ctrl+S),
  it was silently compressed.

===================================================================

M	source/blender/windowmanager/intern/wm_files.c

===================================================================

diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index a52b97254be..1195348ed0d 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -2166,7 +2166,7 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
 {
 	Main *bmain = CTX_data_main(C);
 	char path[FILE_MAX];
-	int fileflags;
+	int fileflags, orig_fileflags;
 
 	save_set_compress(op);
 
@@ -2178,6 +2178,7 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
 		wm_filepath_default(path);
 	}
 
+	orig_fileflags = G.fileflags;
 	fileflags = G.fileflags & ~G_FILE_USERPREFS;
 
 	/* set compression flag */
@@ -2193,8 +2194,18 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
 	         RNA_boolean_get(op->ptr, "copy")),
 	        G_FILE_SAVE_COPY);
 
-	if (wm_file_write(C, path, fileflags, op->reports) != 0)
+	int write_result = wm_file_write(C, path, fileflags, op->reports);
+
+	if ((op->flag & OP_IS_INVOKE) == 0) {
+		/* OP_IS_INVOKE is set when the operator is called from the GUI.
+		 * If it is not set, the operator is called from a script and
+		 * shouldn't influence G.fileflags. */
+		G.fileflags = orig_fileflags;
+	}
+
+	if (write_result != 0) {
 		return OPERATOR_CANCELLED;
+	}
 
 	WM_event_add_notifier(C, NC_WM | ND_FILESAVE, NULL);



More information about the Bf-blender-cvs mailing list