UI: Warning When Dragging Non-Blend File Onto Executable

Dragging a non-Blend file onto the Blender executable currently
silently fails with Blender just aborting. With this PR any files used
as file argument will load Blender and show a warning if the file does
not exist or is not a blend file. Blend files that cannot be read are
treated as they are now.

Pull Request: https://projects.blender.org/blender/blender/pulls/139128
This commit is contained in:
Harley Acheson
2025-08-18 02:18:39 +02:00
committed by Harley Acheson
parent 98869c514a
commit 35d84e3336
4 changed files with 37 additions and 4 deletions

View File

@@ -814,6 +814,8 @@ void wm_event_do_notifiers(bContext *C)
wm_test_autorun_warning(C);
/* Deprecation warning. */
wm_test_gpu_backend_fallback(C);
/* Foreign File warning. */
wm_test_foreign_file_warning(C);
GPU_render_end();
}

View File

@@ -4287,6 +4287,35 @@ void wm_test_autorun_warning(bContext *C)
}
}
void wm_test_foreign_file_warning(bContext *C)
{
if (!G_MAIN->is_read_invalid) {
return;
}
G_MAIN->is_read_invalid = false;
wmWindowManager *wm = CTX_wm_manager(C);
wmWindow *win = (wm->winactive) ? wm->winactive : static_cast<wmWindow *>(wm->windows.first);
if (win) {
/* We want this warning on the Main window, not a child window even if active. See #118765. */
if (win->parent) {
win = win->parent;
}
wmWindow *prevwin = CTX_wm_window(C);
CTX_wm_window_set(C, win);
UI_alert(C,
RPT_("Unable to Load File"),
RPT_("The file specified is not a valid Blend document."),
ALERT_ICON_ERROR,
false);
CTX_wm_window_set(C, prevwin);
}
}
/** \} */
/* -------------------------------------------------------------------- */

View File

@@ -143,3 +143,4 @@ wmOperatorStatus wm_window_new_main_exec(bContext *C, wmOperator *op);
void wm_test_autorun_revert_action_set(wmOperatorType *ot, PointerRNA *ptr);
void wm_test_autorun_warning(bContext *C);
void wm_test_foreign_file_warning(bContext *C);

View File

@@ -2674,16 +2674,17 @@ static bool handle_load_file(bContext *C, const char *filepath_arg, const bool l
if (load_empty_file == false) {
error_msg = error_msg_generic;
}
else if (BLI_exists(filepath)) {
else if (BLI_exists(filepath) && BKE_blendfile_extension_check(filepath)) {
/* When a file is found but can't be loaded, handling it as a new file
* could cause it to be unintentionally overwritten (data loss).
* Further this is almost certainly not that a user would expect or want.
* If they do, they can delete the file beforehand. */
error_msg = error_msg_generic;
}
else if (!BKE_blendfile_extension_check(filepath)) {
/* Unrelated arguments should not be treated as new blend files. */
error_msg = "argument has no '.blend' file extension, not using as new file";
else {
/* Non-blend or non-existing. Continue loading and give warning. */
G_MAIN->is_read_invalid = true;
return true;
}
if (error_msg) {