Fix #137314: Excluded directories ignored when opening from the splash
Regression in [0] which incorrectly swapped the check for the
`use_scripts` property being set with the value it was set to.
Resolve this error as well as the "Recover Last" operator
which never worked.
[0]: 8c688a052c
Pack ported from: dbf6902a19b6979f8be7b314fec33db17801ed73
Pull Request: https://projects.blender.org/blender/blender/pulls/137464
This commit is contained in:
committed by
Thomas Dinges
parent
8cacf61568
commit
eb03c5a2f1
@@ -421,9 +421,20 @@ void WM_window_decoration_style_apply(const wmWindow *win, const bScreen *screen
|
||||
/* `wm_files.cc`. */
|
||||
|
||||
void WM_file_autoexec_init(const char *filepath);
|
||||
bool WM_file_read(bContext *C, const char *filepath, ReportList *reports);
|
||||
/**
|
||||
* \param use_scripts_autoexec_check: When true, script auto-execution checks excluded directories.
|
||||
* Note that this is passed in as an argument because `filepath` may reference a path to recover.
|
||||
* In this case the that used for exclusion is the recovery path which is only known once
|
||||
* the file has been loaded.
|
||||
*/
|
||||
bool WM_file_read(bContext *C,
|
||||
const char *filepath,
|
||||
const bool use_scripts_autoexec_check,
|
||||
ReportList *reports);
|
||||
void WM_file_autosave_init(wmWindowManager *wm);
|
||||
bool WM_file_recover_last_session(bContext *C, ReportList *reports);
|
||||
bool WM_file_recover_last_session(bContext *C,
|
||||
const bool use_scripts_autoexec_check,
|
||||
ReportList *reports);
|
||||
void WM_file_tag_modified();
|
||||
|
||||
/**
|
||||
|
||||
@@ -1041,7 +1041,10 @@ static void file_read_reports_finalize(BlendFileReadReport *bf_reports)
|
||||
bf_reports->resynced_lib_overrides_libraries = nullptr;
|
||||
}
|
||||
|
||||
bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
|
||||
bool WM_file_read(bContext *C,
|
||||
const char *filepath,
|
||||
const bool use_scripts_autoexec_check,
|
||||
ReportList *reports)
|
||||
{
|
||||
/* Assume automated tasks with background, don't write recent file list. */
|
||||
const bool do_history_file_update = (G.background == false) &&
|
||||
@@ -1108,6 +1111,14 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
|
||||
G.f = (G.f & ~flags_keep) | (G_f_orig & flags_keep);
|
||||
}
|
||||
|
||||
/* Set by the `use_scripts` property on file load.
|
||||
* If this was not set, then it should be calculated based on the file-path.
|
||||
* Note that this uses `bmain->filepath` and not `filepath`, necessary when
|
||||
* recovering the last session, where the file-path can be #BLENDER_QUIT_FILE. */
|
||||
if (use_scripts_autoexec_check) {
|
||||
WM_file_autoexec_init(bmain->filepath);
|
||||
}
|
||||
|
||||
WM_check(C); /* Opens window(s), checks keymaps. */
|
||||
|
||||
if (do_history_file_update) {
|
||||
@@ -2463,9 +2474,10 @@ void wm_open_init_load_ui(wmOperator *op, bool use_prefs)
|
||||
}
|
||||
}
|
||||
|
||||
void wm_open_init_use_scripts(wmOperator *op, bool use_prefs)
|
||||
bool wm_open_init_use_scripts(wmOperator *op, bool use_prefs)
|
||||
{
|
||||
PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_scripts");
|
||||
bool use_scripts_autoexec_check = false;
|
||||
if (!RNA_property_is_set(op->ptr, prop)) {
|
||||
/* Use #G_FLAG_SCRIPT_AUTOEXEC rather than the userpref because this means if
|
||||
* the flag has been disabled from the command line, then opening
|
||||
@@ -2474,7 +2486,9 @@ void wm_open_init_use_scripts(wmOperator *op, bool use_prefs)
|
||||
((G.f & G_FLAG_SCRIPT_AUTOEXEC) != 0);
|
||||
|
||||
RNA_property_boolean_set(op->ptr, prop, value);
|
||||
use_scripts_autoexec_check = true;
|
||||
}
|
||||
return use_scripts_autoexec_check;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
@@ -3061,18 +3075,16 @@ void WM_OT_read_factory_settings(wmOperatorType *ot)
|
||||
/**
|
||||
* Wrap #WM_file_read, shared by file reading operators.
|
||||
*/
|
||||
static bool wm_file_read_opwrap(bContext *C, const char *filepath, ReportList *reports)
|
||||
static bool wm_file_read_opwrap(bContext *C,
|
||||
const char *filepath,
|
||||
const bool use_scripts_autoexec_check,
|
||||
ReportList *reports)
|
||||
{
|
||||
/* XXX: wm in context is not set correctly after #WM_file_read -> crash. */
|
||||
/* Do it before for now, but is this correct with multiple windows? */
|
||||
WM_event_add_notifier(C, NC_WINDOW, nullptr);
|
||||
|
||||
/* Set by the "use_scripts" property on file load. */
|
||||
if ((G.f & G_FLAG_SCRIPT_AUTOEXEC) == 0) {
|
||||
WM_file_autoexec_init(filepath);
|
||||
}
|
||||
|
||||
const bool success = WM_file_read(C, filepath, reports);
|
||||
const bool success = WM_file_read(C, filepath, use_scripts_autoexec_check, reports);
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -3173,7 +3185,8 @@ static int wm_open_mainfile__select_file_path(bContext *C, wmOperator *op)
|
||||
|
||||
RNA_string_set(op->ptr, "filepath", blendfile_path);
|
||||
wm_open_init_load_ui(op, true);
|
||||
wm_open_init_use_scripts(op, true);
|
||||
const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, true);
|
||||
UNUSED_VARS(use_scripts_autoexec_check); /* The user can set this in the UI. */
|
||||
op->customdata = nullptr;
|
||||
|
||||
WM_event_add_fileselect(C, op);
|
||||
@@ -3194,11 +3207,11 @@ static int wm_open_mainfile__open(bContext *C, wmOperator *op)
|
||||
|
||||
/* Re-use last loaded setting so we can reload a file without changing. */
|
||||
wm_open_init_load_ui(op, false);
|
||||
wm_open_init_use_scripts(op, false);
|
||||
const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, false);
|
||||
|
||||
SET_FLAG_FROM_TEST(G.fileflags, !RNA_boolean_get(op->ptr, "load_ui"), G_FILE_NO_UI);
|
||||
SET_FLAG_FROM_TEST(G.f, RNA_boolean_get(op->ptr, "use_scripts"), G_FLAG_SCRIPT_AUTOEXEC);
|
||||
success = wm_file_read_opwrap(C, filepath, op->reports);
|
||||
success = wm_file_read_opwrap(C, filepath, use_scripts_autoexec_check, op->reports);
|
||||
|
||||
if (success) {
|
||||
if (G.fileflags & G_FILE_NO_UI) {
|
||||
@@ -3400,12 +3413,12 @@ static int wm_revert_mainfile_exec(bContext *C, wmOperator *op)
|
||||
bool success;
|
||||
char filepath[FILE_MAX];
|
||||
|
||||
wm_open_init_use_scripts(op, false);
|
||||
const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, false);
|
||||
|
||||
SET_FLAG_FROM_TEST(G.f, RNA_boolean_get(op->ptr, "use_scripts"), G_FLAG_SCRIPT_AUTOEXEC);
|
||||
|
||||
STRNCPY(filepath, BKE_main_blendfile_path(bmain));
|
||||
success = wm_file_read_opwrap(C, filepath, op->reports);
|
||||
success = wm_file_read_opwrap(C, filepath, use_scripts_autoexec_check, op->reports);
|
||||
|
||||
if (success) {
|
||||
return OPERATOR_FINISHED;
|
||||
@@ -3438,21 +3451,24 @@ void WM_OT_revert_mainfile(wmOperatorType *ot)
|
||||
/** \name Recover Last Session Operator
|
||||
* \{ */
|
||||
|
||||
bool WM_file_recover_last_session(bContext *C, ReportList *reports)
|
||||
bool WM_file_recover_last_session(bContext *C,
|
||||
const bool use_scripts_autoexec_check,
|
||||
ReportList *reports)
|
||||
{
|
||||
char filepath[FILE_MAX];
|
||||
BLI_path_join(filepath, sizeof(filepath), BKE_tempdir_base(), BLENDER_QUIT_FILE);
|
||||
G.fileflags |= G_FILE_RECOVER_READ;
|
||||
const bool success = wm_file_read_opwrap(C, filepath, reports);
|
||||
const bool success = wm_file_read_opwrap(C, filepath, use_scripts_autoexec_check, reports);
|
||||
G.fileflags &= ~G_FILE_RECOVER_READ;
|
||||
return success;
|
||||
}
|
||||
|
||||
static int wm_recover_last_session_exec(bContext *C, wmOperator *op)
|
||||
static int wm_recover_last_session_impl(bContext *C,
|
||||
wmOperator *op,
|
||||
const bool use_scripts_autoexec_check)
|
||||
{
|
||||
wm_open_init_use_scripts(op, true);
|
||||
SET_FLAG_FROM_TEST(G.f, RNA_boolean_get(op->ptr, "use_scripts"), G_FLAG_SCRIPT_AUTOEXEC);
|
||||
if (WM_file_recover_last_session(C, op->reports)) {
|
||||
if (WM_file_recover_last_session(C, use_scripts_autoexec_check, op->reports)) {
|
||||
if (!G.background) {
|
||||
wmOperatorType *ot = op->type;
|
||||
PointerRNA *props_ptr = MEM_new<PointerRNA>(__func__);
|
||||
@@ -3465,6 +3481,12 @@ static int wm_recover_last_session_exec(bContext *C, wmOperator *op)
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
static int wm_recover_last_session_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, true);
|
||||
return wm_recover_last_session_impl(C, op, use_scripts_autoexec_check);
|
||||
}
|
||||
|
||||
static void wm_recover_last_session_after_dialog_callback(bContext *C, void *user_data)
|
||||
{
|
||||
WM_operator_name_call_with_properties(
|
||||
@@ -3475,14 +3497,14 @@ static int wm_recover_last_session_invoke(bContext *C, wmOperator *op, const wmE
|
||||
{
|
||||
/* Keep the current setting instead of using the preferences since a file selector
|
||||
* doesn't give us the option to change the setting. */
|
||||
wm_open_init_use_scripts(op, false);
|
||||
const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, false);
|
||||
|
||||
if (wm_operator_close_file_dialog_if_needed(
|
||||
C, op, wm_recover_last_session_after_dialog_callback))
|
||||
{
|
||||
return OPERATOR_INTERFACE;
|
||||
}
|
||||
return wm_recover_last_session_exec(C, op);
|
||||
return wm_recover_last_session_impl(C, op, use_scripts_autoexec_check);
|
||||
}
|
||||
|
||||
void WM_OT_recover_last_session(wmOperatorType *ot)
|
||||
@@ -3511,12 +3533,12 @@ static int wm_recover_auto_save_exec(bContext *C, wmOperator *op)
|
||||
RNA_string_get(op->ptr, "filepath", filepath);
|
||||
BLI_path_canonicalize_native(filepath, sizeof(filepath));
|
||||
|
||||
wm_open_init_use_scripts(op, true);
|
||||
const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, true);
|
||||
SET_FLAG_FROM_TEST(G.f, RNA_boolean_get(op->ptr, "use_scripts"), G_FLAG_SCRIPT_AUTOEXEC);
|
||||
|
||||
G.fileflags |= G_FILE_RECOVER_READ;
|
||||
|
||||
success = wm_file_read_opwrap(C, filepath, op->reports);
|
||||
success = wm_file_read_opwrap(C, filepath, use_scripts_autoexec_check, op->reports);
|
||||
|
||||
G.fileflags &= ~G_FILE_RECOVER_READ;
|
||||
|
||||
@@ -3539,7 +3561,8 @@ static int wm_recover_auto_save_invoke(bContext *C, wmOperator *op, const wmEven
|
||||
|
||||
wm_autosave_location(filepath);
|
||||
RNA_string_set(op->ptr, "filepath", filepath);
|
||||
wm_open_init_use_scripts(op, true);
|
||||
const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, true);
|
||||
UNUSED_VARS(use_scripts_autoexec_check); /* The user can set this in the UI. */
|
||||
WM_event_add_fileselect(C, op);
|
||||
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BLI_compiler_attrs.h"
|
||||
|
||||
struct wmOperator;
|
||||
struct wmTimer;
|
||||
struct wmWindow;
|
||||
@@ -119,4 +121,7 @@ void wm_stereo3d_set_cancel(bContext *C, wmOperator *op);
|
||||
* Initialize operator properties.
|
||||
*/
|
||||
void wm_open_init_load_ui(wmOperator *op, bool use_prefs);
|
||||
void wm_open_init_use_scripts(wmOperator *op, bool use_prefs);
|
||||
/**
|
||||
* Return true if the script auto-execution should be cleared based on #WM_file_autoexec_init.
|
||||
*/
|
||||
bool wm_open_init_use_scripts(wmOperator *op, bool use_prefs) ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
@@ -2523,8 +2523,11 @@ static bool handle_load_file(bContext *C, const char *filepath_arg, const bool l
|
||||
/* Load the file. */
|
||||
ReportList reports;
|
||||
BKE_reports_init(&reports, RPT_PRINT);
|
||||
WM_file_autoexec_init(filepath);
|
||||
const bool success = WM_file_read(C, filepath, &reports);
|
||||
/* When activating from the command line there isn't an exact equivalent to operator properties.
|
||||
* Instead, enabling auto-execution via `--enable-autoexec` causes the auto-execution
|
||||
* check to be skipped (if it's set), so it's fine to always enable the check here. */
|
||||
const bool use_scripts_autoexec_check = true;
|
||||
const bool success = WM_file_read(C, filepath, use_scripts_autoexec_check, &reports);
|
||||
BKE_reports_free(&reports);
|
||||
|
||||
if (success) {
|
||||
|
||||
Reference in New Issue
Block a user