Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_files.c
| Show First 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | |||||
| #include "RE_engine.h" | #include "RE_engine.h" | ||||
| #ifdef WITH_PYTHON | #ifdef WITH_PYTHON | ||||
| #include "BPY_extern.h" | #include "BPY_extern.h" | ||||
| #endif | #endif | ||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "CLG_log.h" | |||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "WM_message.h" | #include "WM_message.h" | ||||
| #include "WM_toolsystem.h" | #include "WM_toolsystem.h" | ||||
| #include "wm.h" | #include "wm.h" | ||||
| #include "wm_files.h" | #include "wm_files.h" | ||||
| #include "wm_window.h" | #include "wm_window.h" | ||||
| #include "wm_event_system.h" | #include "wm_event_system.h" | ||||
| static CLG_LogRef LOG = {"wm.files"}; | |||||
| static RecentFile *wm_file_history_find(const char *filepath); | static RecentFile *wm_file_history_find(const char *filepath); | ||||
| static void wm_history_file_free(RecentFile *recent); | static void wm_history_file_free(RecentFile *recent); | ||||
| static void wm_history_file_update(void); | static void wm_history_file_update(void); | ||||
| static void wm_history_file_write(void); | static void wm_history_file_write(void); | ||||
| /* To be able to read files without windows closing, opening, moving | /* To be able to read files without windows closing, opening, moving | ||||
| * we try to prepare for worst case: | * we try to prepare for worst case: | ||||
| * - active window gets active screen from file | * - active window gets active screen from file | ||||
| * - restoring the screens from non-active windows | * - restoring the screens from non-active windows | ||||
| * Best case is all screens match, in that case they get assigned to proper window | * Best case is all screens match, in that case they get assigned to proper window | ||||
| */ | */ | ||||
| static void wm_window_match_init(bContext *C, ListBase *wmlist) | static void wm_window_match_init(bContext *C, ListBase *wmlist) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 664 Lines • ▼ Show 20 Lines | void wm_homefile_read( | ||||
| if (use_userdef) { | if (use_userdef) { | ||||
| if (!use_factory_settings && BLI_exists(filepath_userdef)) { | if (!use_factory_settings && BLI_exists(filepath_userdef)) { | ||||
| UserDef *userdef = BKE_blendfile_userdef_read(filepath_userdef, NULL); | UserDef *userdef = BKE_blendfile_userdef_read(filepath_userdef, NULL); | ||||
| if (userdef != NULL) { | if (userdef != NULL) { | ||||
| BKE_blender_userdef_data_set_and_free(userdef); | BKE_blender_userdef_data_set_and_free(userdef); | ||||
| userdef = NULL; | userdef = NULL; | ||||
| skip_flags |= BLO_READ_SKIP_USERDEF; | skip_flags |= BLO_READ_SKIP_USERDEF; | ||||
| printf("Read prefs: %s\n", filepath_userdef); | CLOG_INFO(&LOG, 1, "Read prefs: %s", filepath_userdef); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| const char *app_template = NULL; | const char *app_template = NULL; | ||||
| bool update_defaults = false; | bool update_defaults = false; | ||||
| bool reset_app_template = false; | bool reset_app_template = false; | ||||
| ▲ Show 20 Lines • Show All 366 Lines • ▼ Show 20 Lines | if (ibuf) { | ||||
| /* add pretty overlay */ | /* add pretty overlay */ | ||||
| IMB_thumb_overlay_blend(ibuf->rect, ibuf->x, ibuf->y, aspect); | IMB_thumb_overlay_blend(ibuf->rect, ibuf->x, ibuf->y, aspect); | ||||
| thumb = BKE_main_thumbnail_from_imbuf(NULL, ibuf); | thumb = BKE_main_thumbnail_from_imbuf(NULL, ibuf); | ||||
| } | } | ||||
| else { | else { | ||||
| /* '*thumb_pt' needs to stay NULL to prevent a bad thumbnail from being handled */ | /* '*thumb_pt' needs to stay NULL to prevent a bad thumbnail from being handled */ | ||||
| fprintf(stderr, "blend_file_thumb failed to create thumbnail: %s\n", err_out); | CLOG_ERROR(&LOG, "blend_file_thumb failed to create thumbnail: %s", err_out); | ||||
| thumb = NULL; | thumb = NULL; | ||||
| } | } | ||||
| /* must be freed by caller */ | /* must be freed by caller */ | ||||
| *thumb_pt = thumb; | *thumb_pt = thumb; | ||||
| return ibuf; | return ibuf; | ||||
| } | } | ||||
| /* easy access from gdb */ | /* easy access from gdb */ | ||||
| bool write_crash_blend(void) | bool write_crash_blend(void) | ||||
| { | { | ||||
| char path[FILE_MAX]; | char path[FILE_MAX]; | ||||
| int fileflags = G.fileflags & ~(G_FILE_HISTORY); /* don't do file history on crash file */ | int fileflags = G.fileflags & ~(G_FILE_HISTORY); /* don't do file history on crash file */ | ||||
| BLI_strncpy(path, BKE_main_blendfile_path_from_global(), sizeof(path)); | BLI_strncpy(path, BKE_main_blendfile_path_from_global(), sizeof(path)); | ||||
| BLI_path_extension_replace(path, sizeof(path), "_crash.blend"); | BLI_path_extension_replace(path, sizeof(path), "_crash.blend"); | ||||
| if (BLO_write_file(G_MAIN, path, fileflags, NULL, NULL)) { | if (BLO_write_file(G_MAIN, path, fileflags, NULL, NULL)) { | ||||
| printf("written: %s\n", path); | CLOG_INFO(&LOG, 0, "Written: %s", path); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else { | else { | ||||
| printf("failed: %s\n", path); | CLOG_ERROR(&LOG, "Failed: %s", path); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * \see #wm_homefile_write_exec wraps #BLO_write_file in a similar way. | * \see #wm_homefile_write_exec wraps #BLO_write_file in a similar way. | ||||
| */ | */ | ||||
| static bool wm_file_write(bContext *C, const char *filepath, int fileflags, ReportList *reports) | static bool wm_file_write(bContext *C, const char *filepath, int fileflags, ReportList *reports) | ||||
| ▲ Show 20 Lines • Show All 307 Lines • ▼ Show 20 Lines | static int wm_homefile_write_exec(bContext *C, wmOperator *op) | ||||
| if (win && WM_window_is_temp_screen(win)) | if (win && WM_window_is_temp_screen(win)) | ||||
| wm_window_close(C, wm, win); | wm_window_close(C, wm, win); | ||||
| /* update keymaps in user preferences */ | /* update keymaps in user preferences */ | ||||
| WM_keyconfig_update(wm); | WM_keyconfig_update(wm); | ||||
| BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_STARTUP_FILE, NULL); | BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_STARTUP_FILE, NULL); | ||||
| printf("Writing homefile: '%s' ", filepath); | CLOG_INFO(&LOG, 0, "Writing homefile: '%s'", filepath); | ||||
| ED_editors_flush_edits(bmain, false); | ED_editors_flush_edits(bmain, false); | ||||
| /* force save as regular blend file */ | /* force save as regular blend file */ | ||||
| fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_HISTORY); | fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_HISTORY); | ||||
| if (BLO_write_file(bmain, filepath, fileflags | G_FILE_USERPREFS, op->reports, NULL) == 0) { | if (BLO_write_file(bmain, filepath, fileflags | G_FILE_USERPREFS, op->reports, NULL) == 0) { | ||||
| printf("fail\n"); | CLOG_ERROR(&LOG, "fail"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| printf("ok\n"); | |||||
| G.save_over = 0; | G.save_over = 0; | ||||
| BLI_callback_exec(bmain, NULL, BLI_CB_EVT_SAVE_POST); | BLI_callback_exec(bmain, NULL, BLI_CB_EVT_SAVE_POST); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void WM_OT_save_homefile(wmOperatorType *ot) | void WM_OT_save_homefile(wmOperatorType *ot) | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | static int wm_userpref_write_exec(bContext *C, wmOperator *op) | ||||
| /* update keymaps in user preferences */ | /* update keymaps in user preferences */ | ||||
| WM_keyconfig_update(wm); | WM_keyconfig_update(wm); | ||||
| if ((cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL))) { | if ((cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL))) { | ||||
| bool ok_write; | bool ok_write; | ||||
| BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_USERPREF_FILE, NULL); | BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_USERPREF_FILE, NULL); | ||||
| printf("Writing userprefs: '%s' ", filepath); | CLOG_INFO(&LOG, 0, "Writing userprefs: '%s'", filepath); | ||||
| if (use_template_userpref) { | if (use_template_userpref) { | ||||
| ok_write = BKE_blendfile_userdef_write_app_template(filepath, op->reports); | ok_write = BKE_blendfile_userdef_write_app_template(filepath, op->reports); | ||||
| } | } | ||||
| else { | else { | ||||
| ok_write = BKE_blendfile_userdef_write(filepath, op->reports); | ok_write = BKE_blendfile_userdef_write(filepath, op->reports); | ||||
| } | } | ||||
| if (ok_write) { | if (!ok_write) { | ||||
| printf("ok\n"); | CLOG_ERROR(&LOG, "fail"); | ||||
| } | |||||
| else { | |||||
| printf("fail\n"); | |||||
| ok = false; | ok = false; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_report(op->reports, RPT_ERROR, "Unable to create userpref path"); | BKE_report(op->reports, RPT_ERROR, "Unable to create userpref path"); | ||||
| } | } | ||||
| if (use_template_userpref) { | if (use_template_userpref) { | ||||
| if ((cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, U.app_template))) { | if ((cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, U.app_template))) { | ||||
| /* Also save app-template prefs */ | /* Also save app-template prefs */ | ||||
| BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_USERPREF_FILE, NULL); | BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_USERPREF_FILE, NULL); | ||||
| printf("Writing userprefs app-template: '%s' ", filepath); | CLOG_INFO(&LOG, 0, "Writing userprefs app-template: '%s'", filepath); | ||||
| if (BKE_blendfile_userdef_write(filepath, op->reports) != 0) { | if (!BKE_blendfile_userdef_write(filepath, op->reports) != 0) { | ||||
| printf("ok\n"); | CLOG_ERROR(&LOG, "fail"); | ||||
| } | |||||
| else { | |||||
| printf("fail\n"); | |||||
| ok = false; | ok = false; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_report(op->reports, RPT_ERROR, "Unable to create app-template userpref path"); | BKE_report(op->reports, RPT_ERROR, "Unable to create app-template userpref path"); | ||||
| ok = false; | ok = false; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 810 Lines • Show Last 20 Lines | |||||