[Bf-blender-cvs] [d55d95b04da] blender-v2.92-release: WM: return success from WM_recover_last_session, minor cleanup

Campbell Barton noreply at git.blender.org
Tue Jan 26 05:16:59 CET 2021


Commit: d55d95b04da42f120406678fc47deb00081f7285
Author: Campbell Barton
Date:   Tue Jan 26 15:08:28 2021 +1100
Branches: blender-v2.92-release
https://developer.blender.org/rBd55d95b04da42f120406678fc47deb00081f7285

WM: return success from WM_recover_last_session, minor cleanup

- Return success from WM_recover_last_session
- Avoid setting global variables is already called in WM_file_read.
  While it didn't cause any problems, these assignments ran even when
  recovering the session failed to load the file.
- Return OPERATOR_CANCELLED when the operator fails.

Returning success is needed to fix T85011.

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

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

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

diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 1f205a71338..540896664da 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -188,7 +188,7 @@ bool WM_stereo3d_enabled(struct wmWindow *win, bool only_fullscreen_test);
 void WM_file_autoexec_init(const char *filepath);
 bool WM_file_read(struct bContext *C, const char *filepath, struct ReportList *reports);
 void WM_autosave_init(struct wmWindowManager *wm);
-void WM_recover_last_session(struct bContext *C, struct ReportList *reports);
+bool WM_recover_last_session(struct bContext *C, struct ReportList *reports);
 void WM_file_tag_modified(void);
 
 struct ID *WM_file_append_datablock(struct Main *bmain,
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index d179cc456f4..bfc3d7e1a5f 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -2549,35 +2549,22 @@ void WM_OT_revert_mainfile(wmOperatorType *ot)
 /** \name Recover Last Session Operator
  * \{ */
 
-void WM_recover_last_session(bContext *C, ReportList *reports)
+bool WM_recover_last_session(bContext *C, ReportList *reports)
 {
   char filepath[FILE_MAX];
-
   BLI_join_dirfile(filepath, sizeof(filepath), BKE_tempdir_base(), BLENDER_QUIT_FILE);
-  /* if reports==NULL, it's called directly without operator, we add a quick check here */
-  if (reports || BLI_exists(filepath)) {
-    G.fileflags |= G_FILE_RECOVER;
-
-    wm_file_read_opwrap(C, filepath, reports, true);
-
-    G.fileflags &= ~G_FILE_RECOVER;
-
-    /* XXX bad global... fixme */
-    Main *bmain = CTX_data_main(C);
-    if (BKE_main_blendfile_path(bmain)[0] != '\0') {
-      G.file_loaded = 1; /* prevents splash to show */
-    }
-    else {
-      G.relbase_valid = 0;
-      G.save_over = 0; /* start with save preference untitled.blend */
-    }
-  }
+  G.fileflags |= G_FILE_RECOVER;
+  const bool success = wm_file_read_opwrap(C, filepath, reports, true);
+  G.fileflags &= ~G_FILE_RECOVER;
+  return success;
 }
 
 static int wm_recover_last_session_exec(bContext *C, wmOperator *op)
 {
-  WM_recover_last_session(C, op->reports);
-  return OPERATOR_FINISHED;
+  if (WM_recover_last_session(C, op->reports)) {
+    return OPERATOR_FINISHED;
+  }
+  return OPERATOR_CANCELLED;
 }
 
 void WM_OT_recover_last_session(wmOperatorType *ot)



More information about the Bf-blender-cvs mailing list