From 35d84e3336b183243f8b8a269a1047c4e77363eb Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Mon, 18 Aug 2025 02:18:39 +0200 Subject: [PATCH] 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 --- .../windowmanager/intern/wm_event_system.cc | 2 ++ .../blender/windowmanager/intern/wm_files.cc | 29 +++++++++++++++++++ source/blender/windowmanager/wm_window.hh | 1 + source/creator/creator_args.cc | 9 +++--- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc index 84f8bb8e505..6c823f592d2 100644 --- a/source/blender/windowmanager/intern/wm_event_system.cc +++ b/source/blender/windowmanager/intern/wm_event_system.cc @@ -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(); } diff --git a/source/blender/windowmanager/intern/wm_files.cc b/source/blender/windowmanager/intern/wm_files.cc index deacb553d4f..b589e96733d 100644 --- a/source/blender/windowmanager/intern/wm_files.cc +++ b/source/blender/windowmanager/intern/wm_files.cc @@ -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(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); + } +} + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/windowmanager/wm_window.hh b/source/blender/windowmanager/wm_window.hh index 25a319768c0..b86f4c13c5f 100644 --- a/source/blender/windowmanager/wm_window.hh +++ b/source/blender/windowmanager/wm_window.hh @@ -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); diff --git a/source/creator/creator_args.cc b/source/creator/creator_args.cc index e883dfcec57..95d31114925 100644 --- a/source/creator/creator_args.cc +++ b/source/creator/creator_args.cc @@ -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) {