Blender V5.3
wm_files.cc File Reference
#include <cerrno>
#include <cstddef>
#include <cstring>
#include <fcntl.h>
#include <fmt/format.h>
#include "MEM_CacheLimiterC-Api.h"
#include "MEM_guardedalloc.h"
#include "BLI_fileops.hh"
#include "BLI_filereader.hh"
#include "BLI_linklist.hh"
#include "BLI_listbase.hh"
#include "BLI_math_base_c.hh"
#include "BLI_math_time.hh"
#include "BLI_memory_cache.hh"
#include "BLI_path_utils.hh"
#include "BLI_string.hh"
#include "BLI_string_utf8.hh"
#include "BLI_system.hh"
#include "BLI_threads.hh"
#include "BLI_time.hh"
#include "BLI_timer.hh"
#include "BLI_utildefines.hh"
#include "BLO_core_blend_header.hh"
#include "BLO_core_file_reader.hh"
#include "BLO_readfile.hh"
#include "BLT_date_string.hh"
#include "BLT_lang.hh"
#include "BLT_translation.hh"
#include "BLF_api.hh"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_userdef_types.h"
#include "DNA_windowmanager_types.h"
#include "DNA_workspace_types.h"
#include "AS_asset_library.hh"
#include "BKE_addon.h"
#include "BKE_appdir.hh"
#include "BKE_autoexec.hh"
#include "BKE_blender.hh"
#include "BKE_blender_project.hh"
#include "BKE_blender_version.h"
#include "BKE_blendfile.hh"
#include "BKE_callbacks.hh"
#include "BKE_context.hh"
#include "BKE_global.hh"
#include "BKE_idprop.hh"
#include "BKE_lib_id.hh"
#include "BKE_lib_override.hh"
#include "BKE_lib_remap.hh"
#include "BKE_library.hh"
#include "BKE_main.hh"
#include "BKE_main_namemap.hh"
#include "BKE_node.hh"
#include "BKE_node_tree_update.hh"
#include "BKE_packedFile.hh"
#include "BKE_report.hh"
#include "BKE_scene.hh"
#include "BKE_screen.hh"
#include "BKE_sound.hh"
#include "BKE_undo_system.hh"
#include "BKE_workspace.hh"
#include "BLO_writefile.hh"
#include "RNA_access.hh"
#include "RNA_define.hh"
#include "IMB_colormanagement.hh"
#include "IMB_imbuf.hh"
#include "IMB_imbuf_types.hh"
#include "IMB_metadata.hh"
#include "IMB_thumbs.hh"
#include "ED_asset.hh"
#include "ED_datafiles.h"
#include "ED_fileselect.hh"
#include "ED_image.hh"
#include "ED_outliner.hh"
#include "ED_render.hh"
#include "ED_screen.hh"
#include "ED_undo.hh"
#include "ED_util.hh"
#include "ED_view3d.hh"
#include "ED_view3d_offscreen.hh"
#include "NOD_composite.hh"
#include "GHOST_ISystemPaths.hh"
#include "GHOST_IWindow.hh"
#include "GPU_context.hh"
#include "SEQ_sequencer.hh"
#include "UI_interface.hh"
#include "UI_interface_layout.hh"
#include "UI_resources.hh"
#include "UI_view2d.hh"
#include "RE_engine.h"
#include "DEG_depsgraph.hh"
#include "WM_api.hh"
#include "WM_keymap.hh"
#include "WM_message.hh"
#include "WM_toolsystem.hh"
#include "WM_types.hh"
#include "wm.hh"
#include "wm_event_system.hh"
#include "wm_files.hh"
#include "wm_window.hh"
#include "CLG_log.h"

Go to the source code of this file.

Classes

struct  blender::wmFileReadPost_Params
struct  blender::OperatorDispatchTarget
struct  blender::FileRuntime

Namespaces

namespace  blender
 BMesh Iterators.

Macros

#define USE_THUMBNAIL_FAST_DOWNSCALE
#define USERDEF_RESTORE(member)

Functions

static void blender::wm_history_file_update ()
static void blender::wm_history_file_write ()
Blend-File History API
static RecentFile * blender::wm_file_history_find (const char *filepath)
static void blender::wm_history_file_free (RecentFile *recent)
static void blender::wm_history_files_free ()
void blender::wm_history_file_read ()
static RecentFile * blender::wm_history_file_new (const char *filepath)
Misc Utility Functions
void blender::WM_file_tag_modified ()
bool blender::wm_file_or_session_data_has_unsaved_changes (const Main *bmain, const wmWindowManager *wm)
Window Matching for File Reading
static BlendFileReadWMSetupData * blender::wm_file_read_setup_wm_init (bContext *C, Main *bmain, const bool is_read_homefile)
static void blender::wm_file_read_setup_wm_substitute_old_window (wmWindowManager *oldwm, wmWindowManager *wm, wmWindow *oldwin, wmWindow *win)
static void blender::wm_file_read_setup_wm_keep_old (const bContext *C, Main *bmain, BlendFileReadWMSetupData *wm_setup_data, wmWindowManager *wm, const bool load_ui)
static void blender::wm_file_read_setup_wm_use_new (bContext *C, Main *, BlendFileReadWMSetupData *wm_setup_data, wmWindowManager *wm)
static void blender::wm_file_read_setup_wm_finalize (bContext *C, Main *bmain, BlendFileReadWMSetupData *wm_setup_data)
Read Exotic File Formats

Currently only supports .blend files, we could support registering other file formats and their loaders.

static int blender::wm_read_exotic (const char *filepath)
Read Blend-File Shared Utilities
void blender::WM_file_autoexec_init (const char *filepath)
void blender::wm_file_read_report (Main *bmain, wmWindow *win)
static void blender::wm_file_read_pre (bool use_data, bool)
static void blender::wm_file_read_post (bContext *C, const char *filepath, const wmFileReadPost_Params *params)
static void blender::wm_read_callback_pre_wrapper (bContext *C, const char *filepath)
static void blender::wm_read_callback_post_wrapper (bContext *C, const char *filepath, const bool success)
Read Startup & Preferences Blend-File API
void blender::wm_homefile_read_ex (bContext *C, const wmHomeFileRead_Params *params_homefile, ReportList *reports, wmFileReadPost_Params **r_params_file_read_post)
void blender::wm_homefile_read (bContext *C, const wmHomeFileRead_Params *params_homefile, ReportList *reports)
void blender::wm_homefile_read_post (bContext *C, const wmFileReadPost_Params *params_file_read_post)
Recent Project Files
static std::optional< std::string > blender::wm_project_root_path_get (const Main *bmain)
static std::string blender::wm_recent_filepath_get (const Main *bmain)
Thumbnail Generation: Screen-Shot / Camera View

Thumbnail Sizes

  • PREVIEW_RENDER_LARGE_HEIGHT * 2 is used to render a large thumbnail, giving some over-sampling when scaled down:
  • There are two outputs for this thumbnail:
    • An image is saved to the thumbnail cache, sized at PREVIEW_RENDER_LARGE_HEIGHT.
    • A smaller thumbnail is stored in the .blend file itself, sized at BLEN_THUMB_SIZE. The size is kept small to prevent thumbnails bloating the size of .blend files.

      The thumbnail will be extracted if the file is shared or the local thumbnail cache is cleared. see: blendthumb_extract.cc for logic that extracts the thumbnail.

static uint8_t * blender::blend_file_thumb_fast_downscale (const uint8_t *src_rect, const int src_size[2], const int dst_size[2])
static int2 blender::blend_file_thumb_clamp_size (const int size[2], const int limit)
static ImBuf * blender::blend_file_thumb_from_screenshot (bContext *C, BlendThumbnail **r_thumb)
static ImBuf * blender::blend_file_thumb_from_camera (const bContext *C, Scene *scene, bScreen *screen, BlendThumbnail **r_thumb)
Write Main Blend-File (internal)
bool blender::write_crash_blend ()
static bool blender::wm_file_write_check_with_report_on_failure (Main *bmain, const char *filepath, ReportList *reports)
static bool blender::wm_file_write (bContext *C, const char *filepath, int fileflags, eBLO_WritePathRemap remap_mode, bool use_save_as_copy, ReportList *reports)
Auto-Save API
static void blender::wm_autosave_location (char filepath[FILE_MAX])
static bool blender::wm_autosave_write_try (Main *bmain, wmWindowManager *wm)
bool blender::WM_autosave_is_scheduled (wmWindowManager *wm)
bool blender::WM_autosave_write (wmWindowManager *wm, Main *bmain, ReportList *reports)
static void blender::wm_autosave_timer_begin_ex (wmWindowManager *wm, double timestep)
void blender::wm_autosave_timer_begin (wmWindowManager *wm)
void blender::wm_autosave_timer_end (wmWindowManager *wm)
void blender::WM_file_autosave_init (wmWindowManager *wm)
void blender::wm_autosave_timer (Main *bmain, wmWindowManager *wm, wmTimer *)
void blender::wm_autosave_delete ()
static wmOperatorStatus blender::wm_save_auto_save_exec (bContext *C, wmOperator *op)
void blender::WM_OT_save_auto_save (wmOperatorType *ot)
Shared Operator Properties
static void blender::read_factory_reset_props (wmOperatorType *ot)
Startup File Save Operator
static wmOperatorStatus blender::wm_homefile_write_exec (bContext *C, wmOperator *op)
static wmOperatorStatus blender::wm_homefile_write_invoke (bContext *C, wmOperator *op, const wmEvent *)
void blender::WM_OT_save_homefile (wmOperatorType *ot)
Write Preferences Operator
static wmOperatorStatus blender::wm_userpref_write_exec (bContext *C, wmOperator *op)
void blender::WM_OT_save_userpref (wmOperatorType *ot)
Read Preferences Operator
static void blender::wm_userpref_read_exceptions (UserDef *userdef_curr, const UserDef *userdef_prev)
static void blender::rna_struct_update_when_changed (bContext *C, Main *bmain, PointerRNA *ptr_a, PointerRNA *ptr_b)
static void blender::wm_userpref_update_when_changed (bContext *C, Main *bmain, UserDef *userdef_prev, UserDef *userdef_curr)
static wmOperatorStatus blender::wm_userpref_read_exec (bContext *C, wmOperator *op)
static wmOperatorStatus blender::wm_userpref_revert_invoke (bContext *C, wmOperator *op, const wmEvent *)
void blender::WM_OT_read_userpref (wmOperatorType *ot)
static wmOperatorStatus blender::wm_userpref_read_invoke (bContext *C, wmOperator *op, const wmEvent *)
void blender::WM_OT_read_factory_userpref (wmOperatorType *ot)
Read File History Operator
static wmOperatorStatus blender::wm_history_file_read_exec (bContext *, wmOperator *)
void blender::WM_OT_read_history (wmOperatorType *ot)
Read Startup & Preferences Operator
static wmOperatorStatus blender::wm_homefile_read_exec (bContext *C, wmOperator *op)
static void blender::wm_homefile_read_after_dialog_callback (bContext *C, void *user_data)
static wmOperatorStatus blender::wm_homefile_read_invoke (bContext *C, wmOperator *op, const wmEvent *)
static void blender::read_homefile_props (wmOperatorType *ot)
void blender::WM_OT_read_homefile (wmOperatorType *ot)
static wmOperatorStatus blender::wm_read_factory_settings_invoke (bContext *C, wmOperator *op, const wmEvent *)
void blender::WM_OT_read_factory_settings (wmOperatorType *ot)
Open Main .blend File Utilities
static bool blender::wm_file_read_opwrap (bContext *C, const char *filepath, const bool use_scripts_autoexec_check, ReportList *reports)
static void blender::create_operator_state (wmOperatorType *ot, int first_state)
static int blender::get_operator_state (wmOperator *op)
static void blender::set_next_operator_state (wmOperator *op, int state)
static wmOperatorStatus blender::operator_state_dispatch (bContext *C, wmOperator *op, OperatorDispatchTarget *targets)
Reload (revert) Main .blend File Operator
static wmOperatorStatus blender::wm_revert_mainfile_invoke (bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus blender::wm_revert_mainfile_exec (bContext *C, wmOperator *op)
static bool blender::wm_revert_mainfile_poll (bContext *)
void blender::WM_OT_revert_mainfile (wmOperatorType *ot)
Recover Last Session Operator
bool blender::WM_file_recover_last_session (bContext *C, const bool use_scripts_autoexec_check, ReportList *reports)
static wmOperatorStatus blender::wm_recover_last_session_impl (bContext *C, wmOperator *op, const bool use_scripts_autoexec_check)
static wmOperatorStatus blender::wm_recover_last_session_exec (bContext *C, wmOperator *op)
static void blender::wm_recover_last_session_after_dialog_callback (bContext *C, void *user_data)
static wmOperatorStatus blender::wm_recover_last_session_invoke (bContext *C, wmOperator *op, const wmEvent *)
void blender::WM_OT_recover_last_session (wmOperatorType *ot)
Auto-Save Main .blend File Operator
static wmOperatorStatus blender::wm_recover_auto_save_exec (bContext *C, wmOperator *op)
static wmOperatorStatus blender::wm_recover_auto_save_invoke (bContext *C, wmOperator *op, const wmEvent *)
void blender::WM_OT_recover_auto_save (wmOperatorType *ot)
Popup Shared Utilities
static void blender::popup_block_wm_generic_callback_free (void *arg)
static void blender::wm_generic_callback_free_user_data_idproperties (void *user_data)
Save Main .blend File Operator
static void blender::wm_filepath_default (const Main *bmain, char *filepath)
static void blender::save_set_compress (wmOperator *op)
static void blender::save_set_filepath (bContext *C, wmOperator *op)
static wmOperatorStatus blender::wm_save_as_mainfile_invoke (bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus blender::wm_save_as_mainfile_exec (bContext *C, wmOperator *op)
static bool blender::wm_save_mainfile_check (bContext *, wmOperator *op)
static std::string blender::wm_save_as_mainfile_get_name (wmOperatorType *ot, PointerRNA *ptr)
static std::string blender::wm_save_as_mainfile_get_description (bContext *, wmOperatorType *, PointerRNA *ptr)
void blender::WM_OT_save_as_mainfile (wmOperatorType *ot)
static wmOperatorStatus blender::wm_save_mainfile_invoke (bContext *C, wmOperator *op, const wmEvent *)
static std::string blender::wm_save_mainfile_get_description (bContext *, wmOperatorType *, PointerRNA *ptr)
void blender::WM_OT_save_mainfile (wmOperatorType *ot)

Variables

static CLG_LogRef blender::LOG = {"blend"}

Preferences Initialization & Versioning

#define BKE_READ_EXOTIC_FAIL_PATH   -3
#define BKE_READ_EXOTIC_FAIL_FORMAT   -2
#define BKE_READ_EXOTIC_FAIL_OPEN   -1
#define BKE_READ_EXOTIC_OK_BLEND   0
static void blender::wm_gpu_backend_override_from_userdef ()
static void blender::wm_init_userdef (Main *bmain)

Initialize <tt>WM_OT_open_*</tt> Properties

Check if load_ui was set by the caller. Fall back to user preference when file flags not specified.

enum class  blender::OpenTrust { blender::FilePath , blender::CurrentSession , blender::Recover }
void blender::wm_open_init_load_ui (wmOperator *op, bool use_prefs)
static bool blender::wm_open_init_use_scripts (wmOperator *op, const OpenTrust source_of_trust)

Open Main .blend File Operator

enum  { blender::OPEN_MAINFILE_STATE_DISCARD_CHANGES , blender::OPEN_MAINFILE_STATE_SELECT_FILE_PATH , blender::OPEN_MAINFILE_STATE_OPEN }
static OperatorDispatchTarget blender::wm_open_mainfile_dispatch_targets []
static wmOperatorStatus blender::wm_open_mainfile_dispatch (bContext *C, wmOperator *op)
static void blender::wm_open_mainfile_after_dialog_callback (bContext *C, void *user_data)
static wmOperatorStatus blender::wm_open_mainfile__discard_changes_exec (bContext *C, wmOperator *op)
static wmOperatorStatus blender::wm_open_mainfile__select_file_path_exec (bContext *C, wmOperator *op)
static wmOperatorStatus blender::wm_open_mainfile__open (bContext *C, wmOperator *op)
static wmOperatorStatus blender::wm_open_mainfile_invoke (bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus blender::wm_open_mainfile_exec (bContext *C, wmOperator *op)
static std::string blender::wm_open_mainfile_get_description (bContext *, wmOperatorType *, PointerRNA *ptr)
 blender::BLI_STATIC_ASSERT (sizeof(FileRuntime)<=sizeof(void *), "Struct must not exceed pointer size")
static bool blender::wm_open_mainfile_check (bContext *, wmOperator *op)
static void blender::wm_open_mainfile_ui (bContext *, wmOperator *op)
static void blender::wm_open_mainfile_def_property_use_scripts (wmOperatorType *ot)
void blender::WM_OT_open_mainfile (wmOperatorType *ot)

Clear Recent Files/Projects List Operators

enum  blender::ClearRecentInclude { blender::CLEAR_RECENT_ALL , blender::CLEAR_RECENT_MISSING }
static const EnumPropertyItem blender::prop_clear_recent_types []
static wmOperatorStatus blender::wm_clear_recent_files_invoke (bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus blender::wm_clear_recent_files_exec (bContext *, wmOperator *op)
static void blender::wm_clear_recent_files_ui (bContext *, wmOperator *op)
void blender::WM_OT_clear_recent_files (wmOperatorType *ot)
static wmOperatorStatus blender::wm_clear_recent_projects_invoke (bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus blender::wm_clear_recent_projects_exec (bContext *, wmOperator *op)
void blender::WM_OT_clear_recent_projects (wmOperatorType *ot)

Read Main Blend-File API

static struct  blender::wm_init_state_app_template = {{0}}
static void blender::file_read_reports_finalize (BlendFileReadReport *bf_reports)
bool blender::WM_file_read (bContext *C, const char *filepath, const bool use_scripts_autoexec_check, ReportList *reports)
bool blender::WM_file_read_project (bContext *C, const char *filepath, ReportList *reports)
void blender::WM_init_state_app_template_set (const char *app_template)
const char * blender::WM_init_state_app_template_get ()

Save Modified Images Dialog

static const char * blender::save_modified_images_dialog_name = "save_modified_images_popup"
static bool blender::wm_show_save_modified_images_dialog (const Main *bmain, wmOperator *op)
static void blender::wm_block_save_modified_images_cancel (bContext *C, void *arg_block, void *)
static void blender::wm_block_save_modified_images_save (bContext *C, void *arg_block, void *arg_data)
static void blender::wm_block_save_modified_images_cancel_button (ui::Block *block, wmGenericCallback *post_action)
static void blender::wm_block_save_modified_images_save_button (ui::Block *block, wmGenericCallback *post_action)
static void blender::wm_block_image_save_errors (ui::Layout &layout, ReportList &reports)
static ui::Block * blender::block_create_save_modified_images_dialog (bContext *C, ARegion *region, void *arg)
static void blender::wm_save_modified_images_dialog (bContext *C, wmGenericCallback *post_action)
static void blender::wm_operator_save_modified_images_dialog (bContext *C, wmOperator *op, wmGenericCallbackFn post_action_fn)

Auto Script Execution Warning Dialog

static struct  blender::wm_test_autorun_revert_action_data = {nullptr, nullptr}
static void blender::wm_test_autorun_revert_action_exec (bContext *C)
static void blender::wm_block_autorun_warning_ignore (bContext *C, ui::Block *block)
static void blender::wm_block_autorun_warning_reload_with_scripts (bContext *C, ui::Block *block)
static void blender::wm_block_autorun_warning_enable_scripts (bContext *C, ui::Block *block)
static ui::Block * blender::block_create_autorun_warning (bContext *C, ARegion *region, void *)
void blender::wm_test_autorun_revert_action_set (wmOperatorType *ot, PointerRNA *ptr)
void blender::wm_test_autorun_warning (bContext *C)
void blender::wm_test_foreign_file_warning (bContext *C)

Save File Forward Compatibility Dialog

static const char * blender::save_file_overwrite_dialog_name = "save_file_overwrite_popup"
static void blender::file_overwrite_detailed_info_show (ui::Layout &parent_layout, Main *bmain)
static void blender::save_file_overwrite_cancel (bContext *C, void *arg_block, void *)
static void blender::save_file_overwrite_cancel_button (ui::Block *block, wmGenericCallback *post_action)
static void blender::save_file_overwrite_confirm (bContext *C, void *arg_block, void *arg_data)
static void blender::save_file_overwrite_confirm_button (ui::Block *block, wmGenericCallback *post_action)
static void blender::save_file_overwrite_saveas (bContext *C, void *arg_block, void *)
static void blender::save_file_overwrite_saveas_button (ui::Block *block, wmGenericCallback *post_action)
static ui::Block * blender::block_create_save_file_overwrite_dialog (bContext *C, ARegion *region, void *arg1)
void blender::wm_save_file_overwrite_dialog (bContext *C, wmOperator *op)

Close File Dialog

static char blender::save_images_when_file_is_closed = true
static const char * blender::close_file_dialog_name = "file_close_popup"
static void blender::wm_block_file_close_cancel (bContext *C, void *arg_block, void *)
static void blender::wm_block_file_close_discard (bContext *C, void *arg_block, void *arg_data)
static void blender::wm_block_file_close_save (bContext *C, void *arg_block, void *arg_data)
static void blender::wm_block_file_close_cancel_button (ui::Block *block, wmGenericCallback *post_action)
static void blender::wm_block_file_close_discard_button (ui::Block *block, wmGenericCallback *post_action)
static void blender::wm_block_file_close_save_button (ui::Block *block, wmGenericCallback *post_action, const bool needs_overwrite_confirm)
static void blender::save_catalogs_when_file_is_closed_set_fn (bContext *, void *arg1, void *)
static ui::Block * blender::block_create__close_file_dialog (bContext *C, ARegion *region, void *arg1)
void blender::wm_close_file_dialog (bContext *C, wmGenericCallback *post_action)
bool blender::wm_operator_close_file_dialog_if_needed (bContext *C, wmOperator *op, wmGenericCallbackFn post_action_fn)

Detailed Description

User level access for blend file read/write, file-history and user-preferences (including relevant operators).

Definition in file wm_files.cc.

Macro Definition Documentation

◆ BKE_READ_EXOTIC_FAIL_FORMAT

#define BKE_READ_EXOTIC_FAIL_FORMAT   -2

Definition at line 569 of file wm_files.cc.

Referenced by blender::WM_file_read(), and blender::wm_read_exotic().

◆ BKE_READ_EXOTIC_FAIL_OPEN

#define BKE_READ_EXOTIC_FAIL_OPEN   -1

Definition at line 570 of file wm_files.cc.

Referenced by blender::WM_file_read(), and blender::wm_read_exotic().

◆ BKE_READ_EXOTIC_FAIL_PATH

#define BKE_READ_EXOTIC_FAIL_PATH   -3

Definition at line 568 of file wm_files.cc.

Referenced by blender::WM_file_read(), and blender::wm_read_exotic().

◆ BKE_READ_EXOTIC_OK_BLEND

#define BKE_READ_EXOTIC_OK_BLEND   0

Definition at line 571 of file wm_files.cc.

Referenced by blender::WM_file_read(), and blender::wm_read_exotic().

◆ USE_THUMBNAIL_FAST_DOWNSCALE

#define USE_THUMBNAIL_FAST_DOWNSCALE

Fast-path for down-scaling byte buffers.

NOTE(@ideasman42) Support alternate logic for scaling byte buffers for thumbnails which doesn't use the higher quality box-filtered floating point math. This may be removed if similar performance can be achieved from other scale methods, especially in debug mode - which could cause file saving to be unreasonably slow (taking seconds just down-scaling the thumbnail).

Definition at line 182 of file wm_files.cc.

◆ USERDEF_RESTORE

#define USERDEF_RESTORE ( member)
Value:
{ \
userdef_curr->member = userdef_prev->member; \
} \
((void)0)

Referenced by blender::wm_userpref_read_exceptions().