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.
This commit is contained in:
Sybren A. Stüvel
2018-10-12 10:24:07 +02:00
parent 5eeb6c00be
commit cd3b313d5f
+13 -2
View File
@@ -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);