Blender V4.5
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.h`
26 * because 'near' is disabled through `BLI_windstuff.h`. */
27# include "BLI_winstuff.h"
28# include <shlobj.h>
29#endif
30
31#include <fmt/format.h>
32
34#include "MEM_guardedalloc.h"
35
36#include "BLI_fileops.h"
37#include "BLI_filereader.h"
38#include "BLI_linklist.h"
39#include "BLI_listbase.h"
40#include "BLI_math_time.h"
41#include "BLI_memory_cache.hh"
42#include "BLI_string.h"
43#include "BLI_system.h"
44#include "BLI_threads.h"
45#include "BLI_time.h"
46#include "BLI_timer.h"
47#include "BLI_utildefines.h"
48#include BLI_SYSTEM_PID_H
49
50#include "BLO_readfile.hh"
51#include "BLT_translation.hh"
52
53#include "BLF_api.hh"
54
55#include "DNA_scene_types.h"
56#include "DNA_screen_types.h"
57#include "DNA_space_types.h"
58#include "DNA_userdef_types.h"
60#include "DNA_workspace_types.h"
61
62#include "AS_asset_library.hh"
63
64#ifndef WITH_CYCLES
65# include "BKE_addon.h"
66#endif
67#include "BKE_appdir.hh"
68#include "BKE_autoexec.hh"
69#include "BKE_blender.hh"
70#include "BKE_blender_version.h"
71#include "BKE_blendfile.hh"
72#include "BKE_callbacks.hh"
73#include "BKE_context.hh"
74#include "BKE_global.hh"
75#include "BKE_idprop.hh"
76#include "BKE_lib_id.hh"
77#include "BKE_lib_override.hh"
78#include "BKE_lib_remap.hh"
79#include "BKE_library.hh"
80#include "BKE_main.hh"
81#include "BKE_main_namemap.hh"
82#include "BKE_node.hh"
83#include "BKE_packedFile.hh"
84#include "BKE_report.hh"
85#include "BKE_scene.hh"
86#include "BKE_screen.hh"
87#include "BKE_sound.h"
88#include "BKE_undo_system.hh"
89#include "BKE_workspace.hh"
90
91#include "BLO_writefile.hh"
92
93#include "RNA_access.hh"
94#include "RNA_define.hh"
95
96#include "IMB_imbuf.hh"
97#include "IMB_imbuf_types.hh"
98#include "IMB_metadata.hh"
99#include "IMB_thumbs.hh"
100
101#include "ED_asset.hh"
102#include "ED_datafiles.h"
103#include "ED_fileselect.hh"
104#include "ED_image.hh"
105#include "ED_outliner.hh"
106#include "ED_render.hh"
107#include "ED_screen.hh"
108#include "ED_undo.hh"
109#include "ED_util.hh"
110#include "ED_view3d.hh"
111#include "ED_view3d_offscreen.hh"
112
113#include "NOD_composite.hh"
114
115#include "GHOST_C-api.h"
116#include "GHOST_Path-api.hh"
117
118#include "GPU_context.hh"
119
120#include "SEQ_sequencer.hh"
121
122#include "UI_interface.hh"
123#include "UI_resources.hh"
124#include "UI_view2d.hh"
125
126/* Only to report a missing engine. */
127#include "RE_engine.h"
128
129#ifdef WITH_PYTHON
130# include "BPY_extern_python.hh"
131# include "BPY_extern_run.hh"
132#endif
133
134#include "DEG_depsgraph.hh"
135
136#include "WM_api.hh"
137#include "WM_keymap.hh"
138#include "WM_message.hh"
139#include "WM_toolsystem.hh"
140#include "WM_types.hh"
141
142#include "wm.hh"
143#include "wm_event_system.hh"
144#include "wm_files.hh"
145#include "wm_window.hh"
146
147#include "CLG_log.h"
148
149static RecentFile *wm_file_history_find(const char *filepath);
150static void wm_history_file_free(RecentFile *recent);
151static void wm_history_files_free();
152static void wm_history_file_update();
153static void wm_history_file_write();
154
156
157static CLG_LogRef LOG = {"wm.files"};
158
168#define USE_THUMBNAIL_FAST_DOWNSCALE
169
170/* -------------------------------------------------------------------- */
173
175{
176 wmWindowManager *wm = static_cast<wmWindowManager *>(G_MAIN->wm.first);
177 if (wm->file_saved) {
178 wm->file_saved = 0;
179 /* Notifier that data changed, for save-over warning or header. */
181 }
182}
183
189
191
192/* -------------------------------------------------------------------- */
195
203
209 Main *bmain,
210 const bool is_read_homefile)
211{
212 using namespace blender;
213 BLI_assert(BLI_listbase_count_at_most(&bmain->wm, 2) <= 1);
214 wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
216 wm_setup_data->is_read_homefile = is_read_homefile;
217 /* This info is not always known yet when this function is called. */
218 wm_setup_data->is_factory_startup = false;
219
220 if (wm == nullptr) {
221 return wm_setup_data;
222 }
223
224 /* First wrap up running stuff.
225 *
226 * Code copied from `wm_init_exit.cc`. */
228
229 wmWindow *active_win = CTX_wm_window(C);
230 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
231 CTX_wm_window_set(C, win); /* Needed by operator close callbacks. */
232 WM_event_remove_handlers(C, &win->handlers);
233 WM_event_remove_handlers(C, &win->modalhandlers);
235 }
236 /* Reset active window. */
237 CTX_wm_window_set(C, active_win);
238
239 /* NOTE(@ideasman42): Clear the message bus so it's always cleared on file load.
240 * Otherwise it's cleared when "Load UI" is set (see #USER_FILENOUI and #wm_close_and_free).
241 * However it's _not_ cleared when the UI is kept. This complicates use from add-ons
242 * which can re-register subscribers on file-load. To support this use case,
243 * it's best to have predictable behavior - always clear. */
244 if (wm->message_bus != nullptr) {
245 WM_msgbus_destroy(wm->message_bus);
246 wm->message_bus = nullptr;
247 }
248
249 /* XXX Hack! We have to clear context popup-region here, because removing all
250 * #wmWindow::modalhandlers above frees the active menu (at least, in the 'startup splash' case),
251 * causing use-after-free error in later handling of the button callbacks in UI code
252 * (see #ui_apply_but_funcs_after()).
253 * Tried solving this by always nullptr-ing context's menu when setting wm/win/etc.,
254 * but it broke popups refreshing (see #47632),
255 * so for now just handling this specific case here. */
256 CTX_wm_region_popup_set(C, nullptr);
257
258 ED_editors_exit(bmain, true);
259
260 /* Asset loading is done by the UI/editors and they keep pointers into it. So make sure to clear
261 * it after UI/editors. */
264
265 /* NOTE: `wm_setup_data->old_wm` cannot be set here, as this pointer may be swapped with the
266 * newly read one in `setup_app_data` process (See #swap_wm_data_for_blendfile). */
267
268 return wm_setup_data;
269}
270
273 wmWindow *oldwin,
274 wmWindow *win)
275{
276 win->ghostwin = oldwin->ghostwin;
277 win->gpuctx = oldwin->gpuctx;
278 win->active = oldwin->active;
279 if (win->active) {
280 wm->winactive = win;
281 }
282 if (oldwm->windrawable == oldwin) {
283 oldwm->windrawable = nullptr;
284 wm->windrawable = win;
285 }
286
287 /* File loading in background mode still calls this. */
288 if (!G.background) {
289 /* Pointer back. */
290 GHOST_SetWindowUserData(static_cast<GHOST_WindowHandle>(win->ghostwin), win);
291 }
292
293 oldwin->ghostwin = nullptr;
294 oldwin->gpuctx = nullptr;
295
296 win->eventstate = oldwin->eventstate;
298 oldwin->eventstate = nullptr;
299 oldwin->event_last_handled = nullptr;
300
301 /* Ensure proper screen re-scaling. */
302 win->sizex = oldwin->sizex;
303 win->sizey = oldwin->sizey;
304 win->posx = oldwin->posx;
305 win->posy = oldwin->posy;
306}
307
318 Main *bmain,
319 BlendFileReadWMSetupData *wm_setup_data,
321 const bool load_ui)
322{
323 /* This data is not needed here, besides detecting that old WM has been kept (in caller code).
324 * Since `old_wm` is kept, do not free it, just clear the pointer as clean-up. */
325 wm_setup_data->old_wm = nullptr;
326
327 if (!load_ui) {
328 /* When loading without UI (i.e. keeping existing UI), no matching needed.
329 *
330 * The other UI data (workspaces, layouts, screens) has also been re-used from old Main, and
331 * newly read one from file has already been discarded in #setup_app_data. */
332 return;
333 }
334
335 /* Old WM is being reused, but other UI data (workspaces, layouts, screens) comes from the new
336 * file, so the WM needs to be updated to use these. */
337 bScreen *screen = CTX_wm_screen(C);
338 if (screen != nullptr) {
339 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
340 WorkSpace *workspace;
341
342 WorkSpaceLayout *layout_ref = BKE_workspace_layout_find_global(bmain, screen, &workspace);
343 BKE_workspace_active_set(win->workspace_hook, workspace);
344 win->scene = CTX_data_scene(C);
345
346 /* All windows get active screen from file. */
347 if (screen->winid == 0) {
348 WM_window_set_active_screen(win, workspace, screen);
349 }
350 else {
351#if 0
352 /* NOTE(@ideasman42): The screen referenced from the window has been freed,
353 * see: #107525. */
355#endif
357 bmain, workspace, layout_ref, win);
358
359 WM_window_set_active_layout(win, workspace, layout_new);
360 }
361
362 bScreen *win_screen = WM_window_get_active_screen(win);
363 win_screen->winid = win->winid;
364 }
365 }
366}
367
369 Main * /*bmain*/,
370 BlendFileReadWMSetupData *wm_setup_data,
372{
373 wmWindowManager *old_wm = wm_setup_data->old_wm;
374
375 wm->op_undo_depth = old_wm->op_undo_depth;
376
377 /* Move existing key configurations into the new WM. */
378 wm->keyconfigs = old_wm->keyconfigs;
379 wm->addonconf = old_wm->addonconf;
380 wm->defaultconf = old_wm->defaultconf;
381 wm->userconf = old_wm->userconf;
382
384 old_wm->addonconf = nullptr;
385 old_wm->defaultconf = nullptr;
386 old_wm->userconf = nullptr;
387
388 /* Ensure new keymaps are made, and space types are set. */
389 wm->init_flag = 0;
390 wm->winactive = nullptr;
391
392 /* Clearing drawable of old WM before deleting any context to avoid clearing the wrong wm. */
394
395 bool has_match = false;
396 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
397 LISTBASE_FOREACH (wmWindow *, old_win, &old_wm->windows) {
398 if (old_win->winid == win->winid) {
399 has_match = true;
400
401 wm_file_read_setup_wm_substitute_old_window(old_wm, wm, old_win, win);
402 }
403 }
404 }
405 /* Ensure that at least one window is kept open so we don't lose the context, see #42303. */
406 if (!has_match) {
408 wm,
409 static_cast<wmWindow *>(old_wm->windows.first),
410 static_cast<wmWindow *>(wm->windows.first));
411 }
412
413 wm_setup_data->old_wm = nullptr;
414 wm_close_and_free(C, old_wm);
415 /* Don't handle user counts as this is only ever called once #G_MAIN has already been freed via
416 * #BKE_main_free so any access to ID's referenced by the window-manager (from ID properties)
417 * will crash. See: #100703. */
418 BKE_libblock_free_data(&old_wm->id, false);
420 MEM_freeN(old_wm);
421}
422
430 Main *bmain,
431 BlendFileReadWMSetupData *wm_setup_data)
432{
433 BLI_assert(BLI_listbase_count_at_most(&bmain->wm, 2) <= 1);
434 BLI_assert(wm_setup_data != nullptr);
435 wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
436
437 /* If reading factory startup file, and there was no previous WM, clear the size of the windows
438 * in newly read WM so that they get resized to occupy the whole available space on current
439 * monitor.
440 */
441 if (wm_setup_data->is_read_homefile && wm_setup_data->is_factory_startup &&
442 wm_setup_data->old_wm == nullptr)
443 {
445 }
446
447 if (wm == nullptr) {
448 /* Add a default WM in case none exists in newly read main (should only happen when opening
449 * an old pre-2.5 .blend file at startup). */
450 wm_add_default(bmain, C);
451 }
452 else if (wm_setup_data->old_wm != nullptr) {
453 if (wm_setup_data->old_wm == wm) {
454 /* Old WM was kept, update it with new workspaces/layouts/screens read from file.
455 *
456 * Happens when not loading UI, or when the newly read file has no WM (pre-2.5 files). */
458 C, bmain, wm_setup_data, wm, (G.fileflags & G_FILE_NO_UI) == 0);
459 }
460 else {
461 /* Using new WM from read file, try to keep current GHOST windows, transfer keymaps, etc.,
462 * from old WM.
463 *
464 * Also takes care of clearing old WM data (temporarily stored in `wm_setup_data->old_wm`).
465 */
466 wm_file_read_setup_wm_use_new(C, bmain, wm_setup_data, wm);
467 }
468 }
469 /* Else just using the new WM read from file, nothing to do. */
470 BLI_assert(wm_setup_data->old_wm == nullptr);
471 MEM_delete(wm_setup_data);
472
473 /* UI Updates. */
474 /* Flag local View3D's to check and exit if they are empty. */
475 LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
476 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
477 LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
478 if (sl->spacetype == SPACE_VIEW3D) {
479 View3D *v3d = reinterpret_cast<View3D *>(sl);
480 if (v3d->localvd) {
482 }
483 }
484 }
485 }
486 }
487}
488
490
491/* -------------------------------------------------------------------- */
494
496{
497 /* Check if GPU backend is already set from the command line arguments. The command line
498 * arguments have higher priority than user preferences. */
500 return;
501 }
502
504}
505
509static void wm_init_userdef(Main *bmain)
510{
511 /* Not versioning, just avoid errors. */
512#ifndef WITH_CYCLES
513 BKE_addon_remove_safe(&U.addons, "cycles");
514#endif
515
517
518 /* Needed so loading a file from the command line respects user-pref #26156. */
519 SET_FLAG_FROM_TEST(G.fileflags, U.flag & USER_FILENOUI, G_FILE_NO_UI);
520
522 G.autoexec_override.value_or((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0),
524
525 /* Only reset "offline mode" if they weren't passes via command line arguments. */
526 if ((G.f & G_FLAG_INTERNET_OVERRIDE_PREF_ANY) == 0) {
528 }
529
530 const int64_t cache_limit = int64_t(U.memcachelimit) * 1024 * 1024;
531 MEM_CacheLimiter_set_maximum(cache_limit);
533
534 BKE_sound_init(bmain);
535
536 /* Update the temporary directory from the preferences or fall back to the system default. */
537 BKE_tempdir_init(U.tempdir);
538
539 /* Update input device preference. */
541
543
546}
547
548/* Return codes. */
549#define BKE_READ_EXOTIC_FAIL_PATH -3 /* File format is not supported. */
550#define BKE_READ_EXOTIC_FAIL_FORMAT -2 /* File format is not supported. */
551#define BKE_READ_EXOTIC_FAIL_OPEN -1 /* Can't open the file. */
552#define BKE_READ_EXOTIC_OK_BLEND 0 /* `.blend` file. */
553#if 0
554# define BKE_READ_EXOTIC_OK_OTHER 1 /* Other supported formats. */
555#endif
556
558
559/* -------------------------------------------------------------------- */
565
566/* Intended to check for non-blender formats but for now it only reads blends. */
567static int wm_read_exotic(const char *filepath)
568{
569 /* Make sure we're not trying to read a directory. */
570
571 int filepath_len = strlen(filepath);
572 if (filepath_len > 0 && ELEM(filepath[filepath_len - 1], '/', '\\')) {
574 }
575
576 /* Open the file. */
577 const int filedes = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
578 if (filedes == -1) {
580 }
581
582 FileReader *rawfile = BLI_filereader_new_file(filedes);
583 if (rawfile == nullptr) {
585 }
586
587 /* Read the header (7 bytes are enough to identify all known types). */
588 char header[7];
589 if (rawfile->read(rawfile, header, sizeof(header)) != sizeof(header)) {
590 rawfile->close(rawfile);
592 }
593 rawfile->seek(rawfile, 0, SEEK_SET);
594
595 /* Check for uncompressed `.blend`. */
596 if (STREQLEN(header, "BLENDER", 7)) {
597 rawfile->close(rawfile);
599 }
600
601 /* Check for compressed `.blend`. */
602 FileReader *compressed_file = nullptr;
603 if (BLI_file_magic_is_gzip(header)) {
604 /* In earlier versions of Blender (before 3.0), compressed files used `Gzip` instead of `Zstd`.
605 * While these files will no longer be written, there still needs to be reading support. */
606 compressed_file = BLI_filereader_new_gzip(rawfile);
607 }
608 else if (BLI_file_magic_is_zstd(header)) {
609 compressed_file = BLI_filereader_new_zstd(rawfile);
610 }
611
612 /* If a compression signature matches,
613 * try decompressing the start and check if it's a `.blend`. */
614 if (compressed_file != nullptr) {
615 size_t len = compressed_file->read(compressed_file, header, sizeof(header));
616 compressed_file->close(compressed_file);
617 if (len == sizeof(header) && STREQLEN(header, "BLENDER", 7)) {
619 }
620 }
621 else {
622 rawfile->close(rawfile);
623 }
624
625 /* Add check for future file formats here. */
626
628}
629
631
632/* -------------------------------------------------------------------- */
635
636void WM_file_autoexec_init(const char *filepath)
637{
638 if (G.autoexec_override.has_value()) {
639 return;
640 }
641 if (G.f & G_FLAG_SCRIPT_AUTOEXEC) {
642 char dirpath[FILE_MAX];
643 BLI_path_split_dir_part(filepath, dirpath, sizeof(dirpath));
644 /* Recovering a session that was never saved has no path to check. */
645 if ((filepath[0] != '\0') && BKE_autoexec_match(dirpath)) {
647 }
648 }
649}
650
652{
653 wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
654 ReportList *reports = &wm->runtime->reports;
655 bool found = false;
656 LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
657 if (scene->r.engine[0] &&
658 BLI_findstring(&R_engines, scene->r.engine, offsetof(RenderEngineType, idname)) == nullptr)
659 {
661 RPT_ERROR,
662 "Engine '%s' not available for scene '%s' (an add-on may need to be installed "
663 "or enabled)",
664 scene->r.engine,
665 scene->id.name + 2);
666 found = true;
667 }
668 }
669
670 if (found) {
671 if (!G.background) {
673 }
674 }
675}
676
683static void wm_file_read_pre(bool use_data, bool /*use_userdef*/)
684{
685 if (use_data) {
687 }
688
689 /* Always do this as both startup and preferences may have loaded in many font's
690 * at a different zoom level to the file being loaded. */
692
694}
695
712
718 const char *filepath,
719 const wmFileReadPost_Params *params)
720{
722
723 const bool use_data = params->use_data;
724 const bool use_userdef = params->use_userdef;
725 const bool is_startup_file = params->is_startup_file;
726 const bool is_factory_startup = params->is_factory_startup;
727 const bool reset_app_template = params->reset_app_template;
728
729 bool addons_loaded = false;
730
731 if (use_data) {
732 if (!G.background) {
733 /* Remove windows which failed to be added via #WM_check. */
735 }
736 CTX_wm_window_set(C, static_cast<wmWindow *>(wm->windows.first));
737 }
738
739#ifdef WITH_PYTHON
740 if (is_startup_file) {
741 /* The following block handles data & preferences being reloaded
742 * which requires resetting some internal variables. */
743 if (!params->is_first_time) {
745 bool reset_all = use_userdef;
746 if (use_userdef || reset_app_template) {
747 /* Only run when we have a template path found. */
749 const char *imports[] = {"bl_app_template_utils", nullptr};
750 BPY_run_string_eval(C, imports, "bl_app_template_utils.reset()");
751 reset_all = true;
752 }
753 }
754 if (reset_all) {
755 const char *imports[] = {"bpy", "addon_utils", nullptr};
757 C,
758 imports,
759 /* Refresh scripts as the preferences may have changed the user-scripts path.
760 *
761 * This is needed when loading settings from the previous version,
762 * otherwise the script path stored in the preferences would be ignored. */
763 "bpy.utils.refresh_script_paths()\n"
764 /* Sync add-ons, these may have changed from the defaults. */
765 "addon_utils.reset_all()");
766 }
767 if (use_data) {
769 }
770 addons_loaded = true;
771 }
772 }
773 else {
774 /* Run any texts that were loaded in and flagged as modules. */
775 if (use_data) {
777 }
778 addons_loaded = true;
779 }
780#else
781 UNUSED_VARS(is_startup_file, reset_app_template);
782#endif /* WITH_PYTHON */
783
784 Main *bmain = CTX_data_main(C);
785
786 if (use_userdef) {
787 if (is_factory_startup) {
789 }
790 }
791
792 if (is_factory_startup && BLT_translate_new_dataname()) {
793 /* Translate workspace names. */
794 LISTBASE_FOREACH_MUTABLE (WorkSpace *, workspace, &bmain->workspaces) {
796 *bmain, workspace->id, CTX_DATA_(BLT_I18NCONTEXT_ID_WORKSPACE, workspace->id.name + 2));
797 }
798 }
799
800 if (use_data) {
801 /* Important to do before nulling the context. */
803
804 /* Load-post must run before evaluating drivers & depsgraph, see: #109720.
805 * On failure, the caller handles #BKE_CB_EVT_LOAD_POST_FAIL. */
806 if (params->success) {
808 }
809
810 if (is_factory_startup) {
812 }
813 }
814
815 if (use_data) {
817
818 /* After load post, so for example the driver namespace can be filled
819 * before evaluating the depsgraph. */
820 if (!G.background || (G.fileflags & G_BACKGROUND_NO_DEPSGRAPH) == 0) {
822 }
823
825
826 /* Add-ons are disabled when loading the startup file, so the Render Layer node in compositor
827 * node trees might be wrong due to missing render engines that are available as add-ons, like
828 * Cycles. So we need to update compositor node trees after reading the file when add-ons are
829 * now loaded. */
830 if (is_startup_file) {
831 FOREACH_NODETREE_BEGIN (bmain, node_tree, owner_id) {
832 if (node_tree->type == NTREE_COMPOSIT) {
834 }
835 }
837 }
838
839#if 1
841 /* Clear static filtered asset tree caches. */
843#else
845#endif
846 }
847
848 /* Report any errors.
849 * Currently disabled if add-ons aren't yet loaded. */
850 if (addons_loaded) {
851 wm_file_read_report(bmain, static_cast<wmWindow *>(wm->windows.first));
852 }
853
854 if (use_data) {
855 if (!G.background) {
856 if (wm->undo_stack == nullptr) {
857 wm->undo_stack = BKE_undosys_stack_create();
858 }
859 else {
860 BKE_undosys_stack_clear(wm->undo_stack);
861 }
862 BKE_undosys_stack_init_from_main(wm->undo_stack, bmain);
864 }
865 }
866
867 if (use_data) {
868 if (!G.background) {
869 /* In background mode this makes it hard to load
870 * a blend file and do anything since the screen
871 * won't be set to a valid value again. */
872 CTX_wm_window_set(C, nullptr); /* Exits queues. */
873
874 /* Ensure auto-run action is not used from a previous blend file load. */
875 wm_test_autorun_revert_action_set(nullptr, nullptr);
876
877 /* Ensure tools are registered. */
879 }
880 }
881}
882
883static void wm_read_callback_pre_wrapper(bContext *C, const char *filepath)
884{
885 /* NOTE: either #BKE_CB_EVT_LOAD_POST or #BKE_CB_EVT_LOAD_POST_FAIL must run.
886 * Runs at the end of this function, don't return beforehand. */
888}
889
890static void wm_read_callback_post_wrapper(bContext *C, const char *filepath, const bool success)
891{
892 Main *bmain = CTX_data_main(C);
893 /* Temporarily set the window context as this was once supported, see: #107759.
894 * If the window is already set, don't change it. */
895 bool has_window = CTX_wm_window(C) != nullptr;
896 if (!has_window) {
897 wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
898 wmWindow *win = static_cast<wmWindow *>(wm->windows.first);
899 CTX_wm_window_set(C, win);
900 }
901
902 /* On success: #BKE_CB_EVT_LOAD_POST runs from #wm_file_read_post. */
903 if (success == false) {
905 }
906
907 /* This function should leave the window null when the function entered. */
908 if (!has_window) {
909 CTX_wm_window_set(C, nullptr);
910 }
911}
912
914
915/* -------------------------------------------------------------------- */
918
920{
921 double duration_whole_minutes, duration_whole_seconds;
922 double duration_libraries_minutes, duration_libraries_seconds;
923 double duration_lib_override_minutes, duration_lib_override_seconds;
924 double duration_lib_override_resync_minutes, duration_lib_override_resync_seconds;
925 double duration_lib_override_recursive_resync_minutes,
926 duration_lib_override_recursive_resync_seconds;
927
929 nullptr,
930 nullptr,
931 &duration_whole_minutes,
932 &duration_whole_seconds,
933 nullptr);
934 BLI_math_time_seconds_decompose(bf_reports->duration.libraries,
935 nullptr,
936 nullptr,
937 &duration_libraries_minutes,
938 &duration_libraries_seconds,
939 nullptr);
940 BLI_math_time_seconds_decompose(bf_reports->duration.lib_overrides,
941 nullptr,
942 nullptr,
943 &duration_lib_override_minutes,
944 &duration_lib_override_seconds,
945 nullptr);
946 BLI_math_time_seconds_decompose(bf_reports->duration.lib_overrides_resync,
947 nullptr,
948 nullptr,
949 &duration_lib_override_resync_minutes,
950 &duration_lib_override_resync_seconds,
951 nullptr);
952 BLI_math_time_seconds_decompose(bf_reports->duration.lib_overrides_recursive_resync,
953 nullptr,
954 nullptr,
955 &duration_lib_override_recursive_resync_minutes,
956 &duration_lib_override_recursive_resync_seconds,
957 nullptr);
958
959 CLOG_INFO(
960 &LOG, 0, "Blender file read in %.0fm%.2fs", duration_whole_minutes, duration_whole_seconds);
961 CLOG_INFO(&LOG,
962 0,
963 " * Loading libraries: %.0fm%.2fs",
964 duration_libraries_minutes,
965 duration_libraries_seconds);
966 CLOG_INFO(&LOG,
967 0,
968 " * Applying overrides: %.0fm%.2fs",
969 duration_lib_override_minutes,
970 duration_lib_override_seconds);
971 CLOG_INFO(&LOG,
972 0,
973 " * Resyncing overrides: %.0fm%.2fs (%d root overrides), including recursive "
974 "resyncs: %.0fm%.2fs)",
975 duration_lib_override_resync_minutes,
976 duration_lib_override_resync_seconds,
977 bf_reports->count.resynced_lib_overrides,
978 duration_lib_override_recursive_resync_minutes,
979 duration_lib_override_recursive_resync_seconds);
980
981 if (bf_reports->resynced_lib_overrides_libraries_count != 0) {
982 for (LinkNode *node_lib = bf_reports->resynced_lib_overrides_libraries; node_lib != nullptr;
983 node_lib = node_lib->next)
984 {
985 Library *library = static_cast<Library *>(node_lib->link);
986 BKE_reportf(bf_reports->reports,
987 RPT_INFO,
988 "Library \"%s\" needs overrides resync",
989 library->filepath);
990 }
991 }
992
993 if (bf_reports->count.missing_libraries != 0 || bf_reports->count.missing_linked_id != 0) {
994 BKE_reportf(bf_reports->reports,
996 "%d libraries and %d linked data-blocks are missing (including %d ObjectData), "
997 "please check the Info and Outliner editors for details",
998 bf_reports->count.missing_libraries,
999 bf_reports->count.missing_linked_id,
1000 bf_reports->count.missing_obdata);
1001 }
1002 else {
1003 if (bf_reports->count.missing_obdata != 0) {
1004 CLOG_WARN(&LOG,
1005 "%d local ObjectData are reported to be missing, this should never happen",
1006 bf_reports->count.missing_obdata);
1007 }
1008 }
1009
1010 if (bf_reports->resynced_lib_overrides_libraries_count != 0) {
1011 BKE_reportf(bf_reports->reports,
1013 "%d libraries have overrides needing resync (auto resynced in %.0fm%.2fs), "
1014 "please check the Info editor for details",
1016 duration_lib_override_recursive_resync_minutes,
1017 duration_lib_override_recursive_resync_seconds);
1018 }
1019
1020 if (bf_reports->count.proxies_to_lib_overrides_success != 0 ||
1021 bf_reports->count.proxies_to_lib_overrides_failures != 0)
1022 {
1023 BKE_reportf(bf_reports->reports,
1025 "Proxies have been removed from Blender (%d proxies were automatically converted "
1026 "to library overrides, %d proxies could not be converted and were cleared). "
1027 "Consider re-saving any library .blend file with the newest Blender version",
1028 bf_reports->count.proxies_to_lib_overrides_success,
1029 bf_reports->count.proxies_to_lib_overrides_failures);
1030 }
1031
1032 if (bf_reports->count.sequence_strips_skipped != 0) {
1033 BKE_reportf(bf_reports->reports,
1034 RPT_ERROR,
1035 "%d sequence strips were not read because they were in a channel larger than %d",
1036 bf_reports->count.sequence_strips_skipped,
1038 }
1039
1041 bf_reports->resynced_lib_overrides_libraries = nullptr;
1042}
1043
1045 const char *filepath,
1046 const bool use_scripts_autoexec_check,
1048{
1049 /* Assume automated tasks with background, don't write recent file list. */
1050 const bool do_history_file_update = (G.background == false) &&
1051 (CTX_wm_manager(C)->op_undo_depth == 0);
1052 bool success = false;
1053
1054 const bool use_data = true;
1055 const bool use_userdef = false;
1056
1057 /* NOTE: a matching #wm_read_callback_post_wrapper must be called. */
1059
1060 Main *bmain = CTX_data_main(C);
1061
1062 /* So we can get the error message. */
1063 errno = 0;
1064
1065 WM_cursor_wait(true);
1066
1067 /* First try to append data from exotic file formats. */
1068 /* It throws error box when file doesn't exist and returns -1. */
1069 /* NOTE(ton): it should set some error message somewhere. */
1070 const int retval = wm_read_exotic(filepath);
1071
1072 /* We didn't succeed, now try to read Blender file. */
1073 if (retval == BKE_READ_EXOTIC_OK_BLEND) {
1074 BlendFileReadParams params{};
1075 params.is_startup = false;
1076 /* Loading preferences when the user intended to load a regular file is a security
1077 * risk, because the excluded path list is also loaded. Further it's just confusing
1078 * if a user loads a file and various preferences change. */
1080
1081 BlendFileReadReport bf_reports{};
1082 bf_reports.reports = reports;
1083 bf_reports.duration.whole = BLI_time_now_seconds();
1084 BlendFileData *bfd = BKE_blendfile_read(filepath, &params, &bf_reports);
1085 if (bfd != nullptr) {
1086 wm_file_read_pre(use_data, use_userdef);
1087
1088 /* Close any user-loaded fonts. */
1090
1091 /* Put WM into a stable state for post-readfile processes (kill jobs, removes event handlers,
1092 * message bus, and so on). */
1093 BlendFileReadWMSetupData *wm_setup_data = wm_file_read_setup_wm_init(C, bmain, false);
1094
1095 /* This flag is initialized by the operator but overwritten on read.
1096 * need to re-enable it here else drivers and registered scripts won't work. */
1097 const int G_f_orig = G.f;
1098
1099 /* Frees the current main and replaces it with the new one read from file. */
1101 C, bfd, &params, wm_setup_data, &bf_reports, false, nullptr);
1102 bmain = CTX_data_main(C);
1103
1104 /* Finalize handling of WM, using the read WM and/or the current WM depending on things like
1105 * whether the UI is loaded from the .blend file or not, etc. */
1106 wm_file_read_setup_wm_finalize(C, bmain, wm_setup_data);
1107
1108 if (G.f != G_f_orig) {
1109 const int flags_keep = G_FLAG_ALL_RUNTIME;
1111 G.f = (G.f & ~flags_keep) | (G_f_orig & flags_keep);
1112 }
1113
1114 /* Set by the `use_scripts` property on file load.
1115 * If this was not set, then it should be calculated based on the file-path.
1116 * Note that this uses `bmain->filepath` and not `filepath`, necessary when
1117 * recovering the last session, where the file-path can be #BLENDER_QUIT_FILE. */
1118 if (use_scripts_autoexec_check) {
1120 }
1121
1122 WM_check(C); /* Opens window(s), checks keymaps. */
1123
1124 if (do_history_file_update) {
1126 }
1127
1128 wmFileReadPost_Params read_file_post_params{};
1129 read_file_post_params.use_data = use_data;
1130 read_file_post_params.use_userdef = use_userdef;
1131 read_file_post_params.is_startup_file = false;
1132 read_file_post_params.is_factory_startup = false;
1133 read_file_post_params.reset_app_template = false;
1134 read_file_post_params.success = true;
1135 read_file_post_params.is_alloc = false;
1136 wm_file_read_post(C, filepath, &read_file_post_params);
1137
1138 bf_reports.duration.whole = BLI_time_now_seconds() - bf_reports.duration.whole;
1139 file_read_reports_finalize(&bf_reports);
1140
1141 success = true;
1142 }
1143 }
1144#if 0
1145 else if (retval == BKE_READ_EXOTIC_OK_OTHER) {
1146 BKE_undo_write(C, "Import file");
1147 }
1148#endif
1149 else if (retval == BKE_READ_EXOTIC_FAIL_OPEN) {
1151 RPT_ERROR,
1152 "Cannot read file \"%s\": %s",
1153 filepath,
1154 errno ? strerror(errno) : RPT_("unable to open the file"));
1155 }
1156 else if (retval == BKE_READ_EXOTIC_FAIL_FORMAT) {
1157 BKE_reportf(reports, RPT_ERROR, "File format is not supported in file \"%s\"", filepath);
1158 }
1159 else if (retval == BKE_READ_EXOTIC_FAIL_PATH) {
1160 BKE_reportf(reports, RPT_ERROR, "File path \"%s\" invalid", filepath);
1161 }
1162 else {
1163 BKE_reportf(reports, RPT_ERROR, "Unknown error loading \"%s\"", filepath);
1164 BLI_assert_msg(0, "invalid 'retval'");
1165 }
1166
1167 /* NOTE: even if the file fails to load, keep the file in the "Recent Files" list.
1168 * This is done because failure to load could be caused by the file-system being
1169 * temporarily offline, see: #127825. */
1170
1171 WM_cursor_wait(false);
1172
1173 wm_read_callback_post_wrapper(C, filepath, success);
1174
1176
1177 return success;
1178}
1179
1180static struct {
1181 char app_template[64];
1182 bool override;
1184
1185void WM_init_state_app_template_set(const char *app_template)
1186{
1187 if (app_template) {
1188 STRNCPY(wm_init_state_app_template.app_template, app_template);
1189 wm_init_state_app_template.override = true;
1190 }
1191 else {
1192 wm_init_state_app_template.app_template[0] = '\0';
1193 wm_init_state_app_template.override = false;
1194 }
1195}
1196
1198{
1199 return wm_init_state_app_template.override ? wm_init_state_app_template.app_template : nullptr;
1200}
1201
1203
1204/* -------------------------------------------------------------------- */
1207
1209 const wmHomeFileRead_Params *params_homefile,
1211 wmFileReadPost_Params **r_params_file_read_post)
1212{
1213 /* NOTE: unlike #WM_file_read, don't set the wait cursor when reading the home-file.
1214 * While technically both are reading a file and could use the wait cursor,
1215 * avoid doing so for the following reasons.
1216 *
1217 * - When loading blend with a file (command line or external file browser)
1218 * the home-file is read before the file being loaded.
1219 * Toggling the wait cursor twice causes the cursor to flicker which looks like a glitch.
1220 * - In practice it's not that useful as users tend not to set scenes with slow loading times
1221 * as their startup.
1222 */
1223
1224/* UNUSED, keep as this may be needed later & the comment below isn't self evident. */
1225#if 0
1226 /* Context does not always have valid main pointer here. */
1227 Main *bmain = G_MAIN;
1228#endif
1229 bool success = false;
1230
1231 /* May be enabled, when the user configuration doesn't exist. */
1232 const bool use_data = params_homefile->use_data;
1233 const bool use_userdef = params_homefile->use_userdef;
1234 bool use_factory_settings = params_homefile->use_factory_settings;
1235 /* Currently this only impacts preferences as it doesn't make much sense to keep the default
1236 * startup open in the case the app-template doesn't happen to define its own startup.
1237 * Unlike preferences where we might want to only reset the app-template part of the preferences
1238 * so as not to reset the preferences for all other Blender instances, see: #96427. */
1239 const bool use_factory_settings_app_template_only =
1241 const bool use_empty_data = params_homefile->use_empty_data;
1242 const char *filepath_startup_override = params_homefile->filepath_startup_override;
1243 const char *app_template_override = params_homefile->app_template_override;
1244
1245 bool filepath_startup_is_factory = true;
1246 char filepath_startup[FILE_MAX];
1247 char filepath_userdef[FILE_MAX];
1248
1249 /* When 'app_template' is set:
1250 * `{BLENDER_USER_CONFIG}/{app_template}`. */
1251 char app_template_system[FILE_MAX];
1252 /* When 'app_template' is set:
1253 * `{BLENDER_SYSTEM_SCRIPTS}/startup/bl_app_templates_system/{app_template}`. */
1254 char app_template_config[FILE_MAX];
1255
1256 eBLOReadSkip skip_flags = eBLOReadSkip(0);
1257
1258 if (use_data == false) {
1259 skip_flags |= BLO_READ_SKIP_DATA;
1260 }
1261 if (use_userdef == false) {
1262 skip_flags |= BLO_READ_SKIP_USERDEF;
1263 }
1264
1265 /* True if we load startup.blend from memory
1266 * or use app-template startup.blend which the user hasn't saved. */
1267 bool is_factory_startup = true;
1268
1269 const char *app_template = nullptr;
1270 bool update_defaults = false;
1271
1272 /* Current Main is not always available in context here. */
1273 Main *bmain = G_MAIN;
1274
1275 if (filepath_startup_override != nullptr) {
1276 /* Pass. */
1277 }
1278 else if (app_template_override) {
1279 /* This may be clearing the current template by setting to an empty string. */
1280 app_template = app_template_override;
1281 }
1282 else if (!use_factory_settings && U.app_template[0]) {
1283 app_template = U.app_template;
1284 }
1285
1286 const bool reset_app_template = ((!app_template && U.app_template[0]) ||
1287 (app_template && !STREQ(app_template, U.app_template)));
1288
1289 /* Options exclude each other. */
1290 BLI_assert((use_factory_settings && filepath_startup_override) == 0);
1291
1293 G.autoexec_override.value_or((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0),
1295
1296 if (use_data) {
1297 if (reset_app_template) {
1298 /* Always load UI when switching to another template. */
1299 G.fileflags &= ~G_FILE_NO_UI;
1300 }
1301 }
1302
1303 if (use_userdef || reset_app_template) {
1304#ifdef WITH_PYTHON
1305 /* This only runs once Blender has already started. */
1306 if (!params_homefile->is_first_time) {
1308 /* This is restored by 'wm_file_read_post', disable before loading any preferences
1309 * so an add-on can read their own preferences when un-registering,
1310 * and use new preferences if/when re-registering, see #67577.
1311 *
1312 * Note that this fits into 'wm_file_read_pre' function but gets messy
1313 * since we need to know if 'reset_app_template' is true. */
1314 const char *imports[] = {"addon_utils", nullptr};
1315 BPY_run_string_eval(C, imports, "addon_utils.disable_all()");
1316 }
1317#endif /* WITH_PYTHON */
1318 }
1319
1320 if (use_data) {
1321 /* NOTE: a matching #wm_read_callback_post_wrapper must be called.
1322 * This runs from #wm_homefile_read_post. */
1324 }
1325
1326 /* For regular file loading this only runs after the file is successfully read.
1327 * In the case of the startup file, the in-memory startup file is used as a fallback
1328 * so we know this will work if all else fails. */
1329 wm_file_read_pre(use_data, use_userdef);
1330
1331 BlendFileReadWMSetupData *wm_setup_data = nullptr;
1332 if (use_data) {
1333 /* Put WM into a stable state for post-readfile processes (kill jobs, removes event handlers,
1334 * message bus, and so on). */
1335 wm_setup_data = wm_file_read_setup_wm_init(C, bmain, true);
1336 }
1337
1338 filepath_startup[0] = '\0';
1339 filepath_userdef[0] = '\0';
1340 app_template_system[0] = '\0';
1341 app_template_config[0] = '\0';
1342
1343 const std::optional<std::string> cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, nullptr);
1344 if (!use_factory_settings) {
1345 if (cfgdir.has_value()) {
1347 filepath_startup, sizeof(filepath_startup), cfgdir->c_str(), BLENDER_STARTUP_FILE);
1348 filepath_startup_is_factory = false;
1349 if (use_userdef) {
1351 filepath_userdef, sizeof(filepath_startup), cfgdir->c_str(), BLENDER_USERPREF_FILE);
1352 }
1353 }
1354 else {
1355 use_factory_settings = true;
1356 }
1357
1358 if (filepath_startup_override) {
1359 STRNCPY(filepath_startup, filepath_startup_override);
1360 filepath_startup_is_factory = false;
1361 }
1362 }
1363
1364 /* Load preferences before `startup.blend`. */
1365 if (use_userdef) {
1366 if (use_factory_settings_app_template_only) {
1367 /* Use the current preferences as-is (only load in the app_template preferences). */
1368 skip_flags |= BLO_READ_SKIP_USERDEF;
1369 }
1370 else if (!use_factory_settings && BLI_exists(filepath_userdef)) {
1371 UserDef *userdef = BKE_blendfile_userdef_read(filepath_userdef, nullptr);
1372 if (userdef != nullptr) {
1373 CLOG_INFO(&LOG, 0, "read prefs: \"%s\"", filepath_userdef);
1374
1376 userdef = nullptr;
1377
1378 skip_flags |= BLO_READ_SKIP_USERDEF;
1379 }
1380 }
1381 }
1382
1383 if ((app_template != nullptr) && (app_template[0] != '\0')) {
1385 app_template, app_template_system, sizeof(app_template_system)))
1386 {
1387 /* Can safely continue with code below, just warn it's not found. */
1388 BKE_reportf(reports, RPT_WARNING, "Application Template \"%s\" not found", app_template);
1389 }
1390
1391 /* Insert template name into startup file. */
1392
1393 /* Note that the path is being set even when `use_factory_settings == true`
1394 * this is done so we can load a templates factory-settings. */
1395 if (!use_factory_settings && cfgdir.has_value()) {
1397 app_template_config, sizeof(app_template_config), cfgdir->c_str(), app_template);
1399 filepath_startup, sizeof(filepath_startup), app_template_config, BLENDER_STARTUP_FILE);
1400 filepath_startup_is_factory = false;
1401 if (BLI_access(filepath_startup, R_OK) != 0) {
1402 filepath_startup[0] = '\0';
1403 }
1404 }
1405 else {
1406 filepath_startup[0] = '\0';
1407 }
1408
1409 if (filepath_startup[0] == '\0') {
1411 filepath_startup, sizeof(filepath_startup), app_template_system, BLENDER_STARTUP_FILE);
1412 filepath_startup_is_factory = true;
1413
1414 /* Update defaults only for system templates. */
1415 update_defaults = true;
1416 }
1417 }
1418
1419 if (!use_factory_settings || (filepath_startup[0] != '\0')) {
1420 if (BLI_access(filepath_startup, R_OK) == 0) {
1421 BlendFileReadParams params{};
1422 params.is_startup = true;
1423 params.is_factory_settings = use_factory_settings;
1424 params.skip_flags = skip_flags | BLO_READ_SKIP_USERDEF;
1425 BlendFileReadReport bf_reports{};
1426 bf_reports.reports = reports;
1427 BlendFileData *bfd = BKE_blendfile_read(filepath_startup, &params, &bf_reports);
1428
1429 if (bfd != nullptr) {
1430 CLOG_INFO(&LOG, 0, "read startup: \"%s\"", filepath_startup);
1431
1432 /* Frees the current main and replaces it with the new one read from file. */
1434 bfd,
1435 &params,
1436 wm_setup_data,
1437 &bf_reports,
1438 update_defaults && use_data,
1439 app_template);
1440 success = true;
1441 bmain = CTX_data_main(C);
1442 }
1443 }
1444 if (success) {
1445 is_factory_startup = filepath_startup_is_factory;
1446 }
1447 }
1448
1449 if (use_userdef) {
1450 if ((skip_flags & BLO_READ_SKIP_USERDEF) == 0) {
1451 UserDef *userdef_default = BKE_blendfile_userdef_from_defaults();
1453 skip_flags |= BLO_READ_SKIP_USERDEF;
1454 }
1455 }
1456
1457 if (success == false && filepath_startup_override && reports) {
1458 /* We can not return from here because wm is already reset. */
1459 BKE_reportf(reports, RPT_ERROR, "Could not read \"%s\"", filepath_startup_override);
1460 }
1461
1462 bool loaded_factory_settings = false;
1463 if (success == false) {
1464 BlendFileReadParams read_file_params{};
1465 read_file_params.is_startup = true;
1466 read_file_params.is_factory_settings = use_factory_settings;
1467 read_file_params.skip_flags = skip_flags;
1469 datatoc_startup_blend, datatoc_startup_blend_size, &read_file_params, nullptr);
1470 if (bfd != nullptr) {
1471 BlendFileReadReport read_report{};
1472 /* Frees the current main and replaces it with the new one read from file. */
1474 C, bfd, &read_file_params, wm_setup_data, &read_report, true, nullptr);
1475 success = true;
1476 loaded_factory_settings = true;
1477 bmain = CTX_data_main(C);
1478 }
1479 }
1480
1481 if (use_empty_data) {
1483 }
1484
1485 /* Load template preferences,
1486 * unlike regular preferences we only use some of the settings,
1487 * see: #BKE_blender_userdef_set_app_template. */
1488 if (app_template_system[0] != '\0') {
1489 char temp_path[FILE_MAX];
1490 temp_path[0] = '\0';
1491 if (!use_factory_settings) {
1492 BLI_path_join(temp_path, sizeof(temp_path), app_template_config, BLENDER_USERPREF_FILE);
1493 if (BLI_access(temp_path, R_OK) != 0) {
1494 temp_path[0] = '\0';
1495 }
1496 }
1497
1498 if (temp_path[0] == '\0') {
1499 BLI_path_join(temp_path, sizeof(temp_path), app_template_system, BLENDER_USERPREF_FILE);
1500 }
1501
1502 if (use_userdef) {
1503 UserDef *userdef_template = nullptr;
1504 /* Just avoids missing file warning. */
1505 if (BLI_exists(temp_path)) {
1506 userdef_template = BKE_blendfile_userdef_read(temp_path, nullptr);
1507 if (userdef_template) {
1508 CLOG_INFO(&LOG, 0, "read prefs from app-template: \"%s\"", temp_path);
1509 }
1510 }
1511 if (userdef_template == nullptr) {
1512 /* We need to have preferences load to overwrite preferences from previous template. */
1513 userdef_template = BKE_blendfile_userdef_from_defaults();
1514 }
1515 if (userdef_template) {
1517 userdef_template = nullptr;
1518 }
1519 }
1520 }
1521
1522 if (app_template_override) {
1523 STRNCPY(U.app_template, app_template_override);
1524 }
1525
1526 if (use_userdef) {
1527 /* Check userdef before open window, keymaps etc. */
1528 wm_init_userdef(bmain);
1529 }
1530
1531 if (use_data) {
1532 /* Finalize handling of WM, using the read WM and/or the current WM depending on things like
1533 * whether the UI is loaded from the .blend file or not, etc. */
1534 wm_setup_data->is_factory_startup = loaded_factory_settings;
1535 wm_file_read_setup_wm_finalize(C, bmain, wm_setup_data);
1536 }
1537
1538 if (use_userdef) {
1539 /* Clear keymaps because the current default keymap may have been initialized
1540 * from user preferences, which have been reset. */
1541 LISTBASE_FOREACH (wmWindowManager *, wm, &bmain->wm) {
1542 if (wm->defaultconf) {
1543 wm->defaultconf->flag &= ~KEYCONF_INIT_DEFAULT;
1544 }
1545 }
1546 }
1547
1548 if (use_data) {
1549 WM_check(C); /* Opens window(s), checks keymaps. */
1550
1551 bmain->filepath[0] = '\0';
1552 }
1553
1554 {
1555 wmFileReadPost_Params params_file_read_post{};
1556 params_file_read_post.use_data = use_data;
1557 params_file_read_post.use_userdef = use_userdef;
1558 params_file_read_post.is_startup_file = true;
1559 params_file_read_post.is_factory_startup = is_factory_startup;
1560 params_file_read_post.is_first_time = params_homefile->is_first_time;
1561
1562 params_file_read_post.reset_app_template = reset_app_template;
1563
1564 params_file_read_post.success = success;
1565 params_file_read_post.is_alloc = false;
1566
1567 if (r_params_file_read_post == nullptr) {
1568 wm_homefile_read_post(C, &params_file_read_post);
1569 }
1570 else {
1571 params_file_read_post.is_alloc = true;
1572 *r_params_file_read_post = MEM_mallocN<wmFileReadPost_Params>(__func__);
1573 **r_params_file_read_post = params_file_read_post;
1574
1575 /* Match #wm_file_read_post which leaves the window cleared too. */
1576 CTX_wm_window_set(C, nullptr);
1577 }
1578 }
1579}
1580
1582 const wmHomeFileRead_Params *params_homefile,
1584{
1585 wm_homefile_read_ex(C, params_homefile, reports, nullptr);
1586}
1587
1588void wm_homefile_read_post(bContext *C, const wmFileReadPost_Params *params_file_read_post)
1589{
1590 const char *filepath = "";
1591 wm_file_read_post(C, filepath, params_file_read_post);
1592
1593 if (params_file_read_post->use_data) {
1594 wm_read_callback_post_wrapper(C, filepath, params_file_read_post->success);
1595 }
1596
1597 if (params_file_read_post->is_alloc) {
1598 MEM_freeN(params_file_read_post);
1599 }
1600}
1601
1603
1604/* -------------------------------------------------------------------- */
1607
1609{
1610 const std::optional<std::string> cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, nullptr);
1611 if (!cfgdir.has_value()) {
1612 return;
1613 }
1614
1615 char filepath[FILE_MAX];
1616 LinkNode *l;
1617 int num;
1618
1619 BLI_path_join(filepath, sizeof(filepath), cfgdir->c_str(), BLENDER_HISTORY_FILE);
1620
1621 LinkNode *lines = BLI_file_read_as_lines(filepath);
1622
1624
1625 /* Read list of recent opened files from #BLENDER_HISTORY_FILE to memory. */
1626 for (l = lines, num = 0; l && (num < U.recent_files); l = l->next) {
1627 const char *line = static_cast<const char *>(l->link);
1628 /* Don't check if files exist, causes slow startup for remote/external drives. */
1629 if (line[0]) {
1630 RecentFile *recent = MEM_mallocN<RecentFile>("RecentFile");
1631 BLI_addtail(&(G.recent_files), recent);
1632 recent->filepath = BLI_strdup(line);
1633 num++;
1634 }
1635 }
1636
1637 BLI_file_free_lines(lines);
1638}
1639
1640static RecentFile *wm_history_file_new(const char *filepath)
1641{
1642 RecentFile *recent = MEM_mallocN<RecentFile>("RecentFile");
1643 recent->filepath = BLI_strdup(filepath);
1644 return recent;
1645}
1646
1648{
1649 BLI_assert(BLI_findindex(&G.recent_files, recent) != -1);
1650 MEM_freeN(recent->filepath);
1651 BLI_freelinkN(&G.recent_files, recent);
1652}
1653
1655{
1656 LISTBASE_FOREACH_MUTABLE (RecentFile *, recent, &G.recent_files) {
1657 wm_history_file_free(recent);
1658 }
1659}
1660
1661static RecentFile *wm_file_history_find(const char *filepath)
1662{
1663 return static_cast<RecentFile *>(
1664 BLI_findstring_ptr(&G.recent_files, filepath, offsetof(RecentFile, filepath)));
1665}
1666
1672{
1673 char filepath[FILE_MAX];
1674 FILE *fp;
1675
1676 /* Will be nullptr in background mode. */
1677 const std::optional<std::string> user_config_dir = BKE_appdir_folder_id_create(
1678 BLENDER_USER_CONFIG, nullptr);
1679 if (!user_config_dir.has_value()) {
1680 return;
1681 }
1682
1683 BLI_path_join(filepath, sizeof(filepath), user_config_dir->c_str(), BLENDER_HISTORY_FILE);
1684
1685 fp = BLI_fopen(filepath, "w");
1686 if (fp) {
1687 LISTBASE_FOREACH (RecentFile *, recent, &G.recent_files) {
1688 fprintf(fp, "%s\n", recent->filepath);
1689 }
1690 fclose(fp);
1691 }
1692}
1693
1698{
1699 RecentFile *recent;
1700 const char *blendfile_path = BKE_main_blendfile_path_from_global();
1701
1702 /* No write history for recovered startup files. */
1703 if (blendfile_path[0] == '\0') {
1704 return;
1705 }
1706
1707 recent = static_cast<RecentFile *>(G.recent_files.first);
1708 /* Refresh #BLENDER_HISTORY_FILE of recent opened files, when current file was changed. */
1709 if (!(recent) || (BLI_path_cmp(recent->filepath, blendfile_path) != 0)) {
1710
1711 recent = wm_file_history_find(blendfile_path);
1712 if (recent) {
1713 BLI_remlink(&G.recent_files, recent);
1714 }
1715 else {
1716 RecentFile *recent_next;
1717 for (recent = static_cast<RecentFile *>(BLI_findlink(&G.recent_files, U.recent_files - 1));
1718 recent;
1719 recent = recent_next)
1720 {
1721 recent_next = recent->next;
1722 wm_history_file_free(recent);
1723 }
1724 recent = wm_history_file_new(blendfile_path);
1725 }
1726
1727 /* Add current file to the beginning of list. */
1728 BLI_addhead(&(G.recent_files), recent);
1729
1730 /* Write current file to #BLENDER_HISTORY_FILE. */
1732
1733 /* Also update most recent files on system. */
1734 GHOST_addToSystemRecentFiles(blendfile_path);
1735 }
1736}
1737
1739
1740/* -------------------------------------------------------------------- */
1760
1761#ifdef USE_THUMBNAIL_FAST_DOWNSCALE
1762static uint8_t *blend_file_thumb_fast_downscale(const uint8_t *src_rect,
1763 const int src_size[2],
1764 const int dst_size[2])
1765{
1766 /* NOTE: this is a faster alternative to #IMBScaleFilter::Box which is
1767 * especially slow in debug builds, normally debug performance isn't a
1768 * consideration however it's slow enough to get in the way of development.
1769 * In release builds this gives ~1.4x speedup. */
1770
1771 /* Scaling using a box-filter where each box uses an integer-rounded region.
1772 * Accept a slightly lower quality scale as this is only for thumbnails.
1773 * In practice the result is visually indistinguishable.
1774 *
1775 * Technically the color accumulation *could* overflow (creating some invalid pixels),
1776 * however this would require the source image to be larger than
1777 * 65,535 pixels squared (when scaling down to 256x256).
1778 * As the source input is a screenshot or a small camera render created for the thumbnail,
1779 * this isn't a concern. */
1780
1781 BLI_assert(dst_size[0] <= src_size[0] && dst_size[1] <= src_size[1]);
1782 uint8_t *dst_rect = MEM_malloc_arrayN<uint8_t>(size_t(4 * dst_size[0] * dst_size[1]), __func__);
1783
1784 /* A row, the width of the destination to accumulate pixel values into
1785 * before writing into the image. */
1786 uint32_t *accum_row = MEM_calloc_arrayN<uint32_t>(size_t(dst_size[0] * 4), __func__);
1787
1788# ifndef NDEBUG
1789 /* Assert that samples are calculated correctly. */
1790 uint64_t sample_count_all = 0;
1791# endif
1792
1793 const uint32_t src_size_x = src_size[0];
1794 const uint32_t src_size_y = src_size[1];
1795
1796 const uint32_t dst_size_x = dst_size[0];
1797 const uint32_t dst_size_y = dst_size[1];
1798 const uint8_t *src_px = src_rect;
1799
1800 uint32_t src_y = 0;
1801 for (uint32_t dst_y = 0; dst_y < dst_size_y; dst_y++) {
1802 const uint32_t src_y_beg = src_y;
1803 const uint32_t src_y_end = ((dst_y + 1) * src_size_y) / dst_size_y;
1804 for (; src_y < src_y_end; src_y++) {
1805 uint32_t *accum = accum_row;
1806 uint32_t src_x = 0;
1807 for (uint32_t dst_x = 0; dst_x < dst_size_x; dst_x++, accum += 4) {
1808 const uint32_t src_x_end = ((dst_x + 1) * src_size_x) / dst_size_x;
1809 for (; src_x < src_x_end; src_x++) {
1810 accum[0] += uint32_t(src_px[0]);
1811 accum[1] += uint32_t(src_px[1]);
1812 accum[2] += uint32_t(src_px[2]);
1813 accum[3] += uint32_t(src_px[3]);
1814 src_px += 4;
1815 }
1816 BLI_assert(src_x == src_x_end);
1817 }
1818 BLI_assert(accum == accum_row + (4 * dst_size[0]));
1819 }
1820
1821 uint32_t *accum = accum_row;
1822 uint8_t *dst_px = dst_rect + ((dst_y * dst_size_x) * 4);
1823 uint32_t src_x_beg = 0;
1824 const uint32_t span_y = src_y_end - src_y_beg;
1825 for (uint32_t dst_x = 0; dst_x < dst_size_x; dst_x++) {
1826 const uint32_t src_x_end = ((dst_x + 1) * src_size_x) / dst_size_x;
1827 const uint32_t span_x = src_x_end - src_x_beg;
1828
1829 const uint32_t sample_count = span_x * span_y;
1830 dst_px[0] = uint8_t(accum[0] / sample_count);
1831 dst_px[1] = uint8_t(accum[1] / sample_count);
1832 dst_px[2] = uint8_t(accum[2] / sample_count);
1833 dst_px[3] = uint8_t(accum[3] / sample_count);
1834 accum[0] = accum[1] = accum[2] = accum[3] = 0;
1835 accum += 4;
1836 dst_px += 4;
1837
1838 src_x_beg = src_x_end;
1839# ifndef NDEBUG
1840 sample_count_all += sample_count;
1841# endif
1842 }
1843 }
1844 BLI_assert(src_px == src_rect + (sizeof(uint8_t[4]) * src_size[0] * src_size[1]));
1845 BLI_assert(sample_count_all == size_t(src_size[0]) * size_t(src_size[1]));
1846
1847 MEM_freeN(accum_row);
1848 return dst_rect;
1849}
1850#endif /* USE_THUMBNAIL_FAST_DOWNSCALE */
1851
1852static blender::int2 blend_file_thumb_clamp_size(const int size[2], const int limit)
1853{
1855 if (size[0] > size[1]) {
1856 result.x = limit;
1857 result.y = max_ii(1, int((float(size[1]) / float(size[0])) * limit));
1858 }
1859 else {
1860 result.x = max_ii(1, int((float(size[0]) / float(size[1])) * limit));
1861 result.y = limit;
1862 }
1863 return result;
1864}
1865
1870{
1871 *r_thumb = nullptr;
1872
1873 wmWindow *win = CTX_wm_window(C);
1874 if (G.background || (win == nullptr)) {
1875 return nullptr;
1876 }
1877
1878 /* The window to capture should be a main window (without parent). */
1879 while (win->parent) {
1880 win = win->parent;
1881 }
1882
1884 int win_size[2];
1885 /* NOTE: always read from front-buffer as drawing a window can cause problems while saving,
1886 * even if this means the thumbnail from the screen-shot fails to be created, see: #98462. */
1887 ImBuf *ibuf = nullptr;
1888
1889 if (uint8_t *buffer = WM_window_pixels_read_from_frontbuffer(wm, win, win_size)) {
1890 const blender::int2 thumb_size_2x = blend_file_thumb_clamp_size(win_size, BLEN_THUMB_SIZE * 2);
1891 const blender::int2 thumb_size = blend_file_thumb_clamp_size(win_size, BLEN_THUMB_SIZE);
1892
1893#ifdef USE_THUMBNAIL_FAST_DOWNSCALE
1894 if ((thumb_size_2x[0] <= win_size[0]) && (thumb_size_2x[1] <= win_size[1])) {
1895 uint8_t *rect_2x = blend_file_thumb_fast_downscale(buffer, win_size, thumb_size_2x);
1896 uint8_t *rect = blend_file_thumb_fast_downscale(rect_2x, thumb_size_2x, thumb_size);
1897
1898 MEM_freeN(buffer);
1899 ibuf = IMB_allocFromBufferOwn(rect_2x, nullptr, thumb_size_2x.x, thumb_size_2x.y, 24);
1900
1901 BlendThumbnail *thumb = BKE_main_thumbnail_from_buffer(nullptr, rect, thumb_size);
1902 MEM_freeN(rect);
1903 *r_thumb = thumb;
1904 }
1905 else
1906#endif /* USE_THUMBNAIL_FAST_DOWNSCALE */
1907 {
1908 ibuf = IMB_allocFromBufferOwn(buffer, nullptr, win_size[0], win_size[1], 24);
1909 BLI_assert(ibuf != nullptr); /* Never expected to fail. */
1910
1911 /* File-system thumbnail image can be 256x256. */
1912 IMB_scale(ibuf, thumb_size_2x.x, thumb_size_2x.y, IMBScaleFilter::Box, false);
1913
1914 /* Thumbnail inside blend should be 128x128. */
1915 ImBuf *thumb_ibuf = IMB_dupImBuf(ibuf);
1916 IMB_scale(thumb_ibuf, thumb_size.x, thumb_size.y, IMBScaleFilter::Box, false);
1917
1918 BlendThumbnail *thumb = BKE_main_thumbnail_from_imbuf(nullptr, thumb_ibuf);
1919 IMB_freeImBuf(thumb_ibuf);
1920 *r_thumb = thumb;
1921 }
1922 }
1923
1924 if (ibuf) {
1925 /* Save metadata for quick access. */
1926 char version_str[10];
1927 SNPRINTF(version_str, "%d.%01d", BLENDER_VERSION / 100, BLENDER_VERSION % 100);
1929 IMB_metadata_set_field(ibuf->metadata, "Thumb::Blender::Version", version_str);
1930 }
1931
1932 /* Must be freed by caller. */
1933 return ibuf;
1934}
1935
1942 Scene *scene,
1943 bScreen *screen,
1944 BlendThumbnail **r_thumb)
1945{
1946 *r_thumb = nullptr;
1947
1948 /* Scene can be nullptr if running a script at startup and calling the save operator. */
1949 if (G.background || scene == nullptr) {
1950 return nullptr;
1951 }
1952
1953 /* Will be scaled down, but gives some nice oversampling. */
1954 ImBuf *ibuf;
1955 BlendThumbnail *thumb;
1957 const float pixelsize_old = U.pixelsize;
1958 wmWindow *windrawable_old = wm->windrawable;
1959 char err_out[256] = "unknown";
1960
1961 /* Screen if no camera found. */
1962 ScrArea *area = nullptr;
1963 ARegion *region = nullptr;
1964 View3D *v3d = nullptr;
1965
1966 if (screen != nullptr) {
1967 area = BKE_screen_find_big_area(screen, SPACE_VIEW3D, 0);
1968 if (area) {
1969 v3d = static_cast<View3D *>(area->spacedata.first);
1971 }
1972 }
1973
1974 if (scene->camera == nullptr && v3d == nullptr) {
1975 return nullptr;
1976 }
1977
1978 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
1979
1980 /* Note that with scaling, this ends up being 0.5,
1981 * as it's a thumbnail, we don't need object centers and friends to be 1:1 size. */
1982 U.pixelsize = 1.0f;
1983
1984 if (scene->camera) {
1986 scene,
1987 (v3d) ? &v3d->shading : nullptr,
1988 (v3d) ? eDrawType(v3d->shading.type) : OB_SOLID,
1989 scene->camera,
1996 nullptr,
1997 nullptr,
1998 nullptr,
1999 err_out);
2000 }
2001 else {
2002 ibuf = ED_view3d_draw_offscreen_imbuf(depsgraph,
2003 scene,
2004 OB_SOLID,
2005 v3d,
2006 region,
2011 nullptr,
2012 true,
2013 nullptr,
2014 nullptr,
2015 true,
2016 err_out);
2017 }
2018
2019 U.pixelsize = pixelsize_old;
2020
2021 /* Reset to old drawable. */
2022 if (windrawable_old) {
2023 wm_window_make_drawable(wm, windrawable_old);
2024 }
2025 else {
2027 }
2028
2029 if (ibuf) {
2030 /* Dirty oversampling. */
2031 ImBuf *thumb_ibuf;
2032 thumb_ibuf = IMB_dupImBuf(ibuf);
2033
2034 /* Save metadata for quick access. */
2035 char version_str[10];
2036 SNPRINTF(version_str, "%d.%01d", BLENDER_VERSION / 100, BLENDER_VERSION % 100);
2038 IMB_metadata_set_field(ibuf->metadata, "Thumb::Blender::Version", version_str);
2039
2040 /* BLEN_THUMB_SIZE is size of thumbnail inside blend file: 128x128. */
2042 thumb = BKE_main_thumbnail_from_imbuf(nullptr, thumb_ibuf);
2043 IMB_freeImBuf(thumb_ibuf);
2044 /* Thumbnail saved to file-system should be 256x256. */
2045 IMB_scale(ibuf,
2049 false);
2050 }
2051 else {
2052 /* '*r_thumb' needs to stay nullptr to prevent a bad thumbnail from being handled. */
2053 CLOG_WARN(&LOG, "failed to create thumbnail: %s", err_out);
2054 thumb = nullptr;
2055 }
2056
2057 /* Must be freed by caller. */
2058 *r_thumb = thumb;
2059
2060 return ibuf;
2061}
2062
2064
2065/* -------------------------------------------------------------------- */
2068
2070{
2071 char filepath[FILE_MAX];
2072
2074 BLI_path_extension_replace(filepath, sizeof(filepath), "_crash.blend");
2075 BlendFileWriteParams params{};
2076 const bool success = BLO_write_file(G_MAIN, filepath, G.fileflags, &params, nullptr);
2077 printf("%s: \"%s\"\n", success ? "written" : "failed", filepath);
2078 return success;
2079}
2080
2086 const char *filepath,
2088{
2089 const int filepath_len = strlen(filepath);
2090 if (filepath_len == 0) {
2091 BKE_report(reports, RPT_ERROR, "Path is empty, cannot save");
2092 return false;
2093 }
2094
2095 if (filepath_len >= FILE_MAX) {
2096 BKE_report(reports, RPT_ERROR, "Path too long, cannot save");
2097 return false;
2098 }
2099
2100 if (bmain->is_asset_edit_file &&
2102 {
2103 BKE_report(reports, RPT_ERROR, "Cannot overwrite files that are managed by the asset system");
2104 return false;
2105 }
2106
2107 LISTBASE_FOREACH (Library *, li, &bmain->libraries) {
2108 if (BLI_path_cmp(li->runtime->filepath_abs, filepath) == 0) {
2109 BKE_reportf(reports, RPT_ERROR, "Cannot overwrite used library '%.240s'", filepath);
2110 return false;
2111 }
2112 }
2113
2114 return true;
2115}
2116
2121 const char *filepath,
2122 int fileflags,
2123 eBLO_WritePathRemap remap_mode,
2124 bool use_save_as_copy,
2126{
2127 Main *bmain = CTX_data_main(C);
2128 BlendThumbnail *thumb = nullptr, *main_thumb = nullptr;
2129 ImBuf *ibuf_thumb = nullptr;
2130
2131 /* NOTE: used to replace the file extension (to ensure `.blend`),
2132 * no need to now because the operator ensures,
2133 * its handy for scripts to save to a predefined name without blender editing it. */
2134
2135 if (!wm_file_write_check_with_report_on_failure(bmain, filepath, reports)) {
2136 return false;
2137 }
2138
2139 /* Call pre-save callbacks before writing preview,
2140 * that way you can generate custom file thumbnail. */
2141
2142 /* NOTE: either #BKE_CB_EVT_SAVE_POST or #BKE_CB_EVT_SAVE_POST_FAIL must run.
2143 * Runs at the end of this function, don't return beforehand. */
2145
2146 /* Check if file write permission is OK. */
2147 if (const int st_mode = BLI_exists(filepath)) {
2148 bool ok = true;
2149
2150 if (!BLI_file_is_writable(filepath)) {
2152 reports, RPT_ERROR, "Cannot save blend file, path \"%s\" is not writable", filepath);
2153 ok = false;
2154 }
2155 else if (S_ISDIR(st_mode)) {
2156 /* While the UI mostly prevents this, it's possible to save to an existing
2157 * directory from Python because the path is used unmodified.
2158 * Besides it being unlikely the user wants to replace a directory,
2159 * the file versioning logic (to create `*.blend1` files)
2160 * would rename the directory with a `1` suffix, see #134101. */
2162 reports, RPT_ERROR, "Cannot save blend file, path \"%s\" is a directory", filepath);
2163 ok = false;
2164 }
2165
2166 if (!ok) {
2168 return false;
2169 }
2170 }
2171
2173
2174 /* Enforce full override check/generation on file save. */
2176
2177 /* NOTE: Ideally we would call `WM_redraw_windows` here to remove any open menus.
2178 * But we can crash if saving from a script, see #92704 & #97627.
2179 * Just checking `!G.background && BLI_thread_is_main()` is not sufficient to fix this.
2180 * Additionally some EGL configurations don't support reading the front-buffer
2181 * immediately after drawing, see: #98462. In that case off-screen drawing is necessary. */
2182
2183 /* Don't forget not to return without! */
2184 WM_cursor_wait(true);
2185
2186 if (U.file_preview_type != USER_FILE_PREVIEW_NONE) {
2187 /* Blend file thumbnail.
2188 *
2189 * - Save before exiting edit-mode, otherwise evaluated-mesh for shared data gets corrupted.
2190 * See #27765.
2191 * - Main can store a `.blend` thumbnail,
2192 * useful for background-mode or thumbnail customization.
2193 */
2194 main_thumb = thumb = bmain->blen_thumb;
2195 if (thumb != nullptr) {
2196 /* In case we are given a valid thumbnail data, just generate image from it. */
2197 ibuf_thumb = BKE_main_thumbnail_to_imbuf(nullptr, thumb);
2198 }
2199 else if (BLI_thread_is_main()) {
2200 int file_preview_type = U.file_preview_type;
2201
2202 if (file_preview_type == USER_FILE_PREVIEW_AUTO) {
2203 Scene *scene = CTX_data_scene(C);
2204 bScreen *screen = CTX_wm_screen(C);
2205 bool do_render = (scene != nullptr && scene->camera != nullptr && screen != nullptr &&
2206 (BKE_screen_find_big_area(screen, SPACE_VIEW3D, 0) != nullptr));
2207 file_preview_type = do_render ? USER_FILE_PREVIEW_CAMERA : USER_FILE_PREVIEW_SCREENSHOT;
2208 }
2209
2210 switch (file_preview_type) {
2212 ibuf_thumb = blend_file_thumb_from_screenshot(C, &thumb);
2213 break;
2214 }
2216 ibuf_thumb = blend_file_thumb_from_camera(
2217 C, CTX_data_scene(C), CTX_wm_screen(C), &thumb);
2218 break;
2219 }
2220 default:
2222 }
2223 }
2224 }
2225
2226 /* Operator now handles overwrite checks. */
2227
2228 if (G.fileflags & G_FILE_AUTOPACK) {
2229 BKE_packedfile_pack_all(bmain, reports, false);
2230 }
2231
2233
2234 /* XXX(ton): temp solution to solve bug, real fix coming. */
2235 bmain->recovered = false;
2236
2237 BlendFileWriteParams blend_write_params{};
2238 blend_write_params.remap_mode = remap_mode;
2239 blend_write_params.use_save_versions = true;
2240 blend_write_params.use_save_as_copy = use_save_as_copy;
2241 blend_write_params.thumb = thumb;
2242
2243 const bool success = BLO_write_file(bmain, filepath, fileflags, &blend_write_params, reports);
2244
2245 if (success) {
2246 const bool do_history_file_update = (G.background == false) &&
2247 (CTX_wm_manager(C)->op_undo_depth == 0);
2248
2249 if (use_save_as_copy == false) {
2250 STRNCPY(bmain->filepath, filepath); /* Is guaranteed current file. */
2251 }
2252
2253 SET_FLAG_FROM_TEST(G.fileflags, fileflags & G_FILE_COMPRESS, G_FILE_COMPRESS);
2254
2255 /* Prevent background mode scripts from clobbering history. */
2256 if (do_history_file_update) {
2258 }
2259
2260 /* Run this function after because the file can't be written before the blend is. */
2261 if (ibuf_thumb) {
2262 IMB_thumb_delete(filepath, THB_FAIL); /* Without this a failed thumb overrides. */
2263 ibuf_thumb = IMB_thumb_create(filepath, THB_LARGE, THB_SOURCE_BLEND, ibuf_thumb);
2264 }
2265 }
2266
2268 bmain, success ? BKE_CB_EVT_SAVE_POST : BKE_CB_EVT_SAVE_POST_FAIL, filepath);
2269
2270 if (ibuf_thumb) {
2271 IMB_freeImBuf(ibuf_thumb);
2272 }
2273 if (thumb && thumb != main_thumb) {
2274 MEM_freeN(thumb);
2275 }
2276
2277 WM_cursor_wait(false);
2278
2279 return success;
2280}
2281
2283
2284/* -------------------------------------------------------------------- */
2287
2288static void wm_autosave_location(char filepath[FILE_MAX])
2289{
2290 const int pid = abs(getpid());
2291 char filename[1024];
2292
2293 /* Normally there is no need to check for this to be nullptr,
2294 * however this runs on exit when it may be cleared. */
2295 Main *bmain = G_MAIN;
2296 const char *blendfile_path = bmain ? BKE_main_blendfile_path(bmain) : nullptr;
2297
2298 if (blendfile_path && (blendfile_path[0] != '\0')) {
2299 const char *basename = BLI_path_basename(blendfile_path);
2300 int len = strlen(basename) - 6;
2301 SNPRINTF(filename, "%.*s_%d_autosave.blend", len, basename, pid);
2302 }
2303 else {
2304 SNPRINTF(filename, "%d_autosave.blend", pid);
2305 }
2306
2307 const char *tempdir_base = BKE_tempdir_base();
2308 BLI_path_join(filepath, FILE_MAX, tempdir_base, filename);
2309}
2310
2312{
2313 char filepath[FILE_MAX];
2314
2315 wm_autosave_location(filepath);
2316
2317 /* Technically, we could always just save here, but that would cause performance regressions
2318 * compared to when the #MemFile undo step was used for saving undo-steps. So for now just skip
2319 * auto-save when we are in a mode where auto-save wouldn't have worked previously anyway. This
2320 * check can be removed once the performance regressions have been solved. */
2321 if (ED_undosys_stack_memfile_get_if_active(wm->undo_stack) != nullptr) {
2322 WM_autosave_write(wm, bmain);
2323 return true;
2324 }
2325 if ((U.uiflag & USER_GLOBALUNDO) == 0) {
2326 WM_autosave_write(wm, bmain);
2327 return true;
2328 }
2329 /* Can't auto-save with MemFile right now, try again later. */
2330 return false;
2331}
2332
2334{
2335 return wm->autosave_scheduled;
2336}
2337
2339{
2341
2342 char filepath[FILE_MAX];
2343 wm_autosave_location(filepath);
2344 /* Save as regular blend file with recovery information and always compress them, see: !132685.
2345 */
2346 const int fileflags = G.fileflags | G_FILE_RECOVER_WRITE | G_FILE_COMPRESS;
2347
2348 /* Error reporting into console. */
2349 BlendFileWriteParams params{};
2350 BLO_write_file(bmain, filepath, fileflags, &params, nullptr);
2351
2352 /* Restart auto-save timer. */
2355
2356 wm->autosave_scheduled = false;
2357}
2358
2359static void wm_autosave_timer_begin_ex(wmWindowManager *wm, double timestep)
2360{
2362
2363 if (U.flag & USER_AUTOSAVE) {
2364 wm->autosavetimer = WM_event_timer_add(wm, nullptr, TIMERAUTOSAVE, timestep);
2365 }
2366}
2367
2372
2374{
2375 if (wm->autosavetimer) {
2376 WM_event_timer_remove(wm, nullptr, wm->autosavetimer);
2377 wm->autosavetimer = nullptr;
2378 }
2379}
2380
2385
2387{
2389
2390 /* If a modal operator is running, don't autosave because we might not be in
2391 * a valid state to save. But try again in 10ms. */
2392 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
2393 LISTBASE_FOREACH (wmEventHandler *, handler_base, &win->modalhandlers) {
2394 if (handler_base->type == WM_HANDLER_TYPE_OP) {
2395 wmEventHandler_Op *handler = (wmEventHandler_Op *)handler_base;
2396 if (handler->op) {
2398 return;
2399 }
2400 }
2401 }
2402 }
2403
2404 wm->autosave_scheduled = false;
2405 if (!wm_autosave_write_try(bmain, wm)) {
2406 wm->autosave_scheduled = true;
2407 }
2408 /* Restart the timer after file write, just in case file write takes a long time. */
2410}
2411
2413{
2414 char filepath[FILE_MAX];
2415
2416 wm_autosave_location(filepath);
2417
2418 if (BLI_exists(filepath)) {
2419 char filepath_quit[FILE_MAX];
2420 BLI_path_join(filepath_quit, sizeof(filepath_quit), BKE_tempdir_base(), BLENDER_QUIT_FILE);
2421
2422 /* For global undo; remove temporarily saved file, otherwise rename. */
2423 if (U.uiflag & USER_GLOBALUNDO) {
2424 BLI_delete(filepath, false, false);
2425 }
2426 else {
2427 BLI_rename_overwrite(filepath, filepath_quit);
2428 }
2429 }
2430}
2431
2433
2434/* -------------------------------------------------------------------- */
2437
2440{
2441 PropertyRNA *prop;
2442
2443 /* So it's possible to reset app-template settings without resetting other defaults. */
2444 prop = RNA_def_boolean(ot->srna,
2445 "use_factory_startup_app_template_only",
2446 false,
2447 "Factory Startup App-Template Only",
2448 "");
2450}
2451
2453
2454/* -------------------------------------------------------------------- */
2461
2462void wm_open_init_load_ui(wmOperator *op, bool use_prefs)
2463{
2464 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "load_ui");
2465 if (!RNA_property_is_set(op->ptr, prop)) {
2466 bool value = use_prefs ? ((U.flag & USER_FILENOUI) == 0) : ((G.fileflags & G_FILE_NO_UI) == 0);
2467
2468 RNA_property_boolean_set(op->ptr, prop, value);
2469 }
2470}
2471
2481
2485[[nodiscard]] static bool wm_open_init_use_scripts(wmOperator *op, const OpenTrust source_of_trust)
2486{
2487 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_scripts");
2488 if (RNA_property_is_set(op->ptr, prop)) {
2489 return false;
2490 }
2491
2492 bool value = false;
2493 switch (source_of_trust) {
2494 case OpenTrust::FilePath: {
2495 char filepath[FILE_MAX] = "";
2496 if (PropertyRNA *prop_filepath = RNA_struct_find_property(op->ptr, "filepath")) {
2497 RNA_property_string_get(op->ptr, prop_filepath, filepath);
2498 }
2499
2500 if (filepath[0] == '\0') {
2501 /* The file selector before a file is chosen, excluded paths are checked once it's set. */
2502 value = G.autoexec_override.value_or((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0);
2503 }
2504 else {
2505 value = BKE_autoexec_default_trust_source(filepath);
2506 }
2507 break;
2508 }
2510 /* Keep the trust of the current session rather than the preference. */
2511 value = (G.f & G_FLAG_SCRIPT_AUTOEXEC) != 0;
2512 break;
2513 }
2514 case OpenTrust::Recover: {
2515 /* It may be in an excluded path so disable auto-execution,
2516 * the user may still opt-in. */
2517 value = G.autoexec_override.value_or(false);
2518 break;
2519 }
2520 }
2521
2522 RNA_property_boolean_set(op->ptr, prop, value);
2523 return true;
2524}
2525
2527
2528/* -------------------------------------------------------------------- */
2531
2537{
2538 Main *bmain = CTX_data_main(C);
2540 wmWindow *win = CTX_wm_window(C);
2541 char filepath[FILE_MAX];
2542 int fileflags;
2543
2544 const char *app_template = U.app_template[0] ? U.app_template : nullptr;
2545 const std::optional<std::string> cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG,
2546 app_template);
2547 if (!cfgdir.has_value()) {
2548 BKE_report(op->reports, RPT_ERROR, "Unable to create user config path");
2549 return OPERATOR_CANCELLED;
2550 }
2551
2552 /* NOTE: either #BKE_CB_EVT_SAVE_POST or #BKE_CB_EVT_SAVE_POST_FAIL must run.
2553 * Runs at the end of this function, don't return beforehand. */
2556
2557 /* Check current window and close it if temp. */
2558 if (win && WM_window_is_temp_screen(win)) {
2559 wm_window_close(C, wm, win);
2560 }
2561
2562 /* Update keymaps in user preferences. */
2564
2565 BLI_path_join(filepath, sizeof(filepath), cfgdir->c_str(), BLENDER_STARTUP_FILE);
2566
2567 if (!G.quiet) {
2568 printf("Writing homefile: \"%s\" ", filepath);
2569 }
2570
2572
2573 /* Force save as regular blend file. */
2574 fileflags = G.fileflags & ~G_FILE_COMPRESS;
2575
2576 BlendFileWriteParams blend_write_params{};
2577 /* Make all paths absolute when saving the startup file.
2578 * On load the `G.main->filepath` will be empty so the paths
2579 * won't have a base for resolving the relative paths. */
2580 blend_write_params.remap_mode = BLO_WRITE_PATH_REMAP_ABSOLUTE;
2581 /* Don't apply any path changes to the current blend file. */
2582 blend_write_params.use_save_as_copy = true;
2583
2584 const bool success = BLO_write_file(
2585 bmain, filepath, fileflags, &blend_write_params, op->reports);
2586
2588
2589 if (success) {
2590 if (!G.quiet) {
2591 printf("ok\n");
2592 }
2593 BKE_report(op->reports, RPT_INFO, "Startup file saved");
2594 return OPERATOR_FINISHED;
2595 }
2596 if (!G.quiet) {
2597 printf("fail\n");
2598 }
2599 return OPERATOR_CANCELLED;
2600}
2601
2603 wmOperator *op,
2604 const wmEvent * /*event*/)
2605{
2606 if (!U.app_template[0]) {
2608 op,
2609 IFACE_("Overwrite Startup File"),
2610 IFACE_("Blender will start next time as it is now."),
2611 IFACE_("Overwrite"),
2613 false);
2614 }
2615
2616 /* A different message if this is overriding a specific template startup file. */
2617 char display_name[FILE_MAX];
2618 BLI_path_to_display_name(display_name, sizeof(display_name), IFACE_(U.app_template));
2619 std::string message = fmt::format(
2620 fmt::runtime(IFACE_("Template \"{}\" will start next time as it is now.")),
2621 IFACE_(display_name));
2623 op,
2624 IFACE_("Overwrite Template Startup File"),
2625 message.c_str(),
2626 IFACE_("Overwrite"),
2628 false);
2629}
2630
2632{
2633 ot->name = "Save Startup File";
2634 ot->idname = "WM_OT_save_homefile";
2635 ot->description = "Make the current file the default startup file";
2636
2639}
2640
2642
2643/* -------------------------------------------------------------------- */
2646
2647/* Only save the prefs block. operator entry. */
2649{
2651
2652 /* Update keymaps in user preferences. */
2654
2655 const bool success = BKE_blendfile_userdef_write_all(op->reports);
2656
2657 return success ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
2658}
2659
2661{
2662 ot->name = "Save Preferences";
2663 ot->idname = "WM_OT_save_userpref";
2664 ot->description = "Make the current preferences default";
2665
2668}
2669
2671
2672/* -------------------------------------------------------------------- */
2675
2679static void wm_userpref_read_exceptions(UserDef *userdef_curr, const UserDef *userdef_prev)
2680{
2681#define USERDEF_RESTORE(member) \
2682 { \
2683 userdef_curr->member = userdef_prev->member; \
2684 } \
2685 ((void)0)
2686
2687 /* Current visible preferences category. */
2688 USERDEF_RESTORE(space_data.section_active);
2689
2690#undef USERDEF_RESTORE
2691}
2692
2694 Main *bmain,
2695 PointerRNA *ptr_a,
2696 PointerRNA *ptr_b)
2697{
2699 PropertyRNA *iterprop = RNA_struct_iterator_property(ptr_a->type);
2700 BLI_assert(ptr_a->type == ptr_b->type);
2701 RNA_property_collection_begin(ptr_a, iterprop, &iter);
2702 for (; iter.valid; RNA_property_collection_next(&iter)) {
2703 PropertyRNA *prop = static_cast<PropertyRNA *>(iter.ptr.data);
2704 if (STREQ(RNA_property_identifier(prop), "rna_type")) {
2705 continue;
2706 }
2707 switch (RNA_property_type(prop)) {
2708 case PROP_POINTER: {
2709 PointerRNA ptr_sub_a = RNA_property_pointer_get(ptr_a, prop);
2710 PointerRNA ptr_sub_b = RNA_property_pointer_get(ptr_b, prop);
2711 rna_struct_update_when_changed(C, bmain, &ptr_sub_a, &ptr_sub_b);
2712 break;
2713 }
2714 case PROP_COLLECTION:
2715 /* Don't handle collections. */
2716 break;
2717 default: {
2718 if (!RNA_property_equals(bmain, ptr_a, ptr_b, prop, RNA_EQ_STRICT)) {
2719 RNA_property_update(C, ptr_b, prop);
2720 }
2721 }
2722 }
2723 }
2725}
2726
2728 Main *bmain,
2729 UserDef *userdef_prev,
2730 UserDef *userdef_curr)
2731{
2732 PointerRNA ptr_a = RNA_pointer_create_discrete(nullptr, &RNA_Preferences, userdef_prev);
2733 PointerRNA ptr_b = RNA_pointer_create_discrete(nullptr, &RNA_Preferences, userdef_curr);
2734 const bool is_dirty = userdef_curr->runtime.is_dirty;
2735
2736 rna_struct_update_when_changed(C, bmain, &ptr_a, &ptr_b);
2737
2740
2741 userdef_curr->runtime.is_dirty = is_dirty;
2742}
2743
2745{
2746 Main *bmain = CTX_data_main(C);
2747 const bool use_data = false;
2748 const bool use_userdef = true;
2749 const bool use_factory_settings = STREQ(op->type->idname, "WM_OT_read_factory_userpref");
2750 const bool use_factory_settings_app_template_only =
2751 (use_factory_settings && RNA_boolean_get(op->ptr, "use_factory_startup_app_template_only"));
2752
2754
2755 UserDef U_backup = blender::dna::shallow_copy(U);
2756
2757 wmHomeFileRead_Params read_homefile_params{};
2758 read_homefile_params.use_data = use_data;
2759 read_homefile_params.use_userdef = use_userdef;
2760 read_homefile_params.use_factory_settings = use_factory_settings;
2761 read_homefile_params.use_factory_settings_app_template_only =
2762 use_factory_settings_app_template_only;
2763 read_homefile_params.use_empty_data = false;
2764 read_homefile_params.filepath_startup_override = nullptr;
2766 wm_homefile_read(C, &read_homefile_params, op->reports);
2767
2768 wm_userpref_read_exceptions(&U, &U_backup);
2769 SET_FLAG_FROM_TEST(G.f, use_factory_settings, G_FLAG_USERPREF_NO_SAVE_ON_EXIT);
2770
2771 wm_userpref_update_when_changed(C, bmain, &U_backup, &U);
2772
2773 if (use_factory_settings) {
2774 U.runtime.is_dirty = true;
2775 }
2776
2778
2779 /* Needed to recalculate UI scaling values (eg, #UserDef.inv_dpi_fac). */
2780 wm_window_clear_drawable(static_cast<wmWindowManager *>(bmain->wm.first));
2781
2783
2784 return OPERATOR_FINISHED;
2785}
2786
2788{
2789 ot->name = "Load Preferences";
2790 ot->idname = "WM_OT_read_userpref";
2791 ot->description = "Load last saved preferences";
2792
2795}
2796
2798 wmOperator *op,
2799 const wmEvent * /*event*/)
2800{
2801 std::string title;
2802
2803 const bool template_only = U.app_template[0] &&
2804 RNA_boolean_get(op->ptr, "use_factory_startup_app_template_only");
2805
2806 if (template_only) {
2807 char display_name[FILE_MAX];
2808 BLI_path_to_display_name(display_name, sizeof(display_name), IFACE_(U.app_template));
2809 title = fmt::format(fmt::runtime(IFACE_("Load Factory \"{}\" Preferences.")),
2810 IFACE_(display_name));
2811 }
2812 else {
2813 title = IFACE_("Load Factory Blender Preferences");
2814 }
2815
2817 C,
2818 op,
2819 title.c_str(),
2820 IFACE_("To make changes to Preferences permanent, use \"Save Preferences\""),
2821 IFACE_("Load"),
2823 false);
2824}
2825
2827{
2828 ot->name = "Load Factory Preferences";
2829 ot->idname = "WM_OT_read_factory_userpref";
2830 ot->description =
2831 "Load factory default preferences. "
2832 "To make changes to preferences permanent, use \"Save Preferences\"";
2833
2836
2838}
2839
2841
2842/* -------------------------------------------------------------------- */
2845
2852
2854{
2855 ot->name = "Reload History File";
2856 ot->idname = "WM_OT_read_history";
2857 ot->description = "Reloads history and bookmarks";
2858
2861
2862 /* This operator is only used for loading settings from a previous blender install. */
2863 ot->flag = OPTYPE_INTERNAL;
2864}
2865
2867
2868/* -------------------------------------------------------------------- */
2873
2875{
2876 const bool use_factory_startup_and_userdef = STREQ(op->type->idname,
2877 "WM_OT_read_factory_settings");
2878 const bool use_factory_settings = use_factory_startup_and_userdef ||
2879 RNA_boolean_get(op->ptr, "use_factory_startup");
2880 const bool use_factory_settings_app_template_only =
2881 (use_factory_startup_and_userdef &&
2882 RNA_boolean_get(op->ptr, "use_factory_startup_app_template_only"));
2883
2884 bool use_userdef = false;
2885 char filepath_buf[FILE_MAX];
2886 const char *filepath = nullptr;
2887 UserDef U_backup = blender::dna::shallow_copy(U);
2888
2889 if (!use_factory_settings) {
2890 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "filepath");
2891
2892 /* This can be used when loading of a start-up file should only change
2893 * the scene content but keep the blender UI as it is. */
2894 wm_open_init_load_ui(op, true);
2895 SET_FLAG_FROM_TEST(G.fileflags, !RNA_boolean_get(op->ptr, "load_ui"), G_FILE_NO_UI);
2896
2897 if (RNA_property_is_set(op->ptr, prop)) {
2898 RNA_property_string_get(op->ptr, prop, filepath_buf);
2899 filepath = filepath_buf;
2900 if (BLI_access(filepath, R_OK)) {
2902 op->reports, RPT_ERROR, "Can't read alternative start-up file: \"%s\"", filepath);
2903 return OPERATOR_CANCELLED;
2904 }
2905 }
2906 }
2907 else {
2908 if (use_factory_startup_and_userdef) {
2909 /* Always load UI for factory settings (prefs will re-init). */
2910 G.fileflags &= ~G_FILE_NO_UI;
2911 /* Always load preferences with factory settings. */
2912 use_userdef = true;
2913 }
2914 }
2915
2916 /* Close any user-loaded fonts. */
2918
2919 char app_template_buf[sizeof(U.app_template)];
2920 const char *app_template;
2921 PropertyRNA *prop_app_template = RNA_struct_find_property(op->ptr, "app_template");
2922 const bool use_splash = !use_factory_settings && RNA_boolean_get(op->ptr, "use_splash");
2923 const bool use_empty_data = RNA_boolean_get(op->ptr, "use_empty");
2924
2925 if (prop_app_template && RNA_property_is_set(op->ptr, prop_app_template)) {
2926 RNA_property_string_get(op->ptr, prop_app_template, app_template_buf);
2927 app_template = app_template_buf;
2928
2929 if (!use_factory_settings) {
2930 /* Always load preferences when switching templates with own preferences. */
2931 use_userdef = BKE_appdir_app_template_has_userpref(app_template) ||
2933 }
2934
2935 /* Turn override off, since we're explicitly loading a different app-template. */
2937 }
2938 else {
2939 /* Normally nullptr, only set when overriding from the command-line. */
2940 app_template = WM_init_state_app_template_get();
2941 }
2942
2943 if (use_userdef) {
2945 }
2946
2947 wmHomeFileRead_Params read_homefile_params{};
2948 read_homefile_params.use_data = true;
2949 read_homefile_params.use_userdef = use_userdef;
2950 read_homefile_params.use_factory_settings = use_factory_settings;
2951 read_homefile_params.use_factory_settings_app_template_only =
2952 use_factory_settings_app_template_only;
2953 read_homefile_params.use_empty_data = use_empty_data;
2954 read_homefile_params.filepath_startup_override = filepath;
2955 read_homefile_params.app_template_override = app_template;
2956 wm_homefile_read(C, &read_homefile_params, op->reports);
2957
2958 if (use_splash) {
2960 }
2961
2962 if (use_userdef) {
2963 wm_userpref_read_exceptions(&U, &U_backup);
2964 SET_FLAG_FROM_TEST(G.f, use_factory_settings, G_FLAG_USERPREF_NO_SAVE_ON_EXIT);
2965
2966 if (use_factory_settings) {
2967 U.runtime.is_dirty = true;
2968 }
2969 }
2970
2971 if (use_userdef) {
2973 }
2974
2975 if (G.fileflags & G_FILE_NO_UI) {
2977 }
2978
2979 return OPERATOR_FINISHED;
2980}
2981
2983{
2985 C, "WM_OT_read_homefile", WM_OP_EXEC_DEFAULT, (IDProperty *)user_data, nullptr);
2986}
2987
2997
2999{
3000 PropertyRNA *prop;
3001
3002 prop = RNA_def_string(ot->srna, "app_template", "Template", sizeof(U.app_template), "", "");
3004
3005 prop = RNA_def_boolean(
3006 ot->srna,
3007 "use_empty",
3008 false,
3009 "Empty",
3010 "After loading, remove everything except scenes, windows, and workspaces. This makes it "
3011 "possible to load the startup file with its scene configuration and window layout intact, "
3012 "but no objects, materials, animations, ...");
3014}
3015
3017{
3018 PropertyRNA *prop;
3019 ot->name = "Reload Start-Up File";
3020 ot->idname = "WM_OT_read_homefile";
3021 ot->description = "Open the default file";
3022
3025
3026 prop = RNA_def_string_file_path(ot->srna,
3027 "filepath",
3028 nullptr,
3029 FILE_MAX,
3030 "File Path",
3031 "Path to an alternative start-up file");
3033
3034 /* So scripts can use an alternative start-up file without the UI. */
3035 prop = RNA_def_boolean(
3036 ot->srna, "load_ui", true, "Load UI", "Load user interface setup from the .blend file");
3038
3039 /* So the splash can be kept open after loading a file (for templates). */
3040 prop = RNA_def_boolean(ot->srna, "use_splash", false, "Splash", "");
3042
3043 /* So scripts can load factory-startup without resetting preferences
3044 * (which has other implications such as reloading all add-ons).
3045 * Match naming for `--factory-startup` command line argument. */
3046 prop = RNA_def_boolean(ot->srna,
3047 "use_factory_startup",
3048 false,
3049 "Factory Startup",
3050 "Load the default ('factory startup') blend file. "
3051 "This is independent of the normal start-up file that the user can save");
3054
3056
3057 /* Omit poll to run in background mode. */
3058}
3059
3061 wmOperator *op,
3062 const wmEvent * /*event*/)
3063{
3065 CTX_wm_manager(C));
3066 std::string title;
3067 const bool template_only = U.app_template[0] &&
3068 RNA_boolean_get(op->ptr, "use_factory_startup_app_template_only");
3069
3070 if (template_only) {
3071 char display_name[FILE_MAX];
3072 BLI_path_to_display_name(display_name, sizeof(display_name), IFACE_(U.app_template));
3073 title = fmt::format(fmt::runtime(IFACE_("Load Factory \"{}\" Startup File and Preferences")),
3074 IFACE_(display_name));
3075 }
3076 else {
3077 title = IFACE_("Load Factory Default Startup File and Preferences");
3078 }
3079
3081 C,
3082 op,
3083 title.c_str(),
3084 unsaved ? IFACE_("To make changes to Preferences permanent, use \"Save Preferences\".\n"
3085 "Warning: Your file is unsaved! Proceeding will abandon your changes.") :
3086 IFACE_("To make changes to Preferences permanent, use \"Save Preferences\"."),
3087 IFACE_("Load"),
3089 false);
3090}
3091
3093{
3094 ot->name = "Load Factory Settings";
3095 ot->idname = "WM_OT_read_factory_settings";
3096 ot->description =
3097 "Load factory default startup file and preferences. "
3098 "To make changes permanent, use \"Save Startup File\" and \"Save Preferences\"";
3099
3102 /* Omit poll to run in background mode. */
3103
3105
3107}
3108
3110
3111/* -------------------------------------------------------------------- */
3114
3119 const char *filepath,
3120 const bool use_scripts_autoexec_check,
3122{
3123 /* XXX: wm in context is not set correctly after #WM_file_read -> crash. */
3124 /* Do it before for now, but is this correct with multiple windows? */
3126
3127 const bool success = WM_file_read(C, filepath, use_scripts_autoexec_check, reports);
3128
3129 return success;
3130}
3131
3132/* Generic operator state utilities. */
3133
3134static void create_operator_state(wmOperatorType *ot, int first_state)
3135{
3136 PropertyRNA *prop = RNA_def_int(
3137 ot->srna, "state", first_state, INT32_MIN, INT32_MAX, "State", "", INT32_MIN, INT32_MAX);
3140}
3141
3143{
3144 return RNA_int_get(op->ptr, "state");
3145}
3146
3148{
3149 RNA_int_set(op->ptr, "state", state);
3150}
3151
3156
3158 wmOperator *op,
3159 OperatorDispatchTarget *targets)
3160{
3161 int state = get_operator_state(op);
3162 for (int i = 0; targets[i].run; i++) {
3163 OperatorDispatchTarget target = targets[i];
3164 if (target.state == state) {
3165 return target.run(C, op);
3166 }
3167 }
3169 return OPERATOR_CANCELLED;
3170}
3171
3173
3174/* -------------------------------------------------------------------- */
3177
3178enum {
3182};
3183
3185
3187{
3189 C, "WM_OT_open_mainfile", WM_OP_INVOKE_DEFAULT, (IDProperty *)user_data, nullptr);
3190}
3191
3206
3208{
3210
3211 Main *bmain = CTX_data_main(C);
3212 const char *blendfile_path = BKE_main_blendfile_path(bmain);
3213
3214 if (CTX_wm_window(C) == nullptr) {
3215 /* In rare cases this could happen, when trying to invoke in background
3216 * mode on load for example. Don't use poll for this because exec()
3217 * can still run without a window. */
3218 BKE_report(op->reports, RPT_ERROR, "Context window not set");
3219 return OPERATOR_CANCELLED;
3220 }
3221
3222 /* If possible, get the name of the most recently used `.blend` file. */
3223 if (G.recent_files.first) {
3224 RecentFile *recent = static_cast<RecentFile *>(G.recent_files.first);
3225 blendfile_path = recent->filepath;
3226 }
3227
3228 RNA_string_set(op->ptr, "filepath", blendfile_path);
3229 wm_open_init_load_ui(op, true);
3230 const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, OpenTrust::FilePath);
3231 UNUSED_VARS(use_scripts_autoexec_check); /* The user can set this in the UI. */
3232 op->customdata = nullptr;
3233
3235
3237}
3238
3240{
3241 char filepath[FILE_MAX];
3242 bool success;
3243
3244 RNA_string_get(op->ptr, "filepath", filepath);
3245 BLI_path_canonicalize_native(filepath, sizeof(filepath));
3246
3247 /* For file opening, also print in console for warnings, not only errors. */
3249
3250 /* Re-use last loaded setting so we can reload a file without changing. */
3251 wm_open_init_load_ui(op, false);
3252 const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, OpenTrust::CurrentSession);
3253
3254 SET_FLAG_FROM_TEST(G.fileflags, !RNA_boolean_get(op->ptr, "load_ui"), G_FILE_NO_UI);
3256 success = wm_file_read_opwrap(C, filepath, use_scripts_autoexec_check, op->reports);
3257
3258 if (success) {
3259 if (G.fileflags & G_FILE_NO_UI) {
3261 }
3263 return OPERATOR_FINISHED;
3264 }
3265 return OPERATOR_CANCELLED;
3266}
3267
3274
3279
3281 wmOperator *op,
3282 const wmEvent * /*event*/)
3283{
3284 return wm_open_mainfile_dispatch(C, op);
3285}
3286
3291
3293 wmOperatorType * /*ot*/,
3294 PointerRNA *ptr)
3295{
3296 if (!RNA_struct_property_is_set(ptr, "filepath")) {
3297 return "";
3298 }
3299
3300 char filepath[FILE_MAX];
3301 RNA_string_get(ptr, "filepath", filepath);
3302
3303 BLI_stat_t stats;
3304 if (BLI_stat(filepath, &stats) == -1) {
3305 return fmt::format("{}\n\n{}", filepath, TIP_("File Not Found"));
3306 }
3307
3308 /* Date. */
3309 char date_str[FILELIST_DIRENTRY_DATE_LEN];
3310 char time_str[FILELIST_DIRENTRY_TIME_LEN];
3311 bool is_today, is_yesterday;
3313 nullptr, int64_t(stats.st_mtime), false, time_str, date_str, &is_today, &is_yesterday);
3314 if (is_today || is_yesterday) {
3315 STRNCPY(date_str, is_today ? TIP_("Today") : TIP_("Yesterday"));
3316 }
3317
3318 /* Size. */
3319 char size_str[FILELIST_DIRENTRY_SIZE_LEN];
3320 BLI_filelist_entry_size_to_string(nullptr, uint64_t(stats.st_size), false, size_str);
3321
3322 return fmt::format("{}\n\n{}: {} {}\n{}: {}",
3323 filepath,
3324 TIP_("Modified"),
3325 date_str,
3326 time_str,
3327 TIP_("Size"),
3328 size_str);
3329}
3330
3331/* Currently fits in a pointer. */
3334};
3335BLI_STATIC_ASSERT(sizeof(FileRuntime) <= sizeof(void *), "Struct must not exceed pointer size");
3336
3338{
3339 FileRuntime *file_info = (FileRuntime *)&op->customdata;
3340 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_scripts");
3341 bool is_untrusted = false;
3342 char filepath[FILE_MAX];
3343 char *lslash;
3344
3345 RNA_string_get(op->ptr, "filepath", filepath);
3346
3347 /* Get the directory. */
3348 lslash = (char *)BLI_path_slash_rfind(filepath);
3349 if (lslash) {
3350 *(lslash + 1) = '\0';
3351 }
3352
3353 /* Excluded paths can't be trusted, unless the command line overrides the preference. */
3354 if (((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) && !G.autoexec_override.has_value()) {
3355 if (BKE_autoexec_match(filepath) == true) {
3356 RNA_property_boolean_set(op->ptr, prop, false);
3357 is_untrusted = true;
3358 }
3359 }
3360
3361 if (file_info) {
3362 file_info->is_untrusted = is_untrusted;
3363 }
3364
3365 return is_untrusted;
3366}
3367
3368static void wm_open_mainfile_ui(bContext * /*C*/, wmOperator *op)
3369{
3370 FileRuntime *file_info = (FileRuntime *)&op->customdata;
3371 uiLayout *layout = op->layout;
3372 const char *autoexec_text;
3373
3374 layout->prop(op->ptr, "load_ui", UI_ITEM_NONE, std::nullopt, ICON_NONE);
3375
3376 uiLayout *col = &layout->column(false);
3377 if (file_info->is_untrusted) {
3378 autoexec_text = IFACE_("Trusted Source [Untrusted Path]");
3379 uiLayoutSetActive(col, false);
3380 uiLayoutSetEnabled(col, false);
3381 }
3382 else {
3383 autoexec_text = IFACE_("Trusted Source");
3384 }
3385
3386 col->prop(op->ptr, "use_scripts", UI_ITEM_NONE, autoexec_text, ICON_NONE);
3387}
3388
3390{
3392 "use_scripts",
3393 false,
3394 "Trusted Source",
3395 "Allow .blend file to execute scripts automatically, default available from "
3396 "system preferences");
3397}
3398
3400{
3401 ot->name = "Open";
3402 ot->idname = "WM_OT_open_mainfile";
3403 ot->description = "Open a Blender file";
3405
3409 ot->ui = wm_open_mainfile_ui;
3410 /* Omit window poll so this can work in background mode. */
3411
3419
3421 ot->srna, "load_ui", true, "Load UI", "Load user interface setup in the .blend file");
3422
3424
3426 ot->srna, "display_file_selector", true, "Display File Selector", "");
3428
3430}
3431
3433
3434/* -------------------------------------------------------------------- */
3437
3439 wmOperator *op,
3440 const wmEvent * /*event*/)
3441{
3442 std::string message = IFACE_("Any unsaved changes will be lost.");
3444 message += "\n";
3445 message += IFACE_("Warning: There are unsaved external image(s).");
3446 }
3447
3449 op,
3450 IFACE_("Revert to the Saved File"),
3451 message.c_str(),
3452 IFACE_("Revert"),
3454 false);
3455}
3456
3458{
3459 Main *bmain = CTX_data_main(C);
3460 bool success;
3461 char filepath[FILE_MAX];
3462
3463 const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, OpenTrust::CurrentSession);
3464
3466
3467 STRNCPY(filepath, BKE_main_blendfile_path(bmain));
3468 success = wm_file_read_opwrap(C, filepath, use_scripts_autoexec_check, op->reports);
3469
3470 if (success) {
3471 return OPERATOR_FINISHED;
3472 }
3473 return OPERATOR_CANCELLED;
3474}
3475
3477{
3478 const char *blendfile_path = BKE_main_blendfile_path_from_global();
3479 return (blendfile_path[0] != '\0');
3480}
3481
3483{
3484 ot->name = "Revert";
3485 ot->idname = "WM_OT_revert_mainfile";
3486 ot->description = "Reload the saved file";
3487
3491
3493}
3494
3496
3497/* -------------------------------------------------------------------- */
3500
3502 const bool use_scripts_autoexec_check,
3504{
3505 char filepath[FILE_MAX];
3506 BLI_path_join(filepath, sizeof(filepath), BKE_tempdir_base(), BLENDER_QUIT_FILE);
3507 G.fileflags |= G_FILE_RECOVER_READ;
3508 const bool success = wm_file_read_opwrap(C, filepath, use_scripts_autoexec_check, reports);
3509 G.fileflags &= ~G_FILE_RECOVER_READ;
3510 return success;
3511}
3512
3514 wmOperator *op,
3515 const bool use_scripts_autoexec_check)
3516{
3518 if (WM_file_recover_last_session(C, use_scripts_autoexec_check, op->reports)) {
3519 if (!G.background) {
3520 wmOperatorType *ot = op->type;
3521 PointerRNA *props_ptr = MEM_new<PointerRNA>(__func__);
3522 WM_operator_properties_create_ptr(props_ptr, ot);
3523 RNA_boolean_set(props_ptr, "use_scripts", true);
3524 wm_test_autorun_revert_action_set(ot, props_ptr);
3525 }
3526 return OPERATOR_FINISHED;
3527 }
3528 return OPERATOR_CANCELLED;
3529}
3530
3532{
3533 const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, OpenTrust::Recover);
3534 return wm_recover_last_session_impl(C, op, use_scripts_autoexec_check);
3535}
3536
3538{
3540 C, "WM_OT_recover_last_session", WM_OP_EXEC_DEFAULT, (IDProperty *)user_data, nullptr);
3541}
3542
3544 wmOperator *op,
3545 const wmEvent * /*event*/)
3546{
3547 const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, OpenTrust::Recover);
3548
3551 {
3552 return OPERATOR_INTERFACE;
3553 }
3554 return wm_recover_last_session_impl(C, op, use_scripts_autoexec_check);
3555}
3556
3558{
3559 ot->name = "Recover Last Session";
3560 ot->idname = "WM_OT_recover_last_session";
3561 ot->description = "Open the last closed file (\"" BLENDER_QUIT_FILE "\")";
3562
3565
3567}
3568
3570
3571/* -------------------------------------------------------------------- */
3574
3576{
3577 char filepath[FILE_MAX];
3578 bool success;
3579
3580 RNA_string_get(op->ptr, "filepath", filepath);
3581 BLI_path_canonicalize_native(filepath, sizeof(filepath));
3582
3583 const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, OpenTrust::Recover);
3585
3586 G.fileflags |= G_FILE_RECOVER_READ;
3587
3588 success = wm_file_read_opwrap(C, filepath, use_scripts_autoexec_check, op->reports);
3589
3590 G.fileflags &= ~G_FILE_RECOVER_READ;
3591
3592 if (success) {
3593 if (!G.background) {
3594 wmOperatorType *ot = op->type;
3595 PointerRNA *props_ptr = MEM_new<PointerRNA>(__func__);
3596 WM_operator_properties_create_ptr(props_ptr, ot);
3597 RNA_boolean_set(props_ptr, "use_scripts", true);
3598 wm_test_autorun_revert_action_set(ot, props_ptr);
3599 }
3600 return OPERATOR_FINISHED;
3601 }
3602 return OPERATOR_CANCELLED;
3603}
3604
3606 wmOperator *op,
3607 const wmEvent * /*event*/)
3608{
3609 char filepath[FILE_MAX];
3610
3611 wm_autosave_location(filepath);
3612 RNA_string_set(op->ptr, "filepath", filepath);
3613 const bool use_scripts_autoexec_check = wm_open_init_use_scripts(op, OpenTrust::Recover);
3614 UNUSED_VARS(use_scripts_autoexec_check); /* The user can set this in the UI. */
3616
3618}
3619
3621{
3622 ot->name = "Recover Auto Save";
3623 ot->idname = "WM_OT_recover_auto_save";
3624 ot->description = "Open an automatically saved file to recover it";
3625
3628
3636
3638}
3639
3641
3642/* -------------------------------------------------------------------- */
3647
3648static void wm_filepath_default(const Main *bmain, char *filepath)
3649{
3650 if (bmain->filepath[0] == '\0') {
3651 char filename_untitled[FILE_MAXFILE];
3652 SNPRINTF(filename_untitled, "%s.blend", DATA_("Untitled"));
3653 BLI_path_filename_ensure(filepath, FILE_MAX, filename_untitled);
3654 }
3655}
3656
3658{
3659 PropertyRNA *prop;
3660
3661 prop = RNA_struct_find_property(op->ptr, "compress");
3662 if (!RNA_property_is_set(op->ptr, prop)) {
3663 const char *blendfile_path = BKE_main_blendfile_path_from_global();
3664 if (blendfile_path[0] != '\0') { /* Keep flag for existing file. */
3665 RNA_property_boolean_set(op->ptr, prop, (G.fileflags & G_FILE_COMPRESS) != 0);
3666 }
3667 else { /* Use userdef for new file. */
3668 RNA_property_boolean_set(op->ptr, prop, (U.flag & USER_FILECOMPRESS) != 0);
3669 }
3670 }
3671}
3672
3674{
3675 Main *bmain = CTX_data_main(C);
3676 PropertyRNA *prop;
3677 char filepath[FILE_MAX];
3678
3679 prop = RNA_struct_find_property(op->ptr, "filepath");
3680 if (!RNA_property_is_set(op->ptr, prop)) {
3681 const char *blendfile_path = BKE_main_blendfile_path(bmain);
3682 /* If not saved before, get the name of the most recently used `.blend` file. */
3683 if ((blendfile_path[0] == '\0') && G.recent_files.first) {
3684 RecentFile *recent = static_cast<RecentFile *>(G.recent_files.first);
3685 STRNCPY(filepath, recent->filepath);
3686 }
3687 else {
3688 STRNCPY(filepath, blendfile_path);
3689 }
3690
3691 /* For convenience when using "Save As" on asset system files:
3692 * Replace `.asset.blend` extension with just `.blend`.
3693 * Asset system files must not be overridden (except by the asset system),
3694 * there are further checks to prevent this entirely. */
3695 if (bmain->is_asset_edit_file &&
3697 {
3698 filepath[strlen(filepath) - strlen(BLENDER_ASSET_FILE_SUFFIX)] = '\0';
3699 BLI_path_extension_ensure(filepath, FILE_MAX, ".blend");
3700 }
3701
3702 wm_filepath_default(bmain, filepath);
3703 RNA_property_string_set(op->ptr, prop, filepath);
3704 }
3705}
3706
3708 wmOperator *op,
3709 const wmEvent * /*event*/)
3710{
3711
3713 save_set_filepath(C, op);
3714
3715 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "relative_remap");
3716 if (!RNA_property_is_set(op->ptr, prop)) {
3717 RNA_property_boolean_set(op->ptr, prop, (U.flag & USER_RELPATHS));
3718 }
3719
3721
3723}
3724
3725/* Function used for #WM_OT_save_mainfile too. */
3727{
3728 Main *bmain = CTX_data_main(C);
3729 char filepath[FILE_MAX];
3730 const bool is_save_as = (op->type->invoke == wm_save_as_mainfile_invoke);
3731 const bool use_save_as_copy = is_save_as && RNA_boolean_get(op->ptr, "copy");
3732
3733 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "incremental");
3734 const bool is_incremental = prop ? RNA_property_boolean_get(op->ptr, prop) : false;
3735
3736 /* We could expose all options to the users however in most cases remapping
3737 * existing relative paths is a good default.
3738 * Users can manually make their paths relative & absolute if they wish. */
3739 const eBLO_WritePathRemap remap_mode = RNA_boolean_get(op->ptr, "relative_remap") ?
3743
3744 const bool is_filepath_set = RNA_struct_property_is_set(op->ptr, "filepath");
3745 if (is_filepath_set) {
3746 RNA_string_get(op->ptr, "filepath", filepath);
3747 BLI_path_canonicalize_native(filepath, sizeof(filepath));
3748 }
3749 else {
3750 STRNCPY(filepath, BKE_main_blendfile_path(bmain));
3751 }
3752
3753 if (filepath[0] == '\0') {
3754 BKE_report(op->reports,
3755 RPT_ERROR,
3756 "Unable to save an unsaved file with an empty or unset \"filepath\" property");
3757 return OPERATOR_CANCELLED;
3758 }
3759
3760 if ((is_save_as == false) && is_incremental) {
3761 char head[FILE_MAXFILE], tail[FILE_MAXFILE];
3762 ushort digits;
3763 int num = BLI_path_sequence_decode(filepath, head, sizeof(head), tail, sizeof(tail), &digits);
3764 /* Numbers greater than INT_MAX return 0, resulting in always appending "1" to the name. */
3765 if (num == 0 && digits == 0) {
3766 /* This does nothing if there are no numbers at the end of the head. */
3768 }
3769
3770 const int tries_limit = 1000;
3771 int tries = 0;
3772 bool in_use = true;
3773 do {
3774 num++;
3775 tries++;
3776 BLI_path_sequence_encode(filepath, sizeof(filepath), head, tail, digits, num);
3777 in_use = BLI_exists(filepath);
3778 } while (in_use && tries < tries_limit && num < INT_MAX);
3779 if (in_use) {
3780 BKE_report(op->reports, RPT_ERROR, "Unable to find an available incremented file name");
3781 return OPERATOR_CANCELLED;
3782 }
3783 }
3784
3785 const int fileflags_orig = G.fileflags;
3786 int fileflags = G.fileflags;
3787
3788 /* Set compression flag. */
3789 SET_FLAG_FROM_TEST(fileflags, RNA_boolean_get(op->ptr, "compress"), G_FILE_COMPRESS);
3790
3791 const bool success = wm_file_write(
3792 C, filepath, fileflags, remap_mode, use_save_as_copy, op->reports);
3793
3794 if ((op->flag & OP_IS_INVOKE) == 0) {
3795 /* OP_IS_INVOKE is set when the operator is called from the GUI.
3796 * If it is not set, the operator is called from a script and
3797 * shouldn't influence G.fileflags. */
3798 G.fileflags = fileflags_orig;
3799 }
3800
3801 if (success == false) {
3802 return OPERATOR_CANCELLED;
3803 }
3804
3805 const char *filename = BLI_path_basename(filepath);
3806
3807 if (is_incremental) {
3808 BKE_reportf(op->reports, RPT_INFO, "Saved incremental as \"%s\"", filename);
3809 }
3810 else if (is_save_as) {
3811 /* use_save_as_copy depends upon is_save_as. */
3812 if (use_save_as_copy) {
3813 BKE_reportf(op->reports, RPT_INFO, "Saved copy as \"%s\"", filename);
3814 }
3815 else {
3816 BKE_reportf(op->reports, RPT_INFO, "Saved as \"%s\"", filename);
3817 }
3818 }
3819 else {
3820 BKE_reportf(op->reports, RPT_INFO, "Saved \"%s\"", filename);
3821 }
3822
3823 if (!use_save_as_copy) {
3824 /* If saved file is the active one, there are technically no more compatibility issues, the
3825 * file on disk now matches the currently opened data version-wise. */
3826 bmain->has_forward_compatibility_issues = false;
3827
3828 /* If saved file is the active one, notify WM so that saved status and window title can be
3829 * updated. */
3832 /* Restart auto-save timer to avoid unnecessary unexpected freezing (because of auto-save)
3833 * when often saving manually. */
3836 wm->autosave_scheduled = false;
3837 }
3838 }
3839
3840 if (!is_save_as && RNA_boolean_get(op->ptr, "exit")) {
3842 }
3843
3844 return OPERATOR_FINISHED;
3845}
3846
3848{
3849 char filepath[FILE_MAX];
3850 RNA_string_get(op->ptr, "filepath", filepath);
3851 if (!BKE_blendfile_extension_check(filepath)) {
3852 /* NOTE(@ideasman42): some users would prefer #BLI_path_extension_replace(),
3853 * we have had some nitpicking bug reports about this.
3854 * Always adding the extension as users may use '.' as part of the file-name. */
3855 BLI_path_extension_ensure(filepath, FILE_MAX, ".blend");
3856 RNA_string_set(op->ptr, "filepath", filepath);
3857 return true;
3858 }
3859 return false;
3860}
3861
3863{
3864 if (RNA_boolean_get(ptr, "copy")) {
3865 return CTX_IFACE_(ot->translation_context, "Save Copy");
3866 }
3867 return "";
3868}
3869
3871 wmOperatorType * /*ot*/,
3872 PointerRNA *ptr)
3873{
3874 if (RNA_boolean_get(ptr, "copy")) {
3875 return BLI_strdup(TIP_(
3876 "Save the current file in the desired location but do not make the saved file active"));
3877 }
3878 return "";
3879}
3880
3882{
3883 PropertyRNA *prop;
3884
3885 ot->name = "Save As";
3886 ot->idname = "WM_OT_save_as_mainfile";
3887 ot->description = "Save the current file in the desired location";
3888
3894 /* Omit window poll so this can work in background mode. */
3895
3899 FILE_SAVE,
3903 RNA_def_boolean(ot->srna, "compress", false, "Compress", "Write compressed .blend file");
3905 "relative_remap",
3906 true,
3907 "Remap Relative",
3908 "Remap relative paths when saving to a different directory");
3909 prop = RNA_def_boolean(
3910 ot->srna,
3911 "copy",
3912 false,
3913 "Save Copy",
3914 "Save a copy of the actual working state but does not make saved file active");
3916}
3917
3919 wmOperator *op,
3920 const wmEvent * /*event*/)
3921{
3923
3924 /* Cancel if no active window. */
3925 if (CTX_wm_window(C) == nullptr) {
3926 return OPERATOR_CANCELLED;
3927 }
3928
3930 save_set_filepath(C, op);
3931
3932 /* If we're saving for the first time and prefer relative paths -
3933 * any existing paths will be absolute,
3934 * enable the option to remap paths to avoid confusion, see: #37240. */
3935 const char *blendfile_path = BKE_main_blendfile_path_from_global();
3936 if ((blendfile_path[0] == '\0') && (U.flag & USER_RELPATHS)) {
3937 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "relative_remap");
3938 if (!RNA_property_is_set(op->ptr, prop)) {
3939 RNA_property_boolean_set(op->ptr, prop, true);
3940 }
3941 }
3942
3943 if (blendfile_path[0] != '\0') {
3947 }
3948 else {
3950 }
3951 }
3952 else {
3955 }
3956
3957 return ret;
3958}
3959
3961 wmOperatorType * /*ot*/,
3962 PointerRNA *ptr)
3963{
3964 if (RNA_boolean_get(ptr, "incremental")) {
3965 return TIP_(
3966 "Save the current Blender file with a numerically incremented name that does not "
3967 "overwrite any existing files");
3968 }
3969 return "";
3970}
3971
3973{
3974 ot->name = "Save Blender File";
3975 ot->idname = "WM_OT_save_mainfile";
3976 ot->description = "Save the current Blender file";
3977
3982 /* Omit window poll so this can work in background mode. */
3983
3984 PropertyRNA *prop;
3988 FILE_SAVE,
3992 RNA_def_boolean(ot->srna, "compress", false, "Compress", "Write compressed .blend file");
3994 "relative_remap",
3995 false,
3996 "Remap Relative",
3997 "Remap relative paths when saving to a different directory");
3998
3999 prop = RNA_def_boolean(ot->srna, "exit", false, "Exit", "Exit Blender after saving");
4001
4002 prop = RNA_def_boolean(ot->srna,
4003 "incremental",
4004 false,
4005 "Incremental",
4006 "Save the current Blender file with a numerically incremented name that "
4007 "does not overwrite any existing files");
4009}
4010
4012
4013/* -------------------------------------------------------------------- */
4016
4018
4020 {CLEAR_RECENT_ALL, "ALL", 0, "All Items", ""},
4021 {CLEAR_RECENT_MISSING, "MISSING", 0, "Items Not Found", ""},
4022 {0, nullptr, 0, nullptr, nullptr},
4023};
4024
4026 wmOperator *op,
4027 const wmEvent *event)
4028{
4030 C, op, event, IFACE_("Clear Recent Files List"), IFACE_("Remove"));
4031}
4032
4034{
4035 ClearRecentInclude include = static_cast<ClearRecentInclude>(RNA_enum_get(op->ptr, "remove"));
4036
4037 if (include == CLEAR_RECENT_ALL) {
4039 }
4040 else if (include == CLEAR_RECENT_MISSING) {
4041 LISTBASE_FOREACH_MUTABLE (RecentFile *, recent, &G.recent_files) {
4042 if (!BLI_exists(recent->filepath)) {
4043 wm_history_file_free(recent);
4044 }
4045 }
4046 }
4047
4049
4050 return OPERATOR_FINISHED;
4051}
4052
4054{
4055 uiLayout *layout = op->layout;
4056 uiLayoutSetPropSep(layout, true);
4057 uiLayoutSetPropDecorate(layout, false);
4058
4059 layout->separator();
4060 layout->prop(op->ptr, "remove", UI_ITEM_R_TOGGLE, std::nullopt, ICON_NONE);
4061 layout->separator();
4062}
4063
4065{
4066 ot->name = "Clear Recent Files List";
4067 ot->idname = "WM_OT_clear_recent_files";
4068 ot->description = "Clear the recent files list";
4069
4073
4074 /* flags */
4075 ot->flag = OPTYPE_REGISTER;
4076
4077 /* props */
4078 ot->prop = RNA_def_enum(
4079 ot->srna, "remove", prop_clear_recent_types, CLEAR_RECENT_ALL, "Remove", "");
4080}
4081
4083
4084/* -------------------------------------------------------------------- */
4087
4088static void wm_block_autorun_warning_ignore(bContext *C, void *arg_block, void * /*arg*/)
4089{
4090 wmWindow *win = CTX_wm_window(C);
4091 UI_popup_block_close(C, win, static_cast<uiBlock *>(arg_block));
4092
4093 /* Free the data as it's no longer needed. */
4094 wm_test_autorun_revert_action_set(nullptr, nullptr);
4095}
4096
4098{
4099 wmWindow *win = CTX_wm_window(C);
4100
4101 UI_popup_block_close(C, win, block);
4102
4103 /* Load file again with scripts enabled.
4104 * The reload is necessary to allow scripts to run when the files loads. */
4106}
4107
4109{
4110 wmWindow *win = CTX_wm_window(C);
4111 Main *bmain = CTX_data_main(C);
4112
4113 UI_popup_block_close(C, win, block);
4114
4115 /* Force a full refresh, but without reloading the file. */
4116 LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
4118 }
4119}
4120
4121/* Build the auto-run warning dialog UI. */
4122static uiBlock *block_create_autorun_warning(bContext *C, ARegion *region, void * /*arg1*/)
4123{
4124 const char *blendfile_path = BKE_main_blendfile_path_from_global();
4126
4127 uiBlock *block = UI_block_begin(
4128 C, region, "autorun_warning_popup", blender::ui::EmbossType::Emboss);
4133
4134 const char *title = RPT_(
4135 "For security reasons, automatic execution of Python scripts "
4136 "in this file was disabled:");
4137 const char *message = RPT_("This may lead to unexpected behavior. Allow at your own risk.");
4138
4139 /* Measure strings to find the longest. */
4140 const uiStyle *style = UI_style_get_dpi();
4141 UI_fontstyle_set(&style->widget);
4142 int text_width = int(BLF_width(style->widget.uifont_id, title, BLF_DRAW_STR_DUMMY_MAX));
4143 text_width = std::max(text_width,
4144 int(BLF_width(style->widget.uifont_id, message, BLF_DRAW_STR_DUMMY_MAX)));
4145
4146 const int dialog_width = std::max(int(500.0f * UI_SCALE_FAC),
4147 text_width + int(style->columnspace * 2.5));
4148 const short icon_size = 40 * UI_SCALE_FAC;
4149 uiLayout *layout = uiItemsAlertBox(
4150 block, style, dialog_width + icon_size, ALERT_ICON_ERROR, icon_size);
4151
4152 /* Title and explanation text. */
4153 uiLayout *col = &layout->column(true);
4154 uiItemL_ex(col, title, ICON_NONE, true, false);
4155 uiItemL_ex(col, G.autoexec_fail, ICON_NONE, false, true);
4156 col->label(message, ICON_NONE);
4157
4158 layout->separator(2.0f);
4159
4160 /* Buttons. */
4161 uiBut *but;
4162 uiLayout *split = &layout->split(0.0f, true);
4163 uiLayoutSetScaleY(split, 1.2f);
4164
4165 /* Empty space. */
4166 col = &split->column(false);
4167 col->separator();
4168
4169 col = &split->column(false);
4170
4171 /* Allow reload if we have a saved file.
4172 * Otherwise just enable scripts and reset the depsgraphs. */
4173 if ((blendfile_path[0] != '\0') && wm->file_saved) {
4174 but = uiDefIconTextBut(block,
4176 0,
4177 ICON_NONE,
4178 IFACE_("Allow Execution"),
4179 0,
4180 0,
4181 50,
4182 UI_UNIT_Y,
4183 nullptr,
4184 0,
4185 0,
4186 TIP_("Reload file with execution of Python scripts enabled"));
4188 but, [block](bContext &C) { wm_block_autorun_warning_reload_with_scripts(&C, block); });
4189 }
4190 else {
4191 but = uiDefIconTextBut(block,
4193 0,
4194 ICON_NONE,
4195 IFACE_("Allow Execution"),
4196 0,
4197 0,
4198 50,
4199 UI_UNIT_Y,
4200 nullptr,
4201 0,
4202 0,
4203 TIP_("Run potentially unsafe scripts in this blend file"));
4204 UI_but_func_set(but,
4205 [block](bContext &C) { wm_block_autorun_warning_enable_scripts(&C, block); });
4206 }
4208
4209 col = &split->column(false);
4210 but = uiDefIconTextBut(block,
4212 0,
4213 ICON_NONE,
4214 IFACE_("Continue Safely"),
4215 0,
4216 0,
4217 50,
4218 UI_UNIT_Y,
4219 nullptr,
4220 0,
4221 0,
4222 TIP_("Continue using file without Python scripts"));
4226
4228
4229 return block;
4230}
4231
4239static struct {
4241 PointerRNA *ptr;
4243
4256
4258{
4261
4262 /* Use regular revert. */
4263 if (ot == nullptr) {
4264 ot = WM_operatortype_find("WM_OT_revert_mainfile", false);
4265 ptr = MEM_new<PointerRNA>(__func__);
4267 RNA_boolean_set(ptr, "use_scripts", true);
4268
4269 /* Set state, so it's freed correctly. */
4271 }
4272
4274 wm_test_autorun_revert_action_set(nullptr, nullptr);
4275}
4276
4278{
4279 /* Test if any auto-execution of scripts failed. */
4280 if ((G.f & G_FLAG_SCRIPT_AUTOEXEC_FAIL) == 0) {
4281 return;
4282 }
4283
4284 /* Only show the warning once. */
4286 return;
4287 }
4288
4290
4292 wmWindow *win = (wm->winactive) ? wm->winactive : static_cast<wmWindow *>(wm->windows.first);
4293
4294 if (win) {
4295 /* We want this warning on the Main window, not a child window even if active. See #118765. */
4296 if (win->parent) {
4297 win = win->parent;
4298 }
4299
4300 wmWindow *prevwin = CTX_wm_window(C);
4301 CTX_wm_window_set(C, win);
4303 CTX_wm_window_set(C, prevwin);
4304 }
4305}
4306
4308
4309/* -------------------------------------------------------------------- */
4312
4313static void free_post_file_close_action(void *arg)
4314{
4315 wmGenericCallback *action = (wmGenericCallback *)arg;
4317}
4318
4319static void wm_free_operator_properties_callback(void *user_data)
4320{
4321 IDProperty *properties = (IDProperty *)user_data;
4322 IDP_FreeProperty(properties);
4323}
4324
4325static const char *save_file_overwrite_dialog_name = "save_file_overwrite_popup";
4326
4327static void file_overwrite_detailed_info_show(uiLayout *parent_layout, Main *bmain)
4328{
4329 uiLayout *layout = &parent_layout->column(true);
4330 /* Trick to make both lines of text below close enough to look like they are part of a same
4331 * block. */
4332 uiLayoutSetScaleY(layout, 0.70f);
4333
4335 char writer_ver_str[16];
4336 char current_ver_str[16];
4337 if (bmain->versionfile == BLENDER_VERSION) {
4339 writer_ver_str, sizeof(writer_ver_str), bmain->versionfile, bmain->subversionfile);
4341 current_ver_str, sizeof(current_ver_str), BLENDER_FILE_VERSION, BLENDER_FILE_SUBVERSION);
4342 }
4343 else {
4345 writer_ver_str, sizeof(writer_ver_str), bmain->versionfile, -1);
4347 current_ver_str, sizeof(current_ver_str), BLENDER_VERSION, -1);
4348 }
4349
4350 char message_line1[256];
4351 char message_line2[256];
4352 SNPRINTF(message_line1,
4353 RPT_("This file was saved by a newer version of Blender (%s)."),
4354 writer_ver_str);
4355 SNPRINTF(message_line2,
4356 RPT_("Saving it with this Blender (%s) may cause loss of data."),
4357 current_ver_str);
4358 layout->label(message_line1, ICON_NONE);
4359 layout->label(message_line2, ICON_NONE);
4360 }
4361
4362 if (bmain->is_asset_edit_file) {
4364 layout->separator(1.4f);
4365 }
4366
4367 layout->label(RPT_("This file is managed by the Blender asset system. It can only be"),
4368 ICON_NONE);
4369 layout->label(RPT_("saved as a new, regular file."), ICON_NONE);
4370 }
4371}
4372
4373static void save_file_overwrite_cancel(bContext *C, void *arg_block, void * /*arg_data*/)
4374{
4375 wmWindow *win = CTX_wm_window(C);
4376 UI_popup_block_close(C, win, static_cast<uiBlock *>(arg_block));
4377}
4378
4380{
4381 uiBut *but = uiDefIconTextBut(
4382 block, UI_BTYPE_BUT, 0, ICON_NONE, IFACE_("Cancel"), 0, 0, 0, UI_UNIT_Y, nullptr, 0, 0, "");
4383 UI_but_func_set(but, save_file_overwrite_cancel, block, post_action);
4385}
4386
4387static void save_file_overwrite_confirm(bContext *C, void *arg_block, void *arg_data)
4388{
4389 wmWindow *win = CTX_wm_window(C);
4390
4391 /* Re-use operator properties as defined for the initial "Save" operator,
4392 * which triggered this "Forward Compatibility" popup. */
4394 static_cast<wmGenericCallback *>(arg_data));
4395
4396 /* Needs to be done after stealing the callback data above, otherwise it would cause a
4397 * use-after-free. */
4398 UI_popup_block_close(C, win, static_cast<uiBlock *>(arg_block));
4399
4400 PointerRNA operator_propptr = {};
4401 PointerRNA *operator_propptr_p = &operator_propptr;
4402 IDProperty *operator_idproperties = static_cast<IDProperty *>(callback->user_data);
4403 WM_operator_properties_alloc(&operator_propptr_p, &operator_idproperties, "WM_OT_save_mainfile");
4404
4405 WM_operator_name_call(C, "WM_OT_save_mainfile", WM_OP_EXEC_DEFAULT, operator_propptr_p, nullptr);
4406
4407 WM_generic_callback_free(callback);
4408}
4409
4411{
4412 uiBut *but = uiDefIconTextBut(block,
4414 0,
4415 ICON_NONE,
4416 IFACE_("Overwrite"),
4417 0,
4418 0,
4419 0,
4420 UI_UNIT_Y,
4421 nullptr,
4422 0,
4423 0,
4424 "");
4425 UI_but_func_set(but, save_file_overwrite_confirm, block, post_action);
4428}
4429
4430static void save_file_overwrite_saveas(bContext *C, void *arg_block, void * /*arg_data*/)
4431{
4432 wmWindow *win = CTX_wm_window(C);
4433 UI_popup_block_close(C, win, static_cast<uiBlock *>(arg_block));
4434
4435 WM_operator_name_call(C, "WM_OT_save_as_mainfile", WM_OP_INVOKE_DEFAULT, nullptr, nullptr);
4436}
4437
4439{
4440 uiBut *but = uiDefIconTextBut(block,
4442 0,
4443 ICON_NONE,
4444 IFACE_("Save As..."),
4445 0,
4446 0,
4447 0,
4448 UI_UNIT_Y,
4449 nullptr,
4450 0,
4451 0,
4452 "");
4453 UI_but_func_set(but, save_file_overwrite_saveas, block, post_action);
4456}
4457
4459{
4460 wmGenericCallback *post_action = static_cast<wmGenericCallback *>(arg1);
4461 Main *bmain = CTX_data_main(C);
4462
4463 uiBlock *block = UI_block_begin(
4468
4469 uiLayout *layout = uiItemsAlertBox(block, 44, ALERT_ICON_WARNING);
4470
4471 /* Title. */
4473 if (bmain->is_asset_edit_file) {
4474 uiItemL_ex(layout,
4475 RPT_("Cannot overwrite asset system files. Save as new file"),
4476 ICON_NONE,
4477 true,
4478 false);
4479 uiItemL_ex(layout, RPT_("with an older Blender version?"), ICON_NONE, true, false);
4480 }
4481 else {
4482 uiItemL_ex(
4483 layout, RPT_("Overwrite file with an older Blender version?"), ICON_NONE, true, false);
4484 }
4485 }
4486 else if (bmain->is_asset_edit_file) {
4487 uiItemL_ex(layout,
4488 RPT_("Cannot overwrite asset system files. Save as new file?"),
4489 ICON_NONE,
4490 true,
4491 false);
4492 }
4493 else {
4495 }
4496
4497 /* Filename. */
4498 const char *blendfile_path = BKE_main_blendfile_path(CTX_data_main(C));
4499 char filename[FILE_MAX];
4500 if (blendfile_path[0] != '\0') {
4501 BLI_path_split_file_part(blendfile_path, filename, sizeof(filename));
4502 }
4503 else {
4504 SNPRINTF(filename, "%s.blend", DATA_("Untitled"));
4505 /* Since this dialog should only be shown when re-saving an existing file, current filepath
4506 * should never be empty. */
4508 }
4509 layout->label(filename, ICON_NONE);
4510
4511 /* Detailed message info. */
4512 file_overwrite_detailed_info_show(layout, bmain);
4513
4514 layout->separator(4.0f);
4515
4516 /* Buttons. */
4517
4518 uiLayout *split = &layout->split(0.3f, true);
4519 uiLayoutSetScaleY(split, 1.2f);
4520
4521 split->column(false);
4522 /* Asset files don't actually allow overriding. */
4523 const bool allow_overwrite = !bmain->is_asset_edit_file;
4524 if (allow_overwrite) {
4525 save_file_overwrite_confirm_button(block, post_action);
4526 }
4527
4528 uiLayout *split_right = &split->split(0.1f, true);
4529
4530 split_right->column(false);
4531 /* Empty space. */
4532
4533 split_right->column(false);
4534 save_file_overwrite_cancel_button(block, post_action);
4535
4536 split_right->column(false);
4537 save_file_overwrite_saveas_button(block, post_action);
4538
4540 return block;
4541}
4542
4555
4557
4558/* -------------------------------------------------------------------- */
4561
4563
4564static void wm_block_file_close_cancel(bContext *C, void *arg_block, void * /*arg_data*/)
4565{
4566 wmWindow *win = CTX_wm_window(C);
4567 UI_popup_block_close(C, win, static_cast<uiBlock *>(arg_block));
4568}
4569
4570static void wm_block_file_close_discard(bContext *C, void *arg_block, void *arg_data)
4571{
4573
4574 /* Close the popup before executing the callback. Otherwise
4575 * the popup might be closed by the callback, which will lead
4576 * to a crash. */
4577 wmWindow *win = CTX_wm_window(C);
4578 UI_popup_block_close(C, win, static_cast<uiBlock *>(arg_block));
4579
4580 callback->exec(C, callback->user_data);
4581 WM_generic_callback_free(callback);
4582}
4583
4584static void wm_block_file_close_save(bContext *C, void *arg_block, void *arg_data)
4585{
4586 const Main *bmain = CTX_data_main(C);
4587 wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
4589 bool execute_callback = true;
4590
4591 wmWindow *win = CTX_wm_window(C);
4592 UI_popup_block_close(C, win, static_cast<uiBlock *>(arg_block));
4593
4594 int modified_images_count = ED_image_save_all_modified_info(CTX_data_main(C), nullptr);
4595 if (modified_images_count > 0 && save_images_when_file_is_closed) {
4596 if (ED_image_should_save_modified(bmain)) {
4600 }
4601 else {
4602 execute_callback = false;
4603 }
4604 }
4605
4606 bool file_has_been_saved_before = BKE_main_blendfile_path(bmain)[0] != '\0';
4607
4608 if (file_has_been_saved_before) {
4610 /* Need to invoke to get the file-browser and choose where to save the new file.
4611 * This also makes it impossible to keep on going with current operation, which is why
4612 * callback cannot be executed anymore.
4613 *
4614 * This is the same situation as what happens when the file has never been saved before
4615 * (outer `else` statement, below). */
4616 WM_operator_name_call(C, "WM_OT_save_as_mainfile", WM_OP_INVOKE_DEFAULT, nullptr, nullptr);
4617 execute_callback = false;
4618 }
4619 else {
4620 if (WM_operator_name_call(C, "WM_OT_save_mainfile", WM_OP_EXEC_DEFAULT, nullptr, nullptr) &
4622 {
4623 execute_callback = false;
4624 }
4625 }
4626 }
4627 else {
4628 WM_operator_name_call(C, "WM_OT_save_mainfile", WM_OP_INVOKE_DEFAULT, nullptr, nullptr);
4629 execute_callback = false;
4630 }
4631
4632 if (execute_callback) {
4633 callback->exec(C, callback->user_data);
4634 }
4635 WM_generic_callback_free(callback);
4636}
4637
4639{
4640 uiBut *but = uiDefIconTextBut(
4641 block, UI_BTYPE_BUT, 0, ICON_NONE, IFACE_("Cancel"), 0, 0, 0, UI_UNIT_Y, nullptr, 0, 0, "");
4642 UI_but_func_set(but, wm_block_file_close_cancel, block, post_action);
4644}
4645
4647{
4648 uiBut *but = uiDefIconTextBut(block,
4650 0,
4651 ICON_NONE,
4652 IFACE_("Don't Save"),
4653 0,
4654 0,
4655 0,
4656 UI_UNIT_Y,
4657 nullptr,
4658 0,
4659 0,
4660 "");
4661 UI_but_func_set(but, wm_block_file_close_discard, block, post_action);
4663}
4664
4666 wmGenericCallback *post_action,
4667 const bool needs_overwrite_confirm)
4668{
4669 uiBut *but = uiDefIconTextBut(
4670 block,
4672 0,
4673 ICON_NONE,
4674 /* Forward compatibility issues force using 'save as' operator instead of 'save' one. */
4675 needs_overwrite_confirm ? IFACE_("Save As...") : IFACE_("Save"),
4676 0,
4677 0,
4678 0,
4679 UI_UNIT_Y,
4680 nullptr,
4681 0,
4682 0,
4683 "");
4684 UI_but_func_set(but, wm_block_file_close_save, block, post_action);
4687}
4688
4689static const char *close_file_dialog_name = "file_close_popup";
4690
4691static void save_catalogs_when_file_is_closed_set_fn(bContext * /*C*/, void *arg1, void * /*arg2*/)
4692{
4693 char *save_catalogs_when_file_is_closed = static_cast<char *>(arg1);
4695 *save_catalogs_when_file_is_closed != 0);
4696}
4697
4699{
4700 using namespace blender;
4701 wmGenericCallback *post_action = (wmGenericCallback *)arg1;
4702 Main *bmain = CTX_data_main(C);
4703
4704 uiBlock *block = UI_block_begin(
4709
4710 uiLayout *layout = uiItemsAlertBox(block, 34, ALERT_ICON_QUESTION);
4711
4712 const bool needs_overwrite_confirm = BKE_main_needs_overwrite_confirm(bmain);
4713
4714 /* Title. */
4715 uiItemL_ex(layout, RPT_("Save changes before closing?"), ICON_NONE, true, false);
4716
4717 /* Filename. */
4718 const char *blendfile_path = BKE_main_blendfile_path(CTX_data_main(C));
4719 char filename[FILE_MAX];
4720 if (blendfile_path[0] != '\0') {
4721 BLI_path_split_file_part(blendfile_path, filename, sizeof(filename));
4722 }
4723 else {
4724 SNPRINTF(filename, "%s.blend", DATA_("Untitled"));
4725 }
4726 layout->label(filename, ICON_NONE);
4727
4728 /* Potential forward compatibility issues message. */
4729 if (needs_overwrite_confirm) {
4730 file_overwrite_detailed_info_show(layout, bmain);
4731 }
4732
4733 /* Image Saving Warnings. */
4736 uint modified_images_count = ED_image_save_all_modified_info(bmain, &reports);
4737
4738 LISTBASE_FOREACH (Report *, report, &reports.list) {
4739 uiLayout *row = &layout->column(false);
4740 uiLayoutSetScaleY(row, 0.6f);
4741 row->separator();
4742
4743 /* Error messages created in ED_image_save_all_modified_info() can be long,
4744 * but are made to separate into two parts at first colon between text and paths.
4745 */
4746 char *message = BLI_strdupn(report->message, report->len);
4747 char *path_info = strstr(message, ": ");
4748 if (path_info) {
4749 /* Terminate message string at colon. */
4750 path_info[1] = '\0';
4751 /* Skip over the ": ". */
4752 path_info += 2;
4753 }
4754 uiItemL_ex(row, message, ICON_NONE, false, true);
4755 if (path_info) {
4756 uiItemL_ex(row, path_info, ICON_NONE, false, true);
4757 }
4758 MEM_freeN(message);
4759 }
4760
4761 /* Used to determine if extra separators are needed. */
4762 bool has_extra_checkboxes = false;
4763
4764 /* Modified Images Checkbox. */
4765 if (modified_images_count > 0) {
4766 char message[64];
4767 SNPRINTF(message, "Save %u modified image(s)", modified_images_count);
4768 /* Only the first checkbox should get extra separation. */
4769 if (!has_extra_checkboxes) {
4770 layout->separator();
4771 }
4772 uiDefButBitC(block,
4774 1,
4775 0,
4776 message,
4777 0,
4778 0,
4779 0,
4780 UI_UNIT_Y,
4782 0,
4783 0,
4784 "");
4785 has_extra_checkboxes = true;
4786 }
4787
4789 static char save_catalogs_when_file_is_closed;
4790
4791 save_catalogs_when_file_is_closed = ed::asset::catalogs_get_save_catalogs_when_file_is_saved();
4792
4793 /* Only the first checkbox should get extra separation. */
4794 if (!has_extra_checkboxes) {
4795 layout->separator();
4796 }
4797 uiBut *but = uiDefButBitC(block,
4799 1,
4800 0,
4801 "Save modified asset catalogs",
4802 0,
4803 0,
4804 0,
4805 UI_UNIT_Y,
4806 &save_catalogs_when_file_is_closed,
4807 0,
4808 0,
4809 "");
4810 UI_but_func_set(but,
4812 &save_catalogs_when_file_is_closed,
4813 nullptr);
4814 has_extra_checkboxes = true;
4815 }
4816
4818
4819 layout->separator(2.0f);
4820
4821 /* Buttons. */
4822#ifdef _WIN32
4823 const bool windows_layout = true;
4824#else
4825 const bool windows_layout = false;
4826#endif
4827
4828 if (windows_layout) {
4829 /* Windows standard layout. */
4830
4831 uiLayout *split = &layout->split(0.0f, true);
4832 uiLayoutSetScaleY(split, 1.2f);
4833
4834 split->column(false);
4835 wm_block_file_close_save_button(block, post_action, needs_overwrite_confirm);
4836
4837 split->column(false);
4838 wm_block_file_close_discard_button(block, post_action);
4839
4840 split->column(false);
4841 wm_block_file_close_cancel_button(block, post_action);
4842 }
4843 else {
4844 /* Non-Windows layout (macOS and Linux). */
4845
4846 uiLayout *split = &layout->split(0.3f, true);
4847 uiLayoutSetScaleY(split, 1.2f);
4848
4849 split->column(false);
4850 wm_block_file_close_discard_button(block, post_action);
4851
4852 uiLayout *split_right = &split->split(0.1f, true);
4853
4854 split_right->column(false);
4855 /* Empty space. */
4856
4857 split_right->column(false);
4858 wm_block_file_close_cancel_button(block, post_action);
4859
4860 split_right->column(false);
4861 wm_block_file_close_save_button(block, post_action, needs_overwrite_confirm);
4862 }
4863
4865 return block;
4866}
4867
4878
4880 wmOperator *op,
4881 wmGenericCallbackFn post_action_fn)
4882{
4883 if (U.uiflag & USER_SAVE_PROMPT &&
4885 {
4887 callback->exec = post_action_fn;
4888 callback->user_data = IDP_CopyProperty(op->properties);
4890 wm_close_file_dialog(C, callback);
4891 return true;
4892 }
4893
4894 return false;
4895}
4896
void AS_asset_libraries_exit()
bool AS_asset_library_has_any_unsaved_catalogs()
bool BKE_addon_remove_safe(struct ListBase *addon_list, const char *module)
Definition addon.cc:56
bool BKE_appdir_app_template_id_search(const char *app_template, char *path, size_t path_maxncpy) ATTR_NONNULL(1)
Definition appdir.cc:1078
void BKE_tempdir_init(const char *userdir)
Definition appdir.cc:1197
@ BLENDER_USER_CONFIG
#define BLENDER_USERPREF_FILE
bool BKE_appdir_app_template_has_userpref(const char *app_template) ATTR_NONNULL(1)
Definition appdir.cc:1092
#define BLENDER_HISTORY_FILE
std::optional< std::string > BKE_appdir_folder_id(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
Definition appdir.cc:717
#define BLENDER_STARTUP_FILE
#define BLENDER_QUIT_FILE
const char * BKE_tempdir_base() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition appdir.cc:1249
bool BKE_appdir_app_template_any()
Definition appdir.cc:1073
std::optional< std::string > BKE_appdir_folder_id_create(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
Definition appdir.cc:777
bool BKE_autoexec_match(const char *path)
Definition autoexec.cc:24
bool BKE_autoexec_default_trust_source(const char *filepath)
Definition autoexec.cc:55
Blender util stuff.
void BKE_blender_userdef_app_template_data_set_and_free(UserDef *userdef)
Definition blender.cc:466
void BKE_blender_userdef_data_set_and_free(UserDef *userdef)
Definition blender.cc:285
#define BLENDER_FILE_SUBVERSION
#define BLENDER_VERSION
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:153
#define BLENDER_FILE_VERSION
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)
bool BKE_blendfile_userdef_write_all(ReportList *reports)
#define BLENDER_ASSET_FILE_SUFFIX
void BKE_blendfile_read_make_empty(bContext *C)
bool BKE_blendfile_extension_check(const char *str)
Definition blendfile.cc:84
UserDef * BKE_blendfile_userdef_from_defaults()
UserDef * BKE_blendfile_userdef_read(const char *filepath, ReportList *reports)
BlendFileData * BKE_blendfile_read(const char *filepath, const BlendFileReadParams *params, BlendFileReadReport *reports)
BlendFileData * BKE_blendfile_read_from_memory(const void *file_buf, int file_buf_size, const BlendFileReadParams *params, ReportList *reports)
void BKE_callback_exec_string(Main *bmain, eCbEvent evt, const char *str)
Definition callbacks.cc:63
void BKE_callback_exec_null(Main *bmain, eCbEvent evt)
Definition callbacks.cc:38
@ BKE_CB_EVT_LOAD_FACTORY_STARTUP_POST
@ BKE_CB_EVT_LOAD_FACTORY_USERDEF_POST
@ BKE_CB_EVT_SAVE_PRE
@ BKE_CB_EVT_LOAD_POST_FAIL
@ BKE_CB_EVT_EXTENSION_REPOS_UPDATE_PRE
@ BKE_CB_EVT_VERSION_UPDATE
@ BKE_CB_EVT_SAVE_POST_FAIL
@ BKE_CB_EVT_SAVE_POST
@ BKE_CB_EVT_LOAD_POST
@ BKE_CB_EVT_LOAD_PRE
@ BKE_CB_EVT_EXTENSION_REPOS_UPDATE_POST
ReportList * CTX_wm_reports(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
bool CTX_py_init_get(bContext *C)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
void CTX_wm_window_set(bContext *C, wmWindow *win)
Main * CTX_data_main(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
wmMsgBus * CTX_wm_message_bus(const bContext *C)
void CTX_wm_region_popup_set(bContext *C, ARegion *region_popup)
@ G_BACKGROUND_NO_DEPSGRAPH
@ G_FILE_RECOVER_READ
@ G_FILE_AUTOPACK
@ G_FILE_RECOVER_WRITE
@ G_FILE_NO_UI
@ G_FILE_COMPRESS
@ G_FLAG_SCRIPT_AUTOEXEC_FAIL_QUIET
@ G_FLAG_USERPREF_NO_SAVE_ON_EXIT
@ G_FLAG_SCRIPT_AUTOEXEC_FAIL
@ G_FLAG_SCRIPT_AUTOEXEC
@ G_FLAG_INTERNET_ALLOW
#define G_FLAG_ALL_READFILE
#define G_MAIN
#define G_FLAG_INTERNET_OVERRIDE_PREF_ANY
#define G_FLAG_ALL_RUNTIME
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1243
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:873
void BKE_libblock_free_data_py(ID *id)
void BKE_libblock_free_data(ID *id, bool do_id_user) ATTR_NONNULL()
IDNewNameResult BKE_libblock_rename(Main &bmain, ID &id, blender::StringRefNull name, const IDNewNameMode mode=IDNewNameMode::RenameExistingNever)
Definition lib_id.cc:2350
void BKE_lib_override_library_main_operations_create(Main *bmain, bool force_auto, int *r_report_flags)
BlendThumbnail * BKE_main_thumbnail_from_imbuf(Main *bmain, ImBuf *img)
Definition main.cc:827
bool BKE_main_needs_overwrite_confirm(const Main *bmain)
Definition main.cc:479
#define BLEN_THUMB_SIZE
Definition BKE_main.hh:657
ImBuf * BKE_main_thumbnail_to_imbuf(Main *bmain, BlendThumbnail *data)
Definition main.cc:851
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:877
BlendThumbnail * BKE_main_thumbnail_from_buffer(Main *bmain, const uint8_t *rect, const int size[2])
Definition main.cc:805
const char * BKE_main_blendfile_path_from_global()
Definition main.cc:882
bool BKE_main_namemap_validate(Main &bmain)
#define FOREACH_NODETREE_END
Definition BKE_node.hh:866
#define FOREACH_NODETREE_BEGIN(bmain, _nodetree, _id)
Definition BKE_node.hh:856
void BKE_packedfile_pack_all(Main *bmain, ReportList *reports, bool verbose)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_reports_free(ReportList *reports)
Definition report.cc:70
void BKE_report_print_level_set(ReportList *reports, eReportType level)
Definition report.cc:238
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:126
void BKE_reports_init(ReportList *reports, int flag)
Definition report.cc:55
void BKE_scene_free_depsgraph_hash(Scene *scene)
Definition scene.cc:3322
ScrArea * BKE_screen_find_big_area(const bScreen *screen, int spacetype, short min)
Definition screen.cc:945
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:847
void BKE_sound_init(struct Main *bmain)
void BKE_undosys_stack_init_from_context(UndoStack *ustack, bContext *C)
void BKE_undosys_stack_clear(UndoStack *ustack)
void BKE_undosys_stack_init_from_main(UndoStack *ustack, Main *bmain)
UndoStack * BKE_undosys_stack_create()
void BKE_workspace_active_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace) SETTER_ATTRS
Definition workspace.cc:565
WorkSpaceLayout * BKE_workspace_layout_find_global(const Main *bmain, const bScreen *screen, WorkSpace **r_workspace) ATTR_NONNULL(1
void BLF_reset_fonts()
Definition blf.cc:83
#define BLF_DRAW_STR_DUMMY_MAX
Definition BLF_api.hh:468
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:805
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define BLI_STATIC_ASSERT(a, msg)
Definition BLI_assert.h:83
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:53
File and directory operations.
int BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:373
bool BLI_file_is_writable(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition fileops_c.cc:291
#define O_BINARY
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BLI_file_magic_is_gzip(const char header[4])
Definition fileops_c.cc:257
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
struct LinkNode * BLI_file_read_as_lines(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:576
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])
void BLI_file_free_lines(struct LinkNode *lines)
Definition storage.cc:622
bool BLI_file_magic_is_zstd(const char header[4])
Definition fileops_c.cc:264
struct stat BLI_stat_t
int BLI_access(const char *filepath, int mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_rename_overwrite(const char *from, const char *to) ATTR_NONNULL()
Definition fileops_c.cc:505
void BLI_filelist_entry_datetime_to_string(const struct stat *st, int64_t ts, bool compact, char r_time[FILELIST_DIRENTRY_TIME_LEN], char r_date[FILELIST_DIRENTRY_DATE_LEN], bool *r_is_today, bool *r_is_yesterday)
int BLI_open(const char *filepath, int oflag, int pmode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
#define FILELIST_DIRENTRY_SIZE_LEN
#define FILELIST_DIRENTRY_DATE_LEN
#define FILELIST_DIRENTRY_TIME_LEN
Wrapper for reading from various sources (e.g. raw files, compressed files, memory....
FileReader * BLI_filereader_new_zstd(FileReader *base) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
FileReader * BLI_filereader_new_file(int filedes) ATTR_WARN_UNUSED_RESULT
FileReader * BLI_filereader_new_gzip(FileReader *base) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:586
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:534
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE void BLI_listbase_clear(ListBase *lb)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:608
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:270
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
int BLI_listbase_count_at_most(const ListBase *listbase, int count_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:511
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:131
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:91
void * BLI_findstring_ptr(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:651
MINLINE int max_ii(int a, int b)
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:12
ATTR_WARN_UNUSED_RESULT const size_t num
bool BLI_path_filename_ensure(char *filepath, size_t filepath_maxncpy, const char *filename) ATTR_NONNULL(1
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void BLI_path_to_display_name(char *display_name, int display_name_maxncpy, const char *name) ATTR_NONNULL(1
#define FILE_MAXFILE
#define FILE_MAX
bool BLI_path_extension_replace(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
#define BLI_path_join(...)
void void void BLI_path_split_file_part(const char *filepath, char *file, size_t file_maxncpy) ATTR_NONNULL(1
int BLI_path_canonicalize_native(char *path, int path_maxncpy)
bool BLI_path_extension_ensure(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
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:57
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
const char * BLI_path_slash_rfind(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
#define BLI_path_cmp
void BLI_path_sequence_encode(char *path, size_t path_maxncpy, const char *head, const char *tail, unsigned short numlen, int pic)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.cc:41
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition string.cc:30
#define SNPRINTF(dst, format,...)
Definition BLI_string.h:599
int BLI_str_rstrip_digits(char *str) ATTR_NONNULL()
Definition string.cc:1022
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
unsigned int uint
unsigned short ushort
int BLI_thread_is_main(void)
Definition threads.cc:179
Platform independent time functions.
double BLI_time_now_seconds(void)
Definition time.cc:65
void BLI_timer_on_file_load(void)
Definition BLI_timer.cc:144
#define UNUSED_VARS(...)
#define STREQLEN(a, b, n)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define STREQ(a, b)
Compatibility-like things for windows.
#define S_ISDIR(x)
external readfile function prototypes.
void BLO_sanitize_experimental_features_userpref_blend(UserDef *userdef)
eBLOReadSkip
@ BLO_READ_SKIP_DATA
@ BLO_READ_SKIP_USERDEF
external writefile.cc function prototypes.
bool BLO_write_file(Main *mainvar, const char *filepath, int write_flags, const BlendFileWriteParams *params, ReportList *reports)
eBLO_WritePathRemap
@ BLO_WRITE_PATH_REMAP_NONE
@ BLO_WRITE_PATH_REMAP_ABSOLUTE
@ BLO_WRITE_PATH_REMAP_RELATIVE
#define RPT_(msgid)
bool BLT_translate_new_dataname()
#define BLT_I18NCONTEXT_ID_WORKSPACE
#define TIP_(msgid)
#define CTX_IFACE_(context, msgid)
#define CTX_DATA_(context, msgid)
#define IFACE_(msgid)
#define DATA_(msgid)
void BPY_python_reset(bContext *C)
bool BPY_run_string_eval(bContext *C, const char *imports[], const char *expr)
bool BPY_run_string_exec(bContext *C, const char *imports[], const char *expr)
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:181
#define CLOG_INFO(clg_ref, level,...)
Definition CLG_log.h:179
@ NTREE_COMPOSIT
eDrawType
@ OB_SOLID
@ R_ALPHAPREMUL
@ RGN_TYPE_WINDOW
@ FILE_SORT_DEFAULT
@ FILE_SORT_TIME
@ FILE_BLENDER
@ FILE_TYPE_BLENDER
@ FILE_TYPE_FOLDER
@ SPACE_VIEW3D
@ FILE_VERTICALDISPLAY
@ FILE_DEFAULTDISPLAY
#define UI_SCALE_FAC
@ USER_SAVE_PROMPT
@ USER_GLOBALUNDO
@ USER_RELPATHS
@ USER_INTERNET_ALLOW
@ USER_FILENOUI
@ USER_FILECOMPRESS
@ USER_SCRIPT_AUTOEXEC_DISABLE
@ USER_AUTOSAVE
@ USER_FILE_PREVIEW_NONE
@ USER_FILE_PREVIEW_CAMERA
@ USER_FILE_PREVIEW_SCREENSHOT
@ USER_FILE_PREVIEW_AUTO
@ V3D_OFSDRAW_NONE
@ V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS
@ V3D_RUNTIME_LOCAL_MAYBE_EMPTY
@ OPERATOR_CANCELLED
@ OPERATOR_INTERFACE
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
@ KEYCONF_INIT_DEFAULT
int datatoc_startup_blend_size
const char datatoc_startup_blend[]
void ED_file_read_bookmarks()
int ED_image_save_all_modified_info(const Main *bmain, ReportList *reports)
bool ED_image_should_save_modified(const Main *bmain)
bool ED_image_save_all_modified(const bContext *C, ReportList *reports)
void ED_outliner_select_sync_from_all_tag(bContext *C)
void ED_preview_restart_queue_free()
void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
WorkSpaceLayout * ED_workspace_layout_duplicate(Main *bmain, WorkSpace *workspace, const WorkSpaceLayout *layout_old, wmWindow *win) ATTR_NONNULL()
MemFile * ED_undosys_stack_memfile_get_if_active(UndoStack *ustack)
void ED_editors_exit(Main *bmain, bool do_undo_system)
Definition ed_util.cc:212
bool ED_editors_flush_edits(Main *bmain)
Definition ed_util.cc:324
void ED_editors_init(bContext *C)
Definition ed_util.cc:88
void ED_view3d_local_collections_reset(const bContext *C, bool reset_all)
ImBuf * ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph, Scene *scene, eDrawType drawtype, View3D *v3d, ARegion *region, int sizex, int sizey, eImBufFlags 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])
ImBuf * ED_view3d_draw_offscreen_imbuf_simple(Depsgraph *depsgraph, Scene *scene, View3DShading *shading_override, eDrawType drawtype, Object *camera, int width, int height, eImBufFlags imbuf_flags, eV3DOffscreenDrawFlag draw_flags, int alpha_mode, const char *viewname, GPUOffScreen *ofs, GPUViewport *viewport, char err_out[256])
GHOST C-API function and type declarations.
void GHOST_SetWindowUserData(GHOST_WindowHandle windowhandle, GHOST_TUserDataPtr user_data)
void GHOST_addToSystemRecentFiles(const char *filepath)
bool GPU_backend_type_selection_is_overridden()
bool GPU_backend_type_selection_detect()
void GPU_backend_type_selection_set_override(eGPUBackendType backend_type)
ImBuf * IMB_dupImBuf(const ImBuf *ibuf1)
ImBuf * IMB_allocFromBufferOwn(uint8_t *byte_buffer, float *float_buffer, unsigned int w, unsigned int h, unsigned int channels)
void IMB_freeImBuf(ImBuf *ibuf)
bool IMB_scale(ImBuf *ibuf, unsigned int newx, unsigned int newy, IMBScaleFilter filter, bool threaded=true)
Definition scaling.cc:777
@ IB_byte_data
void IMB_metadata_set_field(IDProperty *metadata, const char *key, const char *value)
Definition metadata.cc:68
void IMB_metadata_ensure(IDProperty **metadata)
Definition metadata.cc:23
ImBuf * IMB_thumb_create(const char *filepath, ThumbSize size, ThumbSource source, ImBuf *img)
Definition thumbs.cc:486
void IMB_thumb_delete(const char *file_or_lib_path, ThumbSize size)
Definition thumbs.cc:516
@ THB_FAIL
Definition IMB_thumbs.hh:24
@ THB_LARGE
Definition IMB_thumbs.hh:23
@ THB_SOURCE_BLEND
Definition IMB_thumbs.hh:30
#define PREVIEW_RENDER_LARGE_HEIGHT
Definition IMB_thumbs.hh:41
void MEM_CacheLimiter_set_maximum(size_t m)
Read Guarded memory(de)allocation.
@ RNA_EQ_STRICT
@ PROP_POINTER
Definition RNA_types.hh:155
@ PROP_COLLECTION
Definition RNA_types.hh:156
@ PROP_SKIP_SAVE
Definition RNA_types.hh:330
@ PROP_HIDDEN
Definition RNA_types.hh:324
#define C
Definition RandGen.cpp:29
void UI_but_func_set(uiBut *but, std::function< void(bContext &)> func)
#define UI_UNIT_Y
@ UI_BUT_REDALERT
@ UI_BUT_ACTIVE_DEFAULT
uiBut * uiDefIconTextBut(uiBlock *block, int type, int retval, int icon, blender::StringRef str, int x, int y, short width, short height, void *poin, float min, float max, std::optional< blender::StringRef > tip)
void UI_init_userdef()
void UI_block_emboss_set(uiBlock *block, blender::ui::EmbossType emboss)
@ UI_BLOCK_NUMSELECT
@ UI_BLOCK_LOOP
@ UI_BLOCK_KEEP_OPEN
@ UI_BLOCK_NO_WIN_CLIP
void UI_block_theme_style_set(uiBlock *block, char theme_style)
uiBlock * UI_block_begin(const bContext *C, ARegion *region, std::string name, blender::ui::EmbossType emboss)
@ UI_BLOCK_THEME_STYLE_POPUP
void UI_popup_block_invoke(bContext *C, uiBlockCreateFunc func, void *arg, uiFreeArgFunc arg_free)
const uiStyle * UI_style_get_dpi()
@ UI_BUT_TEXT_LEFT
void UI_popup_block_close(bContext *C, wmWindow *win, uiBlock *block)
bool UI_popup_block_name_exists(const bScreen *screen, blender::StringRef name)
uiBut * uiDefButBitC(uiBlock *block, int type, int bit, int retval, blender::StringRef str, int x, int y, short width, short height, char *poin, float min, float max, std::optional< blender::StringRef > tip)
void UI_fontstyle_set(const uiFontStyle *fs)
void UI_but_drawflag_disable(uiBut *but, int flag)
void UI_block_bounds_set_centered(uiBlock *block, int addval)
Definition interface.cc:667
void UI_block_flag_enable(uiBlock *block, int flag)
@ UI_BTYPE_BUT
@ UI_BTYPE_CHECKBOX
void UI_but_flag_enable(uiBut *but, int flag)
@ ALERT_ICON_WARNING
@ ALERT_ICON_QUESTION
@ ALERT_ICON_ERROR
@ UI_ITEM_R_TOGGLE
void uiLayoutSetActive(uiLayout *layout, bool active)
void uiLayoutSetEnabled(uiLayout *layout, bool enabled)
uiLayout * uiItemsAlertBox(uiBlock *block, const uiStyle *style, const int dialog_width, const eAlertIcon icon, const int icon_size)
void uiLayoutSetScaleY(uiLayout *layout, float scale)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
#define UI_ITEM_NONE
void uiLayoutSetPropDecorate(uiLayout *layout, bool is_sep)
uiBut * uiItemL_ex(uiLayout *layout, blender::StringRef name, int icon, bool highlight, bool redalert)
void UI_view2d_zoom_cache_reset()
Definition view2d.cc:1041
@ WM_FILESEL_FILEPATH
Definition WM_api.hh:1075
@ FILE_OPENFILE
Definition WM_api.hh:1084
@ FILE_SAVE
Definition WM_api.hh:1085
#define ND_ASSET_LIST_READING
Definition WM_types.hh:547
#define NC_WINDOW
Definition WM_types.hh:372
#define ND_FILEREAD
Definition WM_types.hh:409
#define NC_WM
Definition WM_types.hh:371
#define ND_DATACHANGED
Definition WM_types.hh:411
ReportList * reports
Definition WM_types.hh:1025
#define NC_ASSET
Definition WM_types.hh:401
@ OPTYPE_INTERNAL
Definition WM_types.hh:202
@ OPTYPE_REGISTER
Definition WM_types.hh:180
@ WM_OP_INVOKE_DEFAULT
Definition WM_types.hh:238
@ WM_OP_EXEC_DEFAULT
Definition WM_types.hh:245
#define ND_FILESAVE
Definition WM_types.hh:410
void(*)(bContext *C, void *user_data) wmGenericCallbackFn
Definition WM_types.hh:147
#define U
ATTR_WARN_UNUSED_RESULT const BMLoop * l
long long int int64_t
unsigned long long int uint64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
static int split(btDbvtNode **leaves, int count, const btVector3 &org, const btVector3 &axis)
Definition btDbvt.cpp:258
constexpr bool endswith(StringRef suffix) const
#define offsetof(t, d)
#define INT32_MAX
#define INT32_MIN
#define abs
#define printf(...)
ListBase R_engines
const int state
#define LOG(severity)
Definition log.h:32
void * MEM_mallocN(size_t len, const char *str)
Definition mallocn.cc:128
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:123
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:133
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
ccl_device_inline float len(const float2 a)
#define G(x, y, z)
void catalogs_set_save_catalogs_when_file_is_saved(bool should_save)
void pre_save_assets(Main *bmain)
void set_approximate_size_limit(int64_t limit_in_bytes)
constexpr int MAX_CHANNELS
VecBase< int32_t, 2 > int2
void ntreeCompositUpdateRLayers(bNodeTree *ntree)
return ret
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_collection_begin(PointerRNA *ptr, PropertyRNA *prop, CollectionPropertyIterator *iter)
PropertyType RNA_property_type(PropertyRNA *prop)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_collection_next(CollectionPropertyIterator *iter)
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
int RNA_int_get(PointerRNA *ptr, const char *name)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void RNA_property_collection_end(CollectionPropertyIterator *iter)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_struct_iterator_property(StructRNA *type)
const char * RNA_property_identifier(const PropertyRNA *prop)
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
bool RNA_property_equals(Main *bmain, PointerRNA *ptr_a, PointerRNA *ptr_b, PropertyRNA *prop, eRNACompareMode mode)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
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)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
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)
struct BMLoop * next
LinkNode * resynced_lib_overrides_libraries
struct BlendFileReadReport::@145061305003275047013263174170047072052332217113 duration
struct BlendFileReadReport::@216371110130101137171157037017121333002167141373 count
int resynced_lib_overrides_libraries_count
wmWindowManager * old_wm
const BlendThumbnail * thumb
eBLO_WritePathRemap remap_mode
FileReaderSeekFn seek
FileReaderCloseFn close
FileReaderReadFn read
bool is_untrusted
Definition wm_files.cc:3333
IDProperty * metadata
char filepath[1024]
Definition DNA_ID.h:507
struct LinkNode * next
void * first
ListBase scenes
Definition BKE_main.hh:245
ListBase wm
Definition BKE_main.hh:276
short subversionfile
Definition BKE_main.hh:156
bool is_asset_edit_file
Definition BKE_main.hh:171
bool has_forward_compatibility_issues
Definition BKE_main.hh:164
char filepath[1024]
Definition BKE_main.hh:155
bool recovered
Definition BKE_main.hh:178
BlendThumbnail * blen_thumb
Definition BKE_main.hh:231
ListBase libraries
Definition BKE_main.hh:246
ListBase screens
Definition BKE_main.hh:261
short versionfile
Definition BKE_main.hh:156
ListBase workspaces
Definition BKE_main.hh:284
wmOperatorStatus(*) run(bContext *C, wmOperator *op)
Definition wm_files.cc:3154
StructRNA * type
Definition RNA_types.hh:52
void * data
Definition RNA_types.hh:53
RecentFile * next
Definition WM_types.hh:1445
char * filepath
Definition WM_types.hh:1446
struct Object * camera
ListBase spacedata
UserDef_Runtime runtime
View3D_Runtime runtime
struct View3D * localvd
View3DShading shading
Wrapper for bScreen.
void label(blender::StringRef name, int icon)
uiLayout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
uiLayout & split(float percentage, bool align)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
uiFontStyle widget
short columnspace
wmGenericCallbackFn exec
Definition WM_types.hh:150
wmGenericUserDataFreeFn free_user_data
Definition WM_types.hh:152
const char * app_template_override
Definition wm_files.hh:58
unsigned int use_factory_settings_app_template_only
Definition wm_files.hh:39
const char * filepath_startup_override
Definition wm_files.hh:53
unsigned int use_factory_settings
Definition wm_files.hh:37
unsigned int is_first_time
Definition wm_files.hh:49
unsigned int use_empty_data
Definition wm_files.hh:44
unsigned int use_data
Definition wm_files.hh:29
unsigned int use_userdef
Definition wm_files.hh:31
const char * name
Definition WM_types.hh:1030
void(*) ui(bContext *C, wmOperator *op)
Definition WM_types.hh:1097
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1062
std::string(*) get_description(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1118
const char * idname
Definition WM_types.hh:1032
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1046
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1086
const char * translation_context
Definition WM_types.hh:1034
const char * description
Definition WM_types.hh:1036
PropertyRNA * prop
Definition WM_types.hh:1136
bool(*) check(bContext *C, wmOperator *op)
Definition WM_types.hh:1054
std::string(*) get_name(wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1112
StructRNA * srna
Definition WM_types.hh:1124
struct ReportList * reports
IDProperty * properties
struct uiLayout * layout
struct wmOperatorType * type
struct PointerRNA * ptr
struct wmKeyConfig * defaultconf
struct wmKeyConfig * userconf
struct wmWindow * windrawable
struct wmKeyConfig * addonconf
struct wmWindow * parent
struct wmEvent * eventstate
struct wmEvent * event_last_handled
i
Definition text_draw.cc:230
void wm_close_and_free(bContext *C, wmWindowManager *wm)
Definition wm.cc:572
void wm_clear_default_size(bContext *C)
Definition wm.cc:512
void WM_check(bContext *C)
Definition wm.cc:473
void WM_keyconfig_reload(bContext *C)
Definition wm.cc:424
void wm_add_default(Main *bmain, bContext *C)
Definition wm.cc:534
void WM_cursor_wait(bool val)
uint8_t * WM_window_pixels_read_from_frontbuffer(const wmWindowManager *wm, const wmWindow *win, int r_size[2])
Definition wm_draw.cc:1298
void WM_event_add_fileselect(bContext *C, wmOperator *op)
void wm_event_do_depsgraph(bContext *C, bool is_after_open_file)
void WM_main_add_notifier(uint type, void *reference)
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wmOperatorCallContext context, PointerRNA *properties, const wmEvent *event)
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wmOperatorCallContext context, PointerRNA *properties, const wmEvent *event)
void WM_report_banner_show(wmWindowManager *wm, wmWindow *win)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorStatus WM_operator_name_call_with_properties(bContext *C, const char *opstring, wmOperatorCallContext context, IDProperty *properties, const wmEvent *event)
void WM_event_remove_handlers(bContext *C, ListBase *handlers)
@ WM_HANDLER_TYPE_OP
@ TIMERAUTOSAVE
void WM_autosave_write(wmWindowManager *wm, Main *bmain)
Definition wm_files.cc:2338
static void free_post_file_close_action(void *arg)
Definition wm_files.cc:4313
void WM_file_autosave_init(wmWindowManager *wm)
Definition wm_files.cc:2381
bool WM_autosave_is_scheduled(wmWindowManager *wm)
Definition wm_files.cc:2333
bool WM_file_read(bContext *C, const char *filepath, const bool use_scripts_autoexec_check, ReportList *reports)
Definition wm_files.cc:1044
void wm_homefile_read(bContext *C, const wmHomeFileRead_Params *params_homefile, ReportList *reports)
Definition wm_files.cc:1581
void wm_autosave_timer_end(wmWindowManager *wm)
Definition wm_files.cc:2373
static void create_operator_state(wmOperatorType *ot, int first_state)
Definition wm_files.cc:3134
#define BKE_READ_EXOTIC_OK_BLEND
Definition wm_files.cc:552
bool wm_operator_close_file_dialog_if_needed(bContext *C, wmOperator *op, wmGenericCallbackFn post_action_fn)
Definition wm_files.cc:4879
static struct @154304145115124041002243022102034323027177041221 wm_init_state_app_template
static void wm_init_userdef(Main *bmain)
Definition wm_files.cc:509
static std::string wm_save_mainfile_get_description(bContext *, wmOperatorType *, PointerRNA *ptr)
Definition wm_files.cc:3960
static wmOperatorStatus wm_recover_last_session_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:3543
static bool wm_save_mainfile_check(bContext *, wmOperator *op)
Definition wm_files.cc:3847
static wmOperatorStatus wm_open_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:3280
static wmOperatorStatus wm_homefile_read_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:2874
static uiBlock * block_create__close_file_dialog(bContext *C, ARegion *region, void *arg1)
Definition wm_files.cc:4698
static BlendFileReadWMSetupData * wm_file_read_setup_wm_init(bContext *C, Main *bmain, const bool is_read_homefile)
Definition wm_files.cc:208
void WM_OT_read_history(wmOperatorType *ot)
Definition wm_files.cc:2853
static wmOperatorStatus wm_history_file_read_exec(bContext *, wmOperator *)
Definition wm_files.cc:2846
static void wm_open_mainfile_after_dialog_callback(bContext *C, void *user_data)
Definition wm_files.cc:3186
static bool wm_file_write_check_with_report_on_failure(Main *bmain, const char *filepath, ReportList *reports)
Definition wm_files.cc:2085
#define BKE_READ_EXOTIC_FAIL_FORMAT
Definition wm_files.cc:550
void wm_test_autorun_revert_action_set(wmOperatorType *ot, PointerRNA *ptr)
Definition wm_files.cc:4244
#define BKE_READ_EXOTIC_FAIL_OPEN
Definition wm_files.cc:551
ClearRecentInclude
Definition wm_files.cc:4017
@ CLEAR_RECENT_MISSING
Definition wm_files.cc:4017
@ CLEAR_RECENT_ALL
Definition wm_files.cc:4017
static uiBlock * block_create_autorun_warning(bContext *C, ARegion *region, void *)
Definition wm_files.cc:4122
bool wm_file_or_session_data_has_unsaved_changes(const Main *bmain, const wmWindowManager *wm)
Definition wm_files.cc:184
static ImBuf * blend_file_thumb_from_screenshot(bContext *C, BlendThumbnail **r_thumb)
Definition wm_files.cc:1869
static bool wm_file_read_opwrap(bContext *C, const char *filepath, const bool use_scripts_autoexec_check, ReportList *reports)
Definition wm_files.cc:3118
void WM_OT_save_as_mainfile(wmOperatorType *ot)
Definition wm_files.cc:3881
void WM_OT_open_mainfile(wmOperatorType *ot)
Definition wm_files.cc:3399
void WM_file_tag_modified()
Definition wm_files.cc:174
static wmOperatorStatus wm_recover_last_session_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:3531
static void wm_block_file_close_cancel_button(uiBlock *block, wmGenericCallback *post_action)
Definition wm_files.cc:4638
static RecentFile * wm_file_history_find(const char *filepath)
Definition wm_files.cc:1661
const char * WM_init_state_app_template_get()
Definition wm_files.cc:1197
void wm_file_read_report(Main *bmain, wmWindow *win)
Definition wm_files.cc:651
void wm_autosave_timer_begin(wmWindowManager *wm)
Definition wm_files.cc:2368
static void rna_struct_update_when_changed(bContext *C, Main *bmain, PointerRNA *ptr_a, PointerRNA *ptr_b)
Definition wm_files.cc:2693
void WM_OT_recover_last_session(wmOperatorType *ot)
Definition wm_files.cc:3557
static void wm_file_read_pre(bool use_data, bool)
Definition wm_files.cc:683
static wmOperatorStatus wm_open_mainfile__select_file_path_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:3207
static blender::int2 blend_file_thumb_clamp_size(const int size[2], const int limit)
Definition wm_files.cc:1852
static void wm_block_autorun_warning_enable_scripts(bContext *C, uiBlock *block)
Definition wm_files.cc:4108
static void save_file_overwrite_saveas(bContext *C, void *arg_block, void *)
Definition wm_files.cc:4430
static void wm_history_files_free()
Definition wm_files.cc:1654
static RecentFile * wm_history_file_new(const char *filepath)
Definition wm_files.cc:1640
static bool wm_revert_mainfile_poll(bContext *)
Definition wm_files.cc:3476
static void wm_read_callback_pre_wrapper(bContext *C, const char *filepath)
Definition wm_files.cc:883
static wmOperatorStatus wm_recover_auto_save_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:3605
void wm_history_file_read()
Definition wm_files.cc:1608
void wm_autosave_delete()
Definition wm_files.cc:2412
static bool wm_open_mainfile_check(bContext *, wmOperator *op)
Definition wm_files.cc:3337
static ImBuf * blend_file_thumb_from_camera(const bContext *C, Scene *scene, bScreen *screen, BlendThumbnail **r_thumb)
Definition wm_files.cc:1941
static void wm_homefile_read_after_dialog_callback(bContext *C, void *user_data)
Definition wm_files.cc:2982
static OperatorDispatchTarget wm_open_mainfile_dispatch_targets[]
Definition wm_files.cc:3268
#define USERDEF_RESTORE(member)
static void wm_userpref_read_exceptions(UserDef *userdef_curr, const UserDef *userdef_prev)
Definition wm_files.cc:2679
static wmOperatorStatus wm_open_mainfile__open(bContext *C, wmOperator *op)
Definition wm_files.cc:3239
void WM_OT_read_userpref(wmOperatorType *ot)
Definition wm_files.cc:2787
static void wm_test_autorun_revert_action_exec(bContext *C)
Definition wm_files.cc:4257
static void wm_recover_last_session_after_dialog_callback(bContext *C, void *user_data)
Definition wm_files.cc:3537
static char save_images_when_file_is_closed
Definition wm_files.cc:4562
static void save_file_overwrite_cancel_button(uiBlock *block, wmGenericCallback *post_action)
Definition wm_files.cc:4379
static void wm_block_file_close_save_button(uiBlock *block, wmGenericCallback *post_action, const bool needs_overwrite_confirm)
Definition wm_files.cc:4665
static wmOperatorStatus wm_userpref_read_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:2797
void WM_OT_save_homefile(wmOperatorType *ot)
Definition wm_files.cc:2631
void WM_OT_read_factory_userpref(wmOperatorType *ot)
Definition wm_files.cc:2826
static void wm_file_read_setup_wm_finalize(bContext *C, Main *bmain, BlendFileReadWMSetupData *wm_setup_data)
Definition wm_files.cc:429
static int get_operator_state(wmOperator *op)
Definition wm_files.cc:3142
static wmOperatorStatus wm_userpref_write_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:2648
void WM_init_state_app_template_set(const char *app_template)
Definition wm_files.cc:1185
static void save_set_compress(wmOperator *op)
Definition wm_files.cc:3657
static wmOperatorStatus wm_revert_mainfile_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:3457
void WM_OT_save_mainfile(wmOperatorType *ot)
Definition wm_files.cc:3972
void WM_OT_recover_auto_save(wmOperatorType *ot)
Definition wm_files.cc:3620
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:1208
static std::string wm_save_as_mainfile_get_description(bContext *, wmOperatorType *, PointerRNA *ptr)
Definition wm_files.cc:3870
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:317
static wmOperatorStatus wm_open_mainfile_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:3287
static wmOperatorStatus wm_read_factory_settings_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:3060
static void wm_block_file_close_discard(bContext *C, void *arg_block, void *arg_data)
Definition wm_files.cc:4570
void wm_autosave_timer(Main *bmain, wmWindowManager *wm, wmTimer *)
Definition wm_files.cc:2386
static void wm_history_file_write()
Definition wm_files.cc:1671
static void set_next_operator_state(wmOperator *op, int state)
Definition wm_files.cc:3147
void WM_file_autoexec_init(const char *filepath)
Definition wm_files.cc:636
static wmOperatorStatus wm_recover_auto_save_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:3575
void wm_homefile_read_post(bContext *C, const wmFileReadPost_Params *params_file_read_post)
Definition wm_files.cc:1588
static wmOperatorStatus wm_open_mainfile__discard_changes_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:3192
static void wm_file_read_post(bContext *C, const char *filepath, const wmFileReadPost_Params *params)
Definition wm_files.cc:717
static void wm_userpref_update_when_changed(bContext *C, Main *bmain, UserDef *userdef_prev, UserDef *userdef_curr)
Definition wm_files.cc:2727
static const char * close_file_dialog_name
Definition wm_files.cc:4689
static void wm_autosave_location(char filepath[FILE_MAX])
Definition wm_files.cc:2288
static wmOperatorStatus wm_clear_recent_files_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition wm_files.cc:4025
static std::string wm_open_mainfile_get_description(bContext *, wmOperatorType *, PointerRNA *ptr)
Definition wm_files.cc:3292
static void save_catalogs_when_file_is_closed_set_fn(bContext *, void *arg1, void *)
Definition wm_files.cc:4691
OpenTrust
Definition wm_files.cc:2473
static bool wm_open_init_use_scripts(wmOperator *op, const OpenTrust source_of_trust)
Definition wm_files.cc:2485
static wmOperatorStatus operator_state_dispatch(bContext *C, wmOperator *op, OperatorDispatchTarget *targets)
Definition wm_files.cc:3157
static void wm_filepath_default(const Main *bmain, char *filepath)
Definition wm_files.cc:3648
void WM_OT_read_factory_settings(wmOperatorType *ot)
Definition wm_files.cc:3092
static wmOperatorStatus wm_homefile_write_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:2602
static bool wm_autosave_write_try(Main *bmain, wmWindowManager *wm)
Definition wm_files.cc:2311
static int wm_read_exotic(const char *filepath)
Definition wm_files.cc:567
static void wm_block_autorun_warning_reload_with_scripts(bContext *C, uiBlock *block)
Definition wm_files.cc:4097
static wmOperatorStatus wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:3707
static void file_overwrite_detailed_info_show(uiLayout *parent_layout, Main *bmain)
Definition wm_files.cc:4327
void wm_test_autorun_warning(bContext *C)
Definition wm_files.cc:4277
static void wm_block_file_close_cancel(bContext *C, void *arg_block, void *)
Definition wm_files.cc:4564
static wmOperatorStatus wm_save_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:3918
static wmOperatorStatus wm_recover_last_session_impl(bContext *C, wmOperator *op, const bool use_scripts_autoexec_check)
Definition wm_files.cc:3513
static void wm_file_read_setup_wm_substitute_old_window(wmWindowManager *oldwm, wmWindowManager *wm, wmWindow *oldwin, wmWindow *win)
Definition wm_files.cc:271
static wmOperatorStatus wm_userpref_read_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:2744
void wm_open_init_load_ui(wmOperator *op, bool use_prefs)
Definition wm_files.cc:2462
static wmOperatorStatus wm_open_mainfile_dispatch(bContext *C, wmOperator *op)
Definition wm_files.cc:3275
static void read_factory_reset_props(wmOperatorType *ot)
Definition wm_files.cc:2439
static void wm_read_callback_post_wrapper(bContext *C, const char *filepath, const bool success)
Definition wm_files.cc:890
static wmOperatorStatus wm_homefile_read_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:2988
static void wm_clear_recent_files_ui(bContext *, wmOperator *op)
Definition wm_files.cc:4053
static void wm_block_autorun_warning_ignore(bContext *C, void *arg_block, void *)
Definition wm_files.cc:4088
static void wm_history_file_free(RecentFile *recent)
Definition wm_files.cc:1647
static void wm_autosave_timer_begin_ex(wmWindowManager *wm, double timestep)
Definition wm_files.cc:2359
static const EnumPropertyItem prop_clear_recent_types[]
Definition wm_files.cc:4019
static void save_file_overwrite_confirm_button(uiBlock *block, wmGenericCallback *post_action)
Definition wm_files.cc:4410
static void wm_open_mainfile_def_property_use_scripts(wmOperatorType *ot)
Definition wm_files.cc:3389
#define BKE_READ_EXOTIC_FAIL_PATH
Definition wm_files.cc:549
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:2120
static void file_read_reports_finalize(BlendFileReadReport *bf_reports)
Definition wm_files.cc:919
static void wm_free_operator_properties_callback(void *user_data)
Definition wm_files.cc:4319
static void wm_block_file_close_save(bContext *C, void *arg_block, void *arg_data)
Definition wm_files.cc:4584
static void save_set_filepath(bContext *C, wmOperator *op)
Definition wm_files.cc:3673
static wmOperatorStatus wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:3726
static uiBlock * block_create_save_file_overwrite_dialog(bContext *C, ARegion *region, void *arg1)
Definition wm_files.cc:4458
static void wm_file_read_setup_wm_use_new(bContext *C, Main *, BlendFileReadWMSetupData *wm_setup_data, wmWindowManager *wm)
Definition wm_files.cc:368
void WM_OT_read_homefile(wmOperatorType *ot)
Definition wm_files.cc:3016
static std::string wm_save_as_mainfile_get_name(wmOperatorType *ot, PointerRNA *ptr)
Definition wm_files.cc:3862
static wmOperatorStatus wm_homefile_write_exec(bContext *C, wmOperator *op)
Definition wm_files.cc:2536
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:1762
static void wm_block_file_close_discard_button(uiBlock *block, wmGenericCallback *post_action)
Definition wm_files.cc:4646
static void wm_open_mainfile_ui(bContext *, wmOperator *op)
Definition wm_files.cc:3368
static void wm_history_file_update()
Definition wm_files.cc:1697
bool write_crash_blend()
Definition wm_files.cc:2069
static wmOperatorStatus wm_revert_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_files.cc:3438
static void wm_gpu_backend_override_from_userdef()
Definition wm_files.cc:495
@ OPEN_MAINFILE_STATE_OPEN
Definition wm_files.cc:3181
@ OPEN_MAINFILE_STATE_DISCARD_CHANGES
Definition wm_files.cc:3179
@ OPEN_MAINFILE_STATE_SELECT_FILE_PATH
Definition wm_files.cc:3180
static struct @070120276367363255060351106017355103302360270115 wm_test_autorun_revert_action_data
void WM_OT_save_userpref(wmOperatorType *ot)
Definition wm_files.cc:2660
static void save_file_overwrite_confirm(bContext *C, void *arg_block, void *arg_data)
Definition wm_files.cc:4387
void WM_OT_clear_recent_files(wmOperatorType *ot)
Definition wm_files.cc:4064
bool WM_file_recover_last_session(bContext *C, const bool use_scripts_autoexec_check, ReportList *reports)
Definition wm_files.cc:3501
static void read_homefile_props(wmOperatorType *ot)
Definition wm_files.cc:2998
void wm_save_file_overwrite_dialog(bContext *C, wmOperator *op)
Definition wm_files.cc:4543
static const char * save_file_overwrite_dialog_name
Definition wm_files.cc:4325
static void save_file_overwrite_cancel(bContext *C, void *arg_block, void *)
Definition wm_files.cc:4373
static wmOperatorStatus wm_clear_recent_files_exec(bContext *, wmOperator *op)
Definition wm_files.cc:4033
static void save_file_overwrite_saveas_button(uiBlock *block, wmGenericCallback *post_action)
Definition wm_files.cc:4438
void WM_OT_revert_mainfile(wmOperatorType *ot)
Definition wm_files.cc:3482
void wm_close_file_dialog(bContext *C, wmGenericCallback *post_action)
Definition wm_files.cc:4868
void WM_reinit_gizmomap_all(Main *bmain)
void WM_init_splash(bContext *C)
void wm_exit_schedule_delayed(const bContext *C)
void WM_jobs_kill_all(wmWindowManager *wm)
Definition wm_jobs.cc:577
void WM_keyconfig_update(wmWindowManager *wm)
void WM_msgbus_destroy(wmMsgBus *mbus)
@ WM_MSG_STATICTYPE_FILE_READ
void WM_msg_publish_static(wmMsgBus *mbus, int event)
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)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void WM_operatortype_last_properties_clear_all()
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)
wmOperatorStatus WM_operator_confirm(bContext *C, wmOperator *op, const wmEvent *)
void WM_operator_properties_alloc(PointerRNA **ptr, IDProperty **properties, const char *opstring)
void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, int icon, bool cancel_default)
void WM_operator_properties_free(PointerRNA *ptr)
void WM_toolsystem_init(const bContext *C)
void WM_generic_callback_free(wmGenericCallback *callback)
Definition wm_utils.cc:20
wmGenericCallback * WM_generic_callback_steal(wmGenericCallback *callback)
Definition wm_utils.cc:30
void WM_init_input_devices()
WorkSpaceLayout * WM_window_get_active_layout(const wmWindow *win)
void wm_window_close(bContext *C, wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:437
void WM_window_set_active_screen(wmWindow *win, WorkSpace *workspace, bScreen *screen)
void wm_window_ghostwindows_remove_invalid(bContext *C, wmWindowManager *wm)
void wm_window_clear_drawable(wmWindowManager *wm)
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const wmEventType event_type, const double time_step)
void wm_window_make_drawable(wmWindowManager *wm, wmWindow *win)
bool WM_window_is_temp_screen(const wmWindow *win)
void WM_window_set_active_layout(wmWindow *win, WorkSpace *workspace, WorkSpaceLayout *layout)
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
bScreen * WM_window_get_active_screen(const wmWindow *win)