Blender V5.3
wm_files.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11
12/* Placed up here because of crappy WINSOCK stuff. */
13#include <cerrno>
14#include <cstddef>
15#include <cstring>
16#include <fcntl.h> /* For open flags (#O_BINARY, #O_RDONLY). */
17
18#ifdef WIN32
19/* Need to include windows.h so _WIN32_IE is defined. */
20# include <windows.h>
21# ifndef _WIN32_IE
22/* Minimal requirements for SHGetSpecialFolderPath on MINGW MSVC has this defined already. */
23# define _WIN32_IE 0x0400
24# endif
25/* For #SHGetSpecialFolderPath, has to be done before `BLI_winstuff.hh`
26 * because 'near' is disabled through `BLI_windstuff.h`. */
27# include "BLI_winstuff.hh"
28# include <shlobj.h>
29#endif
30
31#include <fmt/format.h>
32
34#include "MEM_guardedalloc.h"
35
36#include "BLI_fileops.hh"
37#include "BLI_filereader.hh"
38#include "BLI_linklist.hh"
39#include "BLI_listbase.hh"
40#include "BLI_math_base_c.hh"
41#include "BLI_math_time.hh"
42#include "BLI_memory_cache.hh"
43#include "BLI_path_utils.hh"
44#include "BLI_string.hh"
45#include "BLI_string_utf8.hh"
46#include "BLI_system.hh"
47#include "BLI_threads.hh"
48#include "BLI_time.hh"
49#include "BLI_timer.hh"
50#include "BLI_utildefines.hh"
51#include BLI_SYSTEM_PID_H
52
55#include "BLO_readfile.hh"
56
57#include "BLT_date_string.hh"
58#include "BLT_lang.hh"
59#include "BLT_translation.hh"
60
61#include "BLF_api.hh"
62
63#include "DNA_scene_types.h"
64#include "DNA_screen_types.h"
65#include "DNA_space_types.h"
66#include "DNA_userdef_types.h"
68#include "DNA_workspace_types.h"
69
70#include "AS_asset_library.hh"
71
72#ifndef WITH_CYCLES
73# include "BKE_addon.h"
74#endif
75#include "BKE_appdir.hh"
76#include "BKE_autoexec.hh"
77#include "BKE_blender.hh"
79#include "BKE_blender_version.h"
80#include "BKE_blendfile.hh"
81#include "BKE_callbacks.hh"
82#include "BKE_context.hh"
83#include "BKE_global.hh"
84#include "BKE_idprop.hh"
85#include "BKE_lib_id.hh"
86#include "BKE_lib_override.hh"
87#include "BKE_lib_remap.hh"
88#include "BKE_library.hh"
89#include "BKE_main.hh"
90#include "BKE_main_namemap.hh"
91#include "BKE_node.hh"
93#include "BKE_packedFile.hh"
94#include "BKE_report.hh"
95#include "BKE_scene.hh"
96#include "BKE_screen.hh"
97#include "BKE_sound.hh"
98#include "BKE_undo_system.hh"
99#include "BKE_workspace.hh"
100
101#include "BLO_writefile.hh"
102
103#include "RNA_access.hh"
104#include "RNA_define.hh"
105
106#include "IMB_colormanagement.hh"
107#include "IMB_imbuf.hh"
108#include "IMB_imbuf_types.hh"
109#include "IMB_metadata.hh"
110#include "IMB_thumbs.hh"
111
112#include "ED_asset.hh"
113#include "ED_datafiles.h"
114#include "ED_fileselect.hh"
115#include "ED_image.hh"
116#include "ED_outliner.hh"
117#include "ED_render.hh"
118#include "ED_screen.hh"
119#include "ED_undo.hh"
120#include "ED_util.hh"
121#include "ED_view3d.hh"
122#include "ED_view3d_offscreen.hh"
123
124#include "NOD_composite.hh"
125
126#include "GHOST_ISystemPaths.hh"
127#include "GHOST_IWindow.hh"
128
129#include "GPU_context.hh"
130
131#include "SEQ_sequencer.hh"
132
133#include "UI_interface.hh"
134#include "UI_interface_layout.hh"
135#include "UI_resources.hh"
136#include "UI_view2d.hh"
137
138/* Only to report a missing engine. */
139#include "RE_engine.h"
140
141#ifdef WITH_PYTHON
142# include "BPY_extern_python.hh"
143# include "BPY_extern_run.hh"
144#endif
145
146#include "DEG_depsgraph.hh"
147
148#include "WM_api.hh"
149#include "WM_keymap.hh"
150#include "WM_message.hh"
151#include "WM_toolsystem.hh"
152#include "WM_types.hh"
153
154#include "wm.hh"
155#include "wm_event_system.hh"
156#include "wm_files.hh"
157#include "wm_window.hh"
158
159#include "CLG_log.h"
160
161namespace blender {
162
163static RecentFile *wm_file_history_find(const char *filepath);
164static void wm_history_file_free(RecentFile *recent);
165static void wm_history_files_free();
166static void wm_history_file_update();
167static void wm_history_file_write();
168
170
171static CLG_LogRef LOG = {"blend"};
172
182#define USE_THUMBNAIL_FAST_DOWNSCALE
183
184/* -------------------------------------------------------------------- */
187
189{
190 wmWindowManager *wm = G_MAIN->wm.first();
191 if (wm->file_saved) {
192 wm->file_saved = 0;
193 /* Notifier that data changed, for save-over warning or header. */
195 }
196}
197
203
205
206/* -------------------------------------------------------------------- */
209
217
224 Main *bmain,
225 const bool is_read_homefile)
226{
227 BLI_assert(BLI_listbase_count_at_most(&bmain->wm, 2) <= 1);
228 wmWindowManager *wm = bmain->wm.first();
230 wm_setup_data->is_read_homefile = is_read_homefile;
231 /* This info is not always known yet when this function is called. */
232 wm_setup_data->is_factory_startup = false;
233
234 if (wm == nullptr) {
235 return wm_setup_data;
236 }
237
238 /* First wrap up running stuff.
239 *
240 * Code copied from `wm_init_exit.cc`. */
242
243 wmWindow *active_win = CTX_wm_window(C);
244 for (wmWindow &win : wm->windows) {
245 CTX_wm_window_set(C, &win); /* Needed by operator close callbacks. */
249 }
250 /* Reset active window. */
251 CTX_wm_window_set(C, active_win);
252
253 /* NOTE(@ideasman42): Clear the message bus so it's always cleared on file load.
254 * Otherwise it's cleared when "Load UI" is set (see #USER_FILENOUI and #wm_close_and_free).
255 * However it's _not_ cleared when the UI is kept. This complicates use from add-ons
256 * which can re-register subscribers on file-load. To support this use case,
257 * it's best to have predictable behavior - always clear. */
258 if (wm->runtime->message_bus != nullptr) {
259 WM_msgbus_destroy(wm->runtime->message_bus);
260 wm->runtime->message_bus = nullptr;
261 }
262
263 /* XXX Hack! We have to clear context popup-region here, because removing all
264 * #wmWindow::modalhandlers above frees the active menu (at least, in the 'startup splash' case),
265 * causing use-after-free error in later handling of the button callbacks in UI code
266 * (see #ui_apply_but_funcs_after()).
267 * Tried solving this by always nullptr-ing context's menu when setting wm/win/etc.,
268 * but it broke popups refreshing (see #47632),
269 * so for now just handling this specific case here. */
270 CTX_wm_region_popup_set(C, nullptr);
271
272 ED_editors_exit(bmain, true);
273
274 /* Asset loading is done by the UI/editors and they keep pointers into it. So make sure to clear
275 * it after UI/editors. */
278
279 /* NOTE: `wm_setup_data->old_wm` cannot be set here, as this pointer may be swapped with the
280 * newly read one in `setup_app_data` process (See #swap_wm_data_for_blendfile). */
281
282 return wm_setup_data;
283}
284
287 wmWindow *oldwin,
288 wmWindow *win)
289{
290 win->runtime->ghostwin = oldwin->runtime->ghostwin;
291 win->runtime->gpuctx = oldwin->runtime->gpuctx;
292 win->active = oldwin->active;
293 if (win->active) {
294 wm->runtime->winactive = win;
295 }
296 if (oldwm->runtime->windrawable == oldwin) {
297 oldwm->runtime->windrawable = nullptr;
298 wm->runtime->windrawable = win;
299 }
300
301 /* File loading in background mode still calls this. */
302 if (!G.background) {
303 /* Pointer back. */
304 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
305 ghost_window->setUserData(win);
306 }
307
308 oldwin->runtime->ghostwin = nullptr;
309 oldwin->runtime->gpuctx = nullptr;
310
311 win->runtime->eventstate = oldwin->runtime->eventstate;
313 oldwin->runtime->eventstate = nullptr;
314 oldwin->runtime->event_last_handled = nullptr;
315
316 /* Ensure proper screen re-scaling. */
317 win->sizex = oldwin->sizex;
318 win->sizey = oldwin->sizey;
319 win->posx = oldwin->posx;
320 win->posy = oldwin->posy;
321}
322
333 Main *bmain,
334 BlendFileReadWMSetupData *wm_setup_data,
336 const bool load_ui)
337{
338 /* This data is not needed here, besides detecting that old WM has been kept (in caller code).
339 * Since `old_wm` is kept, do not free it, just clear the pointer as clean-up. */
340 wm_setup_data->old_wm = nullptr;
341
342 if (!load_ui) {
343 /* When loading without UI (i.e. keeping existing UI), no matching needed.
344 *
345 * The other UI data (workspaces, layouts, screens) has also been re-used from old Main, and
346 * newly read one from file has already been discarded in #setup_app_data. */
347 return;
348 }
349
350 /* Old WM is being reused, but other UI data (workspaces, layouts, screens) comes from the new
351 * file, so the WM needs to be updated to use these. */
352 bScreen *screen = CTX_wm_screen(C);
353 if (screen != nullptr) {
354 for (wmWindow &win : wm->windows) {
355 WorkSpace *workspace;
356
357 WorkSpaceLayout *layout_ref = BKE_workspace_layout_find_global(bmain, screen, &workspace);
359 win.scene = CTX_data_scene(C);
360
361 /* All windows get active screen from file. */
362 if (screen->winid == 0) {
363 WM_window_set_active_screen(&win, workspace, screen);
364 }
365 else {
366#if 0
367 /* NOTE(@ideasman42): The screen referenced from the window has been freed,
368 * see: #107525. */
370#endif
372 bmain, workspace, layout_ref, &win);
373
374 WM_window_set_active_layout(&win, workspace, layout_new);
375 }
376
377 bScreen *win_screen = WM_window_get_active_screen(&win);
378 win_screen->winid = win.winid;
379 }
380 }
381}
382
384 Main * /*bmain*/,
385 BlendFileReadWMSetupData *wm_setup_data,
387{
388 wmWindowManager *old_wm = wm_setup_data->old_wm;
389
390 wm->op_undo_depth = old_wm->op_undo_depth;
391
392 /* Move existing key configurations into the new WM. */
393 wm->runtime->keyconfigs = old_wm->runtime->keyconfigs;
394 wm->runtime->addonconf = old_wm->runtime->addonconf;
395 wm->runtime->defaultconf = old_wm->runtime->defaultconf;
396 wm->runtime->userconf = old_wm->runtime->userconf;
397
398 old_wm->runtime->keyconfigs.clear_no_delete();
399 old_wm->runtime->addonconf = nullptr;
400 old_wm->runtime->defaultconf = nullptr;
401 old_wm->runtime->userconf = nullptr;
402
403 /* Ensure new keymaps are made, and space types are set. */
404 wm->init_flag = eWM_InitFlag{};
405 wm->runtime->winactive = nullptr;
406
407 /* Clearing drawable of old WM before deleting any context to avoid clearing the wrong wm. */
409
410 bool has_match = false;
411 for (wmWindow &win : wm->windows) {
412 for (wmWindow &old_win : old_wm->windows) {
413 if (old_win.winid == win.winid) {
414 has_match = true;
415
416 wm_file_read_setup_wm_substitute_old_window(old_wm, wm, &old_win, &win);
417 }
418 }
419 }
420 /* Ensure that at least one window is kept open so we don't lose the context, see #42303. */
421 if (!has_match) {
423 old_wm, wm, old_wm->windows.first(), wm->windows.first());
424 }
425
426 wm_setup_data->old_wm = nullptr;
427 wm_close_and_free(C, old_wm);
428 /* Don't handle user counts as this is only ever called once #G_MAIN has already been freed via
429 * #BKE_main_free so any access to ID's referenced by the window-manager (from ID properties)
430 * will crash. See: #100703. */
431 BKE_libblock_free_data(&old_wm->id, false);
433 MEM_delete(old_wm);
434
435 wmWindow *win = wm->runtime->winactive ? wm->runtime->winactive : wm->windows.first();
437}
438
446 Main *bmain,
447 BlendFileReadWMSetupData *wm_setup_data)
448{
449 BLI_assert(BLI_listbase_count_at_most(&bmain->wm, 2) <= 1);
450 BLI_assert(wm_setup_data != nullptr);
451 wmWindowManager *wm = bmain->wm.first();
452
453 /* If reading factory startup file, and there was no previous WM, clear the size of the windows
454 * in newly read WM so that they get resized to occupy the whole available space on current
455 * monitor.
456 */
457 if (wm_setup_data->is_read_homefile && wm_setup_data->is_factory_startup &&
458 wm_setup_data->old_wm == nullptr)
459 {
461 }
462
463 if (wm == nullptr) {
464 /* Add a default WM in case none exists in newly read main (should only happen when opening
465 * an old pre-2.5 .blend file at startup). */
466 wm_add_default(bmain, C);
467 }
468 else if (wm_setup_data->old_wm != nullptr) {
469 if (wm_setup_data->old_wm == wm) {
470 /* Old WM was kept, update it with new workspaces/layouts/screens read from file.
471 *
472 * Happens when not loading UI, or when the newly read file has no WM (pre-2.5 files). */
474 C, bmain, wm_setup_data, wm, (G.fileflags & G_FILE_NO_UI) == 0);
475 }
476 else {
477 /* Using new WM from read file, try to keep current GHOST windows, transfer keymaps, etc.,
478 * from old WM.
479 *
480 * Also takes care of clearing old WM data (temporarily stored in `wm_setup_data->old_wm`).
481 */
482 wm_file_read_setup_wm_use_new(C, bmain, wm_setup_data, wm);
483 }
484 }
485 /* Else just using the new WM read from file, nothing to do. */
486 BLI_assert(wm_setup_data->old_wm == nullptr);
487 MEM_delete(wm_setup_data);
488
489 /* UI Updates. */
490 /* Flag local View3D's to check and exit if they are empty. */
491 for (bScreen &screen : bmain->screens) {
492 for (ScrArea &area : screen.areabase) {
493 for (SpaceLink &sl : area.spacedata) {
494 if (sl.spacetype == SPACE_VIEW3D) {
495 View3D *v3d = reinterpret_cast<View3D *>(&sl);
496 if (v3d->localvd) {
498 }
499 }
500 }
501 }
502 }
503}
504
506
507/* -------------------------------------------------------------------- */
510
512{
513 /* Check if GPU backend is already set from the command line arguments. The command line
514 * arguments have higher priority than user preferences. */
516 return;
517 }
518
520}
521
525static void wm_init_userdef(Main *bmain)
526{
527 /* Not versioning, just avoid errors. */
528#ifndef WITH_CYCLES
529 BKE_addon_remove_safe(&U.addons, "cycles");
530#endif
531
533
534 /* Needed so loading a file from the command line respects user-pref #26156. */
535 SET_FLAG_FROM_TEST(G.fileflags, U.flag & USER_FILENOUI, G_FILE_NO_UI);
536
538 G.autoexec_override.value_or((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0),
540
541 /* Only reset "offline mode" if they weren't passes via command line arguments. */
542 if ((G.f & G_FLAG_INTERNET_OVERRIDE_PREF_ANY) == 0) {
544 }
545
546 const int64_t cache_limit = int64_t(U.memcachelimit) * 1024 * 1024;
547 MEM_CacheLimiter_set_maximum(cache_limit);
549
550 BKE_sound_init(bmain);
551
552 /* Update the temporary directory from the preferences or fall back to the system default. */
553 BKE_tempdir_init(U.tempdir);
554
555 /* Update input device preference. */
557
558#ifdef WITH_GHOST_CSD
560#endif
561
563
565}
566
567/* Return codes. */
568#define BKE_READ_EXOTIC_FAIL_PATH -3 /* File format is not supported. */
569#define BKE_READ_EXOTIC_FAIL_FORMAT -2 /* File format is not supported. */
570#define BKE_READ_EXOTIC_FAIL_OPEN -1 /* Can't open the file. */
571#define BKE_READ_EXOTIC_OK_BLEND 0 /* `.blend` file. */
572#if 0
573# define BKE_READ_EXOTIC_OK_OTHER 1 /* Other supported formats. */
574#endif
575
577
578/* -------------------------------------------------------------------- */
584
585/* Intended to check for non-blender formats but for now it only reads blends. */
586static int wm_read_exotic(const char *filepath)
587{
588 /* Make sure we're not trying to read a directory. */
589
590 int filepath_len = strlen(filepath);
591 if (filepath_len > 0 && ELEM(filepath[filepath_len - 1], '/', '\\')) {
593 }
594
595 /* Open the file. */
596 const int filedes = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
597 if (filedes == -1) {
599 }
601 if (!file) {
603 }
604 BLI_SCOPED_DEFER([&]() { file->close(file); });
605 const BlenderHeaderVariant header_variant = BLO_readfile_blender_header_decode(file);
606 if (std::holds_alternative<BlenderHeader>(header_variant)) {
608 }
610}
611
613
614/* -------------------------------------------------------------------- */
617
618void WM_file_autoexec_init(const char *filepath)
619{
620 if (G.autoexec_override.has_value()) {
621 return;
622 }
623 if (G.f & G_FLAG_SCRIPT_AUTOEXEC) {
624 /* Recovering a session that was never saved has no path to check. */
625 if ((filepath[0] != '\0') && BKE_autoexec_match(filepath, false, true)) {
627 }
628 }
629}
630
632{
633 wmWindowManager *wm = bmain->wm.first();
634 ReportList *reports = &wm->runtime->reports;
635 bool found = false;
636 for (Scene &scene : bmain->scenes) {
637 if (scene.r.engine[0] &&
638 BLI_findstring(&R_engines, scene.r.engine, offsetof(RenderEngineType, idname)) == nullptr)
639 {
640 BKE_reportf(reports,
641 RPT_ERROR,
642 "Engine '%s' not available for scene '%s' (an add-on may need to be installed "
643 "or enabled)",
644 scene.r.engine,
645 scene.id.name + 2);
646 found = true;
647 }
648 }
649
650 if (found) {
651 if (!G.background) {
653 }
654 }
655}
656
663static void wm_file_read_pre(bool use_data, bool /*use_userdef*/)
664{
665 if (use_data) {
667 }
668
669 /* Always do this as both startup and preferences may have loaded in many font's
670 * at a different zoom level to the file being loaded. */
672}
673
690
696 const char *filepath,
697 const wmFileReadPost_Params *params)
698{
700
701 const bool use_data = params->use_data;
702 const bool use_userdef = params->use_userdef;
703 const bool is_startup_file = params->is_startup_file;
704 const bool is_factory_startup = params->is_factory_startup;
705 const bool reset_app_template = params->reset_app_template;
706
707 bool addons_loaded = false;
708
709 if (use_data) {
710 if (!G.background) {
711 /* Remove windows which failed to be added via #WM_check. */
713 }
714 CTX_wm_window_set(C, wm->windows.first());
715 }
716
717#ifdef WITH_PYTHON
718 if (is_startup_file) {
719 /* The following block handles data & preferences being reloaded
720 * which requires resetting some internal variables. */
721 if (!params->is_first_time) {
723 bool reset_all = use_userdef;
724 if (use_userdef || reset_app_template) {
725 /* Only run when we have a template path found. */
727 const char *imports[] = {"bl_app_template_utils", nullptr};
728 BPY_run_string_eval(C, imports, "bl_app_template_utils.reset()");
729 reset_all = true;
730 }
731 }
732 if (reset_all) {
733 const char *imports[] = {"bpy", "addon_utils", nullptr};
735 C,
736 imports,
737 /* Refresh scripts as the preferences may have changed the user-scripts path.
738 *
739 * This is needed when loading settings from the previous version,
740 * otherwise the script path stored in the preferences would be ignored. */
741 "bpy.utils.refresh_script_paths()\n"
742 /* Sync add-ons, these may have changed from the defaults. */
743 "addon_utils.reset_all()");
744 }
745 if (use_data) {
747 }
748 addons_loaded = true;
749 }
750 }
751 else {
752 /* Run any texts that were loaded in and flagged as modules. */
753 if (use_data) {
755 }
756 addons_loaded = true;
757 }
758#else
759 UNUSED_VARS(is_startup_file, reset_app_template);
760#endif /* WITH_PYTHON */
761
762 Main *bmain = CTX_data_main(C);
763
764 if (use_userdef) {
765 if (is_factory_startup) {
767 }
768 }
769
770 if (is_factory_startup && BLT_translate_new_dataname()) {
771 /* Translate workspace names. */
772 for (WorkSpace &workspace : bmain->workspaces.items_mutable()) {
774 *bmain, workspace.id, CTX_DATA_(BLT_I18NCONTEXT_ID_WORKSPACE, workspace.id.name + 2));
775 }
776 }
777
778 if (use_data) {
779 /* Important to do before nulling the context. */
781
782 /* Load-post must run before evaluating drivers & depsgraph, see: #109720.
783 * On failure, the caller handles #BKE_CB_EVT_LOAD_POST_FAIL. */
784 if (params->success) {
786 }
787
788 if (is_factory_startup) {
790 }
791 }
792
793 if (use_data) {
795
796 /* After load post, so for example the driver namespace can be filled
797 * before evaluating the depsgraph. */
798 if (!G.background || (G.fileflags & G_BACKGROUND_NO_DEPSGRAPH) == 0) {
800 }
801
803
804 /* Add-ons are disabled when loading the startup file, so the Render Layer node in compositor
805 * node trees might be wrong due to missing render engines that are available as add-ons, like
806 * Cycles. So we need to update compositor node trees after reading the file when add-ons are
807 * now loaded. */
808 if (is_startup_file) {
809 for (Scene &scene : bmain->scenes) {
810 BKE_ntree_update_tag_id_changed(bmain, &scene.id);
811 }
812 BKE_ntree_update(*bmain);
813 }
814
815#if 1
817 /* Clear static filtered asset tree caches. */
819#else
821#endif
822 }
823
824 /* Report any errors.
825 * Currently disabled if add-ons aren't yet loaded. */
826 if (addons_loaded) {
827 wm_file_read_report(bmain, wm->windows.first());
828 }
829
830 if (use_data) {
831 if (!G.background) {
832 if (wm->runtime->undo_stack == nullptr) {
833 wm->runtime->undo_stack = BKE_undosys_stack_create();
834 }
835 else {
836 BKE_undosys_stack_clear(wm->runtime->undo_stack);
837 }
838 BKE_undosys_stack_init_from_main(wm->runtime->undo_stack, bmain);
839 BKE_undosys_stack_init_from_context(wm->runtime->undo_stack, C);
840 }
841 }
842
843 if (use_data) {
844 if (!G.background) {
845 /* In background mode this makes it hard to load
846 * a blend file and do anything since the screen
847 * won't be set to a valid value again. */
848 CTX_wm_window_set(C, nullptr); /* Exits queues. */
849
850 /* Ensure auto-run action is not used from a previous blend file load. */
851 wm_test_autorun_revert_action_set(nullptr, nullptr);
852
853 /* Ensure tools are registered. */
855 }
856 }
857}
858
859static void wm_read_callback_pre_wrapper(bContext *C, const char *filepath)
860{
861 Main *bmain = CTX_data_main(C);
862 /* NOTE: either #BKE_CB_EVT_LOAD_POST or #BKE_CB_EVT_LOAD_POST_FAIL must run.
863 * Runs at the end of this function, don't return beforehand. */
865
866 /* Auto save (if enabled) the project config and then see if we should load in a
867 * new project if the project root path has changed.
868 */
870 BKE_blender_project_refresh(bmain, filepath);
871
872 /* The function above switch to the project of the new file, immediately update
873 * color management to match as blend file read needs the project config. */
875}
876
877static void wm_read_callback_post_wrapper(bContext *C, const char *filepath, const bool success)
878{
879 Main *bmain = CTX_data_main(C);
880 /* Temporarily set the window context as this was once supported, see: #107759.
881 * If the window is already set, don't change it. */
882 bool has_window = CTX_wm_window(C) != nullptr;
883 if (!has_window) {
884 wmWindowManager *wm = bmain->wm.first();
885 wmWindow *win = wm->windows.first();
886 CTX_wm_window_set(C, win);
887 }
888
889 /* On success: #BKE_CB_EVT_LOAD_POST runs from #wm_file_read_post. */
890 if (success == false) {
892 }
893
894 /* This function should leave the window null when the function entered. */
895 if (!has_window) {
896 CTX_wm_window_set(C, nullptr);
897 }
898}
899
901
902/* -------------------------------------------------------------------- */
905
907{
908 double duration_whole_minutes, duration_whole_seconds;
909 double duration_libraries_minutes, duration_libraries_seconds;
910 double duration_lib_override_minutes, duration_lib_override_seconds;
911 double duration_lib_override_resync_minutes, duration_lib_override_resync_seconds;
912 double duration_lib_override_recursive_resync_minutes,
913 duration_lib_override_recursive_resync_seconds;
914
916 nullptr,
917 nullptr,
918 &duration_whole_minutes,
919 &duration_whole_seconds,
920 nullptr);
921 BLI_math_time_seconds_decompose(bf_reports->duration.libraries,
922 nullptr,
923 nullptr,
924 &duration_libraries_minutes,
925 &duration_libraries_seconds,
926 nullptr);
927 BLI_math_time_seconds_decompose(bf_reports->duration.lib_overrides,
928 nullptr,
929 nullptr,
930 &duration_lib_override_minutes,
931 &duration_lib_override_seconds,
932 nullptr);
933 BLI_math_time_seconds_decompose(bf_reports->duration.lib_overrides_resync,
934 nullptr,
935 nullptr,
936 &duration_lib_override_resync_minutes,
937 &duration_lib_override_resync_seconds,
938 nullptr);
939 BLI_math_time_seconds_decompose(bf_reports->duration.lib_overrides_recursive_resync,
940 nullptr,
941 nullptr,
942 &duration_lib_override_recursive_resync_minutes,
943 &duration_lib_override_recursive_resync_seconds,
944 nullptr);
945
946 CLOG_INFO(
947 &LOG, "Blender file read in %.0fm%.2fs", duration_whole_minutes, duration_whole_seconds);
948 CLOG_INFO(&LOG,
949 " * Loading libraries: %.0fm%.2fs",
950 duration_libraries_minutes,
951 duration_libraries_seconds);
952 CLOG_INFO(&LOG,
953 " * Applying overrides: %.0fm%.2fs",
954 duration_lib_override_minutes,
955 duration_lib_override_seconds);
956 CLOG_INFO(&LOG,
957 " * Resyncing overrides: %.0fm%.2fs (%d root overrides), including recursive "
958 "resyncs: %.0fm%.2fs)",
959 duration_lib_override_resync_minutes,
960 duration_lib_override_resync_seconds,
961 bf_reports->count.resynced_lib_overrides,
962 duration_lib_override_recursive_resync_minutes,
963 duration_lib_override_recursive_resync_seconds);
964
965 if (bf_reports->resynced_lib_overrides_libraries_count != 0) {
966 for (LinkNode *node_lib = bf_reports->resynced_lib_overrides_libraries; node_lib != nullptr;
967 node_lib = node_lib->next)
968 {
969 Library *library = static_cast<Library *>(node_lib->link);
970 BKE_reportf(bf_reports->reports,
971 RPT_INFO,
972 "Library \"%s\" needs overrides resync",
973 library->filepath);
974 }
975 }
976
977 if (bf_reports->count.missing_libraries != 0 || bf_reports->count.missing_linked_id != 0) {
978 BKE_reportf(bf_reports->reports,
980 "%d libraries and %d linked data-blocks are missing (including %d ObjectData), "
981 "please check the Info and Outliner editors for details",
982 bf_reports->count.missing_libraries,
983 bf_reports->count.missing_linked_id,
984 bf_reports->count.missing_obdata);
985 }
986 else {
987 if (bf_reports->count.missing_obdata != 0) {
988 CLOG_WARN(&LOG,
989 "%d local ObjectData are reported to be missing, this should never happen",
990 bf_reports->count.missing_obdata);
991 }
992 }
993
994 if (bf_reports->resynced_lib_overrides_libraries_count != 0) {
995 BKE_reportf(bf_reports->reports,
997 "%d libraries have overrides needing resync (auto resynced in %.0fm%.2fs), "
998 "please check the Info editor for details",
1000 duration_lib_override_recursive_resync_minutes,
1001 duration_lib_override_recursive_resync_seconds);
1002 }
1003
1004 if (bf_reports->count.proxies_to_lib_overrides_success != 0 ||
1005 bf_reports->count.proxies_to_lib_overrides_failures != 0)
1006 {
1007 BKE_reportf(bf_reports->reports,
1009 "Proxies have been removed from Blender (%d proxies were automatically converted "
1010 "to library overrides, %d proxies could not be converted and were cleared). "
1011 "Consider re-saving any library .blend file with the newest Blender version",
1012 bf_reports->count.proxies_to_lib_overrides_success,
1013 bf_reports->count.proxies_to_lib_overrides_failures);
1014 }
1015
1016 if (bf_reports->count.sequence_strips_skipped != 0) {
1017 BKE_reportf(bf_reports->reports,
1018 RPT_ERROR,
1019 "%d sequence strips were not read because they were in a channel larger than %d",
1020 bf_reports->count.sequence_strips_skipped,
1022 }
1023
1025 bf_reports->resynced_lib_overrides_libraries = nullptr;
1026
1027 if (bf_reports->pre_animato_file_loaded) {
1028 BKE_report(
1029 bf_reports->reports,
1031 "Loaded a pre-2.50 blend file, animation data has not been loaded. Open & save the file "
1032 "with Blender v4.5 to convert animation data.");
1033 }
1034}
1035
1037 const char *filepath,
1038 const bool use_scripts_autoexec_check,
1039 ReportList *reports)
1040{
1041 /* Assume automated tasks with background, don't write recent file list. */
1042 const bool do_history_file_update = (G.background == false) &&
1043 (CTX_wm_manager(C)->op_undo_depth == 0);
1044 bool success = false;
1045
1046 const bool use_data = true;
1047 const bool use_userdef = false;
1048
1049 /* NOTE: a matching #wm_read_callback_post_wrapper must be called. */
1051
1052 Main *bmain = CTX_data_main(C);
1053
1054 /* So we can get the error message. */
1055 errno = 0;
1056
1057 WM_cursor_wait(true);
1058
1059 /* First try to append data from exotic file formats. */
1060 /* It throws error box when file doesn't exist and returns -1. */
1061 /* NOTE(ton): it should set some error message somewhere. */
1062 const int retval = wm_read_exotic(filepath);
1063
1064 /* We didn't succeed, now try to read Blender file. */
1065 if (retval == BKE_READ_EXOTIC_OK_BLEND) {
1066 BlendFileReadParams params{};
1067 params.is_startup = false;
1068 /* Loading preferences when the user intended to load a regular file is a security
1069 * risk, because the excluded path list is also loaded. Further it's just confusing
1070 * if a user loads a file and various preferences change. */
1072
1073 BlendFileReadReport bf_reports{};
1074 bf_reports.reports = reports;
1075 bf_reports.duration.whole = BLI_time_now_seconds();
1076 BlendFileData *bfd = BKE_blendfile_read(filepath, &params, &bf_reports);
1077 if (bfd != nullptr) {
1078 wm_file_read_pre(use_data, use_userdef);
1079
1080 /* Close any user-loaded fonts. */
1082
1083 /* Put WM into a stable state for post-readfile processes (kill jobs, removes event handlers,
1084 * message bus, and so on). */
1085 BlendFileReadWMSetupData *wm_setup_data = wm_file_read_setup_wm_init(C, bmain, false);
1086
1087 /* This flag is initialized by the operator but overwritten on read.
1088 * need to re-enable it here else drivers and registered scripts won't work. */
1089 const int G_f_orig = G.f;
1090
1091 /* Frees the current main and replaces it with the new one read from file. */
1093 C, bfd, &params, wm_setup_data, &bf_reports, false, nullptr);
1094 bmain = CTX_data_main(C);
1095
1096 /* Finalize handling of WM, using the read WM and/or the current WM depending on things like
1097 * whether the UI is loaded from the .blend file or not, etc. */
1098 wm_file_read_setup_wm_finalize(C, bmain, wm_setup_data);
1099
1100 if (G.f != G_f_orig) {
1101 const int flags_keep = G_FLAG_ALL_RUNTIME;
1103 G.f = (G.f & ~flags_keep) | (G_f_orig & flags_keep);
1104 }
1105
1106 /* Set by the `use_scripts` property on file load.
1107 * If this was not set, then it should be calculated based on the file-path.
1108 * Note that this uses `bmain->filepath` and not `filepath`, necessary when
1109 * recovering the last session, where the file-path can be #BLENDER_QUIT_FILE. */
1110 if (use_scripts_autoexec_check) {
1112 }
1113
1114 WM_check(C); /* Opens window(s), checks keymaps. */
1115
1116 if (do_history_file_update) {
1119 }
1120
1121 wmFileReadPost_Params read_file_post_params{};
1122 read_file_post_params.use_data = use_data;
1123 read_file_post_params.use_userdef = use_userdef;
1124 read_file_post_params.is_startup_file = false;
1125 read_file_post_params.is_factory_startup = false;
1126 read_file_post_params.reset_app_template = false;
1127 read_file_post_params.success = true;
1128 read_file_post_params.is_alloc = false;
1129 wm_file_read_post(C, filepath, &read_file_post_params);
1130
1131 bf_reports.duration.whole = BLI_time_now_seconds() - bf_reports.duration.whole;
1132 file_read_reports_finalize(&bf_reports);
1133
1134 success = true;
1135 }
1136 }
1137#if 0
1138 else if (retval == BKE_READ_EXOTIC_OK_OTHER) {
1139 BKE_undo_write(C, "Import file");
1140 }
1141#endif
1142 else if (retval == BKE_READ_EXOTIC_FAIL_OPEN) {
1143 BKE_reportf(reports,
1144 RPT_ERROR,
1145 "Cannot read file \"%s\": %s",
1146 filepath,
1147 errno ? strerror(errno) : RPT_("unable to open the file"));
1148 }
1149 else if (retval == BKE_READ_EXOTIC_FAIL_FORMAT) {
1150 BKE_reportf(reports, RPT_ERROR, "File format is not supported in file \"%s\"", filepath);
1151 }
1152 else if (retval == BKE_READ_EXOTIC_FAIL_PATH) {
1153 BKE_reportf(reports, RPT_ERROR, "File path \"%s\" invalid", filepath);
1154 }
1155 else {
1156 BKE_reportf(reports, RPT_ERROR, "Unknown error loading \"%s\"", filepath);
1157 BLI_assert_msg(0, "invalid 'retval'");
1158 }
1159
1160 /* NOTE: even if the file fails to load, keep the file in the "Recent Files" list.
1161 * This is done because failure to load could be caused by the file-system being
1162 * temporarily offline, see: #127825. */
1163
1164 WM_cursor_wait(false);
1165
1166 wm_read_callback_post_wrapper(C, filepath, success);
1167
1169
1170 return success;
1171}
1172
1173bool WM_file_read_project(bContext *C, const char *filepath, ReportList *reports)
1174{
1175 const std::string project_root_path = BKE_is_path_inside_blender_project(filepath);
1176
1177 if (project_root_path.empty()) {
1179 reports, RPT_ERROR, "Could not find a project within the specified path: %s", filepath);
1180 return false;
1181 }
1182
1183 /* Initialize project before blend file, so it is taken into account. */
1184 if (!BKE_blender_project_init_from_root_path(CTX_data_main(C), project_root_path)) {
1186 reports, RPT_ERROR, "Failed to load project from path: %s", project_root_path.c_str());
1187 return false;
1188 }
1189
1190 /* Read the startup file again with project configuration applied. */
1191 wmHomeFileRead_Params read_homefile_params{};
1192 read_homefile_params.use_data = true;
1193 read_homefile_params.use_userdef = false;
1194 read_homefile_params.use_factory_settings = G.factory_startup;
1196 wm_homefile_read(C, &read_homefile_params, reports);
1197
1198 if (!G.background) {
1200 }
1201
1202 return true;
1203}
1204
1205static struct {
1206 char app_template[64];
1207 bool override;
1209
1210void WM_init_state_app_template_set(const char *app_template)
1211{
1212 if (app_template) {
1213 STRNCPY(wm_init_state_app_template.app_template, app_template);
1214 wm_init_state_app_template.override = true;
1215 }
1216 else {
1217 wm_init_state_app_template.app_template[0] = '\0';
1218 wm_init_state_app_template.override = false;
1219 }
1220}
1221
1223{
1224 return wm_init_state_app_template.override ? wm_init_state_app_template.app_template : nullptr;
1225}
1226
1228
1229/* -------------------------------------------------------------------- */
1232
1234 const wmHomeFileRead_Params *params_homefile,
1235 ReportList *reports,
1236 wmFileReadPost_Params **r_params_file_read_post)
1237{
1238 /* NOTE: unlike #WM_file_read, don't set the wait cursor when reading the home-file.
1239 * While technically both are reading a file and could use the wait cursor,
1240 * avoid doing so for the following reasons.
1241 *
1242 * - When loading blend with a file (command line or external file browser)
1243 * the home-file is read before the file being loaded.
1244 * Toggling the wait cursor twice causes the cursor to flicker which looks like a glitch.
1245 * - In practice it's not that useful as users tend not to set scenes with slow loading times
1246 * as their startup.
1247 */
1248
1249/* UNUSED, keep as this may be needed later & the comment below isn't self evident. */
1250#if 0
1251 /* Context does not always have valid main pointer here. */
1252 Main *bmain = G_MAIN;
1253#endif
1254 bool success = false;
1255
1256 /* May be enabled, when the user configuration doesn't exist. */
1257 const bool use_data = params_homefile->use_data;
1258 const bool use_userdef = params_homefile->use_userdef;
1259 bool use_factory_settings = params_homefile->use_factory_settings;
1260 /* Currently this only impacts preferences as it doesn't make much sense to keep the default
1261 * startup open in the case the app-template doesn't happen to define its own startup.
1262 * Unlike preferences where we might want to only reset the app-template part of the preferences
1263 * so as not to reset the preferences for all other Blender instances, see: #96427. */
1264 const bool use_factory_settings_app_template_only =
1266 const bool use_empty_data = params_homefile->use_empty_data;
1267 const char *filepath_startup_override = params_homefile->filepath_startup_override;
1268 const char *app_template_override = params_homefile->app_template_override;
1269
1270 bool filepath_startup_is_factory = true;
1271 char filepath_startup[FILE_MAX];
1272 char filepath_userdef[FILE_MAX];
1273
1274 /* When 'app_template' is set:
1275 * `{BLENDER_USER_CONFIG}/{app_template}`. */
1276 char app_template_system[FILE_MAX];
1277 /* When 'app_template' is set:
1278 * `{BLENDER_SYSTEM_SCRIPTS}/startup/bl_app_templates_system/{app_template}`. */
1279 char app_template_config[FILE_MAX];
1280
1281 eBLOReadSkip skip_flags = eBLOReadSkip(0);
1282
1283 if (use_data == false) {
1284 skip_flags |= BLO_READ_SKIP_DATA;
1285 }
1286 if (use_userdef == false) {
1287 skip_flags |= BLO_READ_SKIP_USERDEF;
1288 }
1289
1290 /* True if we load startup.blend from memory
1291 * or use app-template startup.blend which the user hasn't saved. */
1292 bool is_factory_startup = true;
1293
1294 const char *app_template = nullptr;
1295 bool update_defaults = false;
1296
1297 /* Current Main is not always available in context here. */
1298 Main *bmain = G_MAIN;
1299
1300 if (filepath_startup_override != nullptr) {
1301 /* Pass. */
1302 }
1303 else if (app_template_override) {
1304 /* This may be clearing the current template by setting to an empty string. */
1305 app_template = app_template_override;
1306 }
1307 else if (!use_factory_settings && U.app_template[0]) {
1308 app_template = U.app_template;
1309 }
1310
1311 const bool reset_app_template = ((!app_template && U.app_template[0]) ||
1312 (app_template && !STREQ(app_template, U.app_template)));
1313
1314 /* Options exclude each other. */
1315 BLI_assert((use_factory_settings && filepath_startup_override) == 0);
1316
1318 G.autoexec_override.value_or((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0),
1320
1321 if (use_data) {
1322 if (reset_app_template) {
1323 /* Always load UI when switching to another template. */
1324 G.fileflags &= ~G_FILE_NO_UI;
1325 }
1326 }
1327
1328 if (use_userdef || reset_app_template) {
1329#ifdef WITH_PYTHON
1330 /* This only runs once Blender has already started. */
1331 if (!params_homefile->is_first_time) {
1333 /* This is restored by 'wm_file_read_post', disable before loading any preferences
1334 * so an add-on can read their own preferences when un-registering,
1335 * and use new preferences if/when re-registering, see #67577.
1336 *
1337 * Note that this fits into 'wm_file_read_pre' function but gets messy
1338 * since we need to know if 'reset_app_template' is true. */
1339 const char *imports[] = {"addon_utils", nullptr};
1340 BPY_run_string_eval(C, imports, "addon_utils.disable_all()");
1341 }
1342#endif /* WITH_PYTHON */
1343 }
1344
1345 if (use_data) {
1346 /* NOTE: a matching #wm_read_callback_post_wrapper must be called.
1347 * This runs from #wm_homefile_read_post. */
1349 }
1350
1351 /* For regular file loading this only runs after the file is successfully read.
1352 * In the case of the startup file, the in-memory startup file is used as a fallback
1353 * so we know this will work if all else fails. */
1354 wm_file_read_pre(use_data, use_userdef);
1355
1356 BlendFileReadWMSetupData *wm_setup_data = nullptr;
1357 if (use_data) {
1358 /* Put WM into a stable state for post-readfile processes (kill jobs, removes event handlers,
1359 * message bus, and so on). */
1360 wm_setup_data = wm_file_read_setup_wm_init(C, bmain, true);
1361 }
1362
1363 filepath_startup[0] = '\0';
1364 filepath_userdef[0] = '\0';
1365 app_template_system[0] = '\0';
1366 app_template_config[0] = '\0';
1367
1368 const std::optional<std::string> cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, nullptr);
1369 if (!use_factory_settings) {
1370 if (cfgdir.has_value()) {
1372 filepath_startup, sizeof(filepath_startup), cfgdir->c_str(), BLENDER_STARTUP_FILE);
1373 filepath_startup_is_factory = false;
1374 if (use_userdef) {
1376 filepath_userdef, sizeof(filepath_startup), cfgdir->c_str(), BLENDER_USERPREF_FILE);
1377 }
1378 }
1379 else {
1380 use_factory_settings = true;
1381 }
1382
1383 if (filepath_startup_override) {
1384 STRNCPY(filepath_startup, filepath_startup_override);
1385 filepath_startup_is_factory = false;
1386 }
1387 }
1388
1389 /* Load preferences before `startup.blend`. */
1390 if (use_userdef) {
1391 if (use_factory_settings_app_template_only) {
1392 /* Use the current preferences as-is (only load in the app_template preferences). */
1393 skip_flags |= BLO_READ_SKIP_USERDEF;
1394 }
1395 else if (!use_factory_settings && BLI_exists(filepath_userdef)) {
1396 UserDef *userdef = BKE_blendfile_userdef_read(filepath_userdef, nullptr);
1397 if (userdef != nullptr) {
1398 CLOG_INFO(&LOG, "Read prefs: \"%s\"", filepath_userdef);
1399
1401 userdef = nullptr;
1402
1403 skip_flags |= BLO_READ_SKIP_USERDEF;
1404 }
1405 }
1406 }
1407
1408 /* Open last project on startup. */
1409 if (params_homefile->is_first_time && use_data && wm_init_last_project_on_startup(bmain)) {
1411 }
1412
1413 if ((app_template != nullptr) && (app_template[0] != '\0')) {
1415 app_template, app_template_system, sizeof(app_template_system)))
1416 {
1417 /* Can safely continue with code below, just warn it's not found. */
1418 BKE_reportf(reports, RPT_WARNING, "Application Template \"%s\" not found", app_template);
1419 }
1420
1421 /* Insert template name into startup file. */
1422
1423 /* Note that the path is being set even when `use_factory_settings == true`
1424 * this is done so we can load a templates factory-settings. */
1425 if (!use_factory_settings && cfgdir.has_value()) {
1427 app_template_config, sizeof(app_template_config), cfgdir->c_str(), app_template);
1429 filepath_startup, sizeof(filepath_startup), app_template_config, BLENDER_STARTUP_FILE);
1430 filepath_startup_is_factory = false;
1431 if (BLI_access(filepath_startup, R_OK) != 0) {
1432 filepath_startup[0] = '\0';
1433 }
1434 }
1435 else {
1436 filepath_startup[0] = '\0';
1437 }
1438
1439 if (filepath_startup[0] == '\0') {
1441 filepath_startup, sizeof(filepath_startup), app_template_system, BLENDER_STARTUP_FILE);
1442 filepath_startup_is_factory = true;
1443
1444 /* Update defaults only for system templates. */
1445 update_defaults = true;
1446 }
1447 }
1448
1449 if (!use_factory_settings || (filepath_startup[0] != '\0')) {
1450 if (BLI_access(filepath_startup, R_OK) == 0) {
1451 BlendFileReadParams params{};
1452 params.is_startup = true;
1453 params.is_factory_settings = use_factory_settings;
1454 params.skip_flags = skip_flags | BLO_READ_SKIP_USERDEF;
1455 BlendFileReadReport bf_reports{};
1456 bf_reports.reports = reports;
1457 BlendFileData *bfd = BKE_blendfile_read(filepath_startup, &params, &bf_reports);
1458
1459 if (bfd != nullptr) {
1460 CLOG_INFO(&LOG, "Read startup: \"%s\"", filepath_startup);
1461
1462 /* Frees the current main and replaces it with the new one read from file. */
1464 bfd,
1465 &params,
1466 wm_setup_data,
1467 &bf_reports,
1468 update_defaults && use_data,
1469 app_template);
1470 success = true;
1471 bmain = CTX_data_main(C);
1472 }
1473 }
1474 if (success) {
1475 is_factory_startup = filepath_startup_is_factory;
1476 }
1477 }
1478
1479 if (use_userdef) {
1480 if ((skip_flags & BLO_READ_SKIP_USERDEF) == 0) {
1481 UserDef *userdef_default = BKE_blendfile_userdef_from_defaults();
1483 skip_flags |= BLO_READ_SKIP_USERDEF;
1484 }
1485 }
1486
1487 if (success == false && filepath_startup_override && reports) {
1488 /* We can not return from here because wm is already reset. */
1489 BKE_reportf(reports, RPT_ERROR, "Could not read \"%s\"", filepath_startup_override);
1490 }
1491
1492 bool loaded_factory_settings = false;
1493 if (success == false) {
1494 BlendFileReadParams read_file_params{};
1495 read_file_params.is_startup = true;
1496 read_file_params.is_factory_settings = use_factory_settings;
1497 read_file_params.skip_flags = skip_flags;
1499 datatoc_startup_blend, datatoc_startup_blend_size, &read_file_params, nullptr);
1500 if (bfd != nullptr) {
1501 BlendFileReadReport read_report{};
1502 /* Frees the current main and replaces it with the new one read from file. */
1504 C, bfd, &read_file_params, wm_setup_data, &read_report, true, nullptr);
1505 success = true;
1506 loaded_factory_settings = true;
1507 bmain = CTX_data_main(C);
1508 }
1509 }
1510
1511 if (use_empty_data) {
1513 }
1514
1515 /* Load template preferences,
1516 * unlike regular preferences we only use some of the settings,
1517 * see: #BKE_blender_userdef_set_app_template. */
1518 if (app_template_system[0] != '\0') {
1519 char temp_path[FILE_MAX];
1520 temp_path[0] = '\0';
1521 if (!use_factory_settings) {
1522 BLI_path_join(temp_path, sizeof(temp_path), app_template_config, BLENDER_USERPREF_FILE);
1523 if (BLI_access(temp_path, R_OK) != 0) {
1524 temp_path[0] = '\0';
1525 }
1526 }
1527
1528 if (temp_path[0] == '\0') {
1529 BLI_path_join(temp_path, sizeof(temp_path), app_template_system, BLENDER_USERPREF_FILE);
1530 }
1531
1532 if (use_userdef) {
1533 UserDef *userdef_template = nullptr;
1534 /* Just avoids missing file warning. */
1535 if (BLI_exists(temp_path)) {
1536 userdef_template = BKE_blendfile_userdef_read(temp_path, nullptr);
1537 if (userdef_template) {
1538 CLOG_INFO(&LOG, "Read prefs from app-template: \"%s\"", temp_path);
1539 }
1540 }
1541 if (userdef_template == nullptr) {
1542 /* We need to have preferences load to overwrite preferences from previous template. */
1543 userdef_template = BKE_blendfile_userdef_from_defaults();
1544 }
1545 if (userdef_template) {
1547 userdef_template = nullptr;
1548 }
1549 }
1550 }
1551
1552 if (app_template_override) {
1553 STRNCPY(U.app_template, app_template_override);
1554 }
1555
1556 if (use_userdef) {
1557 /* Check userdef before open window, keymaps etc. */
1558 wm_init_userdef(bmain);
1559 }
1560
1561 if (use_data) {
1562 /* Finalize handling of WM, using the read WM and/or the current WM depending on things like
1563 * whether the UI is loaded from the .blend file or not, etc. */
1564 wm_setup_data->is_factory_startup = loaded_factory_settings;
1565 wm_file_read_setup_wm_finalize(C, bmain, wm_setup_data);
1566 }
1567
1568 if (use_userdef) {
1569 /* Clear keymaps because the current default keymap may have been initialized
1570 * from user preferences, which have been reset. */
1571 for (wmWindowManager &wm : bmain->wm) {
1572 if (wm.runtime->defaultconf) {
1573 wm.runtime->defaultconf->flag &= ~KEYCONF_INIT_DEFAULT;
1574 }
1575 }
1576 }
1577
1578 if (use_data) {
1579 WM_check(C); /* Opens window(s), checks keymaps. */
1580
1581 bmain->filepath[0] = '\0';
1582 }
1583
1584 {
1585 wmFileReadPost_Params params_file_read_post{};
1586 params_file_read_post.use_data = use_data;
1587 params_file_read_post.use_userdef = use_userdef;
1588 params_file_read_post.is_startup_file = true;
1589 params_file_read_post.is_factory_startup = is_factory_startup;
1590 params_file_read_post.is_first_time = params_homefile->is_first_time;
1591
1592 params_file_read_post.reset_app_template = reset_app_template;
1593
1594 params_file_read_post.success = success;
1595 params_file_read_post.is_alloc = false;
1596
1597 if (r_params_file_read_post == nullptr) {
1598 wm_homefile_read_post(C, &params_file_read_post);
1599 }
1600 else {
1601 params_file_read_post.is_alloc = true;
1602 *r_params_file_read_post = MEM_new_uninitialized<wmFileReadPost_Params>(__func__);
1603 **r_params_file_read_post = params_file_read_post;
1604
1605 /* Match #wm_file_read_post which leaves the window cleared too. */
1606 CTX_wm_window_set(C, nullptr);
1607 }
1608 }
1609}
1610
1612 const wmHomeFileRead_Params *params_homefile,
1613 ReportList *reports)
1614{
1615 wm_homefile_read_ex(C, params_homefile, reports, nullptr);
1616}
1617
1618void wm_homefile_read_post(bContext *C, const wmFileReadPost_Params *params_file_read_post)
1619{
1620 const char *filepath = "";
1621 wm_file_read_post(C, filepath, params_file_read_post);
1622
1623 if (params_file_read_post->use_data) {
1624 wm_read_callback_post_wrapper(C, filepath, params_file_read_post->success);
1625 }
1626
1627 if (params_file_read_post->is_alloc) {
1628 MEM_delete(params_file_read_post);
1629 }
1630}
1631
1633
1634/* -------------------------------------------------------------------- */
1637
1639{
1640 const std::optional<std::string> cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, nullptr);
1641 if (!cfgdir.has_value()) {
1642 return;
1643 }
1644
1645 char filepath[FILE_MAX];
1646 LinkNode *l;
1647 int num;
1648
1649 BLI_path_join(filepath, sizeof(filepath), cfgdir->c_str(), BLENDER_HISTORY_FILE);
1650
1651 LinkNode *lines = BLI_file_read_as_lines(filepath);
1652
1654
1655 /* Read list of recent opened files from #BLENDER_HISTORY_FILE to memory. */
1656 for (l = lines, num = 0; l && (num < U.recent_files); l = l->next) {
1657 const char *line = static_cast<const char *>(l->link);
1658 /* Don't check if files exist, causes slow startup for remote/external drives. */
1659 if (line[0]) {
1660 RecentFile *recent = MEM_new_uninitialized<RecentFile>("RecentFile");
1661 BLI_addtail(&(G.recent_files), recent);
1662 recent->filepath = BLI_strdup(line);
1663 num++;
1664 }
1665 }
1666
1667 BLI_file_free_lines(lines);
1668}
1669
1670static RecentFile *wm_history_file_new(const char *filepath)
1671{
1672 RecentFile *recent = MEM_new_uninitialized<RecentFile>("RecentFile");
1673 recent->filepath = BLI_strdup(filepath);
1674 return recent;
1675}
1676
1678{
1679 BLI_assert(BLI_findindex(&G.recent_files, recent) != -1);
1680 MEM_delete(recent->filepath);
1681 BLI_freelinkN(&G.recent_files, recent);
1682}
1683
1685{
1686 for (RecentFile &recent : G.recent_files.items_mutable()) {
1687 wm_history_file_free(&recent);
1688 }
1689}
1690
1691static RecentFile *wm_file_history_find(const char *filepath)
1692{
1693 return static_cast<RecentFile *>(
1694 BLI_findstring_ptr(&G.recent_files, filepath, offsetof(RecentFile, filepath)));
1695}
1696
1702{
1703 char filepath[FILE_MAX];
1704 FILE *fp;
1705
1706 /* Will be nullptr in background mode. */
1707 const std::optional<std::string> user_config_dir = BKE_appdir_folder_id_create(
1708 BLENDER_USER_CONFIG, nullptr);
1709 if (!user_config_dir.has_value()) {
1710 return;
1711 }
1712
1713 BLI_path_join(filepath, sizeof(filepath), user_config_dir->c_str(), BLENDER_HISTORY_FILE);
1714
1715 fp = BLI_fopen(filepath, "w");
1716 if (fp) {
1717 for (RecentFile &recent : G.recent_files) {
1718 fprintf(fp, "%s\n", recent.filepath);
1719 }
1720 fclose(fp);
1721 }
1722}
1723
1728{
1729 RecentFile *recent;
1730 const char *blendfile_path = BKE_main_blendfile_path_from_global();
1731
1732 /* No write history for recovered startup files. */
1733 if (blendfile_path[0] == '\0') {
1734 return;
1735 }
1736
1737 recent = G.recent_files.first();
1738 /* Refresh #BLENDER_HISTORY_FILE of recent opened files, when current file was changed. */
1739 if (!(recent) || (BLI_path_cmp(recent->filepath, blendfile_path) != 0)) {
1740
1741 recent = wm_file_history_find(blendfile_path);
1742 if (recent) {
1743 BLI_remlink(&G.recent_files, recent);
1744 }
1745 else {
1746 RecentFile *recent_next;
1747 for (recent = static_cast<RecentFile *>(BLI_findlink(&G.recent_files, U.recent_files - 1));
1748 recent;
1749 recent = recent_next)
1750 {
1751 recent_next = recent->next;
1752 wm_history_file_free(recent);
1753 }
1754 recent = wm_history_file_new(blendfile_path);
1755 }
1756
1757 /* Add current file to the beginning of list. */
1758 BLI_addhead(&(G.recent_files), recent);
1759
1760 /* Write current file to #BLENDER_HISTORY_FILE. */
1762
1763 /* Also update most recent files on system. */
1764 const GHOST_ISystemPaths *ghost_system_paths = GHOST_ISystemPaths::get();
1765 ghost_system_paths->addToSystemRecentFiles(blendfile_path);
1766 }
1767}
1768
1770
1771/* -------------------------------------------------------------------- */
1774
1775static std::optional<std::string> wm_project_root_path_get(const Main *bmain)
1776{
1778 bmain, [](const bke::BlenderProject *project) -> std::optional<std::string> {
1779 if (project == nullptr) {
1780 return std::nullopt;
1781 }
1782 return project->get_root_path();
1783 });
1784}
1785
1787static std::string wm_recent_filepath_get(const Main *bmain)
1788{
1789 const std::optional<std::string> root_path = wm_project_root_path_get(bmain);
1790 if (!root_path) {
1791 const RecentFile *recent = G.recent_files.first();
1792 return recent ? recent->filepath : "";
1793 }
1794
1795 /* In a project, use a file from the project, or the project directory. */
1796 for (const RecentFile &recent : G.recent_files) {
1797 if (BLI_path_contains(root_path->c_str(), recent.filepath)) {
1798 return recent.filepath;
1799 }
1800 }
1801
1802 char dirpath[FILE_MAX];
1803 STRNCPY(dirpath, root_path->c_str());
1804 BLI_path_slash_ensure(dirpath, sizeof(dirpath));
1805 return dirpath;
1806}
1807
1809
1810/* -------------------------------------------------------------------- */
1830
1831#ifdef USE_THUMBNAIL_FAST_DOWNSCALE
1833 const int src_size[2],
1834 const int dst_size[2])
1835{
1836 /* NOTE: this is a faster alternative to #IMBScaleFilter::Box which is
1837 * especially slow in debug builds, normally debug performance isn't a
1838 * consideration however it's slow enough to get in the way of development.
1839 * In release builds this gives ~1.4x speedup. */
1840
1841 /* Scaling using a box-filter where each box uses an integer-rounded region.
1842 * Accept a slightly lower quality scale as this is only for thumbnails.
1843 * In practice the result is visually indistinguishable.
1844 *
1845 * Technically the color accumulation *could* overflow (creating some invalid pixels),
1846 * however this would require the source image to be larger than
1847 * 65,535 pixels squared (when scaling down to 256x256).
1848 * As the source input is a screenshot or a small camera render created for the thumbnail,
1849 * this isn't a concern. */
1850
1851 BLI_assert(dst_size[0] <= src_size[0] && dst_size[1] <= src_size[1]);
1852 uint8_t *dst_rect = MEM_new_array_uninitialized<uint8_t>(size_t(4) * dst_size[0] * dst_size[1],
1853 __func__);
1854
1855 /* A row, the width of the destination to accumulate pixel values into
1856 * before writing into the image. */
1857 uint32_t *accum_row = MEM_new_array_zeroed<uint32_t>(size_t(dst_size[0]) * 4, __func__);
1858
1859# ifndef NDEBUG
1860 /* Assert that samples are calculated correctly. */
1861 uint64_t sample_count_all = 0;
1862# endif
1863
1864 const uint32_t src_size_x = src_size[0];
1865 const uint32_t src_size_y = src_size[1];
1866
1867 const uint32_t dst_size_x = dst_size[0];
1868 const uint32_t dst_size_y = dst_size[1];
1869 const uint8_t *src_px = src_rect;
1870
1871 uint32_t src_y = 0;
1872 for (uint32_t dst_y = 0; dst_y < dst_size_y; dst_y++) {
1873 const uint32_t src_y_beg = src_y;
1874 const uint32_t src_y_end = ((dst_y + 1) * src_size_y) / dst_size_y;
1875 for (; src_y < src_y_end; src_y++) {
1876 uint32_t *accum = accum_row;
1877 uint32_t src_x = 0;
1878 for (uint32_t dst_x = 0; dst_x < dst_size_x; dst_x++, accum += 4) {
1879 const uint32_t src_x_end = ((dst_x + 1) * src_size_x) / dst_size_x;
1880 for (; src_x < src_x_end; src_x++) {
1881 accum[0] += uint32_t(src_px[0]);
1882 accum[1] += uint32_t(src_px[1]);
1883 accum[2] += uint32_t(src_px[2]);
1884 accum[3] += uint32_t(src_px[3]);
1885 src_px += 4;
1886 }
1887 BLI_assert(src_x == src_x_end);
1888 }
1889 BLI_assert(accum == accum_row + (4 * dst_size[0]));
1890 }
1891
1892 uint32_t *accum = accum_row;
1893 uint8_t *dst_px = dst_rect + ((dst_y * dst_size_x) * 4);
1894 uint32_t src_x_beg = 0;
1895 const uint32_t span_y = src_y_end - src_y_beg;
1896 for (uint32_t dst_x = 0; dst_x < dst_size_x; dst_x++) {
1897 const uint32_t src_x_end = ((dst_x + 1) * src_size_x) / dst_size_x;
1898 const uint32_t span_x = src_x_end - src_x_beg;
1899
1900 const uint32_t sample_count = span_x * span_y;
1901 dst_px[0] = uint8_t(accum[0] / sample_count);
1902 dst_px[1] = uint8_t(accum[1] / sample_count);
1903 dst_px[2] = uint8_t(accum[2] / sample_count);
1904 dst_px[3] = uint8_t(accum[3] / sample_count);
1905 accum[0] = accum[1] = accum[2] = accum[3] = 0;
1906 accum += 4;
1907 dst_px += 4;
1908
1909 src_x_beg = src_x_end;
1910# ifndef NDEBUG
1911 sample_count_all += sample_count;
1912# endif
1913 }
1914 }
1915 BLI_assert(src_px == src_rect + (sizeof(uint8_t[4]) * src_size[0] * src_size[1]));
1916 BLI_assert(sample_count_all == size_t(src_size[0]) * size_t(src_size[1]));
1917
1918 MEM_delete(accum_row);
1919 return dst_rect;
1920}
1921#endif /* USE_THUMBNAIL_FAST_DOWNSCALE */
1922
1923static int2 blend_file_thumb_clamp_size(const int size[2], const int limit)
1924{
1925 int2 result;
1926 if (size[0] > size[1]) {
1927 result.x = limit;
1928 result.y = max_ii(1, int((float(size[1]) / float(size[0])) * limit));
1929 }
1930 else {
1931 result.x = max_ii(1, int((float(size[0]) / float(size[1])) * limit));
1932 result.y = limit;
1933 }
1934 return result;
1935}
1936
1941{
1942 *r_thumb = nullptr;
1943
1944 wmWindow *win = CTX_wm_window(C);
1945 if (G.background || (win == nullptr)) {
1946 return nullptr;
1947 }
1948
1949 /* The window to capture should be a main window (without parent). */
1950 while (win->parent) {
1951 win = win->parent;
1952 }
1953
1955 int win_size[2];
1956 /* NOTE: always read from front-buffer as drawing a window can cause problems while saving,
1957 * even if this means the thumbnail from the screen-shot fails to be created, see: #98462. */
1958 ImBuf *ibuf = nullptr;
1959
1960 if (uint8_t *buffer = WM_window_pixels_read_from_frontbuffer(wm, win, win_size)) {
1961 const int2 thumb_size_2x = blend_file_thumb_clamp_size(win_size, BLEN_THUMB_SIZE * 2);
1962 const int2 thumb_size = blend_file_thumb_clamp_size(win_size, BLEN_THUMB_SIZE);
1963
1964#ifdef USE_THUMBNAIL_FAST_DOWNSCALE
1965 if ((thumb_size_2x[0] <= win_size[0]) && (thumb_size_2x[1] <= win_size[1])) {
1966 uint8_t *rect_2x = blend_file_thumb_fast_downscale(buffer, win_size, thumb_size_2x);
1967 uint8_t *rect = blend_file_thumb_fast_downscale(rect_2x, thumb_size_2x, thumb_size);
1968
1969 MEM_delete(buffer);
1970 ibuf = IMB_allocFromBufferOwn(rect_2x, nullptr, thumb_size_2x.x, thumb_size_2x.y, 24);
1971
1972 BlendThumbnail *thumb = BKE_main_thumbnail_from_buffer(nullptr, rect, thumb_size);
1973 MEM_delete(rect);
1974 *r_thumb = thumb;
1975 }
1976 else
1977#endif /* USE_THUMBNAIL_FAST_DOWNSCALE */
1978 {
1979 ibuf = IMB_allocFromBufferOwn(buffer, nullptr, win_size[0], win_size[1], 24);
1980 BLI_assert(ibuf != nullptr); /* Never expected to fail. */
1981
1982 /* File-system thumbnail image can be 256x256. */
1983 IMB_scale(ibuf, thumb_size_2x.x, thumb_size_2x.y, IMBScaleFilter::Box, false);
1984
1985 /* Thumbnail inside blend should be 128x128. */
1986 ImBuf *thumb_ibuf = IMB_scale_into_new(
1987 ibuf, thumb_size.x, thumb_size.y, IMBScaleFilter::Box, false);
1988
1989 BlendThumbnail *thumb = BKE_main_thumbnail_from_imbuf(nullptr, thumb_ibuf);
1990 IMB_freeImBuf(thumb_ibuf);
1991 *r_thumb = thumb;
1992 }
1993 }
1994
1995 if (ibuf) {
1996 /* Save metadata for quick access. */
1997 char version_str[10];
1998 SNPRINTF(version_str, "%d.%01d", BLENDER_VERSION / 100, BLENDER_VERSION % 100);
1999 IMB_metadata_set_field(ibuf->metadata_for_write(), "Thumb::Blender::Version", version_str);
2000 }
2001
2002 /* Must be freed by caller. */
2003 return ibuf;
2004}
2005
2012 Scene *scene,
2013 bScreen *screen,
2014 BlendThumbnail **r_thumb)
2015{
2016 *r_thumb = nullptr;
2017
2018 /* Scene can be nullptr if running a script at startup and calling the save operator. */
2019 if (G.background || scene == nullptr) {
2020 return nullptr;
2021 }
2022
2023 /* Will be scaled down, but gives some nice oversampling. */
2024 ImBuf *ibuf;
2025 BlendThumbnail *thumb;
2027 const float pixelsize_old = U.pixelsize;
2028 wmWindow *windrawable_old = wm->runtime->windrawable;
2029 char err_out[256] = "unknown";
2030
2031 /* Screen if no camera found. */
2032 ScrArea *area = nullptr;
2033 ARegion *region = nullptr;
2034 View3D *v3d = nullptr;
2035
2036 if (screen != nullptr) {
2037 area = BKE_screen_find_big_area(screen, SPACE_VIEW3D, 0);
2038 if (area) {
2039 v3d = area->spacedata.first_as<View3D>();
2041 }
2042 }
2043
2044 if (scene->camera == nullptr && v3d == nullptr) {
2045 return nullptr;
2046 }
2047
2048 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
2049
2050 /* Note that with scaling, this ends up being 0.5,
2051 * as it's a thumbnail, we don't need object centers and friends to be 1:1 size. */
2052 U.pixelsize = 1.0f;
2053
2054 if (scene->camera) {
2056 scene,
2057 (v3d) ? &v3d->shading : nullptr,
2058 (v3d) ? eDrawType(v3d->shading.type) : OB_SOLID,
2059 scene->camera,
2066 nullptr,
2067 nullptr,
2068 nullptr,
2069 err_out);
2070 }
2071 else {
2072 ibuf = ED_view3d_draw_offscreen_imbuf(depsgraph,
2073 scene,
2074 OB_SOLID,
2075 v3d,
2076 region,
2081 nullptr,
2082 true,
2083 nullptr,
2084 nullptr,
2085 true,
2086 err_out);
2087 }
2088
2089 U.pixelsize = pixelsize_old;
2090
2091 /* Reset to old drawable. */
2092 if (windrawable_old) {
2093 wm_window_make_drawable(wm, windrawable_old);
2094 }
2095 else {
2097 }
2098
2099 if (ibuf) {
2100 /* Dirty oversampling. */
2101
2102 /* Save metadata for quick access. */
2103 char version_str[10];
2104 SNPRINTF(version_str, "%d.%01d", BLENDER_VERSION / 100, BLENDER_VERSION % 100);
2105 IMB_metadata_set_field(ibuf->metadata_for_write(), "Thumb::Blender::Version", version_str);
2106
2107 /* BLEN_THUMB_SIZE is size of thumbnail inside blend file: 128x128. */
2108 ImBuf *thumb_ibuf = IMB_scale_into_new(
2110 thumb = BKE_main_thumbnail_from_imbuf(nullptr, thumb_ibuf);
2111 IMB_freeImBuf(thumb_ibuf);
2112 /* Thumbnail saved to file-system should be 256x256. */
2113 IMB_scale(ibuf,
2117 false);
2118 }
2119 else {
2120 /* '*r_thumb' needs to stay nullptr to prevent a bad thumbnail from being handled. */
2121 CLOG_WARN(&LOG, "failed to create thumbnail: %s", err_out);
2122 thumb = nullptr;
2123 }
2124
2125 /* Must be freed by caller. */
2126 *r_thumb = thumb;
2127
2128 return ibuf;
2129}
2130
2132
2133/* -------------------------------------------------------------------- */
2136
2138{
2139 char filepath[FILE_MAX];
2140
2142 BLI_path_extension_replace(filepath, sizeof(filepath), "_crash.blend");
2143 BlendFileWriteParams params{};
2144 const bool success = BLO_write_file(G_MAIN, filepath, G.fileflags, &params, nullptr);
2145 printf("%s: \"%s\"\n", success ? "written" : "failed", filepath);
2146 return success;
2147}
2148
2154 const char *filepath,
2155 ReportList *reports)
2156{
2157 const int filepath_len = strlen(filepath);
2158 if (filepath_len == 0) {
2159 BKE_report(reports, RPT_ERROR, "Path is empty, cannot save");
2160 return false;
2161 }
2162
2163 if (filepath_len >= FILE_MAX) {
2164 BKE_report(reports, RPT_ERROR, "Path too long, cannot save");
2165 return false;
2166 }
2167
2168 if (bmain->is_asset_edit_file && StringRef(filepath).endswith(BLENDER_ASSET_FILE_SUFFIX)) {
2169 BKE_report(reports, RPT_ERROR, "Cannot overwrite files that are managed by the asset system");
2170 return false;
2171 }
2172
2173 for (Library &li : bmain->libraries) {
2174 if (BLI_path_cmp(li.runtime->filepath_abs, filepath) == 0) {
2175 BKE_reportf(reports, RPT_ERROR, "Cannot overwrite used library '%.240s'", filepath);
2176 return false;
2177 }
2178 }
2179
2180 return true;
2181}
2182
2187 const char *filepath,
2188 int fileflags,
2189 eBLO_WritePathRemap remap_mode,
2190 bool use_save_as_copy,
2191 ReportList *reports)
2192{
2193 Main *bmain = CTX_data_main(C);
2194 BlendThumbnail *thumb = nullptr, *main_thumb = nullptr;
2195 ImBuf *ibuf_thumb = nullptr;
2196
2197 /* NOTE: used to replace the file extension (to ensure `.blend`),
2198 * no need to now because the operator ensures,
2199 * its handy for scripts to save to a predefined name without blender editing it. */
2200
2201 if (!wm_file_write_check_with_report_on_failure(bmain, filepath, reports)) {
2202 return false;
2203 }
2204
2205 /* Call pre-save callbacks before writing preview,
2206 * that way you can generate custom file thumbnail. */
2207
2208 /* NOTE: either #BKE_CB_EVT_SAVE_POST or #BKE_CB_EVT_SAVE_POST_FAIL must run.
2209 * Runs at the end of this function, don't return beforehand. */
2211
2212 /* Check if file write permission is OK. */
2213 if (const int st_mode = BLI_file_stat_mode(filepath)) {
2214 bool ok = true;
2215
2216 if (!BLI_file_is_writable(filepath)) {
2218 reports, RPT_ERROR, "Cannot save blend file, path \"%s\" is not writable", filepath);
2219 ok = false;
2220 }
2221 else if (S_ISDIR(st_mode)) {
2222 /* While the UI mostly prevents this, it's possible to save to an existing
2223 * directory from Python because the path is used unmodified.
2224 * Besides it being unlikely the user wants to replace a directory,
2225 * the file versioning logic (to create `*.blend1` files)
2226 * would rename the directory with a `1` suffix, see #134101. */
2228 reports, RPT_ERROR, "Cannot save blend file, path \"%s\" is a directory", filepath);
2229 ok = false;
2230 }
2231
2232 if (!ok) {
2234 return false;
2235 }
2236 }
2237
2239
2240 /* Enforce full override check/generation on file save. */
2242
2243 /* NOTE: Ideally we would call `WM_redraw_windows` here to remove any open menus.
2244 * But we can crash if saving from a script, see #92704 & #97627.
2245 * Just checking `!G.background && BLI_thread_is_main()` is not sufficient to fix this.
2246 * Additionally some EGL configurations don't support reading the front-buffer
2247 * immediately after drawing, see: #98462. In that case off-screen drawing is necessary. */
2248
2249 /* Don't forget not to return without! */
2250 WM_cursor_wait(true);
2251
2252 if (U.file_preview_type != USER_FILE_PREVIEW_NONE) {
2253 /* Blend file thumbnail.
2254 *
2255 * - Save before exiting edit-mode, otherwise evaluated-mesh for shared data gets corrupted.
2256 * See #27765.
2257 * - Main can store a `.blend` thumbnail,
2258 * useful for background-mode or thumbnail customization.
2259 */
2260 main_thumb = thumb = bmain->blen_thumb;
2261 if (thumb != nullptr) {
2262 /* In case we are given a valid thumbnail data, just generate image from it. */
2263 ibuf_thumb = BKE_main_thumbnail_to_imbuf(nullptr, thumb);
2264 }
2265 else if (BLI_thread_is_main()) {
2266 int file_preview_type = U.file_preview_type;
2267
2268 if (file_preview_type == USER_FILE_PREVIEW_AUTO) {
2269 Scene *scene = CTX_data_scene(C);
2270 bScreen *screen = CTX_wm_screen(C);
2271 bool do_render = (scene != nullptr && scene->camera != nullptr && screen != nullptr &&
2272 (BKE_screen_find_big_area(screen, SPACE_VIEW3D, 0) != nullptr));
2273 file_preview_type = do_render ? USER_FILE_PREVIEW_CAMERA : USER_FILE_PREVIEW_SCREENSHOT;
2274 }
2275
2276 switch (file_preview_type) {
2278 ibuf_thumb = blend_file_thumb_from_screenshot(C, &thumb);
2279 break;
2280 }
2282 ibuf_thumb = blend_file_thumb_from_camera(
2283 C, CTX_data_scene(C), CTX_wm_screen(C), &thumb);
2284 break;
2285 }
2286 default:
2288 }
2289 }
2290 }
2291
2292 /* Operator now handles overwrite checks. */
2293
2294 if (G.fileflags & G_FILE_AUTOPACK) {
2295 BKE_packedfile_pack_all(bmain, reports, false);
2296 }
2297
2299
2300 /* XXX(ton): temp solution to solve bug, real fix coming. */
2301 bmain->recovered = false;
2302
2303 BlendFileWriteParams blend_write_params{};
2304 blend_write_params.remap_mode = remap_mode;
2305 blend_write_params.use_save_versions = true;
2306 blend_write_params.use_save_as_copy = use_save_as_copy;
2307 blend_write_params.thumb = thumb;
2308
2309 const bool success = BLO_write_file(bmain, filepath, fileflags, &blend_write_params, reports);
2310
2311 if (success) {
2312 if (use_save_as_copy == false) {
2313 STRNCPY(bmain->filepath, filepath); /* Is guaranteed current file. */
2314 }
2315
2316 SET_FLAG_FROM_TEST(G.fileflags, fileflags & G_FILE_COMPRESS, G_FILE_COMPRESS);
2317
2318 /* Run this function after because the file can't be written before the blend is. */
2319 if (ibuf_thumb) {
2320 IMB_thumb_delete(filepath, THB_FAIL); /* Without this a failed thumb overrides. */
2321 /* `IMB_thumb_create()` may return nullptr, `ibuf_thumb` may then leak that buffers' memory.
2322 */
2323 ImBuf *saved_ibuf_thumb = IMB_thumb_create(
2324 filepath, THB_LARGE, THB_SOURCE_BLEND, ibuf_thumb);
2325 if (saved_ibuf_thumb) {
2326 ibuf_thumb = saved_ibuf_thumb;
2327 }
2328 }
2329 }
2330
2332 bmain, filepath, success ? BKE_CB_EVT_SAVE_POST : BKE_CB_EVT_SAVE_POST_FAIL);
2333
2334 /* Auto save (if enabled) the project config and then see if we should load in a
2335 * new project if the project root path has changed.
2336 */
2339
2340 /* Prevent background mode scripts from clobbering history.
2341 * After BKE_blender_project_refresh which activates the project. */
2342 const bool do_history_file_update = (G.background == false) &&
2343 (CTX_wm_manager(C)->op_undo_depth == 0);
2344 if (success && do_history_file_update) {
2347 }
2348
2349 if (ibuf_thumb) {
2350 IMB_freeImBuf(ibuf_thumb);
2351 }
2352 if (thumb && thumb != main_thumb) {
2353 MEM_delete(thumb);
2354 }
2355
2356 WM_cursor_wait(false);
2357
2358 return success;
2359}
2360
2362
2363/* -------------------------------------------------------------------- */
2366
2367static void wm_autosave_location(char filepath[FILE_MAX])
2368{
2369 const int pid = abs(getpid());
2370 char filename[FILE_MAX];
2371
2372 /* Normally there is no need to check for this to be nullptr,
2373 * however this runs on exit when it may be cleared. */
2374 Main *bmain = G_MAIN;
2375 const char *blendfile_path = bmain ? BKE_main_blendfile_path(bmain) : nullptr;
2376
2377 if (blendfile_path && (blendfile_path[0] != '\0')) {
2378 const char *basename = BLI_path_basename(blendfile_path);
2379 int len = strlen(basename) - 6;
2380 SNPRINTF(filename, "%.*s_%d_autosave.blend", len, basename, pid);
2381 }
2382 else {
2383 SNPRINTF(filename, "%d_autosave.blend", pid);
2384 }
2385
2386 const char *tempdir_base = BKE_tempdir_base();
2387 BLI_path_join(filepath, FILE_MAX, tempdir_base, filename);
2388}
2389
2391{
2392 if (wm->file_saved) {
2393 /* When file is already saved, skip creating an auto-save file, see: #146003 */
2394 return true;
2395 }
2396
2397 char filepath[FILE_MAX];
2398 wm_autosave_location(filepath);
2399
2400 /* Technically, we could always just save here, but that would cause performance regressions
2401 * compared to when the #MemFile undo step was used for saving undo-steps. So for now just skip
2402 * auto-save when we are in a mode where auto-save wouldn't have worked previously anyway. This
2403 * check can be removed once the performance regressions have been solved. */
2404 if (ED_undosys_autosave_compatible(wm->runtime->undo_stack)) {
2405 const bool success = WM_autosave_write(wm, bmain, &wm->runtime->reports);
2406 if (!success) {
2407 WM_report_banner_show(wm, nullptr);
2408 }
2409 return success;
2410 }
2411 if ((U.uiflag & USER_GLOBALUNDO) == 0) {
2412 const bool success = WM_autosave_write(wm, bmain, &wm->runtime->reports);
2413 if (!success) {
2414 WM_report_banner_show(wm, nullptr);
2415 }
2416 return success;
2417 }
2418 /* Can't auto-save with MemFile right now, try again later. */
2419 return false;
2420}
2421
2423{
2424 return wm->autosave_scheduled;
2425}
2426
2428{
2431
2432 char filepath[FILE_MAX];
2433 wm_autosave_location(filepath);
2434 /* Save as regular blend file with recovery information and always compress them, see: !132685.
2435 */
2436 const int fileflags = G.fileflags | G_FILE_RECOVER_WRITE | G_FILE_COMPRESS;
2437
2438 /* Error reporting into console. */
2439 BlendFileWriteParams params{};
2440 const bool success = BLO_write_file(bmain, filepath, fileflags, &params, reports);
2441
2442 /* Restart auto-save timer. */
2445
2446 wm->autosave_scheduled = !success;
2447 return success;
2448}
2449
2450static void wm_autosave_timer_begin_ex(wmWindowManager *wm, double timestep)
2451{
2453
2454 if (U.flag & USER_AUTOSAVE) {
2455 wm->autosavetimer = WM_event_timer_add(wm, nullptr, TIMERAUTOSAVE, timestep);
2456 }
2457}
2458
2463
2465{
2466 if (wm->autosavetimer) {
2467 WM_event_timer_remove(wm, nullptr, wm->autosavetimer);
2468 wm->autosavetimer = nullptr;
2469 }
2470}
2471
2476
2478{
2480
2481 /* If a modal operator is running, don't autosave because we might not be in
2482 * a valid state to save. But try again in 10ms. */
2483 for (wmWindow &win : wm->windows) {
2484 for (wmEventHandler &handler_base : win.runtime->modalhandlers) {
2485 if (handler_base.type == WM_HANDLER_TYPE_OP) {
2486 wmEventHandler_Op *handler = reinterpret_cast<wmEventHandler_Op *>(&handler_base);
2487 if (handler->op) {
2489 return;
2490 }
2491 }
2492 }
2493 }
2494
2495 wm->autosave_scheduled = false;
2496 if (!wm_autosave_write_try(bmain, wm)) {
2497 wm->autosave_scheduled = true;
2498 }
2499 /* Restart the timer after file write, just in case file write takes a long time. */
2501}
2502
2504{
2505 char filepath[FILE_MAX];
2506
2507 wm_autosave_location(filepath);
2508
2509 if (BLI_exists(filepath)) {
2510 char filepath_quit[FILE_MAX];
2511 BLI_path_join(filepath_quit, sizeof(filepath_quit), BKE_tempdir_base(), BLENDER_QUIT_FILE);
2512
2513 /* For global undo; remove temporarily saved file, otherwise rename. */
2514 if (U.uiflag & USER_GLOBALUNDO) {
2515 BLI_delete(filepath, false, false);
2516 }
2517 else {
2518 BLI_rename_overwrite(filepath, filepath_quit);
2519 }
2520 }
2521}
2522
2524{
2525 const bool success = WM_autosave_write(CTX_wm_manager(C), CTX_data_main(C), op->reports);
2526 return success ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
2527}
2528
2530{
2531 ot->name = "Save Autosave";
2532 ot->idname = "WM_OT_save_auto_save";
2533 ot->description = "Create an autosave in the temp directory for the current file";
2534
2536}
2537
2539
2540/* -------------------------------------------------------------------- */
2543
2546{
2547 PropertyRNA *prop;
2548
2549 /* So it's possible to reset app-template settings without resetting other defaults. */
2550 prop = RNA_def_boolean(ot->srna,
2551 "use_factory_startup_app_template_only",
2552 false,
2553 "Factory Startup App-Template Only",
2554 "");
2556}
2557
2559
2560/* -------------------------------------------------------------------- */
2567
2568void wm_open_init_load_ui(wmOperator *op, bool use_prefs)
2569{
2570 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "load_ui");
2571 if (!RNA_property_is_set(op->ptr, prop)) {
2572 bool value = use_prefs ? ((U.flag & USER_FILENOUI) == 0) : ((G.fileflags & G_FILE_NO_UI) == 0);
2573
2574 RNA_property_boolean_set(op->ptr, prop, value);
2575 }
2576}
2577
2587
2591[[nodiscard]] static bool wm_open_init_use_scripts(wmOperator *op, const OpenTrust source_of_trust)
2592{
2593 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_scripts");
2594 if (RNA_property_is_set(op->ptr, prop)) {
2595 return false;
2596 }
2597
2598 bool value = false;
2599 switch (source_of_trust) {
2600 case OpenTrust::FilePath: {
2601 char filepath[FILE_MAX] = "";
2602 if (PropertyRNA *prop_filepath = RNA_struct_find_property(op->ptr, "filepath")) {
2603 RNA_property_string_get(op->ptr, prop_filepath, filepath);
2604 }
2605
2606 if (filepath[0] == '\0') {
2607 /* The file selector before a file is chosen, excluded paths are checked once it's set. */
2608 value = G.autoexec_override.value_or((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0);
2609 }
2610 else {
2611 value = BKE_autoexec_default_trust_source(filepath,
2612 {
2613 .skip_overrides = false,
2614 .canonicalize = true,
2615 .strip_filename = true,
2616 });
2617 }
2618 break;
2619 }
2621 /* Keep the trust of the current session rather than the preference. */
2622 value = (G.f & G_FLAG_SCRIPT_AUTOEXEC) != 0;
2623 break;
2624 }
2625 case OpenTrust::Recover: {
2626 /* It may be in an excluded path so disable auto-execution,
2627 * the user may still opt-in. */
2628 value = G.autoexec_override.value_or(false);
2629 break;
2630 }
2631 }
2632
2633 RNA_property_boolean_set(op->ptr, prop, value);
2634 return true;
2635}
2636
2638
2639/* -------------------------------------------------------------------- */
2642
2648{
2649 Main *bmain = CTX_data_main(C);
2651 wmWindow *win = CTX_wm_window(C);
2652 char filepath[FILE_MAX];
2653 int fileflags;
2654
2655 const char *app_template = U.app_template[0] ? U.app_template : nullptr;
2656 const std::optional<std::string> cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG,
2657 app_template);
2658 if (!cfgdir.has_value()) {
2659 BKE_report(op->reports, RPT_ERROR, "Unable to create user config path");
2660 return OPERATOR_CANCELLED;
2661 }
2662
2663 /* NOTE: either #BKE_CB_EVT_SAVE_POST or #BKE_CB_EVT_SAVE_POST_FAIL must run.
2664 * Runs at the end of this function, don't return beforehand. */
2667
2668 /* Check current window and close it if temp. */
2669 if (win && WM_window_is_temp_screen(win)) {
2671 }
2672
2673 /* Update keymaps in user preferences. */
2675
2676 BLI_path_join(filepath, sizeof(filepath), cfgdir->c_str(), BLENDER_STARTUP_FILE);
2677
2678 CLOG_INFO_NOCHECK(&LOG, "Writing startup file: \"%s\" ", filepath);
2679
2681
2682 /* Force save as regular blend file. */
2683 fileflags = G.fileflags & ~G_FILE_COMPRESS;
2684
2685 BlendFileWriteParams blend_write_params{};
2686 /* Make all paths absolute when saving the startup file.
2687 * On load the `G.main->filepath` will be empty so the paths
2688 * won't have a base for resolving the relative paths. */
2689 blend_write_params.remap_mode = BLO_WRITE_PATH_REMAP_ABSOLUTE;
2690 /* Don't apply any path changes to the current blend file. */
2691 blend_write_params.use_save_as_copy = true;
2692
2693 const bool success = BLO_write_file(
2694 bmain, filepath, fileflags, &blend_write_params, op->reports);
2695
2697
2698 if (success) {
2699 BKE_report(op->reports, RPT_INFO, "Startup file saved");
2700 return OPERATOR_FINISHED;
2701 }
2702 CLOG_WARN(&LOG, "Failed to write startup file");
2703 return OPERATOR_CANCELLED;
2704}
2705
2707 wmOperator *op,
2708 const wmEvent * /*event*/)
2709{
2710 if (!U.app_template[0]) {
2712 op,
2713 IFACE_("Overwrite Startup File"),
2714 IFACE_("Blender will start next time as it is now."),
2715 IFACE_("Overwrite"),
2717 false);
2718 }
2719
2720 /* A different message if this is overriding a specific template startup file. */
2721 char display_name[FILE_MAX];
2722 BLI_path_to_display_name(display_name, sizeof(display_name), IFACE_(U.app_template));
2723 std::string message = fmt::format(
2724 fmt::runtime(IFACE_("Template \"{}\" will start next time as it is now.")),
2725 IFACE_(display_name));
2727 op,
2728 IFACE_("Overwrite Template Startup File"),
2729 message.c_str(),
2730 IFACE_("Overwrite"),
2732 false);
2733}
2734
2736{
2737 ot->name = "Save Startup File";
2738 ot->idname = "WM_OT_save_homefile";
2739 ot->description = "Make the current file the default startup file";
2740
2743}
2744
2746
2747/* -------------------------------------------------------------------- */
2750
2751/* Only save the prefs block. operator entry. */
2753{
2755
2756 /* Update keymaps in user preferences. */
2758
2759 const bool success = BKE_blendfile_userdef_write_all(op->reports);
2760
2761 return success ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
2762}
2763
2765{
2766 ot->name = "Save Preferences";
2767 ot->idname = "WM_OT_save_userpref";
2768 ot->description = "Make the current preferences default";
2769
2772}
2773
2775
2776/* -------------------------------------------------------------------- */
2779
2783static void wm_userpref_read_exceptions(UserDef *userdef_curr, const UserDef *userdef_prev)
2784{
2785#define USERDEF_RESTORE(member) \
2786 { \
2787 userdef_curr->member = userdef_prev->member; \
2788 } \
2789 ((void)0)
2790
2791 /* Current visible preferences category. */
2792 USERDEF_RESTORE(space_data.section_active);
2793
2794#undef USERDEF_RESTORE
2795}
2796
2798 Main *bmain,
2799 PointerRNA *ptr_a,
2800 PointerRNA *ptr_b)
2801{
2803 PropertyRNA *iterprop = RNA_struct_iterator_property(ptr_a->type);
2804 BLI_assert(ptr_a->type == ptr_b->type);
2805 RNA_property_collection_begin(ptr_a, iterprop, &iter);
2806 for (; iter.valid; RNA_property_collection_next(&iter)) {
2807 PropertyRNA *prop = static_cast<PropertyRNA *>(iter.ptr.data);
2808 if (STREQ(RNA_property_identifier(prop), "rna_type")) {
2809 continue;
2810 }
2811 switch (RNA_property_type(prop)) {
2812 case PROP_POINTER: {
2813 PointerRNA ptr_sub_a = RNA_property_pointer_get(ptr_a, prop);
2814 PointerRNA ptr_sub_b = RNA_property_pointer_get(ptr_b, prop);
2815 rna_struct_update_when_changed(C, bmain, &ptr_sub_a, &ptr_sub_b);
2816 break;
2817 }
2818 case PROP_COLLECTION:
2819 /* Don't handle collections. */
2820 break;
2821 default: {
2822 if (!RNA_property_equals(bmain, ptr_a, ptr_b, prop, RNA_EQ_STRICT)) {
2823 RNA_property_update(C, ptr_b, prop);
2824 }
2825 }
2826 }
2827 }
2829}
2830
2832 Main *bmain,
2833 UserDef *userdef_prev,
2834 UserDef *userdef_curr)
2835{
2836 PointerRNA ptr_a = RNA_pointer_create_discrete(nullptr, RNA_Preferences, userdef_prev);
2837 PointerRNA ptr_b = RNA_pointer_create_discrete(nullptr, RNA_Preferences, userdef_curr);
2838 const bool is_dirty = userdef_curr->runtime.is_dirty;
2839
2840 rna_struct_update_when_changed(C, bmain, &ptr_a, &ptr_b);
2841
2844
2845 userdef_curr->runtime.is_dirty = is_dirty;
2846}
2847
2849{
2850 Main *bmain = CTX_data_main(C);
2851 const bool use_data = false;
2852 const bool use_userdef = true;
2853 const bool use_factory_settings = STREQ(op->type->idname, "WM_OT_read_factory_userpref");
2854 const bool use_factory_settings_app_template_only =
2855 (use_factory_settings && RNA_boolean_get(op->ptr, "use_factory_startup_app_template_only"));
2856
2858
2859 UserDef U_backup = dna::shallow_copy(U);
2860
2861 wmHomeFileRead_Params read_homefile_params{};
2862 read_homefile_params.use_data = use_data;
2863 read_homefile_params.use_userdef = use_userdef;
2864 read_homefile_params.use_factory_settings = use_factory_settings;
2865 read_homefile_params.use_factory_settings_app_template_only =
2866 use_factory_settings_app_template_only;
2867 read_homefile_params.use_empty_data = false;
2868 read_homefile_params.filepath_startup_override = nullptr;
2870 wm_homefile_read(C, &read_homefile_params, op->reports);
2871
2872 wm_userpref_read_exceptions(&U, &U_backup);
2873 SET_FLAG_FROM_TEST(G.f, use_factory_settings, G_FLAG_USERPREF_NO_SAVE_ON_EXIT);
2874
2875 wm_userpref_update_when_changed(C, bmain, &U_backup, &U);
2876
2877 if (use_factory_settings) {
2878 U.runtime.is_dirty = true;
2879
2880 /* Default to Interface if Developer Tools section is active before Load Factory Preferences.
2881 */
2882 if (U.space_data.section_active == USER_SECTION_DEVELOPER_TOOLS &&
2883 !(U.flag & USER_DEVELOPER_UI))
2884 {
2885 U.space_data.section_active = USER_SECTION_INTERFACE;
2886 }
2887 }
2888
2890
2891 /* Needed to recalculate UI scaling values (eg, #UserDef.inv_scale_factor). */
2892 wm_window_clear_drawable(bmain->wm.first());
2893
2896
2897 return OPERATOR_FINISHED;
2898}
2899
2901 wmOperator *op,
2902 const wmEvent * /*event*/)
2903{
2905 op,
2906 IFACE_("Revert to Saved Preferences"),
2907 IFACE_("Reload preferences from the last saved state"),
2908 IFACE_("Revert"),
2910 false);
2911}
2912
2914{
2915 ot->name = "Load Preferences";
2916 ot->idname = "WM_OT_read_userpref";
2917 ot->description = "Load last saved preferences";
2918
2921}
2922
2924 wmOperator *op,
2925 const wmEvent * /*event*/)
2926{
2927 std::string title;
2928
2929 const bool template_only = U.app_template[0] &&
2930 RNA_boolean_get(op->ptr, "use_factory_startup_app_template_only");
2931
2932 if (template_only) {
2933 char display_name[FILE_MAX];
2934 BLI_path_to_display_name(display_name, sizeof(display_name), IFACE_(U.app_template));
2935 title = fmt::format(fmt::runtime(IFACE_("Load Factory \"{}\" Preferences.")),
2936 IFACE_(display_name));
2937 }
2938 else {
2939 title = IFACE_("Load Factory Blender Preferences");
2940 }
2941
2943 C,
2944 op,
2945 title.c_str(),
2946 IFACE_("To make changes to Preferences permanent, use \"Save Preferences\""),
2947 IFACE_("Load"),
2949 false);
2950}
2951
2953{
2954 ot->name = "Load Factory Preferences";
2955 ot->idname = "WM_OT_read_factory_userpref";
2956 ot->description =
2957 "Load factory default preferences. "
2958 "To make changes to preferences permanent, use \"Save Preferences\"";
2959
2962
2964}
2965
2967
2968/* -------------------------------------------------------------------- */
2971
2978
2980{
2981 ot->name = "Reload History File";
2982 ot->idname = "WM_OT_read_history";
2983 ot->description = "Reloads history and bookmarks";
2984
2987
2988 /* This operator is only used for loading settings from a previous blender install. */
2989 ot->flag = OPTYPE_INTERNAL;
2990}
2991
2993
2994/* -------------------------------------------------------------------- */
2999
3001{
3002 const bool use_factory_startup_and_userdef = STREQ(op->type->idname,
3003 "WM_OT_read_factory_settings");
3004 const bool use_factory_settings = use_factory_startup_and_userdef ||
3005 RNA_boolean_get(op->ptr, "use_factory_startup");
3006 const bool use_factory_settings_app_template_only =
3007 (use_factory_startup_and_userdef &&
3008 RNA_boolean_get(op->ptr, "use_factory_startup_app_template_only"));
3009
3010 bool use_userdef = false;
3011 char filepath_buf[FILE_MAX];
3012 const char *filepath = nullptr;
3013 UserDef U_backup = dna::shallow_copy(U);
3014
3015 if (!use_factory_settings) {
3016 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "filepath");
3017
3018 /* This can be used when loading of a start-up file should only change
3019 * the scene content but keep the blender UI as it is. */
3020 wm_open_init_load_ui(op, true);
3021 SET_FLAG_FROM_TEST(G.fileflags, !RNA_boolean_get(op->ptr, "load_ui"), G_FILE_NO_UI);
3022
3023 if (RNA_property_is_set(op->ptr, prop)) {
3024 RNA_property_string_get(op->ptr, prop, filepath_buf);
3025 filepath = filepath_buf;
3026 if (BLI_access(filepath, R_OK)) {
3028 op->reports, RPT_ERROR, "Cannot read alternative start-up file: \"%s\"", filepath);
3029 return OPERATOR_CANCELLED;
3030 }
3031 }
3032 }
3033 else {
3034 if (use_factory_startup_and_userdef) {
3035 /* Always load UI for factory settings (prefs will re-init). */
3036 G.fileflags &= ~G_FILE_NO_UI;
3037 /* Always load preferences with factory settings. */
3038 use_userdef = true;
3039 }
3040 }
3041
3042 /* Close any user-loaded fonts. */
3044
3045 char app_template_buf[sizeof(U.app_template)];
3046 const char *app_template;
3047 PropertyRNA *prop_app_template = RNA_struct_find_property(op->ptr, "app_template");
3048 const bool use_splash = !use_factory_settings && RNA_boolean_get(op->ptr, "use_splash");
3049 const bool use_empty_data = RNA_boolean_get(op->ptr, "use_empty");
3050
3051 if (prop_app_template && RNA_property_is_set(op->ptr, prop_app_template)) {
3052 RNA_property_string_get(op->ptr, prop_app_template, app_template_buf);
3053 app_template = app_template_buf;
3054
3055 if (!use_factory_settings) {
3056 /* Always load preferences when switching templates with own preferences. */
3057 use_userdef = BKE_appdir_app_template_has_userpref(app_template) ||
3059 }
3060
3061 /* Turn override off, since we're explicitly loading a different app-template. */
3063 }
3064 else {
3065 /* Normally nullptr, only set when overriding from the command-line. */
3066 app_template = WM_init_state_app_template_get();
3067 }
3068
3069 if (use_userdef) {
3071 }
3072
3073 wmHomeFileRead_Params read_homefile_params{};
3074 read_homefile_params.use_data = true;
3075 read_homefile_params.use_userdef = use_userdef;
3076 read_homefile_params.use_factory_settings = use_factory_settings;
3077 read_homefile_params.use_factory_settings_app_template_only =
3078 use_factory_settings_app_template_only;
3079 read_homefile_params.use_empty_data = use_empty_data;
3080 read_homefile_params.filepath_startup_override = filepath;
3081 read_homefile_params.app_template_override = app_template;
3082 wm_homefile_read(C, &read_homefile_params, op->reports);
3083
3084 if (use_splash) {
3086 }
3087
3088 if (use_userdef) {
3089 wm_userpref_read_exceptions(&U, &U_backup);
3090 SET_FLAG_FROM_TEST(G.f, use_factory_settings, G_FLAG_USERPREF_NO_SAVE_ON_EXIT);
3091
3092 if (use_factory_settings) {
3093 U.runtime.is_dirty = true;
3094
3095 /* Default to Interface if Developer Tools section is active before Load Factory Settings. */
3096 if (U.space_data.section_active == USER_SECTION_DEVELOPER_TOOLS &&
3097 !(U.flag & USER_DEVELOPER_UI))
3098 {
3099 U.space_data.section_active = USER_SECTION_INTERFACE;
3100 }
3101 }
3102 }
3103
3104 if (use_userdef) {
3105 BLT_lang_set(nullptr);
3107 }
3108
3109 if (G.fileflags & G_FILE_NO_UI) {
3111 }
3112
3113 return OPERATOR_FINISHED;
3114}
3115
3117{
3119 "WM_OT_read_homefile",
3121 static_cast<IDProperty *>(user_data),
3122 nullptr);
3123}
3124
3134
3136{
3137 PropertyRNA *prop;
3138
3139 prop = RNA_def_string(ot->srna, "app_template", "Template", sizeof(U.app_template), "", "");
3141
3142 prop = RNA_def_boolean(
3143 ot->srna,
3144 "use_empty",
3145 false,
3146 "Empty",
3147 "After loading, remove everything except scenes, windows, and workspaces. This makes it "
3148 "possible to load the startup file with its scene configuration and window layout intact, "
3149 "but no objects, materials, animations, ...");
3151}
3152
3154{
3155 PropertyRNA *prop;
3156 ot->name = "Reload Start-Up File";
3157 ot->idname = "WM_OT_read_homefile";
3158 ot->description = "Open the default file";
3159
3162
3163 prop = RNA_def_string_file_path(ot->srna,
3164 "filepath",
3165 nullptr,
3166 FILE_MAX,
3167 "File Path",
3168 "Path to an alternative start-up file");
3170
3171 /* So scripts can use an alternative start-up file without the UI. */
3172 prop = RNA_def_boolean(
3173 ot->srna, "load_ui", true, "Load UI", "Load user interface setup from the .blend file");
3175
3176 /* So the splash can be kept open after loading a file (for templates). */
3177 prop = RNA_def_boolean(ot->srna, "use_splash", false, "Splash", "");
3179
3180 /* So scripts can load factory-startup without resetting preferences
3181 * (which has other implications such as reloading all add-ons).
3182 * Match naming for `--factory-startup` command line argument. */
3183 prop = RNA_def_boolean(ot->srna,
3184 "use_factory_startup",
3185 false,
3186 "Factory Startup",
3187 "Load the default ('factory startup') blend file. "
3188 "This is independent of the normal start-up file that the user can save");
3191
3193
3194 /* Omit poll to run in background mode. */
3195}
3196
3198 wmOperator *op,
3199 const wmEvent * /*event*/)
3200{
3202 CTX_wm_manager(C));
3203 std::string title;
3204 const bool template_only = U.app_template[0] &&
3205 RNA_boolean_get(op->ptr, "use_factory_startup_app_template_only");
3206
3207 if (template_only) {
3208 char display_name[FILE_MAX];
3209 BLI_path_to_display_name(display_name, sizeof(display_name), IFACE_(U.app_template));
3210 title = fmt::format(fmt::runtime(IFACE_("Load Factory \"{}\" Startup File and Preferences")),
3211 IFACE_(display_name));
3212 }
3213 else {
3214 title = IFACE_("Load Factory Default Startup File and Preferences");
3215 }
3216
3218 C,
3219 op,
3220 title.c_str(),
3221 unsaved ? IFACE_("To make changes to Preferences permanent, use \"Save Preferences\".\n"
3222 "Warning: Your file is unsaved! Proceeding will abandon your changes.") :
3223 IFACE_("To make changes to Preferences permanent, use \"Save Preferences\"."),
3224 IFACE_("Load"),
3226 false);
3227}
3228
3230{
3231 ot->name = "Load Factory Settings";
3232 ot->idname = "WM_OT_read_factory_settings";
3233 ot->description =
3234 "Load factory default startup file and preferences. "
3235 "To make changes permanent, use \"Save Startup File\" and \"Save Preferences\"";
3236
3239 /* Omit poll to run in background mode. */
3240
3242
3244}
3245
3247
3248/* -------------------------------------------------------------------- */
3251
3256 const char *filepath,
3257 const bool use_scripts_autoexec_check,
3258 ReportList *reports)
3259{
3260 /* XXX: wm in context is not set correctly after #WM_file_read -> crash. */
3261 /* Do it before for now, but is this correct with multiple windows? */
3263
3264 const bool success = WM_file_read(C, filepath, use_scripts_autoexec_check, reports);
3265
3266 return success;
3267}
3268
3269/* Generic operator state utilities. */
3270
3271static void create_operator_state(wmOperatorType *ot, int first_state)
3272{
3273 PropertyRNA *prop = RNA_def_int(
3274 ot->srna, "state", first_state, INT32_MIN, INT32_MAX, "State", "", INT32_MIN, INT32_MAX);
3277}
3278
3280{
3281 return RNA_int_get(op->ptr, "state");
3282}
3283
3285{
3286 RNA_int_set(op->ptr, "state", state);
3287}
3288
3293
3295 wmOperator *op,
3296 OperatorDispatchTarget *targets)
3297{
3298 int state = get_operator_state(op);
3299 for (int i = 0; targets[i].run; i++) {
3300 OperatorDispatchTarget target = targets[i];
3301 if (target.state == state) {
3302 return target.run(C, op);
3303 }
3304 }
3306 return OPERATOR_CANCELLED;
3307}
3308
3310
3311/* -------------------------------------------------------------------- */
3314
3315enum {
3319};
3320
3321static wmOperatorStatus wm_open_mainfile_dispatch(bContext *C, wmOperator *op);
3322
3324{
3326 "WM_OT_open_mainfile",
3328 static_cast<IDProperty *>(user_data),
3329 nullptr);
3330}
3331
3346
3348{
3350
3351 Main *bmain = CTX_data_main(C);
3352 const char *blendfile_path = BKE_main_blendfile_path(bmain);
3353
3354 if (CTX_wm_window(C) == nullptr) {
3355 /* In rare cases this could happen, when trying to invoke in background
3356 * mode on load for example. Don't use poll for this because exec()
3357 * can still run without a window. */
3358 BKE_report(op->reports, RPT_ERROR, "Context window not set");
3359 return OPERATOR_CANCELLED;
3360 }
3361
3362 /* If possible, get the name of the most recently used `.blend` file. */
3363 const std::string recent_filepath = wm_recent_filepath_get(bmain);
3364 if (!recent_filepath.empty()) {
3365 blendfile_path = recent_filepath.c_str();
3366 }
3367
3368 RNA_string_set(op->ptr, "filepath", blendfile_path);
3369 wm_open_init_load_ui(op, true);
3370 const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, OpenTrust::FilePath);
3371 UNUSED_VARS(use_scripts_autoexec_check); /* The user can set this in the UI. */
3372 op->customdata = nullptr;
3373
3375
3377}
3378
3380{
3381 char filepath[FILE_MAX];
3382 bool success;
3383
3384 RNA_string_get(op->ptr, "filepath", filepath);
3385 BLI_path_canonicalize_native(filepath, sizeof(filepath));
3386
3387 /* For file opening, also print in console for warnings, not only errors. */
3389
3390 /* Re-use last loaded setting so we can reload a file without changing. */
3391 wm_open_init_load_ui(op, false);
3392 const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, OpenTrust::CurrentSession);
3393
3394 SET_FLAG_FROM_TEST(G.fileflags, !RNA_boolean_get(op->ptr, "load_ui"), G_FILE_NO_UI);
3396 success = wm_file_read_opwrap(C, filepath, use_scripts_autoexec_check, op->reports);
3397
3398 if (success) {
3399 if (G.fileflags & G_FILE_NO_UI) {
3401 }
3403
3405
3406 return OPERATOR_FINISHED;
3407 }
3408 return OPERATOR_CANCELLED;
3409}
3410
3417
3422
3424 wmOperator *op,
3425 const wmEvent * /*event*/)
3426{
3427 return wm_open_mainfile_dispatch(C, op);
3428}
3429
3434
3436 wmOperatorType * /*ot*/,
3437 PointerRNA *ptr)
3438{
3439 if (!RNA_struct_property_is_set(ptr, "filepath")) {
3440 return "";
3441 }
3442
3443 char filepath[FILE_MAX];
3444 RNA_string_get(ptr, "filepath", filepath);
3445
3446 BLI_stat_t stats;
3447 if (BLI_stat(filepath, &stats) == -1) {
3448 return fmt::format("{}\n\n{}", filepath, TIP_("File Not Found"));
3449 }
3450
3451 /* Date. */
3452 const tm mod_time = date_string::localtime_safe(stats.st_mtime);
3453 const time_t ts_now = time(nullptr);
3454 const tm now_tm = date_string::localtime_safe(ts_now);
3455 const char *lang = BLT_lang_get();
3456 std::string modified_s = blender::date_string::datetime(mod_time,
3457 lang,
3458 date_string::DateFormat(U.date_format),
3459 date_string::TimeFormat(U.time_format),
3460 &now_tm,
3461 TIP_("Today"),
3462 TIP_("Yesterday"));
3463
3464 /* Size. */
3465 char size_str[FILELIST_DIRENTRY_SIZE_LEN];
3466 BLI_filelist_entry_size_to_string(nullptr, uint64_t(stats.st_size), false, size_str);
3467
3468 return fmt::format(
3469 "{}\n\n{}: {}\n{}: {}", filepath, TIP_("Modified"), modified_s, TIP_("Size"), size_str);
3470}
3471
3472/* Currently fits in a pointer. */
3475};
3476BLI_STATIC_ASSERT(sizeof(FileRuntime) <= sizeof(void *), "Struct must not exceed pointer size");
3477
3479{
3480 FileRuntime *file_info = reinterpret_cast<FileRuntime *>(&op->customdata);
3481 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_scripts");
3482 bool is_untrusted = false;
3483 char filepath[FILE_MAX];
3484
3485 RNA_string_get(op->ptr, "filepath", filepath);
3486
3487 /* Excluded paths can't be trusted, unless the command line overrides the preference. */
3488 if (((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) && !G.autoexec_override.has_value()) {
3489 /* The file selector may start without a path, e.g. an unsaved session. */
3490 if ((filepath[0] != '\0') && BKE_autoexec_match(filepath, true, true)) {
3491 RNA_property_boolean_set(op->ptr, prop, false);
3492 is_untrusted = true;
3493 }
3494 }
3495
3496 if (file_info) {
3497 file_info->is_untrusted = is_untrusted;
3498 }
3499
3500 return is_untrusted;
3501}
3502
3503static void wm_open_mainfile_ui(bContext * /*C*/, wmOperator *op)
3504{
3505 FileRuntime *file_info = reinterpret_cast<FileRuntime *>(&op->customdata);
3506 ui::Layout &layout = *op->layout;
3507 const char *autoexec_text;
3508
3509 layout.prop(op->ptr, "load_ui", UI_ITEM_NONE, std::nullopt, ICON_NONE);
3510
3511 ui::Layout &col = layout.column(false);
3512 if (file_info->is_untrusted) {
3513 autoexec_text = IFACE_("Trusted Source [Untrusted Path]");
3514 col.active_set(false);
3515 col.enabled_set(false);
3516 }
3517 else {
3518 autoexec_text = IFACE_("Trusted Source");
3519 }
3520
3521 col.prop(op->ptr, "use_scripts", UI_ITEM_NONE, autoexec_text, ICON_NONE);
3522}
3523
3525{
3527 "use_scripts",
3528 false,
3529 "Trusted Source",
3530 "Allow .blend file to execute scripts automatically, default available from "
3531 "system preferences");
3532}
3533
3535{
3536 ot->name = "Open";
3537 ot->idname = "WM_OT_open_mainfile";
3538 ot->description = "Open a Blender file";
3540
3544 ot->ui = wm_open_mainfile_ui;
3545 /* Omit window poll so this can work in background mode. */
3546
3554
3556 ot->srna, "load_ui", true, "Load UI", "Load user interface setup in the .blend file");
3557
3559
3561 ot->srna, "display_file_selector", true, "Display File Selector", "");
3563
3565}
3566
3568
3569/* -------------------------------------------------------------------- */
3572
3574 wmOperator *op,
3575 const wmEvent * /*event*/)
3576{
3577 std::string message = IFACE_("Any unsaved changes will be lost.");
3579 message += "\n";
3580 message += IFACE_("Warning: There are unsaved external image(s).");
3581 }
3582
3584 op,
3585 IFACE_("Revert to the Saved File"),
3586 message.c_str(),
3587 IFACE_("Revert"),
3589 false);
3590}
3591
3593{
3594 Main *bmain = CTX_data_main(C);
3595 bool success;
3596 char filepath[FILE_MAX];
3597
3598 const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, OpenTrust::CurrentSession);
3599
3601
3602 STRNCPY(filepath, BKE_main_blendfile_path(bmain));
3603 success = wm_file_read_opwrap(C, filepath, use_scripts_autoexec_check, op->reports);
3604
3605 if (success) {
3606 return OPERATOR_FINISHED;
3607 }
3608 return OPERATOR_CANCELLED;
3609}
3610
3612{
3613 const char *blendfile_path = BKE_main_blendfile_path_from_global();
3614 return (blendfile_path[0] != '\0');
3615}
3616
3618{
3619 ot->name = "Revert";
3620 ot->idname = "WM_OT_revert_mainfile";
3621 ot->description = "Reload the saved file";
3622
3626
3628}
3629
3631
3632/* -------------------------------------------------------------------- */
3635
3637 const bool use_scripts_autoexec_check,
3638 ReportList *reports)
3639{
3640 char filepath[FILE_MAX];
3641 BLI_path_join(filepath, sizeof(filepath), BKE_tempdir_base(), BLENDER_QUIT_FILE);
3642 G.fileflags |= G_FILE_RECOVER_READ;
3643 const bool success = wm_file_read_opwrap(C, filepath, use_scripts_autoexec_check, reports);
3644 G.fileflags &= ~G_FILE_RECOVER_READ;
3645 return success;
3646}
3647
3649 wmOperator *op,
3650 const bool use_scripts_autoexec_check)
3651{
3653 if (WM_file_recover_last_session(C, use_scripts_autoexec_check, op->reports)) {
3654 if (!G.background) {
3655 wmOperatorType *ot = op->type;
3656 PointerRNA *props_ptr = MEM_new<PointerRNA>(__func__, WM_operator_properties_create_ptr(ot));
3657 RNA_boolean_set(props_ptr, "use_scripts", true);
3658 wm_test_autorun_revert_action_set(ot, props_ptr);
3659 }
3660 return OPERATOR_FINISHED;
3661 }
3662 return OPERATOR_CANCELLED;
3663}
3664
3666{
3667 const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, OpenTrust::Recover);
3668 return wm_recover_last_session_impl(C, op, use_scripts_autoexec_check);
3669}
3670
3672{
3674 "WM_OT_recover_last_session",
3676 static_cast<IDProperty *>(user_data),
3677 nullptr);
3678}
3679
3681 wmOperator *op,
3682 const wmEvent * /*event*/)
3683{
3684 const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, OpenTrust::Recover);
3685
3688 {
3689 return OPERATOR_INTERFACE;
3690 }
3691 return wm_recover_last_session_impl(C, op, use_scripts_autoexec_check);
3692}
3693
3695{
3696 ot->name = "Recover Last Session";
3697 ot->idname = "WM_OT_recover_last_session";
3698 ot->description = "Open the last closed file (\"" BLENDER_QUIT_FILE "\")";
3699
3702
3704}
3705
3707
3708/* -------------------------------------------------------------------- */
3711
3713{
3714 char filepath[FILE_MAX];
3715 bool success;
3716
3717 RNA_string_get(op->ptr, "filepath", filepath);
3718 BLI_path_canonicalize_native(filepath, sizeof(filepath));
3719
3720 const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, OpenTrust::Recover);
3722
3723 G.fileflags |= G_FILE_RECOVER_READ;
3724
3725 success = wm_file_read_opwrap(C, filepath, use_scripts_autoexec_check, op->reports);
3726
3727 G.fileflags &= ~G_FILE_RECOVER_READ;
3728
3729 if (success) {
3730 if (!G.background) {
3731 wmOperatorType *ot = op->type;
3732 PointerRNA *props_ptr = MEM_new<PointerRNA>(__func__, WM_operator_properties_create_ptr(ot));
3733 RNA_boolean_set(props_ptr, "use_scripts", true);
3734 wm_test_autorun_revert_action_set(ot, props_ptr);
3735 }
3736 return OPERATOR_FINISHED;
3737 }
3738 return OPERATOR_CANCELLED;
3739}
3740
3742 wmOperator *op,
3743 const wmEvent * /*event*/)
3744{
3745 char filepath[FILE_MAX];
3746
3747 wm_autosave_location(filepath);
3748 RNA_string_set(op->ptr, "filepath", filepath);
3749 const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, OpenTrust::Recover);
3750 UNUSED_VARS(use_scripts_autoexec_check); /* The user can set this in the UI. */
3752
3754}
3755
3757{
3758 ot->name = "Recover Auto Save";
3759 ot->idname = "WM_OT_recover_auto_save";
3760 ot->description = "Open an automatically saved file to recover it";
3761
3764
3772
3774}
3775
3777
3778/* -------------------------------------------------------------------- */
3781
3783{
3784 wmGenericCallback *action = static_cast<wmGenericCallback *>(arg);
3786}
3787
3789{
3790 IDProperty *properties = static_cast<IDProperty *>(user_data);
3791 IDP_FreeProperty(properties);
3792}
3793
3795
3796/* -------------------------------------------------------------------- */
3799
3801{
3802 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "show_save_modified_images_dialog");
3803 const bool show_save_image_dialog = prop ? RNA_property_boolean_get(op->ptr, prop) : false;
3804
3805 /* Toggle RNA property "show_save_modified_images_dialog" to false to prevent opening the popup
3806 * dialog in an infinite loop. */
3807 if (show_save_image_dialog) {
3808 RNA_property_boolean_set(op->ptr, prop, false);
3809 }
3810
3811 return !G.background && U.save_modified_images == USER_SAVE_MODIFIED_IMAGES_ASK &&
3812 show_save_image_dialog && ED_image_save_all_modified_info(bmain, nullptr) > 0;
3813}
3814
3815static void wm_block_save_modified_images_cancel(bContext *C, void *arg_block, void * /*arg_data*/)
3816{
3817 wmWindow *win = CTX_wm_window(C);
3818 popup_block_close(C, win, static_cast<ui::Block *>(arg_block));
3819}
3820
3821static void wm_block_save_modified_images_save(bContext *C, void *arg_block, void *arg_data)
3822{
3823 const Main *bmain = CTX_data_main(C);
3824 wmWindowManager *wm = bmain->wm.first();
3826 static_cast<wmGenericCallback *>(arg_data));
3827
3828 wmWindow *win = CTX_wm_window(C);
3829 popup_block_close(C, win, static_cast<ui::Block *>(arg_block));
3830
3831 if (wm->runtime->save_modified_images_when_file_is_saved && ED_image_should_save_modified(bmain))
3832 {
3833 ReportList *reports = CTX_wm_reports(C);
3834 bool is_successful = ED_image_save_all_modified(C, reports);
3835 if (!is_successful) {
3837 }
3838 }
3839
3840 callback->exec(C, callback->user_data);
3841 WM_generic_callback_free(callback);
3842}
3843
3845 wmGenericCallback *post_action)
3846{
3847 ui::Button *but = uiDefIconTextBut(
3848 block, ui::ButtonType::But, ICON_NONE, IFACE_("Cancel"), 0, 0, 0, UI_UNIT_Y, nullptr, "");
3849 button_func_set(but, wm_block_save_modified_images_cancel, block, post_action);
3850 button_drawflag_disable(but, ui::BUT_TEXT_LEFT);
3851}
3852
3854 wmGenericCallback *post_action)
3855{
3856 ui::Button *but = uiDefIconTextBut(
3857 block, ui::ButtonType::But, ICON_NONE, IFACE_("Save"), 0, 0, 0, UI_UNIT_Y, nullptr, "");
3858 button_func_set(but, wm_block_save_modified_images_save, block, post_action);
3859 button_drawflag_disable(but, ui::BUT_TEXT_LEFT);
3860 button_flag_enable(but, ui::BUT_ACTIVE_DEFAULT);
3861}
3862
3864{
3865 for (Report &report : reports.list) {
3866 ui::Layout &row = layout.column(false);
3867 row.scale_y_set(0.6f);
3868 row.separator();
3869
3870 /* Error messages created in ED_image_save_all_modified_info() can be long,
3871 * but are made to separate into two parts at first colon between text and paths.
3872 */
3873 char *message = BLI_strdupn(report.message, report.len);
3874 char *path_info = strstr(message, ": ");
3875 if (path_info) {
3876 /* Terminate message string at colon. */
3877 path_info[1] = '\0';
3878 /* Skip over the ": ". */
3879 path_info += 2;
3880 }
3881 uiItemL_ex(&row, message, ICON_NONE, false, true);
3882 if (path_info) {
3883 uiItemL_ex(&row, path_info, ICON_NONE, false, true);
3884 }
3885 MEM_delete(message);
3886 }
3887}
3888
3889static const char *save_modified_images_dialog_name = "save_modified_images_popup";
3890
3892{
3893 wmGenericCallback *post_action = static_cast<wmGenericCallback *>(arg);
3894 Main *bmain = CTX_data_main(C);
3895 wmWindowManager *wm = bmain->wm.first();
3896
3897 ui::Block *block = block_begin(
3899 block_flag_enable(
3901 block_theme_style_set(block, ui::BLOCK_THEME_STYLE_POPUP);
3902
3903 ui::Layout &layout = *uiItemsAlertBox(
3905
3906 /* Title. */
3907 uiItemL_ex(
3908 &layout, RPT_("Images are not automatically saved with the file"), ICON_NONE, true, false);
3909
3910 /* Image Saving Warnings. */
3911 ReportList reports;
3912 BKE_reports_init(&reports, RPT_STORE);
3913 uint modified_images_count = ED_image_save_all_modified_info(bmain, &reports);
3914 wm_block_image_save_errors(layout, reports);
3915
3916 /* Modified Images Checkbox. */
3917 std::string message = fmt::format(fmt::runtime(RPT_("Save {} modified image(s)")),
3918 modified_images_count);
3919 layout.separator();
3920 uiDefButV(block,
3922 message,
3923 0,
3924 0,
3925 0,
3926 UI_UNIT_Y,
3927 &wm->runtime->save_modified_images_when_file_is_saved,
3928 0,
3929 0,
3930 "");
3931
3932 BKE_reports_free(&reports);
3933
3934 layout.separator(2.0f);
3935
3936 /* Buttons. */
3937#ifdef _WIN32
3938 const bool windows_layout = true;
3939#else
3940 const bool windows_layout = false;
3941#endif
3942
3943 if (windows_layout) {
3944 /* Windows standard layout. */
3945
3946 ui::Layout &split = layout.split(0.0f, true);
3947 split.scale_y_set(1.2f);
3948
3949 split.column(false);
3951
3952 split.column(false);
3953 /* Empty space. */
3954
3955 split.column(false);
3957 }
3958 else {
3959 /* Non-Windows layout (macOS and Linux). */
3960
3961 ui::Layout &split = layout.split(0.3f, true);
3962 split.scale_y_set(1.2f);
3963
3964 split.column(false);
3965 /* Empty space. */
3966
3967 ui::Layout &split_right = split.split(0.1f, true);
3968
3969 split_right.column(false);
3970 /* Empty space. */
3971
3972 split_right.column(false);
3974
3975 split_right.column(false);
3977 }
3978
3979 block_bounds_set_centered(block, 14 * UI_SCALE_FAC);
3980 return block;
3981}
3982
3995
3997 wmOperator *op,
3998 wmGenericCallbackFn post_action_fn)
3999{
4000 wmGenericCallback *callback = MEM_new<wmGenericCallback>(__func__);
4001 callback->exec = post_action_fn;
4002 callback->user_data = IDP_CopyProperty(op->properties);
4005}
4006
4008
4009/* -------------------------------------------------------------------- */
4014
4015static void wm_filepath_default(const Main *bmain, char *filepath)
4016{
4017 if (bmain->filepath[0] == '\0') {
4018 char filename_untitled[FILE_MAXFILE];
4019 /* While a filename need not be UTF8, at this point the constructed name should be UTF8. */
4020 SNPRINTF_UTF8(filename_untitled, "%s.blend", DATA_("Untitled"));
4021 BLI_path_filename_ensure(filepath, FILE_MAX, filename_untitled);
4022 }
4023}
4024
4026{
4027 PropertyRNA *prop;
4028
4029 prop = RNA_struct_find_property(op->ptr, "compress");
4030 if (!RNA_property_is_set(op->ptr, prop)) {
4031 const char *blendfile_path = BKE_main_blendfile_path_from_global();
4032 if (blendfile_path[0] != '\0') { /* Keep flag for existing file. */
4033 RNA_property_boolean_set(op->ptr, prop, (G.fileflags & G_FILE_COMPRESS) != 0);
4034 }
4035 else { /* Use userdef for new file. */
4036 RNA_property_boolean_set(op->ptr, prop, (U.flag & USER_FILECOMPRESS) != 0);
4037 }
4038 }
4039}
4040
4042{
4043 Main *bmain = CTX_data_main(C);
4044 PropertyRNA *prop;
4045 char filepath[FILE_MAX];
4046
4047 prop = RNA_struct_find_property(op->ptr, "filepath");
4048 if (!RNA_property_is_set(op->ptr, prop)) {
4049 const char *blendfile_path = BKE_main_blendfile_path(bmain);
4050 /* If not saved before, get the name of the most recently used `.blend` file. */
4051 if (blendfile_path[0] == '\0') {
4052 STRNCPY(filepath, wm_recent_filepath_get(bmain).c_str());
4053 }
4054 else {
4055 STRNCPY(filepath, blendfile_path);
4056 }
4057
4058 /* For convenience when using "Save As" on asset system files:
4059 * Replace `.asset.blend` extension with just `.blend`.
4060 * Asset system files must not be overridden (except by the asset system),
4061 * there are further checks to prevent this entirely. */
4062 if (bmain->is_asset_edit_file && StringRef(filepath).endswith(BLENDER_ASSET_FILE_SUFFIX)) {
4063 filepath[strlen(filepath) - strlen(BLENDER_ASSET_FILE_SUFFIX)] = '\0';
4064 BLI_path_extension_ensure(filepath, FILE_MAX, ".blend");
4065 }
4066
4067 wm_filepath_default(bmain, filepath);
4068 RNA_property_string_set(op->ptr, prop, filepath);
4069 }
4070}
4071
4073 wmOperator *op,
4074 const wmEvent * /*event*/)
4075{
4077 wm_operator_save_modified_images_dialog(C, op, [](bContext *C, void *user_data) {
4079 "WM_OT_save_as_mainfile",
4081 static_cast<IDProperty *>(user_data),
4082 nullptr);
4083 });
4084 return OPERATOR_INTERFACE;
4085 }
4086
4088 save_set_filepath(C, op);
4089
4090 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "relative_remap");
4091 if (!RNA_property_is_set(op->ptr, prop)) {
4092 RNA_property_boolean_set(op->ptr, prop, (U.flag & USER_RELPATHS));
4093 }
4094
4096
4098}
4099
4100/* Function used for #WM_OT_save_mainfile too. */
4102{
4103 Main *bmain = CTX_data_main(C);
4104 char filepath[FILE_MAX];
4105 const bool is_save_as = (op->type->invoke == wm_save_as_mainfile_invoke);
4106 const bool use_save_as_copy = is_save_as && RNA_boolean_get(op->ptr, "copy");
4107
4108 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "incremental");
4109 const bool is_incremental = prop ? RNA_property_boolean_get(op->ptr, prop) : false;
4110
4111 if (U.save_modified_images == USER_SAVE_MODIFIED_IMAGES_ALWAYS &&
4112 ED_image_save_all_modified_info(bmain, nullptr) > 0)
4113 {
4114 ReportList *reports = CTX_wm_reports(C);
4115 const bool is_successful = ED_image_save_all_modified(C, reports);
4116 if (!is_successful) {
4117 WM_report_banner_show(bmain->wm.first(), CTX_wm_window(C));
4118 }
4119 }
4120 else if (wm_show_save_modified_images_dialog(bmain, op)) {
4121 wm_operator_save_modified_images_dialog(C, op, [](bContext *C, void *user_data) {
4123 "WM_OT_save_mainfile",
4125 static_cast<IDProperty *>(user_data),
4126 nullptr);
4127 });
4128 return OPERATOR_INTERFACE;
4129 }
4130
4131 /* We could expose all options to the users however in most cases remapping
4132 * existing relative paths is a good default.
4133 * Users can manually make their paths relative & absolute if they wish. */
4134 const eBLO_WritePathRemap remap_mode = RNA_boolean_get(op->ptr, "relative_remap") ?
4138
4139 const bool is_filepath_set = RNA_struct_property_is_set(op->ptr, "filepath");
4140 if (is_filepath_set) {
4141 RNA_string_get(op->ptr, "filepath", filepath);
4142 BLI_path_canonicalize_native(filepath, sizeof(filepath));
4143 }
4144 else {
4145 STRNCPY(filepath, BKE_main_blendfile_path(bmain));
4146 }
4147
4148 if (filepath[0] == '\0') {
4149 BKE_report(op->reports,
4150 RPT_ERROR,
4151 "Unable to save an unsaved file with an empty or unset \"filepath\" property");
4152 return OPERATOR_CANCELLED;
4153 }
4154
4155 if ((is_save_as == false) && is_incremental) {
4156 char head[FILE_MAXFILE], tail[FILE_MAXFILE];
4157 ushort digits;
4158 int num = BLI_path_sequence_decode(filepath, head, sizeof(head), tail, sizeof(tail), &digits);
4159 /* Numbers greater than INT_MAX return 0, resulting in always appending "1" to the name. */
4160 if (num == 0 && digits == 0) {
4161 /* This does nothing if there are no numbers at the end of the head. */
4163 }
4164
4165 const int tries_limit = 1000;
4166 int tries = 0;
4167 bool in_use = true;
4168 do {
4169 num++;
4170 tries++;
4171 BLI_path_sequence_encode(filepath, sizeof(filepath), head, tail, digits, num);
4172 in_use = BLI_exists(filepath);
4173 } while (in_use && tries < tries_limit && num < INT_MAX);
4174 if (in_use) {
4175 BKE_report(op->reports, RPT_ERROR, "Unable to find an available incremented file name");
4176 return OPERATOR_CANCELLED;
4177 }
4178 }
4179
4180 const int fileflags_orig = G.fileflags;
4181 int fileflags = G.fileflags;
4182
4183 /* Set compression flag. */
4184 SET_FLAG_FROM_TEST(fileflags, RNA_boolean_get(op->ptr, "compress"), G_FILE_COMPRESS);
4185
4186 const bool success = wm_file_write(
4187 C, filepath, fileflags, remap_mode, use_save_as_copy, op->reports);
4188
4189 if ((op->flag & OP_IS_INVOKE) == 0) {
4190 /* OP_IS_INVOKE is set when the operator is called from the GUI.
4191 * If it is not set, the operator is called from a script and
4192 * shouldn't influence G.fileflags. */
4193 G.fileflags = fileflags_orig;
4194 }
4195
4196 if (success == false) {
4197 return OPERATOR_CANCELLED;
4198 }
4199
4200 const char *filename = BLI_path_basename(filepath);
4201
4202 if (is_incremental) {
4203 BKE_reportf(op->reports, RPT_INFO, "Saved incremental as \"%s\"", filename);
4204 }
4205 else if (is_save_as) {
4206 /* use_save_as_copy depends upon is_save_as. */
4207 if (use_save_as_copy) {
4208 BKE_reportf(op->reports, RPT_INFO, "Saved copy as \"%s\"", filename);
4209 }
4210 else {
4211 BKE_reportf(op->reports, RPT_INFO, "Saved as \"%s\"", filename);
4212 }
4213 }
4214 else {
4215 BKE_reportf(op->reports, RPT_INFO, "Saved \"%s\"", filename);
4216 }
4217
4218 if (!use_save_as_copy) {
4219 /* If saved file is the active one, there are technically no more compatibility issues, the
4220 * file on disk now matches the currently opened data version-wise. */
4221 bmain->has_forward_compatibility_issues = false;
4223
4224 /* If saved file is the active one, notify WM so that saved status and window title can be
4225 * updated. */
4228 /* Restart auto-save timer to avoid unnecessary unexpected freezing (because of auto-save)
4229 * when often saving manually. */
4232 wm->autosave_scheduled = false;
4233 }
4234 }
4235
4237
4238 if (!is_save_as && RNA_boolean_get(op->ptr, "exit")) {
4240 }
4241
4242 return OPERATOR_FINISHED;
4243}
4244
4246{
4247 char filepath[FILE_MAX];
4248 RNA_string_get(op->ptr, "filepath", filepath);
4249 if (!BKE_blendfile_extension_check(filepath)) {
4250 /* NOTE(@ideasman42): some users would prefer #BLI_path_extension_replace(),
4251 * we have had some nitpicking bug reports about this.
4252 * Always adding the extension as users may use '.' as part of the file-name. */
4253 BLI_path_extension_ensure(filepath, FILE_MAX, ".blend");
4254 RNA_string_set(op->ptr, "filepath", filepath);
4255 return true;
4256 }
4257 return false;
4258}
4259
4261{
4262 if (RNA_boolean_get(ptr, "copy")) {
4263 return CTX_IFACE_(ot->translation_context, "Save Copy");
4264 }
4265 return "";
4266}
4267
4269 wmOperatorType * /*ot*/,
4270 PointerRNA *ptr)
4271{
4272 if (RNA_boolean_get(ptr, "copy")) {
4273 return BLI_strdup(TIP_(
4274 "Save the current file in the desired location but do not make the saved file active"));
4275 }
4276 return "";
4277}
4278
4280{
4281 PropertyRNA *prop;
4282
4283 ot->name = "Save As";
4284 ot->idname = "WM_OT_save_as_mainfile";
4285 ot->description = "Save the current file in the desired location";
4286
4292 /* Omit window poll so this can work in background mode. */
4293
4297 FILE_SAVE,
4301 RNA_def_boolean(ot->srna, "compress", false, "Compress", "Write compressed .blend file");
4303 "relative_remap",
4304 true,
4305 "Remap Relative",
4306 "Remap relative paths when saving to a different directory");
4307 prop = RNA_def_boolean(
4308 ot->srna,
4309 "copy",
4310 false,
4311 "Save Copy",
4312 "Save a copy of the actual working state but does not make saved file active");
4314
4315 prop = RNA_def_boolean(
4316 ot->srna,
4317 "show_save_modified_images_dialog",
4318 false,
4319 "Show Save Modified Images Dialog",
4320 "Show a popup dialog to save modified images before saving the blend file");
4322}
4323
4325 wmOperator *op,
4326 const wmEvent * /*event*/)
4327{
4328 const Main *bmain = CTX_data_main(C);
4330
4331 /* Cancel if no active window. */
4332 if (CTX_wm_window(C) == nullptr) {
4333 return OPERATOR_CANCELLED;
4334 }
4335
4336 if (wm_show_save_modified_images_dialog(bmain, op)) {
4337 wm_operator_save_modified_images_dialog(C, op, [](bContext *C, void *user_data) {
4339 "WM_OT_save_mainfile",
4341 static_cast<IDProperty *>(user_data),
4342 nullptr);
4343 });
4344 return OPERATOR_INTERFACE;
4345 }
4346
4348 save_set_filepath(C, op);
4349
4350 /* If we're saving for the first time and prefer relative paths -
4351 * any existing paths will be absolute,
4352 * enable the option to remap paths to avoid confusion, see: #37240. */
4353 const char *blendfile_path = BKE_main_blendfile_path_from_global();
4354 if ((blendfile_path[0] == '\0') && (U.flag & USER_RELPATHS)) {
4355 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "relative_remap");
4356 if (!RNA_property_is_set(op->ptr, prop)) {
4357 RNA_property_boolean_set(op->ptr, prop, true);
4358 }
4359 }
4360
4361 if (blendfile_path[0] != '\0') {
4365 }
4366 else {
4368 }
4369 }
4370 else {
4373 }
4374
4375 return ret;
4376}
4377
4379 wmOperatorType * /*ot*/,
4380 PointerRNA *ptr)
4381{
4382 if (RNA_boolean_get(ptr, "incremental")) {
4383 return TIP_(
4384 "Save the current Blender file with a numerically incremented name that does not "
4385 "overwrite any existing files");
4386 }
4387 return "";
4388}
4389
4391{
4392 ot->name = "Save Blender File";
4393 ot->idname = "WM_OT_save_mainfile";
4394 ot->description = "Save the current Blender file";
4395
4400 /* Omit window poll so this can work in background mode. */
4401
4402 PropertyRNA *prop;
4406 FILE_SAVE,
4410 RNA_def_boolean(ot->srna, "compress", false, "Compress", "Write compressed .blend file");
4412 "relative_remap",
4413 false,
4414 "Remap Relative",
4415 "Remap relative paths when saving to a different directory");
4416
4417 prop = RNA_def_boolean(ot->srna, "exit", false, "Exit", "Exit Blender after saving");
4419
4420 prop = RNA_def_boolean(ot->srna,
4421 "incremental",
4422 false,
4423 "Incremental",
4424 "Save the current Blender file with a numerically incremented name that "
4425 "does not overwrite any existing files");
4427
4428 prop = RNA_def_boolean(
4429 ot->srna,
4430 "show_save_modified_images_dialog",
4431 false,
4432 "Show Save Modified Images Dialog",
4433 "Show a popup dialog to save modified images before saving the blend file");
4435}
4436
4438
4439/* -------------------------------------------------------------------- */
4442
4444
4446 {CLEAR_RECENT_ALL, "ALL", 0, "All Items", ""},
4447 {CLEAR_RECENT_MISSING, "MISSING", 0, "Items Not Found", ""},
4448 {0, nullptr, 0, nullptr, nullptr},
4449};
4450
4452 wmOperator *op,
4453 const wmEvent *event)
4454{
4456 C, op, event, IFACE_("Clear Recent Files List"), IFACE_("Remove"));
4457}
4458
4460{
4461 ClearRecentInclude include = static_cast<ClearRecentInclude>(RNA_enum_get(op->ptr, "remove"));
4462
4463 if (include == CLEAR_RECENT_ALL) {
4465 }
4466 else if (include == CLEAR_RECENT_MISSING) {
4467 for (RecentFile &recent : G.recent_files.items_mutable()) {
4468 if (!BLI_exists(recent.filepath)) {
4469 wm_history_file_free(&recent);
4470 }
4471 }
4472 }
4473
4475
4476 return OPERATOR_FINISHED;
4477}
4478
4480{
4481 ui::Layout &layout = *op->layout;
4482 layout.use_property_split_set(true);
4483 layout.use_property_decorate_set(false);
4484
4485 layout.separator();
4486 layout.prop(op->ptr, "remove", ui::ITEM_R_TOGGLE, std::nullopt, ICON_NONE);
4487 layout.separator();
4488}
4489
4491{
4492 ot->name = "Clear Recent Files List";
4493 ot->idname = "WM_OT_clear_recent_files";
4494 ot->description = "Clear the recent files list";
4495
4499
4500 /* flags */
4501 ot->flag = OPTYPE_REGISTER;
4502
4503 /* props */
4504 ot->prop = RNA_def_enum(
4505 ot->srna, "remove", prop_clear_recent_types, CLEAR_RECENT_ALL, "Remove", "");
4506}
4507
4509 wmOperator *op,
4510 const wmEvent *event)
4511{
4513 C, op, event, IFACE_("Clear Recent Projects List"), IFACE_("Remove"));
4514}
4515
4522
4524{
4525 ot->name = "Clear Recent Projects List";
4526 ot->idname = "WM_OT_clear_recent_projects";
4527 ot->description = "Clear the recent projects list";
4528
4532
4533 /* flags */
4534 ot->flag = OPTYPE_REGISTER;
4535
4536 /* props */
4537 ot->prop = RNA_def_enum(
4538 ot->srna, "remove", prop_clear_recent_types, CLEAR_RECENT_ALL, "Remove", "");
4539}
4540
4542
4543/* -------------------------------------------------------------------- */
4546
4548{
4549 wmWindow *win = CTX_wm_window(C);
4550 popup_block_close(C, win, block);
4551
4552 /* Free the data as it's no longer needed. */
4553 wm_test_autorun_revert_action_set(nullptr, nullptr);
4554}
4555
4557{
4558 wmWindow *win = CTX_wm_window(C);
4559
4560 popup_block_close(C, win, block);
4561
4562 /* Load file again with scripts enabled.
4563 * The reload is necessary to allow scripts to run when the files loads. */
4565}
4566
4568{
4569 wmWindow *win = CTX_wm_window(C);
4570 Main *bmain = CTX_data_main(C);
4571
4572 popup_block_close(C, win, block);
4573
4574 /* Force a full refresh, but without reloading the file. */
4575 for (Scene &scene : bmain->scenes) {
4577 }
4578}
4579
4580/* Build the auto-run warning dialog UI. */
4581static ui::Block *block_create_autorun_warning(bContext *C, ARegion *region, void * /*arg1*/)
4582{
4583 const char *blendfile_path = BKE_main_blendfile_path_from_global();
4585
4586 ui::Block *block = block_begin(C, region, "autorun_warning_popup", ui::EmbossType::Emboss);
4587 block_flag_enable(
4589 block_theme_style_set(block, ui::BLOCK_THEME_STYLE_POPUP);
4590 block_emboss_set(block, ui::EmbossType::Emboss);
4591
4592 const char *title = RPT_(
4593 "For security reasons, automatic execution of Python scripts "
4594 "in this file was disabled:");
4595 const char *message = RPT_("This may lead to unexpected behavior. Allow at your own risk.");
4596
4597 /* Measure strings to find the longest. */
4598 const uiStyle *style = ui::style_get_dpi();
4599 ui::fontstyle_set(&style->widget);
4600 int text_width = int(BLF_width(style->widget.uifont_id, title, BLF_DRAW_STR_DUMMY_MAX));
4601 text_width = std::max(text_width,
4602 int(BLF_width(style->widget.uifont_id, message, BLF_DRAW_STR_DUMMY_MAX)));
4603
4604 const int dialog_width = std::max(int(500.0f * UI_SCALE_FAC),
4605 text_width + int(style->columnspace * 2.5));
4606 const short icon_size = 40 * UI_SCALE_FAC;
4607 ui::Layout &layout = *uiItemsAlertBox(
4608 block, style, dialog_width + icon_size, ui::AlertIcon::Error, icon_size);
4609
4610 /* Title and explanation text. */
4611 ui::Layout &col = layout.column(true);
4612 uiItemL_ex(&col, title, ICON_NONE, true, false);
4613 uiItemL_ex(&col, G.autoexec_fail, ICON_NONE, false, true);
4614 col.label(message, ICON_NONE);
4615
4616 layout.separator(2.0f);
4617
4618 /* Buttons. */
4619 ui::Button *but;
4620 ui::Layout &split = layout.split(0.0f, true);
4621 split.scale_y_set(1.2f);
4622
4623 /* Empty space. */
4624 split.column(false).separator();
4625
4626 split.column(false);
4627
4628 /* Allow reload if we have a saved file.
4629 * Otherwise just enable scripts and reset the depsgraphs. */
4630 if ((blendfile_path[0] != '\0') && wm->file_saved) {
4631 but = uiDefIconTextBut(block,
4633 ICON_NONE,
4634 IFACE_("Allow Execution"),
4635 0,
4636 0,
4637 50,
4638 UI_UNIT_Y,
4639 nullptr,
4640 TIP_("Reload file with execution of Python scripts enabled"));
4641 button_func_set(
4642 but, [block](bContext &C) { wm_block_autorun_warning_reload_with_scripts(&C, block); });
4643 }
4644 else {
4645 but = uiDefIconTextBut(block,
4647 ICON_NONE,
4648 IFACE_("Allow Execution"),
4649 0,
4650 0,
4651 50,
4652 UI_UNIT_Y,
4653 nullptr,
4654 TIP_("Run potentially unsafe scripts in this blend file"));
4655 button_func_set(but,
4656 [block](bContext &C) { wm_block_autorun_warning_enable_scripts(&C, block); });
4657 }
4658 button_drawflag_disable(but, ui::BUT_TEXT_LEFT);
4659
4660 split.column(false);
4661 but = uiDefIconTextBut(block,
4663 ICON_NONE,
4664 IFACE_("Continue Safely"),
4665 0,
4666 0,
4667 50,
4668 UI_UNIT_Y,
4669 nullptr,
4670 TIP_("Continue using file without Python scripts"));
4671 button_func_set(but, [block](bContext &C) { wm_block_autorun_warning_ignore(&C, block); });
4672 button_drawflag_disable(but, ui::BUT_TEXT_LEFT);
4673 button_flag_enable(but, ui::BUT_ACTIVE_DEFAULT);
4674
4675 block_bounds_set_centered(block, 14 * UI_SCALE_FAC);
4676
4677 return block;
4678}
4679
4687static struct {
4689 PointerRNA *ptr;
4691
4704
4706{
4709
4710 /* Use regular revert. */
4711 if (ot == nullptr) {
4712 ot = WM_operatortype_find("WM_OT_revert_mainfile", false);
4713 ptr = MEM_new<PointerRNA>(__func__, WM_operator_properties_create_ptr(ot));
4714 RNA_boolean_set(ptr, "use_scripts", true);
4715
4716 /* Set state, so it's freed correctly. */
4718 }
4719
4721 wm_test_autorun_revert_action_set(nullptr, nullptr);
4722}
4723
4725{
4726 /* Test if any auto-execution of scripts failed. */
4727 if ((G.f & G_FLAG_SCRIPT_AUTOEXEC_FAIL) == 0) {
4728 return;
4729 }
4730
4731 /* Only show the warning once. */
4733 return;
4734 }
4735
4737
4739 wmWindow *win = (wm->runtime->winactive) ? wm->runtime->winactive : wm->windows.first();
4740
4741 if (win) {
4742 /* We want this warning on the Main window, not a child window even if active. See #118765. */
4743 if (win->parent) {
4744 win = win->parent;
4745 }
4746
4747 wmWindow *prevwin = CTX_wm_window(C);
4748 CTX_wm_window_set(C, win);
4750 CTX_wm_window_set(C, prevwin);
4751 }
4752}
4753
4755{
4756 if (!G_MAIN->is_read_invalid) {
4757 return;
4758 }
4759
4760 G_MAIN->is_read_invalid = false;
4761
4763 wmWindow *win = (wm->runtime->winactive) ? wm->runtime->winactive : wm->windows.first();
4764
4765 if (win) {
4766 /* We want this warning on the Main window, not a child window even if active. See #118765. */
4767 if (win->parent) {
4768 win = win->parent;
4769 }
4770
4771 wmWindow *prevwin = CTX_wm_window(C);
4772 CTX_wm_window_set(C, win);
4773 alert(C,
4774 RPT_("Unable to Load File"),
4775 RPT_("The file is not a valid Blender file."),
4777 false);
4778
4779 CTX_wm_window_set(C, prevwin);
4780 }
4781}
4782
4784
4785/* -------------------------------------------------------------------- */
4788
4789static const char *save_file_overwrite_dialog_name = "save_file_overwrite_popup";
4790
4791static void file_overwrite_detailed_info_show(ui::Layout &parent_layout, Main *bmain)
4792{
4793 ui::Layout &layout = parent_layout.column(true);
4794 /* Trick to make both lines of text below close enough to look like they are part of a same
4795 * block. */
4796 layout.scale_y_set(0.70f);
4797
4799 char writer_ver_str[16];
4800 char current_ver_str[16];
4801 if (bmain->versionfile == BLENDER_VERSION) {
4803 writer_ver_str, sizeof(writer_ver_str), bmain->versionfile, bmain->subversionfile);
4805 current_ver_str, sizeof(current_ver_str), BLENDER_FILE_VERSION, BLENDER_FILE_SUBVERSION);
4806 }
4807 else {
4809 writer_ver_str, sizeof(writer_ver_str), bmain->versionfile, -1);
4811 current_ver_str, sizeof(current_ver_str), BLENDER_VERSION, -1);
4812 }
4813
4814 char message_line1[256];
4815 char message_line2[256];
4816 SNPRINTF(message_line1,
4817 RPT_("This file was saved by a newer version of Blender (%s)."),
4818 writer_ver_str);
4819 SNPRINTF(message_line2,
4820 RPT_("Saving it with this Blender (%s) may cause loss of data."),
4821 current_ver_str);
4822 layout.label(message_line1, ICON_NONE);
4823 layout.label(message_line2, ICON_NONE);
4824 }
4825
4826 if (bmain->is_asset_edit_file) {
4828 layout.separator(1.4f);
4829 }
4830
4831 layout.label(RPT_("This file is managed by the Blender asset system. It can only be"),
4832 ICON_NONE);
4833 layout.label(RPT_("saved as a new, regular file."), ICON_NONE);
4834 }
4835
4838 layout.separator(1.4f);
4839 }
4841 RPT_("OpenColorIO configuration failed to load.") :
4842 RPT_("Displays, views or color spaces in this file were missing and have "
4843 "been changed."),
4844 ICON_NONE);
4845 layout.label(RPT_("Saving it with this OpenColorIO configuration may cause loss of data."),
4846 ICON_NONE);
4847 }
4848}
4849
4850static void save_file_overwrite_cancel(bContext *C, void *arg_block, void * /*arg_data*/)
4851{
4852 wmWindow *win = CTX_wm_window(C);
4853 popup_block_close(C, win, static_cast<ui::Block *>(arg_block));
4854}
4855
4857{
4858 ui::Button *but = uiDefIconTextBut(
4859 block, ui::ButtonType::But, ICON_NONE, IFACE_("Cancel"), 0, 0, 0, UI_UNIT_Y, nullptr, "");
4860 button_func_set(but, save_file_overwrite_cancel, block, post_action);
4861 button_drawflag_disable(but, ui::BUT_TEXT_LEFT);
4862}
4863
4864static void save_file_overwrite_confirm(bContext *C, void *arg_block, void *arg_data)
4865{
4866 wmWindow *win = CTX_wm_window(C);
4867
4868 /* Re-use operator properties as defined for the initial "Save" operator,
4869 * which triggered this "Forward Compatibility" popup. */
4871 static_cast<wmGenericCallback *>(arg_data));
4872
4873 /* Needs to be done after stealing the callback data above, otherwise it would cause a
4874 * use-after-free. */
4875 popup_block_close(C, win, static_cast<ui::Block *>(arg_block));
4876
4877 PointerRNA operator_propptr = {};
4878 PointerRNA *operator_propptr_p = &operator_propptr;
4879 IDProperty *operator_idproperties = static_cast<IDProperty *>(callback->user_data);
4880 WM_operator_properties_alloc(&operator_propptr_p, &operator_idproperties, "WM_OT_save_mainfile");
4881
4883 C, "WM_OT_save_mainfile", wm::OpCallContext::ExecDefault, operator_propptr_p, nullptr);
4884
4885 WM_generic_callback_free(callback);
4886}
4887
4889{
4890 ui::Button *but = uiDefIconTextBut(
4891 block, ui::ButtonType::But, ICON_NONE, IFACE_("Overwrite"), 0, 0, 0, UI_UNIT_Y, nullptr, "");
4892 button_func_set(but, save_file_overwrite_confirm, block, post_action);
4893 button_drawflag_disable(but, ui::BUT_TEXT_LEFT);
4894 button_flag_enable(but, ui::BUT_REDALERT);
4895}
4896
4897static void save_file_overwrite_saveas(bContext *C, void *arg_block, void * /*arg_data*/)
4898{
4899 wmWindow *win = CTX_wm_window(C);
4900 popup_block_close(C, win, static_cast<ui::Block *>(arg_block));
4901
4903 C, "WM_OT_save_as_mainfile", wm::OpCallContext::InvokeDefault, nullptr, nullptr);
4904}
4905
4907{
4908 ui::Button *but = uiDefIconTextBut(block,
4910 ICON_NONE,
4911 IFACE_("Save As..."),
4912 0,
4913 0,
4914 0,
4915 UI_UNIT_Y,
4916 nullptr,
4917 "");
4918 button_func_set(but, save_file_overwrite_saveas, block, post_action);
4919 button_drawflag_disable(but, ui::BUT_TEXT_LEFT);
4920 button_flag_enable(but, ui::BUT_ACTIVE_DEFAULT);
4921}
4922
4924{
4925 wmGenericCallback *post_action = static_cast<wmGenericCallback *>(arg1);
4926 Main *bmain = CTX_data_main(C);
4927
4928 ui::Block *block = block_begin(
4930 block_flag_enable(
4932 block_theme_style_set(block, ui::BLOCK_THEME_STYLE_POPUP);
4933
4934 ui::Layout &layout = *uiItemsAlertBox(block, 44, ui::AlertIcon::Warning);
4935
4936 /* Title. */
4938 if (bmain->is_asset_edit_file) {
4939 uiItemL_ex(&layout,
4940 RPT_("Cannot overwrite asset system files. Save as new file"),
4941 ICON_NONE,
4942 true,
4943 false);
4944 uiItemL_ex(&layout, RPT_("with an older Blender version?"), ICON_NONE, true, false);
4945 }
4946 else {
4947 uiItemL_ex(
4948 &layout, RPT_("Overwrite file with an older Blender version?"), ICON_NONE, true, false);
4949 }
4950 }
4951 else if (bmain->is_asset_edit_file) {
4952 uiItemL_ex(&layout,
4953 RPT_("Cannot overwrite asset system files. Save as new file?"),
4954 ICON_NONE,
4955 true,
4956 false);
4957 }
4958 else if (!bmain->colorspace.is_missing_opencolorio_config) {
4960 }
4961
4963 uiItemL_ex(&layout,
4964 RPT_("Overwrite file with current OpenColorIO configuration?"),
4965 ICON_NONE,
4966 true,
4967 false);
4968 }
4969
4970 /* Filename. */
4971 const char *blendfile_path = BKE_main_blendfile_path(CTX_data_main(C));
4972 char filename[FILE_MAX];
4973 if (blendfile_path[0] != '\0') {
4974 BLI_path_split_file_part(blendfile_path, filename, sizeof(filename));
4975 }
4976 else {
4977 /* While a filename need not be UTF8, at this point the constructed name should be UTF8. */
4978 SNPRINTF_UTF8(filename, "%s.blend", DATA_("Untitled"));
4979 /* Since this dialog should only be shown when re-saving an existing file, current filepath
4980 * should never be empty. */
4982 }
4983 layout.label(filename, ICON_NONE);
4984
4985 /* Detailed message info. */
4986 file_overwrite_detailed_info_show(layout, bmain);
4987
4988 layout.separator(4.0f);
4989
4990 /* Buttons. */
4991
4992 ui::Layout &split = layout.split(0.3f, true);
4993 split.scale_y_set(1.2f);
4994
4995 split.column(false);
4996 /* Asset files don't actually allow overriding. */
4997 const bool allow_overwrite = !bmain->is_asset_edit_file;
4998 if (allow_overwrite) {
4999 save_file_overwrite_confirm_button(block, post_action);
5000 }
5001
5002 ui::Layout &split_right = split.split(0.1f, true);
5003
5004 split_right.column(false);
5005 /* Empty space. */
5006
5007 split_right.column(false);
5008 save_file_overwrite_cancel_button(block, post_action);
5009
5010 split_right.column(false);
5011 save_file_overwrite_saveas_button(block, post_action);
5012
5013 block_bounds_set_centered(block, 14 * UI_SCALE_FAC);
5014 return block;
5015}
5016
5018{
5020 wmGenericCallback *callback = MEM_new<wmGenericCallback>(__func__);
5021 callback->exec = nullptr;
5022 callback->user_data = IDP_CopyProperty(op->properties);
5024
5027 callback,
5029 }
5030}
5031
5033
5034/* -------------------------------------------------------------------- */
5037
5039
5040static void wm_block_file_close_cancel(bContext *C, void *arg_block, void * /*arg_data*/)
5041{
5042 wmWindow *win = CTX_wm_window(C);
5043 popup_block_close(C, win, static_cast<ui::Block *>(arg_block));
5044}
5045
5046static void wm_block_file_close_discard(bContext *C, void *arg_block, void *arg_data)
5047{
5049 static_cast<wmGenericCallback *>(arg_data));
5050
5051 /* Close the popup before executing the callback. Otherwise
5052 * the popup might be closed by the callback, which will lead
5053 * to a crash. */
5054 wmWindow *win = CTX_wm_window(C);
5055 popup_block_close(C, win, static_cast<ui::Block *>(arg_block));
5056
5057 callback->exec(C, callback->user_data);
5058 WM_generic_callback_free(callback);
5059}
5060
5061static void wm_block_file_close_save(bContext *C, void *arg_block, void *arg_data)
5062{
5063 const Main *bmain = CTX_data_main(C);
5064 wmWindowManager *wm = bmain->wm.first();
5066 static_cast<wmGenericCallback *>(arg_data));
5067 bool execute_callback = true;
5068
5069 wmWindow *win = CTX_wm_window(C);
5070 popup_block_close(C, win, static_cast<ui::Block *>(arg_block));
5071
5072 int modified_images_count = ED_image_save_all_modified_info(CTX_data_main(C), nullptr);
5073 if (modified_images_count > 0 && save_images_when_file_is_closed) {
5074 if (ED_image_should_save_modified(bmain)) {
5075 ReportList *reports = CTX_wm_reports(C);
5076 ED_image_save_all_modified(C, reports);
5078 }
5079 else {
5080 execute_callback = false;
5081 }
5082 }
5083
5084 bool file_has_been_saved_before = BKE_main_blendfile_path(bmain)[0] != '\0';
5085
5086 if (file_has_been_saved_before) {
5088 {
5089 /* Need to invoke to get the file-browser and choose where to save the new file.
5090 * This also makes it impossible to keep on going with current operation, which is why
5091 * callback cannot be executed anymore.
5092 *
5093 * This is the same situation as what happens when the file has never been saved before
5094 * (outer `else` statement, below). */
5096 C, "WM_OT_save_as_mainfile", wm::OpCallContext::InvokeDefault, nullptr, nullptr);
5097 execute_callback = false;
5098 }
5099 else {
5101 C, "WM_OT_save_mainfile", wm::OpCallContext::ExecDefault, nullptr, nullptr);
5102 if (status & OPERATOR_CANCELLED) {
5103 execute_callback = false;
5104 }
5105 }
5106 }
5107 else {
5109 C, "WM_OT_save_mainfile", wm::OpCallContext::InvokeDefault, nullptr, nullptr);
5110 execute_callback = false;
5111 }
5112
5113 if (execute_callback) {
5114 callback->exec(C, callback->user_data);
5115 }
5116 WM_generic_callback_free(callback);
5117}
5118
5120{
5121 ui::Button *but = uiDefIconTextBut(
5122 block, ui::ButtonType::But, ICON_NONE, IFACE_("Cancel"), 0, 0, 0, UI_UNIT_Y, nullptr, "");
5123 button_func_set(but, wm_block_file_close_cancel, block, post_action);
5124 button_drawflag_disable(but, ui::BUT_TEXT_LEFT);
5125}
5126
5128{
5129 ui::Button *but = uiDefIconTextBut(block,
5131 ICON_NONE,
5132 IFACE_("Don't Save"),
5133 0,
5134 0,
5135 0,
5136 UI_UNIT_Y,
5137 nullptr,
5138 "");
5139 button_func_set(but, wm_block_file_close_discard, block, post_action);
5140 button_drawflag_disable(but, ui::BUT_TEXT_LEFT);
5141}
5142
5144 wmGenericCallback *post_action,
5145 const bool needs_overwrite_confirm)
5146{
5147 ui::Button *but = uiDefIconTextBut(
5148 block,
5150 ICON_NONE,
5151 /* Forward compatibility issues force using 'save as' operator instead of 'save' one. */
5152 needs_overwrite_confirm ? IFACE_("Save As...") : IFACE_("Save"),
5153 0,
5154 0,
5155 0,
5156 UI_UNIT_Y,
5157 nullptr,
5158 "");
5159 button_func_set(but, wm_block_file_close_save, block, post_action);
5160 button_drawflag_disable(but, ui::BUT_TEXT_LEFT);
5161 button_flag_enable(but, ui::BUT_ACTIVE_DEFAULT);
5162}
5163
5164static const char *close_file_dialog_name = "file_close_popup";
5165
5166static void save_catalogs_when_file_is_closed_set_fn(bContext * /*C*/, void *arg1, void * /*arg2*/)
5167{
5168 char *save_catalogs_when_file_is_closed = static_cast<char *>(arg1);
5169 ed::asset::catalogs_set_save_catalogs_when_file_is_saved(*save_catalogs_when_file_is_closed !=
5170 0);
5171}
5172
5174{
5175 wmGenericCallback *post_action = static_cast<wmGenericCallback *>(arg1);
5176 Main *bmain = CTX_data_main(C);
5177
5178 ui::Block *block = block_begin(C, region, close_file_dialog_name, ui::EmbossType::Emboss);
5179 block_flag_enable(
5181 block_theme_style_set(block, ui::BLOCK_THEME_STYLE_POPUP);
5182
5183 ui::Layout &layout = *uiItemsAlertBox(
5185
5186 const bool needs_overwrite_confirm = BKE_main_needs_overwrite_confirm(bmain);
5187
5188 /* Title. */
5189 uiItemL_ex(&layout, RPT_("Save changes before closing?"), ICON_NONE, true, false);
5190
5191 /* Filename. */
5192 const char *blendfile_path = BKE_main_blendfile_path(CTX_data_main(C));
5193 char filename[FILE_MAX];
5194 if (blendfile_path[0] != '\0') {
5195 BLI_path_split_file_part(blendfile_path, filename, sizeof(filename));
5196 }
5197 else {
5198 /* While a filename need not be UTF8, at this point the constructed name should be UTF8. */
5199 SNPRINTF_UTF8(filename, "%s.blend", DATA_("Untitled"));
5200 }
5201 layout.label(filename, ICON_NONE);
5202
5203 /* Potential forward compatibility issues message. */
5204 if (needs_overwrite_confirm) {
5205 file_overwrite_detailed_info_show(layout, bmain);
5206 }
5207
5208 /* Image Saving Warnings. */
5209 ReportList reports;
5210 BKE_reports_init(&reports, RPT_STORE);
5211 uint modified_images_count = ED_image_save_all_modified_info(bmain, &reports);
5212 wm_block_image_save_errors(layout, reports);
5213
5214 /* Used to determine if extra separators are needed. */
5215 bool has_extra_checkboxes = false;
5216
5217 /* Modified Images Checkbox. */
5218 if (modified_images_count > 0) {
5219 std::string message = fmt::format(fmt::runtime(RPT_("Save {} modified image(s)")),
5220 modified_images_count);
5221 /* Only the first checkbox should get extra separation. */
5222 if (!has_extra_checkboxes) {
5223 layout.separator();
5224 }
5225 uiDefButV(block,
5227 message,
5228 0,
5229 0,
5230 0,
5231 UI_UNIT_Y,
5233 0,
5234 0,
5235 "");
5236 has_extra_checkboxes = true;
5237 }
5238
5240 static char save_catalogs_when_file_is_closed;
5241
5242 save_catalogs_when_file_is_closed = ed::asset::catalogs_get_save_catalogs_when_file_is_saved();
5243
5244 /* Only the first checkbox should get extra separation. */
5245 if (!has_extra_checkboxes) {
5246 layout.separator();
5247 }
5248 ui::Button *but = uiDefButBit(block,
5250 1,
5251 "Save modified asset catalogs",
5252 0,
5253 0,
5254 0,
5255 UI_UNIT_Y,
5256 &save_catalogs_when_file_is_closed,
5257 0,
5258 0,
5259 "");
5260 button_func_set(but,
5262 &save_catalogs_when_file_is_closed,
5263 nullptr);
5264 has_extra_checkboxes = true;
5265 }
5266
5267 BKE_reports_free(&reports);
5268
5269 layout.separator(2.0f);
5270
5271 /* Buttons. */
5272#ifdef _WIN32
5273 const bool windows_layout = true;
5274#else
5275 const bool windows_layout = false;
5276#endif
5277
5278 if (windows_layout) {
5279 /* Windows standard layout. */
5280
5281 ui::Layout &split = layout.split(0.0f, true);
5282 split.scale_y_set(1.2f);
5283
5284 split.column(false);
5285 wm_block_file_close_save_button(block, post_action, needs_overwrite_confirm);
5286
5287 split.column(false);
5288 wm_block_file_close_discard_button(block, post_action);
5289
5290 split.column(false);
5291 wm_block_file_close_cancel_button(block, post_action);
5292 }
5293 else {
5294 /* Non-Windows layout (macOS and Linux). */
5295
5296 ui::Layout &split = layout.split(0.3f, true);
5297 split.scale_y_set(1.2f);
5298
5299 split.column(false);
5300 wm_block_file_close_discard_button(block, post_action);
5301
5302 ui::Layout &split_right = split.split(0.1f, true);
5303
5304 split_right.column(false);
5305 /* Empty space. */
5306
5307 split_right.column(false);
5308 wm_block_file_close_cancel_button(block, post_action);
5309
5310 split_right.column(false);
5311 wm_block_file_close_save_button(block, post_action, needs_overwrite_confirm);
5312 }
5313
5314 block_bounds_set_centered(block, 14 * UI_SCALE_FAC);
5315 return block;
5316}
5317
5330
5332 wmOperator *op,
5333 wmGenericCallbackFn post_action_fn)
5334{
5335 if (U.uiflag & USER_SAVE_PROMPT &&
5337 {
5338 wmGenericCallback *callback = MEM_new<wmGenericCallback>(__func__);
5339 callback->exec = post_action_fn;
5340 callback->user_data = IDP_CopyProperty(op->properties);
5342 wm_close_file_dialog(C, callback);
5343 return true;
5344 }
5345
5346 return false;
5347}
5348
5350
5351} // namespace blender
#define BLENDER_USERPREF_FILE
#define BLENDER_HISTORY_FILE
#define BLENDER_STARTUP_FILE
#define BLENDER_QUIT_FILE
Blender util stuff.
#define BLENDER_FILE_SUBVERSION
#define BLENDER_VERSION
#define BLENDER_FILE_VERSION
#define BLENDER_ASSET_FILE_SUFFIX
#define G_FLAG_ALL_READFILE
#define G_MAIN
#define G_FLAG_INTERNET_OVERRIDE_PREF_ANY
#define G_FLAG_ALL_RUNTIME
#define BLEN_THUMB_SIZE
Definition BKE_main.hh:977
#define INT32_MAX
#define INT32_MIN
#define BLF_DRAW_STR_DUMMY_MAX
Definition BLF_api.hh:456
File and directory operations.
#define O_BINARY
#define FILELIST_DIRENTRY_SIZE_LEN
Wrapper for reading from various sources (e.g. raw files, compressed files, memory....
#define BLI_SCOPED_DEFER(function_to_defer)
#define FILE_MAXFILE
#define FILE_MAX
#define BLI_path_join(...)
#define BLI_path_cmp
#define SNPRINTF(dst, format,...)
#define SNPRINTF_UTF8(dst, format,...)
Platform independent time functions.
Compatibility-like things for windows.
#define S_ISDIR(x)
external readfile function prototypes.
external writefile.cc function prototypes.
#define RPT_(msgid)
#define BLT_I18NCONTEXT_ID_WORKSPACE
#define TIP_(msgid)
#define CTX_IFACE_(context, msgid)
#define CTX_DATA_(context, msgid)
#define IFACE_(msgid)
#define DATA_(msgid)
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
#define CLOG_INFO_NOCHECK(clg_ref, format,...)
Definition CLG_log.h:204
#define CLOG_INFO(clg_ref,...)
Definition CLG_log.h:190
#define UI_SCALE_FAC
int datatoc_startup_blend_size
const char datatoc_startup_blend[]
#define PREVIEW_RENDER_LARGE_HEIGHT
Definition IMB_thumbs.hh:77
void MEM_CacheLimiter_set_maximum(size_t m)
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_ITEM_NONE
#define ND_UI_FONT
Definition WM_types.hh:602
#define ND_ASSET_LIST_READING
Definition WM_types.hh:593
#define NC_WINDOW
Definition WM_types.hh:388
#define ND_FILEREAD
Definition WM_types.hh:428
#define NC_WM
Definition WM_types.hh:387
#define ND_DATACHANGED
Definition WM_types.hh:430
#define NC_ASSET
Definition WM_types.hh:417
#define NC_UI
Definition WM_types.hh:422
#define ND_FILESAVE
Definition WM_types.hh:429
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
static GHOST_ISystemPaths * get()
virtual void addToSystemRecentFiles(const char *filepath) const =0
virtual void setUserData(const GHOST_TUserDataPtr user_data)=0
#define offsetof(t, d)
#define INT_MAX
#define abs
const int state
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
std::string datetime(const std::tm &date_time, StringRef locale_iso={}, DateFormat date_format=DateFormat::Default, TimeFormat time_format=TimeFormat::H24, const std::tm *now=nullptr, StringRef today={}, StringRef yesterday={})
std::tm localtime_safe(time_t time)
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
Definition DNA_defs.h:147
void catalogs_set_save_catalogs_when_file_is_saved(bool should_save)
void pre_save_assets(Main *bmain)
std::string filename(const std::string_view &str, size_t pos)
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition abc_util.cc:68
void set_approximate_size_limit(int64_t limit_in_bytes)
constexpr int MAX_CHANNELS
void init_userdef()
void fontstyle_set(const uiFontStyle *fs)
const uiStyle * style_get_dpi()
void popup_block_invoke(bContext *C, BlockCreateFunc func, void *arg, FreeArgFunc arg_free, StructRNA *srna_owner=nullptr)
void view2d_zoom_cache_reset()
Definition view2d.cc:1026
bool popup_block_name_exists(const bScreen *screen, StringRef name)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static wmOperatorStatus wm_clear_recent_files_exec(bContext *, wmOperator *op)
Definition wm_files.cc:4459
UserDef U
Definition blender.cc:58
WorkSpaceLayout * ED_workspace_layout_duplicate(Main *bmain, WorkSpace *workspace, const WorkSpaceLayout *layout_old, wmWindow *win) ATTR_NONNULL()
static void wm_file_read_setup_wm_use_new(bContext *C, Main *, BlendFileReadWMSetupData *wm_setup_data, wmWindowManager *wm)
Definition wm_files.cc:383
void BKE_undosys_stack_init_from_main(UndoStack *ustack, Main *bmain)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static std::string wm_save_mainfile_get_description(bContext *, wmOperatorType *, PointerRNA *ptr)
Definition wm_files.cc:4378
void WM_OT_clear_recent_files(wmOperatorType *ot)
Definition wm_files.cc:4490
PropertyRNA * RNA_def_string_file_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
@ V3D_RUNTIME_LOCAL_MAYBE_EMPTY
@ OPEN_MAINFILE_STATE_SELECT_FILE_PATH
Definition wm_files.cc:3317
@ OPEN_MAINFILE_STATE_DISCARD_CHANGES
Definition wm_files.cc:3316
@ OPEN_MAINFILE_STATE_OPEN
Definition wm_files.cc:3318
static bool wm_show_save_modified_images_dialog(const Main *bmain, wmOperator *op)
Definition wm_files.cc:3800
static ImBuf * blend_file_thumb_from_camera(const bContext *C, Scene *scene, bScreen *screen, BlendThumbnail **r_thumb)
Definition wm_files.cc:2011
unsigned __int64 uint64_t
Definition BKE_text.h:91
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
void BKE_blender_userdef_data_set_and_free(UserDef *userdef)
Definition blender.cc:286
ImBuf * ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph, Scene *scene, eDrawType drawtype, View3D *v3d, ARegion *region, int sizex, int sizey, ImBufFlags imbuf_flag, int alpha_mode, const char *viewname, bool restore_rv3d_mats, GPUOffScreen *ofs, GPUViewport *viewport, bool use_camera_view_bounds, char err_out[256])
void WM_OT_save_as_mainfile(wmOperatorType *ot)
Definition wm_files.cc:4279
__int64 int64_t
Definition BKE_text.h:90
void BKE_callback_exec_string(Main *bmain, const char *str, eCbEvent evt)
Definition callbacks.cc:76
BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings)==CTX_MODE_NUM+1, "Must have a string for each context mode") const char *CTX_data_mode_string(const bContext *C)
static wmOperatorStatus wm_userpref_read_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:2923
static void wm_history_files_free()
Definition wm_files.cc:1684
void WM_report_banner_show(wmWindowManager *wm, wmWindow *win)
void BKE_workspace_active_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace) SETTER_ATTRS
Definition workspace.cc:637
char * STRNCPY(char(&dst)[N], const char *src)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static void save_file_overwrite_cancel(bContext *C, void *arg_block, void *)
Definition wm_files.cc:4850
static bool wm_file_write_check_with_report_on_failure(Main *bmain, const char *filepath, ReportList *reports)
Definition wm_files.cc:2153
void BKE_ntree_update(Main &bmain, std::optional< Span< bNodeTree * > > modified_trees=std::nullopt, const NodeTreeUpdateExtraParams &params={})
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
ImBuf * IMB_allocFromBufferOwn(uint8_t *byte_buffer, float *float_buffer, unsigned int w, unsigned int h, unsigned int channels)
@ RPT_WARNING
Definition BKE_report.hh:40
wmOperatorStatus WM_operator_confirm(bContext *C, wmOperator *op, const wmEvent *)
bool ED_editors_flush_edits(Main *bmain)
Definition ed_util.cc:335
void wm_history_file_read()
Definition wm_files.cc:1638
bool CTX_py_init_get(const bContext *C)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void WM_generic_callback_free(wmGenericCallback *callback)
Definition wm_utils.cc:22
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:835
void WM_msgbus_destroy(wmMsgBus *mbus)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
static wmOperatorStatus wm_open_mainfile_dispatch(bContext *C, wmOperator *op)
Definition wm_files.cc:3418
static void rna_struct_update_when_changed(bContext *C, Main *bmain, PointerRNA *ptr_a, PointerRNA *ptr_b)
Definition wm_files.cc:2797
static void create_operator_state(wmOperatorType *ot, int first_state)
Definition wm_files.cc:3271
const char * WM_init_state_app_template_get()
Definition wm_files.cc:1222
void WM_operator_properties_alloc(PointerRNA **ptr, IDProperty **properties, const char *opstring)
static wmOperatorStatus wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:4101
void BKE_blender_project_recent_clear(bool only_missing)
static void wm_history_file_update()
Definition wm_files.cc:1727
unsigned int uint
Definition BKE_text.h:55
void IMB_colormanagement_project_read_post(Main *bmain)
static void wm_history_file_write()
Definition wm_files.cc:1701
static void wm_block_save_modified_images_save(bContext *C, void *arg_block, void *arg_data)
Definition wm_files.cc:3821
void WM_OT_read_factory_settings(wmOperatorType *ot)
Definition wm_files.cc:3229
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BKE_blender_project_config_autosave(Main *bmain)
@ BKE_CB_EVT_LOAD_FACTORY_USERDEF_POST
@ BKE_CB_EVT_SAVE_POST_FAIL
@ BKE_CB_EVT_VERSION_UPDATE
@ BKE_CB_EVT_LOAD_PRE
@ BKE_CB_EVT_SAVE_POST
@ BKE_CB_EVT_EXTENSION_REPOS_UPDATE_PRE
@ BKE_CB_EVT_LOAD_POST
@ BKE_CB_EVT_EXTENSION_REPOS_UPDATE_POST
@ BKE_CB_EVT_LOAD_FACTORY_STARTUP_POST
@ BKE_CB_EVT_LOAD_POST_FAIL
@ BKE_CB_EVT_SAVE_PRE
void BKE_ntree_update_tag_id_changed(Main *bmain, ID *id)
void BLT_lang_set(const char *)
Definition blt_lang.cc:253
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
static void save_file_overwrite_confirm_button(ui::Block *block, wmGenericCallback *post_action)
Definition wm_files.cc:4888
static std::string wm_open_mainfile_get_description(bContext *, wmOperatorType *, PointerRNA *ptr)
Definition wm_files.cc:3435
bool wm_operator_close_file_dialog_if_needed(bContext *C, wmOperator *op, wmGenericCallbackFn post_action_fn)
Definition wm_files.cc:5331
static void wm_block_file_close_discard(bContext *C, void *arg_block, void *arg_data)
Definition wm_files.cc:5046
ImBuf * BKE_main_thumbnail_to_imbuf(Main *bmain, BlendThumbnail *data)
Definition main.cc:1029
void BKE_reports_free(ReportList *reports)
Definition report.cc:106
void BKE_report_print_level_set(ReportList *reports, eReportType level)
Definition report.cc:276
static void wm_block_file_close_save(bContext *C, void *arg_block, void *arg_data)
Definition wm_files.cc:5061
bool BLO_write_file(Main *mainvar, const char *filepath, int write_flags, const BlendFileWriteParams *params, ReportList *reports)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
static wmOperatorStatus wm_clear_recent_projects_exec(bContext *, wmOperator *op)
Definition wm_files.cc:4516
void BKE_callback_exec_null(Main *bmain, eCbEvent evt)
Definition callbacks.cc:40
std::optional< std::string > BKE_appdir_folder_id_create(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
Definition appdir.cc:822
bool WM_file_read(bContext *C, const char *filepath, const bool use_scripts_autoexec_check, ReportList *reports)
Definition wm_files.cc:1036
void BKE_blendfile_read_make_empty(bContext *C)
@ WM_MSG_STATICTYPE_FILE_READ
void WM_operator_properties_free(PointerRNA *ptr)
ImBuf * IMB_thumb_create(const char *filepath, ThumbSize size, ThumbSource source, ImBuf *img)
Definition thumbs.cc:541
static void save_file_overwrite_confirm(bContext *C, void *arg_block, void *arg_data)
Definition wm_files.cc:4864
UserDef * BKE_blendfile_userdef_read(const char *filepath, ReportList *reports)
static bool wm_open_mainfile_check(bContext *, wmOperator *op)
Definition wm_files.cc:3478
static wmOperatorStatus wm_revert_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:3573
const char * RNA_property_identifier(const PropertyRNA *prop)
static void wm_block_save_modified_images_cancel(bContext *C, void *arg_block, void *)
Definition wm_files.cc:3815
static wmOperatorStatus wm_clear_recent_projects_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition wm_files.cc:4508
static void wm_block_file_close_cancel_button(ui::Block *block, wmGenericCallback *post_action)
Definition wm_files.cc:5119
static void wm_block_autorun_warning_enable_scripts(bContext *C, ui::Block *block)
Definition wm_files.cc:4567
static void wm_block_file_close_discard_button(ui::Block *block, wmGenericCallback *post_action)
Definition wm_files.cc:5127
static void wm_read_callback_pre_wrapper(bContext *C, const char *filepath)
Definition wm_files.cc:859
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:986
void BKE_reports_init(ReportList *reports, int flag)
Definition report.cc:91
bool wm_init_last_project_on_startup(Main *bmain)
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
static void wm_block_image_save_errors(ui::Layout &layout, ReportList &reports)
Definition wm_files.cc:3863
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void wm_window_ghostwindows_remove_invalid(bContext *C, wmWindowManager *wm)
void BLI_math_time_seconds_decompose(double seconds, double *r_days, double *r_hours, double *r_minutes, double *r_seconds, double *r_milliseconds)
Definition math_time.cc:14
void CTX_wm_window_set(bContext *C, wmWindow *win)
WorkSpaceLayout * WM_window_get_active_layout(const wmWindow *win)
static wmOperatorStatus wm_recover_auto_save_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:3741
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
static void wm_block_file_close_save_button(ui::Block *block, wmGenericCallback *post_action, const bool needs_overwrite_confirm)
Definition wm_files.cc:5143
static void wm_gpu_backend_override_from_userdef()
Definition wm_files.cc:511
void WM_keyconfig_update(wmWindowManager *wm)
unsigned short ushort
Definition BKE_text.h:56
void BKE_blender_project_refresh(Main *bmain, const char *filepath)
static BlendFileReadWMSetupData * wm_file_read_setup_wm_init(bContext *C, Main *bmain, const bool is_read_homefile)
Definition wm_files.cc:223
static std::optional< std::string > wm_project_root_path_get(const Main *bmain)
Definition wm_files.cc:1775
void ED_editors_init(bContext *C)
Definition ed_util.cc:103
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void RNA_property_collection_begin(PointerRNA *ptr, PropertyRNA *prop, CollectionPropertyIterator *iter)
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
static wmOperatorStatus wm_userpref_write_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:2752
static void read_homefile_props(wmOperatorType *ot)
Definition wm_files.cc:3135
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
void BLF_reset_fonts()
Definition blf.cc:85
FileReader * BLO_file_reader_uncompressed_from_descriptor(int filedes)
@ V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
void WM_window_set_active_layout(wmWindow *win, WorkSpace *workspace, WorkSpaceLayout *layout)
void ED_outliner_select_sync_from_all_tag(bContext *C)
static wmOperatorStatus wm_save_auto_save_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:2523
int RNA_int_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus wm_open_mainfile__open(bContext *C, wmOperator *op)
Definition wm_files.cc:3379
wmWindow * CTX_wm_window(const bContext *C)
bool AS_asset_library_has_any_unsaved_catalogs()
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void ED_file_read_bookmarks()
const char * BKE_main_blendfile_path_from_global()
Definition main.cc:1063
MINLINE int max_ii(int a, int b)
static void wm_block_save_modified_images_save_button(ui::Block *block, wmGenericCallback *post_action)
Definition wm_files.cc:3853
static std::string wm_save_as_mainfile_get_description(bContext *, wmOperatorType *, PointerRNA *ptr)
Definition wm_files.cc:4268
void IMB_thumb_delete(const char *file_or_lib_path, ThumbSize size)
Definition thumbs.cc:583
void WM_file_autosave_init(wmWindowManager *wm)
Definition wm_files.cc:2472
auto BKE_blender_project_read_callback(const Main *bmain, Fn lambda)
void BKE_blender_userdef_app_template_data_set_and_free(UserDef *userdef)
Definition blender.cc:463
PropertyRNA * RNA_struct_iterator_property(StructRNA *type)
bool WM_autosave_write(wmWindowManager *wm, Main *bmain, ReportList *reports)
Definition wm_files.cc:2427
int BLI_file_stat_mode(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:362
UndoStack * BKE_undosys_stack_create()
void wm_test_autorun_warning(bContext *C)
Definition wm_files.cc:4724
BlendThumbnail * BKE_main_thumbnail_from_imbuf(Main *bmain, ImBuf *img)
Definition main.cc:1005
void wm_save_file_overwrite_dialog(bContext *C, wmOperator *op)
Definition wm_files.cc:5017
bool GPU_backend_type_selection_is_overridden()
int BLI_open(const char *filepath, int oflag, int pmode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static const char * save_modified_images_dialog_name
Definition wm_files.cc:3889
static void wm_read_callback_post_wrapper(bContext *C, const char *filepath, const bool success)
Definition wm_files.cc:877
static ImBuf * blend_file_thumb_from_screenshot(bContext *C, BlendThumbnail **r_thumb)
Definition wm_files.cc:1940
bool BKE_appdir_app_template_any()
Definition appdir.cc:1122
void WM_operatortype_last_properties_clear_all()
void WM_OT_open_mainfile(wmOperatorType *ot)
Definition wm_files.cc:3534
void WM_operator_properties_filesel(wmOperatorType *ot, const int filter, const short type, const eFileSel_Action action, const eFileSel_Flag flag, const short display, const short sort)
void WM_OT_save_homefile(wmOperatorType *ot)
Definition wm_files.cc:2735
void WM_reinit_gizmomap_all(Main *bmain)
static uint8_t * blend_file_thumb_fast_downscale(const uint8_t *src_rect, const int src_size[2], const int dst_size[2])
Definition wm_files.cc:1832
void wm_file_read_report(Main *bmain, wmWindow *win)
Definition wm_files.cc:631
static wmOperatorStatus wm_open_mainfile__select_file_path_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:3347
void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
static wmOperatorStatus operator_state_dispatch(bContext *C, wmOperator *op, OperatorDispatchTarget *targets)
Definition wm_files.cc:3294
void WM_init_splash(bContext *C)
bool wm_file_or_session_data_has_unsaved_changes(const Main *bmain, const wmWindowManager *wm)
Definition wm_files.cc:198
ClearRecentInclude
Definition wm_files.cc:4443
@ CLEAR_RECENT_ALL
Definition wm_files.cc:4443
@ CLEAR_RECENT_MISSING
Definition wm_files.cc:4443
bool ED_image_save_all_modified(const bContext *C, ReportList *reports)
static wmOperatorStatus wm_userpref_read_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:2848
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
void BKE_libblock_free_data(ID *id, bool do_id_user) ATTR_NONNULL()
void wm_window_make_drawable(wmWindowManager *wm, wmWindow *win)
Global G
Definition blender.cc:57
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:1058
static void save_set_compress(wmOperator *op)
Definition wm_files.cc:4025
void WM_window_set_active_screen(wmWindow *win, WorkSpace *workspace, bScreen *screen)
struct LinkNode * BLI_file_read_as_lines(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:591
static void wm_file_read_setup_wm_keep_old(const bContext *C, Main *bmain, BlendFileReadWMSetupData *wm_setup_data, wmWindowManager *wm, const bool load_ui)
Definition wm_files.cc:332
static wmOperatorStatus wm_save_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:4324
void wm_close_and_free(bContext *C, wmWindowManager *wm)
Definition wm.cc:593
bool BKE_main_needs_overwrite_confirm(const Main *bmain)
Definition main.cc:655
static wmOperatorStatus wm_recover_last_session_impl(bContext *C, wmOperator *op, const bool use_scripts_autoexec_check)
Definition wm_files.cc:3648
PropertyType RNA_property_type(PropertyRNA *prop)
void WM_OT_read_factory_userpref(wmOperatorType *ot)
Definition wm_files.cc:2952
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
bool BLI_path_extension_ensure(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
unsigned int uint32_t
Definition BKE_text.h:81
void BKE_blendfile_read_setup_readfile(bContext *C, BlendFileData *bfd, const BlendFileReadParams *params, BlendFileReadWMSetupData *wm_setup_data, BlendFileReadReport *reports, bool startup_update_defaults, const char *startup_app_template)
static void wm_userpref_update_when_changed(bContext *C, Main *bmain, UserDef *userdef_prev, UserDef *userdef_curr)
Definition wm_files.cc:2831
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
static ui::Block * block_create__close_file_dialog(bContext *C, ARegion *region, void *arg1)
Definition wm_files.cc:5173
@ G_BACKGROUND_NO_DEPSGRAPH
@ G_FILE_RECOVER_READ
@ G_FILE_RECOVER_WRITE
@ G_FILE_COMPRESS
@ G_FILE_AUTOPACK
std::optional< std::string > BKE_appdir_folder_id(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
Definition appdir.cc:762
static void save_file_overwrite_saveas(bContext *C, void *arg_block, void *)
Definition wm_files.cc:4897
void WM_event_remove_handlers(bContext *C, ListBaseT< wmEventHandler > *handlers)
void wm_autosave_timer_begin(wmWindowManager *wm)
Definition wm_files.cc:2459
static int2 blend_file_thumb_clamp_size(const int size[2], const int limit)
Definition wm_files.cc:1923
void BKE_undosys_stack_clear(UndoStack *ustack)
void WM_OT_recover_last_session(wmOperatorType *ot)
Definition wm_files.cc:3694
void * BLI_findstring_ptr(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:658
void IMB_freeImBuf(ImBuf *ibuf)
VecBase< int32_t, 2 > int2
static void wm_generic_callback_free_user_data_idproperties(void *user_data)
Definition wm_files.cc:3788
BlendThumbnail * BKE_main_thumbnail_from_buffer(Main *bmain, const uint8_t *rect, const int size[2])
Definition main.cc:983
static void wm_block_file_close_cancel(bContext *C, void *arg_block, void *)
Definition wm_files.cc:5040
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
bool BLT_translate_new_dataname()
static void wm_save_modified_images_dialog(bContext *C, wmGenericCallback *post_action)
Definition wm_files.cc:3983
@ USER_SECTION_DEVELOPER_TOOLS
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
int BLI_path_canonicalize_native(char *path, int path_maxncpy)
bool WM_file_recover_last_session(bContext *C, const bool use_scripts_autoexec_check, ReportList *reports)
Definition wm_files.cc:3636
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_COLLECTION
Definition RNA_types.hh:216
static wmOperatorStatus wm_history_file_read_exec(bContext *, wmOperator *)
Definition wm_files.cc:2972
void WM_keyconfig_reload(bContext *C)
Definition wm.cc:444
@ BLO_WRITE_PATH_REMAP_RELATIVE
@ BLO_WRITE_PATH_REMAP_NONE
@ BLO_WRITE_PATH_REMAP_ABSOLUTE
static wmOperatorStatus wm_userpref_revert_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:2900
void WM_OT_revert_mainfile(wmOperatorType *ot)
Definition wm_files.cc:3617
static void wm_clear_recent_files_ui(bContext *, wmOperator *op)
Definition wm_files.cc:4479
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void BKE_blender_project_recent_update(const Main *bmain)
static void save_file_overwrite_saveas_button(ui::Block *block, wmGenericCallback *post_action)
Definition wm_files.cc:4906
static void file_overwrite_detailed_info_show(ui::Layout &parent_layout, Main *bmain)
Definition wm_files.cc:4791
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
void RNA_property_collection_end(CollectionPropertyIterator *iter)
static std::string wm_save_as_mainfile_get_name(wmOperatorType *ot, PointerRNA *ptr)
Definition wm_files.cc:4260
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
@ WM_FILESEL_FILEPATH
Definition WM_api.hh:1332
void wm_homefile_read_post(bContext *C, const wmFileReadPost_Params *params_file_read_post)
Definition wm_files.cc:1618
bool BKE_appdir_app_template_id_search(const char *app_template, char *path, size_t path_maxncpy) ATTR_NONNULL(1)
Definition appdir.cc:1127
wmWindowManager * CTX_wm_manager(const bContext *C)
static ui::Block * block_create_save_modified_images_dialog(bContext *C, ARegion *region, void *arg)
Definition wm_files.cc:3891
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
int BLI_access(const char *filepath, int mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void WM_OT_read_userpref(wmOperatorType *ot)
Definition wm_files.cc:2913
static char save_images_when_file_is_closed
Definition wm_files.cc:5038
static void wm_history_file_free(RecentFile *recent)
Definition wm_files.cc:1677
std::variant< BlenderHeaderInvalid, BlenderHeaderUnknown, BlenderHeader > BlenderHeaderVariant
void WM_toolsystem_init(const bContext *C)
static void read_factory_reset_props(wmOperatorType *ot)
Definition wm_files.cc:2545
unsigned char uint8_t
Definition BKE_text.h:79
void wm_window_close_request(bContext *C, wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:483
void ED_image_internal_autosave_flush(const Main *bmain)
static void save_file_overwrite_cancel_button(ui::Block *block, wmGenericCallback *post_action)
Definition wm_files.cc:4856
WorkSpaceLayout * BKE_workspace_layout_find_global(const Main *bmain, const bScreen *screen, WorkSpace **r_workspace) ATTR_NONNULL(1
Definition workspace.cc:516
void GPU_backend_type_selection_set_override(GPUBackendType backend_type)
@ USER_FILE_PREVIEW_CAMERA
@ USER_FILE_PREVIEW_SCREENSHOT
void wm_test_autorun_revert_action_set(wmOperatorType *ot, PointerRNA *ptr)
Definition wm_files.cc:4692
static void wm_open_mainfile_ui(bContext *, wmOperator *op)
Definition wm_files.cc:3503
void BKE_scene_free_depsgraph_hash(Scene *scene)
Definition scene.cc:3548
void wm_event_do_depsgraph(bContext *C, bool is_after_open_file)
bool BKE_appdir_app_template_has_userpref(const char *app_template) ATTR_NONNULL(1)
Definition appdir.cc:1141
void WM_init_input_devices()
static RecentFile * wm_history_file_new(const char *filepath)
Definition wm_files.cc:1670
void ED_editors_exit(Main *bmain, bool do_undo_system)
Definition ed_util.cc:230
bool WM_file_read_project(bContext *C, const char *filepath, ReportList *reports)
Definition wm_files.cc:1173
void BLO_sanitize_experimental_features_userpref_blend(UserDef *userdef)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:277
static void wm_autosave_location(char filepath[FILE_MAX])
Definition wm_files.cc:2367
void wm_homefile_read_ex(bContext *C, const wmHomeFileRead_Params *params_homefile, ReportList *reports, wmFileReadPost_Params **r_params_file_read_post)
Definition wm_files.cc:1233
void BPY_python_reset(bContext *C)
bool BPY_run_string_eval(bContext *C, const char *imports[], const char *expr)
static wmOperatorStatus wm_homefile_read_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:3125
BlendFileData * BKE_blendfile_read_from_memory(const void *file_buf, int file_buf_size, const BlendFileReadParams *params, ReportList *reports)
int BLI_thread_is_main()
Definition threads.cc:184
int BLI_rename_overwrite(const char *from, const char *to) ATTR_NONNULL()
Definition fileops_c.cc:541
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
void AS_asset_libraries_exit()
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
static bool wm_save_mainfile_check(bContext *, wmOperator *op)
Definition wm_files.cc:4245
static bool wm_file_read_opwrap(bContext *C, const char *filepath, const bool use_scripts_autoexec_check, ReportList *reports)
Definition wm_files.cc:3255
static bool wm_open_init_use_scripts(wmOperator *op, const OpenTrust source_of_trust)
Definition wm_files.cc:2591
void wm_autosave_timer(Main *bmain, wmWindowManager *wm, wmTimer *)
Definition wm_files.cc:2477
void BKE_packedfile_pack_all(Main *bmain, ReportList *reports, bool verbose)
void wm_window_clear_drawable(wmWindowManager *wm)
bool BLI_file_is_writable(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition fileops_c.cc:293
static int get_operator_state(wmOperator *op)
Definition wm_files.cc:3279
void WM_OT_clear_recent_projects(wmOperatorType *ot)
Definition wm_files.cc:4523
static bool wm_revert_mainfile_poll(bContext *)
Definition wm_files.cc:3611
static wmOperatorStatus wm_homefile_write_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:2647
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
ATTR_WARN_UNUSED_RESULT const size_t num
static void wm_block_save_modified_images_cancel_button(ui::Block *block, wmGenericCallback *post_action)
Definition wm_files.cc:3844
ListBaseT< RenderEngineType > R_engines
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static void save_set_filepath(bContext *C, wmOperator *op)
Definition wm_files.cc:4041
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, ui::AlertIcon icon, bool cancel_default)
bool write_crash_blend()
Definition wm_files.cc:2137
void CTX_wm_region_popup_set(bContext *C, ARegion *region_popup)
static void set_next_operator_state(wmOperator *op, int state)
Definition wm_files.cc:3284
const char * BKE_tempdir_base() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition appdir.cc:1288
int BLI_path_slash_ensure(char *path, size_t path_maxncpy) ATTR_NONNULL(1)
bool BLI_path_extension_replace(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
static bool wm_autosave_write_try(Main *bmain, wmWindowManager *wm)
Definition wm_files.cc:2390
void WM_OT_save_mainfile(wmOperatorType *ot)
Definition wm_files.cc:4390
void WM_OT_save_userpref(wmOperatorType *ot)
Definition wm_files.cc:2764
void BLI_timer_on_file_load()
Definition BLI_timer.cc:144
bool BKE_main_namemap_validate(Main &bmain)
int BLI_listbase_count_at_most(const ListBase *listbase, int count_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:518
static wmOperatorStatus wm_open_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:3423
void BKE_sound_init(Main *bmain)
static void wm_homefile_read_after_dialog_callback(bContext *C, void *user_data)
Definition wm_files.cc:3116
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmMsgBus * CTX_wm_message_bus(const bContext *C)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void BKE_lib_override_library_main_operations_create(Main *bmain, bool force_auto, int *r_report_flags)
@ BLO_READ_SKIP_USERDEF
@ BLO_READ_SKIP_DATA
static const char * close_file_dialog_name
Definition wm_files.cc:5164
void BLI_path_to_display_name(char *display_name, int display_name_maxncpy, const char *name) ATTR_NONNULL(1
bool BLI_path_filename_ensure(char *filepath, size_t filepath_maxncpy, const char *filename) ATTR_NONNULL(1
void wm_exit_schedule_delayed(const bContext *C)
static void wm_recover_last_session_after_dialog_callback(bContext *C, void *user_data)
Definition wm_files.cc:3671
@ THB_SOURCE_BLEND
Definition IMB_thumbs.hh:35
std::string BKE_is_path_inside_blender_project(const char *path)
void RNA_property_collection_next(CollectionPropertyIterator *iter)
wmOperatorStatus WM_operator_props_popup_confirm_ex(bContext *C, wmOperator *op, const wmEvent *, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message)
static void wm_autosave_timer_begin_ex(wmWindowManager *wm, double timestep)
Definition wm_files.cc:2450
void wm_test_foreign_file_warning(bContext *C)
Definition wm_files.cc:4754
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
static struct blender::@303146302033074327013102311372206230213006073251 wm_init_state_app_template
wmOperatorStatus WM_operator_name_call_with_properties(bContext *C, const char *opstring, wm::OpCallContext context, IDProperty *properties, const wmEvent *event)
void IMB_colormanagement_file_save_post(Main *bmain)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
static const char * save_file_overwrite_dialog_name
Definition wm_files.cc:4789
void wm_add_default(Main *bmain, bContext *C)
Definition wm.cc:557
static void wm_file_read_post(bContext *C, const char *filepath, const wmFileReadPost_Params *params)
Definition wm_files.cc:695
void WM_msg_publish_static(wmMsgBus *mbus, int event)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
wmGenericCallback * WM_generic_callback_steal(wmGenericCallback *callback)
Definition wm_utils.cc:32
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
IDNewNameResult BKE_libblock_rename(Main &bmain, ID &id, StringRefNull name, const IDNewNameMode mode=IDNewNameMode::RenameExistingNever)
Definition lib_id.cc:2632
void void void BLI_path_split_file_part(const char *filepath, char *file, size_t file_maxncpy) ATTR_NONNULL(1
static void wm_block_autorun_warning_ignore(bContext *C, ui::Block *block)
Definition wm_files.cc:4547
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
@ FILE_SAVE
Definition WM_api.hh:1342
@ FILE_OPENFILE
Definition WM_api.hh:1341
static void wm_block_autorun_warning_reload_with_scripts(bContext *C, ui::Block *block)
Definition wm_files.cc:4556
void wm_autosave_delete()
Definition wm_files.cc:2503
void WM_file_tag_modified()
Definition wm_files.cc:188
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc)
static void file_read_reports_finalize(BlendFileReadReport *bf_reports)
Definition wm_files.cc:906
static wmOperatorStatus wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:4072
@ G_FLAG_USERPREF_NO_SAVE_ON_EXIT
@ G_FLAG_INTERNET_ALLOW
@ G_FLAG_SCRIPT_AUTOEXEC_FAIL_QUIET
@ G_FLAG_SCRIPT_AUTOEXEC_FAIL
@ G_FLAG_SCRIPT_AUTOEXEC
Main * CTX_data_main(const bContext *C)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
void wm_homefile_read(bContext *C, const wmHomeFileRead_Params *params_homefile, ReportList *reports)
Definition wm_files.cc:1611
static void popup_block_wm_generic_callback_free(void *arg)
Definition wm_files.cc:3782
static void wm_file_read_setup_wm_substitute_old_window(wmWindowManager *oldwm, wmWindowManager *wm, wmWindow *oldwin, wmWindow *win)
Definition wm_files.cc:285
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1403
static struct blender::@126022146021364353211265170353257024064164030157 wm_test_autorun_revert_action_data
static ui::Block * block_create_save_file_overwrite_dialog(bContext *C, ARegion *region, void *arg1)
Definition wm_files.cc:4923
BlendFileData * BKE_blendfile_read(const char *filepath, const BlendFileReadParams *params, BlendFileReadReport *reports)
void WM_OT_read_homefile(wmOperatorType *ot)
Definition wm_files.cc:3153
bool BKE_autoexec_default_trust_source(const char *path, const AutoExec_Params &params)
Definition autoexec.cc:103
bool WM_autosave_is_scheduled(wmWindowManager *wm)
Definition wm_files.cc:2422
static void wm_filepath_default(const Main *bmain, char *filepath)
Definition wm_files.cc:4015
void BKE_undosys_stack_init_from_context(UndoStack *ustack, bContext *C)
void WM_OT_save_auto_save(wmOperatorType *ot)
Definition wm_files.cc:2529
static wmOperatorStatus wm_clear_recent_files_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition wm_files.cc:4451
@ USER_SCRIPT_AUTOEXEC_DISABLE
bool BKE_blendfile_userdef_write_all(ReportList *reports)
static wmOperatorStatus wm_open_mainfile_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:3430
bool BLI_path_contains(const char *container_path, const char *containee_path) ATTR_NONNULL(1
const char * BLT_lang_get()
Definition blt_lang.cc:268
static wmOperatorStatus wm_open_mainfile__discard_changes_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:3332
bool BKE_addon_remove_safe(ListBaseT< bAddon > *addon_list, const char *module)
Definition addon.cc:58
static ui::Block * block_create_autorun_warning(bContext *C, ARegion *region, void *)
Definition wm_files.cc:4581
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
static void save_catalogs_when_file_is_closed_set_fn(bContext *, void *arg1, void *)
Definition wm_files.cc:5166
static void wm_userpref_read_exceptions(UserDef *userdef_curr, const UserDef *userdef_prev)
Definition wm_files.cc:2783
ScrArea * BKE_screen_find_big_area(const bScreen *screen, int spacetype, short min)
Definition screen.cc:1189
int BLI_path_sequence_decode(const char *path, char *head, size_t head_maxncpy, char *tail, size_t tail_maxncpy, unsigned short *r_digits_len)
Definition path_utils.cc:61
uint8_t * WM_window_pixels_read_from_frontbuffer(const wmWindowManager *wm, const wmWindow *win, int r_size[2])
Definition wm_draw.cc:1402
bool BKE_autoexec_match(const char *path, bool canonicalize, bool strip_filename)
Definition autoexec.cc:95
void BLI_path_sequence_encode(char *path, size_t path_maxncpy, const char *head, const char *tail, unsigned short numlen, int pic)
bool BKE_blendfile_extension_check(const char *str)
Definition blendfile.cc:88
static CLG_LogRef LOG
Definition logging.cpp:12
void WM_window_csd_params_update()
double BLI_time_now_seconds()
Definition time.cc:30
static std::string wm_recent_filepath_get(const Main *bmain)
Definition wm_files.cc:1787
static void wm_init_userdef(Main *bmain)
Definition wm_files.cc:525
static void wm_file_read_pre(bool use_data, bool)
Definition wm_files.cc:663
static void wm_test_autorun_revert_action_exec(bContext *C)
Definition wm_files.cc:4705
static wmOperatorStatus wm_homefile_write_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:2706
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Scene * CTX_data_scene(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
static bool wm_file_write(bContext *C, const char *filepath, int fileflags, eBLO_WritePathRemap remap_mode, bool use_save_as_copy, ReportList *reports)
Definition wm_files.cc:2186
bool BPY_run_string_exec(bContext *C, const char *imports[], const char *expr)
void WM_OT_recover_auto_save(wmOperatorType *ot)
Definition wm_files.cc:3756
static void wm_operator_save_modified_images_dialog(bContext *C, wmOperator *op, wmGenericCallbackFn post_action_fn)
Definition wm_files.cc:3996
void wm_clear_default_size(bContext *C)
Definition wm.cc:535
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
bool ED_undosys_autosave_compatible(UndoStack *ustack)
void WM_jobs_kill_all(wmWindowManager *wm)
Definition wm_jobs.cc:621
static wmOperatorStatus wm_revert_mainfile_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:3592
std::string RNA_string_get(PointerRNA *ptr, const char *name)
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const wmEventType event_type, const double time_step)
struct stat BLI_stat_t
ImBuf * ED_view3d_draw_offscreen_imbuf_simple(Depsgraph *depsgraph, Scene *scene, View3DShading *shading_override, eDrawType drawtype, Object *camera, int width, int height, ImBufFlags imbuf_flags, eV3DOffscreenDrawFlag draw_flags, int alpha_mode, const char *viewname, GPUOffScreen *ofs, GPUViewport *viewport, char err_out[256])
void wm_close_file_dialog(bContext *C, wmGenericCallback *post_action)
Definition wm_files.cc:5318
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
int BLI_str_rstrip_digits(char *str) ATTR_NONNULL()
@ BLENDER_USER_CONFIG
void WM_check(bContext *C)
Definition wm.cc:493
void(*)(bContext *C, void *user_data) wmGenericCallbackFn
Definition WM_types.hh:155
ImBuf * IMB_scale_into_new(const ImBuf *ibuf, int2 new_size, IMBScaleFilter filter, bool threaded=true)
Definition scaling.cc:531
ReportList * CTX_wm_reports(const bContext *C)
bool IMB_scale(ImBuf *ibuf, int2 new_size, IMBScaleFilter filter, bool threaded=true)
Definition scaling.cc:467
void BKE_blender_version_blendfile_string_from_values(char *str_buff, const size_t str_buff_maxncpy, const short file_version, const short file_subversion)
Definition blender.cc:157
static void wm_file_read_setup_wm_finalize(bContext *C, Main *bmain, BlendFileReadWMSetupData *wm_setup_data)
Definition wm_files.cc:445
static wmOperatorStatus wm_homefile_read_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:3000
static RecentFile * wm_file_history_find(const char *filepath)
Definition wm_files.cc:1691
bScreen * WM_window_get_active_screen(const wmWindow *win)
void WM_cursor_wait(bool val)
void BLI_file_free_lines(struct LinkNode *lines)
Definition storage.cc:637
static void wm_open_mainfile_def_property_use_scripts(wmOperatorType *ot)
Definition wm_files.cc:3524
bool BKE_blender_project_init_from_root_path(Main *bmain, std::string project_root_path)
int ED_image_save_all_modified_info(const Main *bmain, ReportList *reports)
void wm_autosave_timer_end(wmWindowManager *wm)
Definition wm_files.cc:2464
void ED_view3d_local_collections_reset(const bContext *C, bool reset_all)
static const EnumPropertyItem prop_clear_recent_types[]
Definition wm_files.cc:4445
static void wm_open_mainfile_after_dialog_callback(bContext *C, void *user_data)
Definition wm_files.cc:3323
void wm_open_init_load_ui(wmOperator *op, bool use_prefs)
Definition wm_files.cc:2568
bool ED_image_should_save_modified(const Main *bmain)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
static wmOperatorStatus wm_recover_last_session_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:3680
void BKE_tempdir_init(const char *userdir)
Definition appdir.cc:1245
void IMB_metadata_set_field(IDProperty *metadata, const char *key, const char *value)
void WM_event_add_fileselect(bContext *C, wmOperator *op)
bool WM_window_is_temp_screen(const wmWindow *win)
static wmOperatorStatus wm_recover_last_session_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:3665
void WM_file_autoexec_init(const char *filepath)
Definition wm_files.cc:618
void WM_OT_read_history(wmOperatorType *ot)
Definition wm_files.cc:2979
void WM_init_state_app_template_set(const char *app_template)
Definition wm_files.cc:1210
BlenderHeaderVariant BLO_readfile_blender_header_decode(FileReader *file)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
@ USER_SAVE_MODIFIED_IMAGES_ALWAYS
@ USER_SAVE_MODIFIED_IMAGES_ASK
static int wm_read_exotic(const char *filepath)
Definition wm_files.cc:586
bool RNA_property_equals(Main *bmain, PointerRNA *ptr_a, PointerRNA *ptr_b, PropertyRNA *prop, eRNACompareMode mode)
void BKE_libblock_free_data_py(ID *id)
static wmOperatorStatus wm_read_factory_settings_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:3197
static wmOperatorStatus wm_recover_auto_save_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:3712
void BLI_filelist_entry_size_to_string(const struct stat *st, uint64_t st_size_fallback, bool compact, char r_size[FILELIST_DIRENTRY_SIZE_LEN])
UserDef * BKE_blendfile_userdef_from_defaults()
static OperatorDispatchTarget wm_open_mainfile_dispatch_targets[]
Definition wm_files.cc:3411
struct blender::BlendFileReadReport::@140003175311343306107257242277261221002217304000 count
LinkNode * resynced_lib_overrides_libraries
struct blender::BlendFileReadReport::@070156237370130334241363347365056360307125257043 duration
eBLO_WritePathRemap remap_mode
const BlendThumbnail * thumb
FileReaderCloseFn close
char name[258]
Definition DNA_ID.h:433
IDProperty * metadata_for_write()
bke::library::LibraryRuntime * runtime
Definition DNA_ID.h:591
struct LinkNode * next
ListBaseT< wmWindowManager > wm
Definition BKE_main.hh:415
char filepath[1024]
Definition BKE_main.hh:267
MainColorspace colorspace
Definition BKE_main.hh:371
ListBaseT< Library > libraries
Definition BKE_main.hh:387
short versionfile
Definition BKE_main.hh:269
short subversionfile
Definition BKE_main.hh:270
bool is_asset_edit_file
Definition BKE_main.hh:288
ListBaseT< WorkSpace > workspaces
Definition BKE_main.hh:423
bool has_forward_compatibility_issues
Definition BKE_main.hh:281
ListBaseT< Scene > scenes
Definition BKE_main.hh:386
BlendThumbnail * blen_thumb
Definition BKE_main.hh:356
ListBaseT< bScreen > screens
Definition BKE_main.hh:400
wmOperatorStatus(*) run(bContext *C, wmOperator *op)
Definition wm_files.cc:3291
StructRNA * type
Definition RNA_types.hh:63
RecentFile * next
Definition WM_types.hh:1555
ListBaseT< Report > list
Definition BKE_report.hh:79
const char * message
Definition BKE_report.hh:73
struct Object * camera
struct RenderData r
ListBaseT< SpaceLink > spacedata
UserDef_Runtime runtime
View3DShading shading
struct View3D * localvd
View3D_Runtime runtime
ListBaseT< struct ScrArea > areabase
ListBaseT< wmKeyConfig > keyconfigs
ListBaseT< wmEventHandler > handlers
ListBaseT< wmEventHandler > modalhandlers
void enabled_set(bool enabled)
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
void label(StringRef name, int icon)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void active_set(bool active)
Layout & split(float percentage, bool align)
Layout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
void scale_y_set(float scale)
eWM_EventHandlerType type
wmGenericUserDataFreeFn free_user_data
Definition WM_types.hh:160
wmGenericCallbackFn exec
Definition WM_types.hh:158
unsigned int use_factory_settings
Definition wm_files.hh:39
const char * filepath_startup_override
Definition wm_files.hh:55
unsigned int use_factory_settings_app_template_only
Definition wm_files.hh:41
const char * app_template_override
Definition wm_files.hh:60
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
bool(*) check(bContext *C, wmOperator *op)
Definition WM_types.hh:1133
const char * description
Definition WM_types.hh:1115
const char * translation_context
Definition WM_types.hh:1113
void(*) ui(bContext *C, wmOperator *op)
Definition WM_types.hh:1176
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
std::string(*) get_description(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1197
std::string(*) get_name(wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1191
struct ReportList * reports
struct wmOperatorType * type
bke::WindowManagerRuntime * runtime
bke::WindowRuntime * runtime
struct WorkSpaceInstanceHook * workspace_hook
uiFontStyle widget
short columnspace
#define BKE_READ_EXOTIC_OK_BLEND
Definition wm_files.cc:571
#define BKE_READ_EXOTIC_FAIL_FORMAT
Definition wm_files.cc:569
#define BKE_READ_EXOTIC_FAIL_OPEN
Definition wm_files.cc:570
#define USERDEF_RESTORE(member)
#define BKE_READ_EXOTIC_FAIL_PATH
Definition wm_files.cc:568