From 481cdb08ed6f33a09d0e6843d1024db93c301178 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 5 Jun 2018 15:10:33 +0200 Subject: Cleanup: use new accessors to blendfile path (Main.name). --- source/blender/windowmanager/intern/wm_files.c | 63 +++++++++++++--------- .../blender/windowmanager/intern/wm_files_link.c | 4 +- source/blender/windowmanager/intern/wm_init_exit.c | 4 +- source/blender/windowmanager/intern/wm_operators.c | 2 +- source/blender/windowmanager/intern/wm_window.c | 12 +++-- 5 files changed, 49 insertions(+), 36 deletions(-) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index d52f622d8b4..66080e3722f 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -559,6 +559,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) /* we didn't succeed, now try to read Blender file */ if (retval == BKE_READ_EXOTIC_OK_BLEND) { + Main *bmain = CTX_data_main(C); int G_f = G.f; ListBase wmbase; @@ -570,7 +571,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) G.relbase_valid = 1; retval = BKE_blendfile_read(C, filepath, reports, 0); /* when loading startup.blend's, we can be left with a blank path */ - if (G.main->name[0]) { + if (BKE_main_blendfile_path(bmain)) { G.save_over = 1; } else { @@ -655,6 +656,7 @@ int wm_homefile_read( bool use_factory_settings, bool use_empty_data, bool use_userdef, const char *filepath_startup_override, const char *app_template_override) { + Main *bmain = CTX_data_main(C); ListBase wmbase; bool success = false; @@ -855,7 +857,7 @@ int wm_homefile_read( wm_window_match_do(C, &wmbase); WM_check(C); /* opens window(s), checks keymaps */ - G.main->name[0] = '\0'; + bmain->name[0] = '\0'; if (use_userdef) { /* When loading factory settings, the reset solid OpenGL lights need to be applied. */ @@ -961,16 +963,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(); /* no write history for recovered startup files */ - if (G.main->name[0] == 0) + if (blendfile_name[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, G.main->name) != 0)) { + if (!(recent) || (BLI_path_cmp(recent->filepath, blendfile_name) != 0)) { - recent = wm_file_history_find(G.main->name); + recent = wm_file_history_find(blendfile_name); if (recent) { BLI_remlink(&G.recent_files, recent); } @@ -980,7 +984,7 @@ static void wm_history_file_update(void) recent_next = recent->next; wm_history_file_free(recent); } - recent = wm_history_file_new(G.main->name); + recent = wm_history_file_new(blendfile_name); } /* add current file to the beginning of list */ @@ -990,7 +994,7 @@ static void wm_history_file_update(void) wm_history_file_write(); /* also update most recent files on System */ - GHOST_addToSystemRecentFiles(G.main->name); + GHOST_addToSystemRecentFiles(blendfile_name); } } @@ -1077,7 +1081,7 @@ bool write_crash_blend(void) char path[FILE_MAX]; int fileflags = G.fileflags & ~(G_FILE_HISTORY); /* don't do file history on crash file */ - BLI_strncpy(path, G.main->name, sizeof(path)); + BLI_strncpy(path, BKE_main_blendfile_path_from_global(), sizeof(path)); BLI_replace_extension(path, sizeof(path), "_crash.blend"); if (BLO_write_file(G.main, path, fileflags, NULL, NULL)) { printf("written: %s\n", path); @@ -1094,6 +1098,7 @@ bool write_crash_blend(void) */ static int wm_file_write(bContext *C, const char *filepath, int fileflags, ReportList *reports) { + Main *bmain = CTX_data_main(C); Library *li; int len; int ret = -1; @@ -1123,7 +1128,7 @@ static int wm_file_write(bContext *C, const char *filepath, int fileflags, Repor * its handy for scripts to save to a predefined name without blender editing it */ /* send the OnSave event */ - for (li = G.main->library.first; li; li = li->id.next) { + for (li = bmain->library.first; li; li = li->id.next) { if (BLI_path_cmp(li->filepath, filepath) == 0) { BKE_reportf(reports, RPT_ERROR, "Cannot overwrite used library '%.240s'", filepath); return ret; @@ -1131,7 +1136,7 @@ static int wm_file_write(bContext *C, const char *filepath, int fileflags, Repor } /* Call pre-save callbacks befores writing preview, that way you can generate custom file thumbnail... */ - BLI_callback_exec(G.main, NULL, BLI_CB_EVT_SAVE_PRE); + BLI_callback_exec(bmain, NULL, BLI_CB_EVT_SAVE_PRE); /* blend file thumbnail */ /* save before exit_editmode, otherwise derivedmeshes for shared data corrupt #27765) */ @@ -1144,7 +1149,7 @@ static int wm_file_write(bContext *C, const char *filepath, int fileflags, Repor /* operator now handles overwrite checks */ if (G.fileflags & G_AUTOPACK) { - packAll(G.main, reports, false); + packAll(bmain, reports, false); } /* don't forget not to return without! */ @@ -1156,19 +1161,19 @@ static int wm_file_write(bContext *C, const char *filepath, int fileflags, Repor /* first time saving */ /* XXX temp solution to solve bug, real fix coming (ton) */ - if ((G.main->name[0] == '\0') && !(fileflags & G_FILE_SAVE_COPY)) { - BLI_strncpy(G.main->name, filepath, sizeof(G.main->name)); + if ((BKE_main_blendfile_path(bmain)[0] == '\0') && !(fileflags & G_FILE_SAVE_COPY)) { + BLI_strncpy(bmain->name, filepath, sizeof(bmain->name)); } /* XXX temp solution to solve bug, real fix coming (ton) */ - G.main->recovered = 0; + bmain->recovered = 0; if (BLO_write_file(CTX_data_main(C), filepath, fileflags, reports, thumb)) { const bool do_history = (G.background == false) && (CTX_wm_manager(C)->op_undo_depth == 0); if (!(fileflags & G_FILE_SAVE_COPY)) { G.relbase_valid = 1; - BLI_strncpy(G.main->name, filepath, sizeof(G.main->name)); /* is guaranteed current file */ + BLI_strncpy(bmain->name, filepath, sizeof(bmain->name)); /* is guaranteed current file */ G.save_over = 1; /* disable untitled.blend convention */ } @@ -1181,7 +1186,7 @@ static int wm_file_write(bContext *C, const char *filepath, int fileflags, Repor wm_history_file_update(); } - BLI_callback_exec(G.main, NULL, BLI_CB_EVT_SAVE_POST); + BLI_callback_exec(bmain, NULL, BLI_CB_EVT_SAVE_POST); /* run this function after because the file cant be written before the blend is */ if (ibuf_thumb) { @@ -1215,7 +1220,7 @@ void wm_autosave_location(char *filepath) #endif if (G.main && G.relbase_valid) { - const char *basename = BLI_path_basename(G.main->name); + const char *basename = BLI_path_basename(BKE_main_blendfile_path_from_global()); int len = strlen(basename) - 6; BLI_snprintf(path, sizeof(path), "%.*s.blend", len, basename); } @@ -1709,7 +1714,8 @@ struct FileRuntime { static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - const char *openname = G.main->name; + Main *bmain = CTX_data_main(C); + const char *openname = BKE_main_blendfile_path(bmain); if (CTX_wm_window(C) == NULL) { /* in rare cases this could happen, when trying to invoke in background @@ -1848,6 +1854,7 @@ void WM_OT_open_mainfile(wmOperatorType *ot) static int wm_revert_mainfile_exec(bContext *C, wmOperator *op) { + Main *bmain = CTX_data_main(C); bool success; char filepath[FILE_MAX]; @@ -1858,7 +1865,7 @@ static int wm_revert_mainfile_exec(bContext *C, wmOperator *op) else G.f &= ~G_SCRIPT_AUTOEXEC; - BLI_strncpy(filepath, G.main->name, sizeof(filepath)); + BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath)); success = wm_file_read_opwrap(C, filepath, op->reports, !(G.f & G_SCRIPT_AUTOEXEC)); if (success) { @@ -1896,6 +1903,7 @@ void WM_OT_revert_mainfile(wmOperatorType *ot) void WM_recover_last_session(bContext *C, ReportList *reports) { + Main *bmain = CTX_data_main(C); char filepath[FILE_MAX]; BLI_make_file_string("/", filepath, BKE_tempdir_base(), BLENDER_QUIT_FILE); @@ -1908,8 +1916,9 @@ void WM_recover_last_session(bContext *C, ReportList *reports) G.fileflags &= ~G_FILE_RECOVER; /* XXX bad global... fixme */ - if (G.main->name[0]) + if (BKE_main_blendfile_path(bmain)[0] != '\0') { G.file_loaded = 1; /* prevents splash to show */ + } else { G.relbase_valid = 0; G.save_over = 0; /* start with save preference untitled.blend */ @@ -2008,20 +2017,21 @@ static void save_set_compress(wmOperator *op) } } -static void save_set_filepath(wmOperator *op) +static void save_set_filepath(bContext *C, wmOperator *op) { + Main *bmain = CTX_data_main(C); PropertyRNA *prop; char name[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 (G.main->name[0] == 0 && G.recent_files.first) { + 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); } else { - BLI_strncpy(name, G.main->name, FILE_MAX); + BLI_strncpy(name, bmain->name, FILE_MAX); } wm_filepath_default(name); @@ -2033,7 +2043,7 @@ static int wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent { save_set_compress(op); - save_set_filepath(op); + save_set_filepath(C, op); WM_event_add_fileselect(C, op); @@ -2043,6 +2053,7 @@ static int wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent /* function used for WM_OT_save_mainfile too */ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op) { + Main *bmain = CTX_data_main(C); char path[FILE_MAX]; int fileflags; @@ -2052,7 +2063,7 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op) RNA_string_get(op->ptr, "filepath", path); } else { - BLI_strncpy(path, G.main->name, FILE_MAX); + BLI_strncpy(path, BKE_main_blendfile_path(bmain), FILE_MAX); wm_filepath_default(path); } @@ -2146,7 +2157,7 @@ static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *U return OPERATOR_CANCELLED; save_set_compress(op); - save_set_filepath(op); + save_set_filepath(C, op); /* 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 [#37240] */ diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c index a2cd701b768..5f0c905dfd4 100644 --- a/source/blender/windowmanager/intern/wm_files_link.c +++ b/source/blender/windowmanager/intern/wm_files_link.c @@ -115,7 +115,7 @@ static int wm_link_append_invoke(bContext *C, wmOperator *op, const wmEvent *UNU } else if (G.relbase_valid) { char path[FILE_MAX]; - BLI_strncpy(path, G.main->name, sizeof(G.main->name)); + BLI_strncpy(path, BKE_main_blendfile_path_from_global(), sizeof(path)); BLI_parent_dir(path); RNA_string_set(op->ptr, "filepath", path); } @@ -297,7 +297,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op) BKE_reportf(op->reports, RPT_ERROR, "'%s': nothing indicated", path); return OPERATOR_CANCELLED; } - else if (BLI_path_cmp(bmain->name, libname) == 0) { + else if (BLI_path_cmp(BKE_main_blendfile_path(bmain), libname) == 0) { BKE_reportf(op->reports, RPT_ERROR, "'%s': cannot use current file as library", path); return OPERATOR_CANCELLED; } diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index d47152700ec..dd4a150305d 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -259,11 +259,11 @@ void WM_init(bContext *C, int argc, const char **argv) /* allow a path of "", this is what happens when making a new file */ #if 0 - if (G.main->name[0] == 0) + if (BKE_main_blendfile_path_from_global()[0] == '\0') BLI_make_file_string("/", G.main->name, BKE_appdir_folder_default(), "untitled.blend"); #endif - BLI_strncpy(G.lib, G.main->name, FILE_MAX); + BLI_strncpy(G.lib, BKE_main_blendfile_path_from_global(), sizeof(G.lib)); #ifdef WITH_COMPOSITOR if (1) { diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index f4acfb6d809..c0c6b1edcaf 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1335,7 +1335,7 @@ ID *WM_operator_drop_load_path(struct bContext *C, wmOperator *op, const short i if (is_relative_path ) { if (exists == false) { if (idcode == ID_IM) { - BLI_path_rel(((Image *)id)->name, bmain->name); + BLI_path_rel(((Image *)id)->name, BKE_main_blendfile_path(bmain)); } else { BLI_assert(0); diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index d49df7ae09b..c7805184819 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -338,6 +338,7 @@ static void wm_block_confirm_quit_save(bContext *C, void *arg_block, void *UNUSE /* Build the confirm dialog UI */ static uiBlock *block_create_confirm_quit(struct bContext *C, struct ARegion *ar, void *UNUSED(arg1)) { + Main *bmain = CTX_data_main(C); uiStyle *style = UI_style_get(); uiBlock *block = UI_block_begin(C, ar, "confirm_quit_popup", UI_EMBOSS); @@ -351,11 +352,11 @@ static uiBlock *block_create_confirm_quit(struct bContext *C, struct ARegion *ar /* Text and some vertical space */ { char *message; - if (G.main->name[0] == '\0') { + if (BKE_main_blendfile_path(bmain)[0] == '\0') { message = BLI_strdup(IFACE_("This file has not been saved yet. Save before closing?")); } else { - const char *basename = BLI_path_basename(G.main->name); + const char *basename = BLI_path_basename(BKE_main_blendfile_path(bmain)); message = BLI_sprintfN(IFACE_("Save changes to \"%s\" before closing?"), basename); } uiItemL(layout, message, ICON_ERROR); @@ -496,9 +497,10 @@ void wm_window_title(wmWindowManager *wm, wmWindow *win) } else if (win->ghostwin) { /* this is set to 1 if you don't have startup.blend open */ - if (G.save_over && G.main->name[0]) { - char str[sizeof(G.main->name) + 24]; - BLI_snprintf(str, sizeof(str), "Blender%s [%s%s]", wm->file_saved ? "" : "*", G.main->name, + if (G.save_over && BKE_main_blendfile_path_from_global()[0]) { + char str[sizeof(((Main *)NULL)->name) + 24]; + BLI_snprintf(str, sizeof(str), "Blender%s [%s%s]", wm->file_saved ? "" : "*", + BKE_main_blendfile_path_from_global(), G.main->recovered ? " (Recovered)" : ""); GHOST_SetTitle(win->ghostwin, str); } -- cgit v1.2.3