From 3850fdd5b957aa3b8f70d3c0b952b07af6b07fe1 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 24 Nov 2021 11:20:35 +0100 Subject: Assets: Sanitize threaded preview creation with undo Basically, this fixes disappearing previews when editing asset metadata or performing undo/redo actions. The preview generation in a background job will eventually modify ID data, but the undo push was done prior to that. So obviously, an undo then would mean the preview is lost. This patch makes it so undo/redo will regenerate the preview, if the preview rendering was invoked but not finished in the undone/redone state. The preview flag PRV_UNFINISHED wasn't entirely what we needed. So I had to change it to a slightly different flag, with different semantics. --- source/blender/windowmanager/intern/wm_files.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source/blender/windowmanager/intern/wm_files.c') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index a301b17227d..e95ce98352a 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -111,6 +111,7 @@ #include "ED_fileselect.h" #include "ED_image.h" #include "ED_outliner.h" +#include "ED_render.h" #include "ED_screen.h" #include "ED_undo.h" #include "ED_util.h" @@ -620,6 +621,8 @@ static void wm_file_read_pre(bContext *C, bool use_data, bool UNUSED(use_userdef /* Always do this as both startup and preferences may have loaded in many font's * at a different zoom level to the file being loaded. */ UI_view2d_zoom_cache_reset(); + + ED_preview_restart_queue_free(); } /** -- cgit v1.2.3 From 7e927174396443cdc4c5544dad13faca7299d183 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 8 Dec 2021 17:12:41 +1100 Subject: Cleanup: move public doc-strings into headers for 'windowmanager' Ref T92709 --- source/blender/windowmanager/intern/wm_files.c | 31 -------------------------- 1 file changed, 31 deletions(-) (limited to 'source/blender/windowmanager/intern/wm_files.c') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index e95ce98352a..a2a09f9b0bc 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -171,9 +171,6 @@ void WM_file_tag_modified(void) } } -/** - * Check if there is data that would be lost when closing the current file without saving. - */ bool wm_file_or_session_data_has_unsaved_changes(const Main *bmain, const wmWindowManager *wm) { return !wm->file_saved || ED_image_should_save_modified(bmain) || @@ -1035,12 +1032,6 @@ static struct { bool override; } wm_init_state_app_template = {{0}}; -/** - * Used for setting app-template from the command line: - * - non-empty string: overrides. - * - empty string: override, using no app template. - * - NULL: clears override. - */ void WM_init_state_app_template_set(const char *app_template) { if (app_template) { @@ -1064,16 +1055,6 @@ const char *WM_init_state_app_template_get(void) /** \name Read Startup & Preferences Blend-File API * \{ */ -/** - * Called on startup, (context entirely filled with NULLs) - * or called for 'New File' both `startup.blend` and `userpref.blend` are checked. - * - * \param r_params_file_read_post: Support postponed initialization, - * needed for initial startup when only some sub-systems have been initialized. - * When non-null, #wm_file_read_post doesn't run, instead it's arguments are stored - * in this return argument. - * The caller is responsible for calling #wm_homefile_read_post with this return argument. - */ void wm_homefile_read_ex(bContext *C, const struct wmHomeFileRead_Params *params_homefile, ReportList *reports, @@ -1409,10 +1390,6 @@ void wm_homefile_read(bContext *C, wm_homefile_read_ex(C, params_homefile, reports, NULL); } -/** - * Special case, support deferred execution of #wm_file_read_post, - * Needed when loading for the first time to workaround order of initialization bug, see T89046. - */ void wm_homefile_read_post(struct bContext *C, const struct wmFileReadPost_Params *params_file_read_post) { @@ -1724,7 +1701,6 @@ static ImBuf *blend_file_thumb_from_camera(const bContext *C, return ibuf; } -/* easy access from gdb */ bool write_crash_blend(void) { char path[FILE_MAX]; @@ -2009,9 +1985,6 @@ void WM_autosave_init(wmWindowManager *wm) wm_autosave_timer_begin(wm); } -/** - * Run the auto-save timer action. - */ void wm_autosave_timer(Main *bmain, wmWindowManager *wm, wmTimer *UNUSED(wt)) { wm_autosave_timer_end(wm); @@ -3813,10 +3786,6 @@ static void wm_free_operator_properties_callback(void *user_data) IDP_FreeProperty(properties); } -/** - * \return True if the dialog was created, the calling operator should return #OPERATOR_INTERFACE - * then. - */ bool wm_operator_close_file_dialog_if_needed(bContext *C, wmOperator *op, wmGenericCallbackFn post_action_fn) -- cgit v1.2.3 From 8ad2642c4717dcfad31626f7eebac325a9827b73 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 13 Dec 2021 16:22:19 +1100 Subject: Cleanup: use "filepath" term for Main, BlendFileData & FileGlobal Use "filepath" which is the current convention for naming full paths. - Main use "name" which isn't obviously a file path. - BlendFileData & FileGlobal used "filename" which is often used for the name component of a path (without the directory). --- source/blender/windowmanager/intern/wm_files.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source/blender/windowmanager/intern/wm_files.c') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index a2a09f9b0bc..e753c083805 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -1356,7 +1356,7 @@ void wm_homefile_read_ex(bContext *C, if (use_data) { WM_check(C); /* opens window(s), checks keymaps */ - bmain->name[0] = '\0'; + bmain->filepath[0] = '\0'; /* start with save preference untitled.blend */ G.save_over = 0; @@ -1828,7 +1828,7 @@ static bool wm_file_write(bContext *C, /* First time saving. */ /* XXX(ton): temp solution to solve bug, real fix coming. */ if ((BKE_main_blendfile_path(bmain)[0] == '\0') && (use_save_as_copy == false)) { - BLI_strncpy(bmain->name, filepath, sizeof(bmain->name)); + STRNCPY(bmain->filepath, filepath); } /* XXX(ton): temp solution to solve bug, real fix coming. */ @@ -1849,7 +1849,7 @@ static bool wm_file_write(bContext *C, if (use_save_as_copy == false) { G.relbase_valid = 1; - BLI_strncpy(bmain->name, filepath, sizeof(bmain->name)); /* is guaranteed current file */ + STRNCPY(bmain->filepath, filepath); /* is guaranteed current file */ G.save_over = 1; /* disable untitled.blend convention */ } @@ -3035,21 +3035,21 @@ static void save_set_filepath(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); PropertyRNA *prop; - char name[FILE_MAX]; + char filepath[FILE_MAX]; prop = RNA_struct_find_property(op->ptr, "filepath"); if (!RNA_property_is_set(op->ptr, prop)) { /* if not saved before, get the name of the most recently used .blend file */ if (BKE_main_blendfile_path(bmain)[0] == '\0' && G.recent_files.first) { struct RecentFile *recent = G.recent_files.first; - BLI_strncpy(name, recent->filepath, FILE_MAX); + STRNCPY(filepath, recent->filepath); } else { - BLI_strncpy(name, bmain->name, FILE_MAX); + STRNCPY(filepath, bmain->filepath); } - wm_filepath_default(name); - RNA_property_string_set(op->ptr, prop, name); + wm_filepath_default(filepath); + RNA_property_string_set(op->ptr, prop, filepath); } } -- cgit v1.2.3 From 2a0a6a0541eaff06659a06ef18cac05e5674c844 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 14 Dec 2021 09:42:46 +1100 Subject: Remove G.save_over The difference between G.save_over and G.relbase_valid was minor. There is one change in functionality. When saving the default-startup file from an already loaded blend file - future save actions will continue to write to the originally loaded file instead of prompting the user to select a location to save the file. This change makes saving the startup file behave the same way "Save a Copy" does. Reviewed By: brecht Ref D13556 --- source/blender/windowmanager/intern/wm_files.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'source/blender/windowmanager/intern/wm_files.c') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index e753c083805..f3cf5dca040 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -957,11 +957,9 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) /* When recovering a session from an unsaved file, this can have a blank path. */ if (BKE_main_blendfile_path(bmain)[0] != '\0') { - G.save_over = 1; G.relbase_valid = 1; } else { - G.save_over = 0; G.relbase_valid = 0; } @@ -1357,9 +1355,6 @@ void wm_homefile_read_ex(bContext *C, WM_check(C); /* opens window(s), checks keymaps */ bmain->filepath[0] = '\0'; - - /* start with save preference untitled.blend */ - G.save_over = 0; } { @@ -1850,8 +1845,6 @@ static bool wm_file_write(bContext *C, if (use_save_as_copy == false) { G.relbase_valid = 1; STRNCPY(bmain->filepath, filepath); /* is guaranteed current file */ - - G.save_over = 1; /* disable untitled.blend convention */ } SET_FLAG_FROM_TEST(G.fileflags, fileflags & G_FILE_COMPRESS, G_FILE_COMPRESS); @@ -2126,7 +2119,6 @@ static int wm_homefile_write_exec(bContext *C, wmOperator *op) printf("ok\n"); BKE_report(op->reports, RPT_INFO, "Startup file saved"); - G.save_over = 0; BKE_callback_exec_null(bmain, BKE_CB_EVT_SAVE_POST); @@ -3011,7 +3003,7 @@ void WM_OT_recover_auto_save(wmOperatorType *ot) static void wm_filepath_default(char *filepath) { - if (G.save_over == false) { + if (G.relbase_valid == false) { BLI_path_filename_ensure(filepath, FILE_MAX, "untitled.blend"); } } @@ -3022,7 +3014,7 @@ static void save_set_compress(wmOperator *op) prop = RNA_struct_find_property(op->ptr, "compress"); if (!RNA_property_is_set(op->ptr, prop)) { - if (G.save_over) { /* keep flag for existing file */ + if (G.relbase_valid) { /* keep flag for existing file */ RNA_property_boolean_set(op->ptr, prop, (G.fileflags & G_FILE_COMPRESS) != 0); } else { /* use userdef for new file */ @@ -3210,7 +3202,7 @@ static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *U } } - if (G.save_over) { + if (G.relbase_valid) { char path[FILE_MAX]; RNA_string_get(op->ptr, "filepath", path); -- cgit v1.2.3 From c097c7b855d4b01950494dc369e9def59486b0fd Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 14 Dec 2021 15:49:31 +1100 Subject: Cleanup: correct unbalanced doxygen groups Also add groups in some files. --- source/blender/windowmanager/intern/wm_files.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source/blender/windowmanager/intern/wm_files.c') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index f3cf5dca040..8f05e6ccaba 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -1392,6 +1392,8 @@ void wm_homefile_read_post(struct bContext *C, MEM_freeN((void *)params_file_read_post); } +/** \} */ + /* -------------------------------------------------------------------- */ /** \name Blend-File History API * \{ */ -- cgit v1.2.3 From 5cce6894d2a7704dcd445d471764af4c6baa65aa Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 14 Dec 2021 21:32:14 +1100 Subject: Cleanup: consistent naming for the blender file name --- source/blender/windowmanager/intern/wm_files.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'source/blender/windowmanager/intern/wm_files.c') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 8f05e6ccaba..eb1be7ef484 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -1491,18 +1491,18 @@ static void wm_history_file_write(void) static void wm_history_file_update(void) { RecentFile *recent; - const char *blendfile_name = BKE_main_blendfile_path_from_global(); + const char *blendfile_path = BKE_main_blendfile_path_from_global(); - /* no write history for recovered startup files */ - if (blendfile_name[0] == '\0') { + /* No write history for recovered startup files. */ + if (blendfile_path[0] == '\0') { return; } recent = G.recent_files.first; /* refresh recent-files.txt of recent opened files, when current file was changed */ - if (!(recent) || (BLI_path_cmp(recent->filepath, blendfile_name) != 0)) { + if (!(recent) || (BLI_path_cmp(recent->filepath, blendfile_path) != 0)) { - recent = wm_file_history_find(blendfile_name); + recent = wm_file_history_find(blendfile_path); if (recent) { BLI_remlink(&G.recent_files, recent); } @@ -1513,7 +1513,7 @@ static void wm_history_file_update(void) recent_next = recent->next; wm_history_file_free(recent); } - recent = wm_history_file_new(blendfile_name); + recent = wm_history_file_new(blendfile_path); } /* add current file to the beginning of list */ @@ -1523,7 +1523,7 @@ static void wm_history_file_update(void) wm_history_file_write(); /* also update most recent files on System */ - GHOST_addToSystemRecentFiles(blendfile_name); + GHOST_addToSystemRecentFiles(blendfile_path); } } @@ -2607,7 +2607,7 @@ static int wm_open_mainfile__select_file_path(bContext *C, wmOperator *op) set_next_operator_state(op, OPEN_MAINFILE_STATE_OPEN); Main *bmain = CTX_data_main(C); - const char *openname = BKE_main_blendfile_path(bmain); + const char *blendfile_path = BKE_main_blendfile_path(bmain); if (CTX_wm_window(C) == NULL) { /* in rare cases this could happen, when trying to invoke in background @@ -2620,10 +2620,10 @@ static int wm_open_mainfile__select_file_path(bContext *C, wmOperator *op) /* if possible, get the name of the most recently used .blend file */ if (G.recent_files.first) { struct RecentFile *recent = G.recent_files.first; - openname = recent->filepath; + blendfile_path = recent->filepath; } - RNA_string_set(op->ptr, "filepath", openname); + RNA_string_set(op->ptr, "filepath", blendfile_path); wm_open_init_load_ui(op, true); wm_open_init_use_scripts(op, true); op->customdata = NULL; @@ -3610,10 +3610,10 @@ static uiBlock *block_create__close_file_dialog(struct bContext *C, uiItemL_ex(layout, TIP_("Save changes before closing?"), ICON_NONE, true, false); /* Filename. */ - const char *blendfile_pathpath = BKE_main_blendfile_path(CTX_data_main(C)); + const char *blendfile_path = BKE_main_blendfile_path(CTX_data_main(C)); char filename[FILE_MAX]; - if (blendfile_pathpath[0] != '\0') { - BLI_split_file_part(blendfile_pathpath, filename, sizeof(filename)); + if (blendfile_path[0] != '\0') { + BLI_split_file_part(blendfile_path, filename, sizeof(filename)); } else { STRNCPY(filename, "untitled.blend"); -- cgit v1.2.3 From 644eb68524b9fc709891860e2c0c40782325a62b Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 14 Dec 2021 13:50:40 -0800 Subject: Fix T93949: Preview Image Error When No Screen Fix an error if "File Preview Type" is "Auto" and there is no screen. See D13574 for details. Differential Revision: https://developer.blender.org/D13574 Reviewed by Julian Eisel --- source/blender/windowmanager/intern/wm_files.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source/blender/windowmanager/intern/wm_files.c') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index eb1be7ef484..ddc4692084e 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -1793,8 +1793,9 @@ static bool wm_file_write(bContext *C, if (file_preview_type == USER_FILE_PREVIEW_AUTO) { Scene *scene = CTX_data_scene(C); - bool do_render = (scene != NULL && scene->camera != NULL && - (BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_VIEW3D, 0) != NULL)); + bScreen *screen = CTX_wm_screen(C); + bool do_render = (scene != NULL && scene->camera != NULL && screen != NULL && + (BKE_screen_find_big_area(screen, SPACE_VIEW3D, 0) != NULL)); file_preview_type = do_render ? USER_FILE_PREVIEW_CAMERA : USER_FILE_PREVIEW_SCREENSHOT; } -- cgit v1.2.3 From 5de109cc2d220ca3bd731216b9cd521269ad663e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 16 Dec 2021 11:38:10 +1100 Subject: Remove G.relbase_valid In almost all cases there is no difference between `G.relbase_valid` and checking `G.main->filepath` isn't an empty string. In many places a non-empty string is already being used instead of `G.relbase_valid`. The only situation where this was needed was when saving from `wm_file_write` where they temporarily became out of sync. This has been replaced by adding a new member to `BlendFileWriteParams` to account for saving an unsaved file for the first time. Reviewed By: brecht Ref D13564 --- source/blender/windowmanager/intern/wm_files.c | 53 +++++++++++++------------- 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'source/blender/windowmanager/intern/wm_files.c') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index ddc4692084e..0867ed5303c 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -955,14 +955,6 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) /* #BKE_blendfile_read_result_setup sets new Main into context. */ Main *bmain = CTX_data_main(C); - /* When recovering a session from an unsaved file, this can have a blank path. */ - if (BKE_main_blendfile_path(bmain)[0] != '\0') { - G.relbase_valid = 1; - } - else { - G.relbase_valid = 0; - } - /* match the read WM with current WM */ wm_window_match_do(C, &wmbase, &bmain->wm, &bmain->wm); WM_check(C); /* opens window(s), checks keymaps */ @@ -1149,8 +1141,6 @@ void wm_homefile_read_ex(bContext *C, wm_file_read_pre(C, use_data, use_userdef); if (use_data) { - G.relbase_valid = 0; - /* put aside screens to match with persistent windows later */ wm_window_match_init(C, &wmbase); } @@ -1825,7 +1815,8 @@ static bool wm_file_write(bContext *C, /* First time saving. */ /* XXX(ton): temp solution to solve bug, real fix coming. */ - if ((BKE_main_blendfile_path(bmain)[0] == '\0') && (use_save_as_copy == false)) { + const bool relbase_valid = (bmain->filepath[0] != '\0'); + if ((relbase_valid == false) && (use_save_as_copy == false)) { STRNCPY(bmain->filepath, filepath); } @@ -1839,6 +1830,7 @@ static bool wm_file_write(bContext *C, .remap_mode = remap_mode, .use_save_versions = true, .use_save_as_copy = use_save_as_copy, + .use_save_first_time = !relbase_valid, .thumb = thumb, }, reports)) { @@ -1846,7 +1838,6 @@ static bool wm_file_write(bContext *C, (CTX_wm_manager(C)->op_undo_depth == 0); if (use_save_as_copy == false) { - G.relbase_valid = 1; STRNCPY(bmain->filepath, filepath); /* is guaranteed current file */ } @@ -1898,8 +1889,13 @@ static void wm_autosave_location(char *filepath) const char *savedir; #endif - if (G_MAIN && G.relbase_valid) { - const char *basename = BLI_path_basename(BKE_main_blendfile_path_from_global()); + /* Normally there is no need to check for this to be NULL, + * however this runs on exit when it may be cleared. */ + Main *bmain = G_MAIN; + const char *blendfile_path = bmain ? BKE_main_blendfile_path(bmain) : NULL; + + if (blendfile_path && (blendfile_path[0] != '\0')) { + const char *basename = BLI_path_basename(blendfile_path); int len = strlen(basename) - 6; BLI_snprintf(path, sizeof(path), "%.*s_%d_autosave.blend", len, basename, pid); } @@ -2109,7 +2105,7 @@ static int wm_homefile_write_exec(bContext *C, wmOperator *op) fileflags, &(const struct BlendFileWriteParams){ /* Make all paths absolute when saving the startup file. - * On load the `G.relbase_valid` will be false so the paths + * On load the `G.main->filepath` will be empty so the paths * won't have a base for resolving the relative paths. */ .remap_mode = BLO_WRITE_PATH_REMAP_ABSOLUTE, /* Don't apply any path changes to the current blend file. */ @@ -2847,7 +2843,8 @@ static int wm_revert_mainfile_exec(bContext *C, wmOperator *op) static bool wm_revert_mainfile_poll(bContext *UNUSED(C)) { - return G.relbase_valid; + const char *blendfile_path = BKE_main_blendfile_path_from_global(); + return (blendfile_path[0] != '\0'); } void WM_OT_revert_mainfile(wmOperatorType *ot) @@ -3004,9 +3001,9 @@ void WM_OT_recover_auto_save(wmOperatorType *ot) * Both #WM_OT_save_as_mainfile & #WM_OT_save_mainfile. * \{ */ -static void wm_filepath_default(char *filepath) +static void wm_filepath_default(const Main *bmain, char *filepath) { - if (G.relbase_valid == false) { + if (bmain->filepath[0] == '\0') { BLI_path_filename_ensure(filepath, FILE_MAX, "untitled.blend"); } } @@ -3017,7 +3014,8 @@ static void save_set_compress(wmOperator *op) prop = RNA_struct_find_property(op->ptr, "compress"); if (!RNA_property_is_set(op->ptr, prop)) { - if (G.relbase_valid) { /* keep flag for existing file */ + const char *blendfile_path = BKE_main_blendfile_path_from_global(); + if (blendfile_path[0] != '\0') { /* Keep flag for existing file. */ RNA_property_boolean_set(op->ptr, prop, (G.fileflags & G_FILE_COMPRESS) != 0); } else { /* use userdef for new file */ @@ -3034,16 +3032,17 @@ static void save_set_filepath(bContext *C, wmOperator *op) prop = RNA_struct_find_property(op->ptr, "filepath"); if (!RNA_property_is_set(op->ptr, prop)) { + const char *blendfile_path = BKE_main_blendfile_path(bmain); /* if not saved before, get the name of the most recently used .blend file */ - if (BKE_main_blendfile_path(bmain)[0] == '\0' && G.recent_files.first) { + if ((blendfile_path[0] == '\0') && G.recent_files.first) { struct RecentFile *recent = G.recent_files.first; STRNCPY(filepath, recent->filepath); } else { - STRNCPY(filepath, bmain->filepath); + STRNCPY(filepath, blendfile_path); } - wm_filepath_default(filepath); + wm_filepath_default(bmain, filepath); RNA_property_string_set(op->ptr, prop, filepath); } } @@ -3081,7 +3080,7 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op) } else { BLI_strncpy(path, BKE_main_blendfile_path(bmain), FILE_MAX); - wm_filepath_default(path); + wm_filepath_default(bmain, path); } const int fileflags_orig = G.fileflags; @@ -3198,14 +3197,15 @@ static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *U /* if we're saving for the first time and prefer relative paths - * any existing paths will be absolute, * enable the option to remap paths to avoid confusion T37240. */ - if ((G.relbase_valid == false) && (U.flag & USER_RELPATHS)) { + const char *blendfile_path = BKE_main_blendfile_path_from_global(); + if ((blendfile_path[0] == '\0') && (U.flag & USER_RELPATHS)) { PropertyRNA *prop = RNA_struct_find_property(op->ptr, "relative_remap"); if (!RNA_property_is_set(op->ptr, prop)) { RNA_property_boolean_set(op->ptr, prop, true); } } - if (G.relbase_valid) { + if (blendfile_path[0] != '\0') { char path[FILE_MAX]; RNA_string_get(op->ptr, "filepath", path); @@ -3307,6 +3307,7 @@ static uiBlock *block_create_autorun_warning(struct bContext *C, struct ARegion *region, void *UNUSED(arg1)) { + const char *blendfile_path = BKE_main_blendfile_path_from_global(); wmWindowManager *wm = CTX_wm_manager(C); uiBlock *block = UI_block_begin(C, region, "autorun_warning_popup", UI_EMBOSS); @@ -3354,7 +3355,7 @@ static uiBlock *block_create_autorun_warning(struct bContext *C, /* Allow reload if we have a saved file. * Otherwise just enable scripts and reset the depsgraphs. */ - if (G.relbase_valid && wm->file_saved) { + if ((blendfile_path[0] != '\0') && wm->file_saved) { but = uiDefIconTextBut(block, UI_BTYPE_BUT, 0, -- cgit v1.2.3 From 15c36170092d26b7d6106924270b6e590627fcb6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 16 Dec 2021 16:17:26 +1100 Subject: Cleanup: simplify file saving logic Revert part of the fix from 073669dd8588a3b80dfffee98b4f239b4baee8c8 that initialized the file-path on first save as it's no longer needed. Also remove relbase argument to BLI_path_normalize as the destination file paths shouldn't use relative locations. --- source/blender/windowmanager/intern/wm_files.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'source/blender/windowmanager/intern/wm_files.c') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 0867ed5303c..7ac9395e16c 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -1813,24 +1813,16 @@ static bool wm_file_write(bContext *C, ED_editors_flush_edits(bmain); - /* First time saving. */ - /* XXX(ton): temp solution to solve bug, real fix coming. */ - const bool relbase_valid = (bmain->filepath[0] != '\0'); - if ((relbase_valid == false) && (use_save_as_copy == false)) { - STRNCPY(bmain->filepath, filepath); - } - /* XXX(ton): temp solution to solve bug, real fix coming. */ bmain->recovered = 0; - if (BLO_write_file(CTX_data_main(C), + if (BLO_write_file(bmain, filepath, fileflags, &(const struct BlendFileWriteParams){ .remap_mode = remap_mode, .use_save_versions = true, .use_save_as_copy = use_save_as_copy, - .use_save_first_time = !relbase_valid, .thumb = thumb, }, reports)) { -- cgit v1.2.3 From 8dbd406ea0f495b3d404a7433a32b4781953e55a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 16 Dec 2021 16:17:28 +1100 Subject: WM: various changes to file writing behavior Saving with only a filename (from Python) wasn't being prevented, while it would successfully write the file to the working-directory, path remapping and setting relative paths wouldn't work afterwards as `Main.filepath` would have no directory component. Disallow this since it's a corner case which only ever occurs when path names without any directories are used from Python, the overhead of expanding the working-directory for all data saving operations isn't worthwhile. The following changes have been made: - bpy.ops.wm.save_mainfile() without a filepath argument fails & reports and error when the file hasn't been saved. Previously it would write to "untitled.blend" and set the `G.main->filepath` to this as well. - bpy.ops.wm.save_mainfile(filepath="untitled.blend") fails & reports and error as the filename has no directory component. - `BLI_path_is_abs_from_cwd` was added to check if the path would attempt to expand to the CWD. --- source/blender/windowmanager/intern/wm_files.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'source/blender/windowmanager/intern/wm_files.c') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 7ac9395e16c..1d3fa158ac1 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -3067,12 +3067,32 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op) BLO_WRITE_PATH_REMAP_NONE; save_set_compress(op); - if (RNA_struct_property_is_set(op->ptr, "filepath")) { + const bool is_filepath_set = RNA_struct_property_is_set(op->ptr, "filepath"); + if (is_filepath_set) { RNA_string_get(op->ptr, "filepath", path); } else { - BLI_strncpy(path, BKE_main_blendfile_path(bmain), FILE_MAX); - wm_filepath_default(bmain, path); + STRNCPY(path, BKE_main_blendfile_path(bmain)); + } + + if (path[0] == '\0') { + BKE_report(op->reports, + RPT_ERROR, + "Unable to save an unsaved file with an empty or unset \"filepath\" property"); + return OPERATOR_CANCELLED; + } + + /* NOTE(@campbellbarton): only check this for file-path properties so saving an already + * saved file never fails with an error. + * Even though this should never happen, there may be some corner case where a malformed + * path is stored in `G.main->filepath`: when the file path is initialized from recovering + * a blend file - for example, so in this case failing to save isn't ideal. */ + if (is_filepath_set && !BLI_path_is_abs_from_cwd(path)) { + BKE_reportf(op->reports, + RPT_ERROR, + "The \"filepath\" property was not an absolute path: \"%s\"", + path); + return OPERATOR_CANCELLED; } const int fileflags_orig = G.fileflags; -- cgit v1.2.3