diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2018-06-05 16:10:33 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2018-06-05 17:33:46 +0300 |
commit | 481cdb08ed6f33a09d0e6843d1024db93c301178 (patch) | |
tree | 77166d130bfff2d5dca884676aaeff6bc0758f96 /source/blender/windowmanager/intern/wm_files.c | |
parent | 1d97e948d2c4867306e7fb5ce5fccf8b72c13391 (diff) |
Cleanup: use new accessors to blendfile path (Main.name).
Diffstat (limited to 'source/blender/windowmanager/intern/wm_files.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 63 |
1 files changed, 37 insertions, 26 deletions
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] */ |