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/editors/interface/interface_ops.c | 2 +- source/blender/editors/io/io_alembic.c | 8 ++-- source/blender/editors/io/io_cache.c | 2 +- source/blender/editors/io/io_collada.c | 7 +++- source/blender/editors/object/object_bake_api.c | 3 +- source/blender/editors/object/object_modifier.c | 2 +- source/blender/editors/render/render_opengl.c | 6 +-- source/blender/editors/render/render_preview.c | 6 +-- source/blender/editors/render/render_shading.c | 3 +- source/blender/editors/screen/screendump.c | 6 +-- source/blender/editors/sound/sound_ops.c | 2 +- source/blender/editors/space_buttons/buttons_ops.c | 5 ++- source/blender/editors/space_clip/clip_ops.c | 4 +- source/blender/editors/space_file/file_draw.c | 6 ++- source/blender/editors/space_file/file_intern.h | 6 +-- source/blender/editors/space_file/file_ops.c | 48 +++++++++++++--------- source/blender/editors/space_file/filelist.c | 5 ++- source/blender/editors/space_file/filesel.c | 12 +++--- source/blender/editors/space_image/image_ops.c | 16 ++++---- source/blender/editors/space_info/info_ops.c | 4 +- .../blender/editors/space_outliner/outliner_draw.c | 2 +- .../editors/space_sequencer/sequencer_add.c | 4 +- .../editors/space_sequencer/sequencer_edit.c | 6 +-- source/blender/editors/space_text/text_ops.c | 8 ++-- source/blender/editors/util/ed_util.c | 4 +- 25 files changed, 99 insertions(+), 78 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index a8531fad477..4f5e7a67367 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -742,7 +742,7 @@ static int editsource_text_edit( } if (text == NULL) { - text = BKE_text_load(bmain, filepath, bmain->name); + text = BKE_text_load(bmain, filepath, BKE_main_blendfile_path(bmain)); id_us_ensure_real(&text->id); } diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c index 08181af2ef3..671857443d2 100644 --- a/source/blender/editors/io/io_alembic.c +++ b/source/blender/editors/io/io_alembic.c @@ -79,11 +79,11 @@ static int wm_alembic_export_invoke(bContext *C, wmOperator *op, const wmEvent * Main *bmain = CTX_data_main(C); char filepath[FILE_MAX]; - if (bmain->name[0] == '\0') { + if (BKE_main_blendfile_path(bmain)[0] == '\0') { BLI_strncpy(filepath, "untitled", sizeof(filepath)); } else { - BLI_strncpy(filepath, bmain->name, sizeof(filepath)); + BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath)); } BLI_replace_extension(filepath, sizeof(filepath), ".abc"); @@ -422,12 +422,12 @@ static int get_sequence_len(char *filename, int *ofs) } char path[FILE_MAX]; - BLI_path_abs(filename, G.main->name); + BLI_path_abs(filename, BKE_main_blendfile_path_from_global()); BLI_split_dir_part(filename, path, FILE_MAX); if (path[0] == '\0') { /* The filename had no path, so just use the blend file path. */ - BLI_split_dir_part(G.main->name, path, FILE_MAX); + BLI_split_dir_part(BKE_main_blendfile_path_from_global(), path, FILE_MAX); } DIR *dir = opendir(path); diff --git a/source/blender/editors/io/io_cache.c b/source/blender/editors/io/io_cache.c index eb79d0bec13..b13eaced843 100644 --- a/source/blender/editors/io/io_cache.c +++ b/source/blender/editors/io/io_cache.c @@ -60,7 +60,7 @@ static int cachefile_open_invoke(bContext *C, wmOperator *op, const wmEvent *eve char filepath[FILE_MAX]; Main *bmain = CTX_data_main(C); - BLI_strncpy(filepath, bmain->name, sizeof(filepath)); + BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath)); BLI_replace_extension(filepath, sizeof(filepath), ".abc"); RNA_string_set(op->ptr, "filepath", filepath); } diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index 83f5af0709d..d61eb80e9bc 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -60,13 +60,16 @@ static int wm_collada_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { + Main *bmain = CTX_data_main(C); + if (!RNA_struct_property_is_set(op->ptr, "filepath")) { char filepath[FILE_MAX]; + const char *blendfile_path = BKE_main_blendfile_path(bmain); - if (G.main->name[0] == 0) + if (blendfile_path[0] == '\0') BLI_strncpy(filepath, "untitled", sizeof(filepath)); else - BLI_strncpy(filepath, G.main->name, sizeof(filepath)); + BLI_strncpy(filepath, blendfile_path, sizeof(filepath)); BLI_replace_extension(filepath, sizeof(filepath), ".dae"); RNA_string_set(op->ptr, "filepath", filepath); diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c index 3e0f62154ac..c9be331b6d5 100644 --- a/source/blender/editors/object/object_bake_api.c +++ b/source/blender/editors/object/object_bake_api.c @@ -1010,7 +1010,8 @@ cage_cleanup: BakeData *bake = &scene->r.bake; char name[FILE_MAX]; - BKE_image_path_from_imtype(name, filepath, bmain->name, 0, bake->im_format.imtype, true, false, NULL); + BKE_image_path_from_imtype(name, filepath, BKE_main_blendfile_path(bmain), + 0, bake->im_format.imtype, true, false, NULL); if (is_automatic_name) { BLI_path_suffix(name, FILE_MAX, ob_low->id.name + 2, "_"); diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index c79be8ed223..b42732bd25d 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -1308,7 +1308,7 @@ static int multires_external_save_exec(bContext *C, wmOperator *op) RNA_string_get(op->ptr, "filepath", path); if (relative) - BLI_path_rel(path, bmain->name); + BLI_path_rel(path, BKE_main_blendfile_path(bmain)); CustomData_external_add(&me->ldata, &me->id, CD_MDISPS, me->totloop, path); CustomData_external_write(&me->ldata, &me->id, CD_MASK_MESH, me->totloop, 0); diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index cdbfac06422..53849e0b3f3 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -407,7 +407,7 @@ static void screen_opengl_render_write(OGLRender *oglrender) rr = RE_AcquireResultRead(oglrender->re); BKE_image_path_from_imformat( - name, scene->r.pic, oglrender->bmain->name, scene->r.cfra, + name, scene->r.pic, BKE_main_blendfile_path(oglrender->bmain), scene->r.cfra, &scene->r.im_format, (scene->r.scemode & R_EXTENSION) != 0, false, NULL); /* write images as individual images or stereo */ @@ -936,7 +936,7 @@ static void write_result_func(TaskPool * __restrict pool, char name[FILE_MAX]; BKE_image_path_from_imformat(name, scene->r.pic, - oglrender->bmain->name, + BKE_main_blendfile_path(oglrender->bmain), cfra, &scene->r.im_format, (scene->r.scemode & R_EXTENSION) != 0, @@ -1027,7 +1027,7 @@ static bool screen_opengl_render_anim_step(bContext *C, wmOperator *op) if (!is_movie) { BKE_image_path_from_imformat( - name, scene->r.pic, oglrender->bmain->name, scene->r.cfra, + name, scene->r.pic, BKE_main_blendfile_path(oglrender->bmain), scene->r.cfra, &scene->r.im_format, (scene->r.scemode & R_EXTENSION) != 0, true, NULL); if ((scene->r.mode & R_NO_OVERWRITE) && BLI_exists(name)) { diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index dc79d5d9847..808e36a0d90 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -114,7 +114,7 @@ ImBuf *get_brush_icon(Brush *brush) // first use the path directly to try and load the file BLI_strncpy(path, brush->icon_filepath, sizeof(brush->icon_filepath)); - BLI_path_abs(path, G.main->name); + BLI_path_abs(path, BKE_main_blendfile_path_from_global()); /* use default colorspaces for brushes */ brush->icon_imbuf = IMB_loadiffname(path, flags, NULL); @@ -123,7 +123,7 @@ ImBuf *get_brush_icon(Brush *brush) if (!(brush->icon_imbuf)) { folder = BKE_appdir_folder_id(BLENDER_DATAFILES, "brushicons"); - BLI_make_file_string(G.main->name, path, folder, brush->icon_filepath); + BLI_make_file_string(BKE_main_blendfile_path_from_global(), path, folder, brush->icon_filepath); if (path[0]) { /* use fefault color spaces */ @@ -278,7 +278,7 @@ static Scene *preview_prepare_scene(Main *bmain, Scene *scene, ID *id, int id_ty Base *base; Main *pr_main = sp->pr_main; - memcpy(pr_main->name, bmain->name, sizeof(pr_main->name)); + memcpy(pr_main->name, BKE_main_blendfile_path(bmain), sizeof(pr_main->name)); sce = preview_get_scene(pr_main); if (sce) { diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index fe87f8bdbb2..2083317f6a7 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -1572,13 +1572,14 @@ static int envmap_save_exec(bContext *C, wmOperator *op) static int envmap_save_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { + Main *bmain = CTX_data_main(C); //Scene *scene= CTX_data_scene(C); if (RNA_struct_property_is_set(op->ptr, "filepath")) return envmap_save_exec(C, op); //RNA_enum_set(op->ptr, "file_type", scene->r.im_format.imtype); - RNA_string_set(op->ptr, "filepath", G.main->name); + RNA_string_set(op->ptr, "filepath", BKE_main_blendfile_path(bmain)); WM_event_add_fileselect(C, op); return OPERATOR_RUNNING_MODAL; diff --git a/source/blender/editors/screen/screendump.c b/source/blender/editors/screen/screendump.c index 8274ca68d7e..ec01aceeb6c 100644 --- a/source/blender/editors/screen/screendump.c +++ b/source/blender/editors/screen/screendump.c @@ -192,7 +192,7 @@ static int screenshot_exec(bContext *C, wmOperator *op) char path[FILE_MAX]; RNA_string_get(op->ptr, "filepath", path); - BLI_path_abs(path, G.main->name); + BLI_path_abs(path, BKE_main_blendfile_path_from_global()); /* operator ensures the extension */ ibuf = IMB_allocImBuf(scd->dumpsx, scd->dumpsy, 24, 0); @@ -231,7 +231,7 @@ static int screenshot_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED( /* extension is added by 'screenshot_check' after */ char filepath[FILE_MAX] = "//screen"; if (G.relbase_valid) { - BLI_strncpy(filepath, G.main->name, sizeof(filepath)); + BLI_strncpy(filepath, BKE_main_blendfile_path_from_global(), sizeof(filepath)); BLI_replace_extension(filepath, sizeof(filepath), ""); /* strip '.blend' */ } RNA_string_set(op->ptr, "filepath", filepath); @@ -407,7 +407,7 @@ static void screenshot_startjob(void *sjv, short *stop, short *do_update, float int ok; BKE_image_path_from_imformat( - name, rd.pic, sj->bmain->name, rd.cfra, + name, rd.pic, BKE_main_blendfile_path(sj->bmain), rd.cfra, &rd.im_format, (rd.scemode & R_EXTENSION) != 0, true, NULL); ibuf->rect = sj->dumprect; diff --git a/source/blender/editors/sound/sound_ops.c b/source/blender/editors/sound/sound_ops.c index a7660092e6d..ad8469a7c6a 100644 --- a/source/blender/editors/sound/sound_ops.c +++ b/source/blender/editors/sound/sound_ops.c @@ -374,7 +374,7 @@ static int sound_mixdown_exec(bContext *C, wmOperator *op) specs.rate = scene->r.ffcodecdata.audio_mixrate; BLI_strncpy(filename, path, sizeof(filename)); - BLI_path_abs(filename, bmain->name); + BLI_path_abs(filename, BKE_main_blendfile_path(bmain)); if (split) result = AUD_mixdown_per_channel(scene->sound_scene, SFRA * specs.rate / FPS, (EFRA - SFRA + 1) * specs.rate / FPS, diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c index 813f4202a49..47f97b8087f 100644 --- a/source/blender/editors/space_buttons/buttons_ops.c +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -102,6 +102,7 @@ typedef struct FileBrowseOp { static int file_browse_exec(bContext *C, wmOperator *op) { + Main *bmain = CTX_data_main(C); FileBrowseOp *fbo = op->customdata; ID *id; char *str, path[FILE_MAX]; @@ -118,14 +119,14 @@ static int file_browse_exec(bContext *C, wmOperator *op) id = fbo->ptr.id.data; BLI_strncpy(path, str, FILE_MAX); - BLI_path_abs(path, id ? ID_BLEND_PATH(G.main, id) : G.main->name); + BLI_path_abs(path, id ? ID_BLEND_PATH(bmain, id) : BKE_main_blendfile_path(bmain)); if (BLI_is_dir(path)) { /* do this first so '//' isnt converted to '//\' on windows */ BLI_add_slash(path); if (is_relative) { BLI_strncpy(path, str, FILE_MAX); - BLI_path_rel(path, G.main->name); + BLI_path_rel(path, BKE_main_blendfile_path(bmain)); str = MEM_reallocN(str, strlen(path) + 2); BLI_strncpy(str, path, FILE_MAX); } diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index af5a33bbebe..172ea0f8554 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -317,7 +317,7 @@ static int reload_exec(bContext *C, wmOperator *UNUSED(op)) if (!clip) return OPERATOR_CANCELLED; - BKE_movieclip_reload(clip); + BKE_movieclip_reload(CTX_data_main(C), clip); WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip); @@ -1314,7 +1314,7 @@ static void proxy_endjob(void *pjv) if (pj->clip->source == MCLIP_SRC_MOVIE) { /* Timecode might have changed, so do a full reload to deal with this. */ - BKE_movieclip_reload(pj->clip); + BKE_movieclip_reload(pj->main, pj->clip); } else { /* For image sequences we'll preserve original cache. */ diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index befdf6751ee..fd9a9ff9ab1 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -412,6 +412,7 @@ static void file_draw_preview( static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname) { + Main *bmain = CTX_data_main(C); char newname[FILE_MAX + 12]; char orgname[FILE_MAX + 12]; char filename[FILE_MAX + 12]; @@ -420,10 +421,11 @@ static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname) ScrArea *sa = CTX_wm_area(C); ARegion *ar = CTX_wm_region(C); - BLI_make_file_string(G.main->name, orgname, sfile->params->dir, oldname); + const char *blendfile_path = BKE_main_blendfile_path(bmain); + BLI_make_file_string(blendfile_path, orgname, sfile->params->dir, oldname); BLI_strncpy(filename, sfile->params->renameedit, sizeof(filename)); BLI_filename_make_safe(filename); - BLI_make_file_string(G.main->name, newname, sfile->params->dir, filename); + BLI_make_file_string(blendfile_path, newname, sfile->params->dir, filename); if (!STREQ(orgname, newname)) { if (!BLI_exists(newname)) { diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index 977d9fe7f3a..742715039cf 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -109,9 +109,9 @@ void file_filename_enter_handle(bContext *C, void *arg_unused, void *arg_but); int file_highlight_set(struct SpaceFile *sfile, struct ARegion *ar, int mx, int my); void file_sfile_filepath_set(struct SpaceFile *sfile, const char *filepath); -void file_sfile_to_operator_ex(struct wmOperator *op, struct SpaceFile *sfile, char *filepath); -void file_sfile_to_operator(struct wmOperator *op, struct SpaceFile *sfile); -void file_operator_to_sfile(struct SpaceFile *sfile, struct wmOperator *op); +void file_sfile_to_operator_ex(bContext *C, struct wmOperator *op, struct SpaceFile *sfile, char *filepath); +void file_sfile_to_operator(bContext *C, struct wmOperator *op, struct SpaceFile *sfile); +void file_operator_to_sfile(bContext *C, struct SpaceFile *sfile, struct wmOperator *op); /* filesel.c */ diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 828cca53012..0cd31ce7ca5 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -176,6 +176,7 @@ static FileSelection file_selection_get(bContext *C, const rcti *rect, bool fill static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen) { + Main *bmain = CTX_data_main(C); FileSelect retval = FILE_SELECT_NOTHING; SpaceFile *sfile = CTX_wm_space_file(C); FileSelectParams *params = ED_fileselect_get_params(sfile); @@ -213,7 +214,7 @@ static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen) } } else { - BLI_cleanup_dir(G.main->name, params->dir); + BLI_cleanup_dir(BKE_main_blendfile_path(bmain), params->dir); strcat(params->dir, file->relpath); BLI_add_slash(params->dir); } @@ -826,6 +827,7 @@ void FILE_OT_select_all_toggle(wmOperatorType *ot) /* Note we could get rid of this one, but it's used by some addon so... Does not hurt keeping it around for now. */ static int bookmark_select_exec(bContext *C, wmOperator *op) { + Main *bmain = CTX_data_main(C); SpaceFile *sfile = CTX_wm_space_file(C); PropertyRNA *prop; @@ -835,7 +837,7 @@ static int bookmark_select_exec(bContext *C, wmOperator *op) RNA_property_string_get(op->ptr, prop, entry); BLI_strncpy(params->dir, entry, sizeof(params->dir)); - BLI_cleanup_dir(G.main->name, params->dir); + BLI_cleanup_dir(BKE_main_blendfile_path(bmain), params->dir); ED_file_change_dir(C); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); @@ -1200,15 +1202,16 @@ void FILE_OT_cancel(struct wmOperatorType *ot) } -void file_sfile_to_operator_ex(wmOperator *op, SpaceFile *sfile, char *filepath) +void file_sfile_to_operator_ex(bContext *C, wmOperator *op, SpaceFile *sfile, char *filepath) { + Main *bmain = CTX_data_main(C); PropertyRNA *prop; BLI_join_dirfile(filepath, FILE_MAX, sfile->params->dir, sfile->params->file); /* XXX, not real length */ if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) { if (RNA_property_boolean_get(op->ptr, prop)) { - BLI_path_rel(filepath, G.main->name); + BLI_path_rel(filepath, BKE_main_blendfile_path(bmain)); } } @@ -1270,15 +1273,16 @@ void file_sfile_to_operator_ex(wmOperator *op, SpaceFile *sfile, char *filepath) } } -void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile) +void file_sfile_to_operator(bContext *C, wmOperator *op, SpaceFile *sfile) { char filepath[FILE_MAX]; - file_sfile_to_operator_ex(op, sfile, filepath); + file_sfile_to_operator_ex(C, op, sfile, filepath); } -void file_operator_to_sfile(SpaceFile *sfile, wmOperator *op) +void file_operator_to_sfile(bContext *C, SpaceFile *sfile, wmOperator *op) { + Main *bmain = CTX_data_main(C); PropertyRNA *prop; /* If neither of the above are set, split the filepath back */ @@ -1298,7 +1302,7 @@ void file_operator_to_sfile(SpaceFile *sfile, wmOperator *op) /* we could check for relative_path property which is used when converting * in the other direction but doesnt hurt to do this every time */ - BLI_path_abs(sfile->params->dir, G.main->name); + BLI_path_abs(sfile->params->dir, BKE_main_blendfile_path(bmain)); /* XXX, files and dirs updates missing, not really so important though */ } @@ -1330,11 +1334,11 @@ void file_draw_check(bContext *C) wmOperator *op = sfile->op; if (op) { /* fail on reload */ if (op->type->check) { - file_sfile_to_operator(op, sfile); + file_sfile_to_operator(C, op, sfile); /* redraw */ if (op->type->check(C, op)) { - file_operator_to_sfile(sfile, op); + file_operator_to_sfile(C, sfile, op); /* redraw, else the changed settings wont get updated */ ED_area_tag_redraw(CTX_wm_area(C)); @@ -1369,6 +1373,7 @@ bool file_draw_check_exists(SpaceFile *sfile) int file_exec(bContext *C, wmOperator *exec_op) { + Main *bmain = CTX_data_main(C); wmWindowManager *wm = CTX_wm_manager(C); SpaceFile *sfile = CTX_wm_space_file(C); const struct FileDirEntry *file = filelist_file(sfile->files, sfile->params->active_file); @@ -1384,7 +1389,7 @@ int file_exec(bContext *C, wmOperator *exec_op) BLI_parent_dir(sfile->params->dir); } else { - BLI_cleanup_path(G.main->name, sfile->params->dir); + BLI_cleanup_path(BKE_main_blendfile_path(bmain), sfile->params->dir); BLI_path_append(sfile->params->dir, sizeof(sfile->params->dir) - 1, file->relpath); BLI_add_slash(sfile->params->dir); } @@ -1413,14 +1418,14 @@ int file_exec(bContext *C, wmOperator *exec_op) sfile->op = NULL; - file_sfile_to_operator_ex(op, sfile, filepath); + file_sfile_to_operator_ex(C, op, sfile, filepath); if (BLI_exists(sfile->params->dir)) { fsmenu_insert_entry(ED_fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir, NULL, FS_INSERT_SAVE | FS_INSERT_FIRST); } - BLI_make_file_string(G.main->name, filepath, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), + BLI_make_file_string(BKE_main_blendfile_path(bmain), filepath, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE); fsmenu_write_file(ED_fsmenu_get(), filepath); WM_event_fileselect_event(wm, op, EVT_FILESELECT_EXEC); @@ -1452,11 +1457,12 @@ void FILE_OT_execute(struct wmOperatorType *ot) int file_parent_exec(bContext *C, wmOperator *UNUSED(unused)) { + Main *bmain = CTX_data_main(C); SpaceFile *sfile = CTX_wm_space_file(C); if (sfile->params) { if (BLI_parent_dir(sfile->params->dir)) { - BLI_cleanup_dir(G.main->name, sfile->params->dir); + BLI_cleanup_dir(BKE_main_blendfile_path(bmain), sfile->params->dir); ED_file_change_dir(C); if (sfile->params->recursion_level > 1) { /* Disable 'dirtree' recursion when going up in tree. */ @@ -1694,7 +1700,7 @@ static int filepath_drop_exec(bContext *C, wmOperator *op) file_sfile_filepath_set(sfile, filepath); if (sfile->op) { - file_sfile_to_operator(sfile->op, sfile); + file_sfile_to_operator(C, sfile->op, sfile); file_draw_check(C); } @@ -1840,12 +1846,13 @@ void FILE_OT_directory_new(struct wmOperatorType *ot) /* TODO This should go to BLI_path_utils. */ static void file_expand_directory(bContext *C) { + Main *bmain = CTX_data_main(C); SpaceFile *sfile = CTX_wm_space_file(C); if (sfile->params) { if (BLI_path_is_rel(sfile->params->dir)) { /* Use of 'default' folder here is just to avoid an error message on '//' prefix. */ - BLI_path_abs(sfile->params->dir, G.relbase_valid ? G.main->name : BKE_appdir_folder_default()); + BLI_path_abs(sfile->params->dir, G.relbase_valid ? BKE_main_blendfile_path(bmain) : BKE_appdir_folder_default()); } else if (sfile->params->dir[0] == '~') { char tmpstr[sizeof(sfile->params->dir) - 1]; @@ -1898,6 +1905,7 @@ static bool can_create_dir(const char *dir) void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UNUSED(arg_but)) { + Main *bmain = CTX_data_main(C); SpaceFile *sfile = CTX_wm_space_file(C); if (sfile->params) { @@ -1928,7 +1936,7 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN } } - BLI_cleanup_dir(G.main->name, sfile->params->dir); + BLI_cleanup_dir(BKE_main_blendfile_path(bmain), sfile->params->dir); if (filelist_is_dir(sfile->files, sfile->params->dir)) { /* if directory exists, enter it immediately */ @@ -1975,6 +1983,7 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN void file_filename_enter_handle(bContext *C, void *UNUSED(arg_unused), void *arg_but) { + Main *bmain = CTX_data_main(C); SpaceFile *sfile = CTX_wm_space_file(C); uiBut *but = arg_but; char matched_file[FILE_MAX]; @@ -2004,7 +2013,7 @@ void file_filename_enter_handle(bContext *C, void *UNUSED(arg_unused), void *arg /* if directory, open it and empty filename field */ if (filelist_is_dir(sfile->files, filepath)) { - BLI_cleanup_dir(G.main->name, filepath); + BLI_cleanup_dir(BKE_main_blendfile_path(bmain), filepath); BLI_strncpy(sfile->params->dir, filepath, sizeof(sfile->params->dir)); sfile->params->file[0] = '\0'; ED_file_change_dir(C); @@ -2269,6 +2278,7 @@ static int file_delete_poll(bContext *C) int file_delete_exec(bContext *C, wmOperator *op) { char str[FILE_MAX]; + Main *bmain = CTX_data_main(C); wmWindowManager *wm = CTX_wm_manager(C); SpaceFile *sfile = CTX_wm_space_file(C); ScrArea *sa = CTX_wm_area(C); @@ -2281,7 +2291,7 @@ int file_delete_exec(bContext *C, wmOperator *op) for (i = 0; i < numfiles; i++) { if (filelist_entry_select_index_get(sfile->files, i, CHECK_FILES)) { file = filelist_file(sfile->files, i); - BLI_make_file_string(G.main->name, str, sfile->params->dir, file->relpath); + BLI_make_file_string(BKE_main_blendfile_path(bmain), str, sfile->params->dir, file->relpath); if (BLI_delete(str, false, false) != 0 || BLI_exists(str)) { diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index c975479e402..0dd0aca48c6 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -1419,7 +1419,7 @@ void filelist_setdir(struct FileList *filelist, char *r_dir) { BLI_assert(strlen(r_dir) < FILE_MAX_LIBEXTRA); - BLI_cleanup_dir(G.main->name, r_dir); + BLI_cleanup_dir(BKE_main_blendfile_path_from_global(), r_dir); const bool is_valid_path = filelist->checkdirf(filelist, r_dir, true); BLI_assert(is_valid_path); UNUSED_VARS_NDEBUG(is_valid_path); @@ -2700,13 +2700,14 @@ static void filelist_readjob_free(void *flrjv) void filelist_readjob_start(FileList *filelist, const bContext *C) { + Main *bmain = CTX_data_main(C); wmJob *wm_job; FileListReadJob *flrj; /* prepare job data */ flrj = MEM_callocN(sizeof(*flrj), __func__); flrj->filelist = filelist; - BLI_strncpy(flrj->main_name, G.main->name, sizeof(flrj->main_name)); + BLI_strncpy(flrj->main_name, BKE_main_blendfile_path(bmain), sizeof(flrj->main_name)); filelist->flags &= ~(FL_FORCE_RESET | FL_IS_READY); filelist->flags |= FL_IS_PENDING; diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 99307b1961d..4723ee07a7d 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -96,11 +96,13 @@ short ED_fileselect_set_params(SpaceFile *sfile) FileSelectParams *params; wmOperator *op = sfile->op; + const char *blendfile_path = BKE_main_blendfile_path_from_global(); + /* create new parameters if necessary */ if (!sfile->params) { sfile->params = MEM_callocN(sizeof(FileSelectParams), "fileselparams"); /* set path to most recently opened .blend */ - BLI_split_dirfile(G.main->name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file)); + BLI_split_dirfile(blendfile_path, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file)); sfile->params->filter_glob[0] = '\0'; /* set the default thumbnails size */ sfile->params->thumbnail_size = 128; @@ -149,8 +151,8 @@ short ED_fileselect_set_params(SpaceFile *sfile) } if (params->dir[0]) { - BLI_cleanup_dir(G.main->name, params->dir); - BLI_path_abs(params->dir, G.main->name); + BLI_cleanup_dir(blendfile_path, params->dir); + BLI_path_abs(params->dir, blendfile_path); } if (is_directory == true && is_filename == false && is_filepath == false && is_files == false) { @@ -282,8 +284,8 @@ short ED_fileselect_set_params(SpaceFile *sfile) sfile->folders_prev = folderlist_new(); if (!sfile->params->dir[0]) { - if (G.main->name[0]) { - BLI_split_dir_part(G.main->name, sfile->params->dir, sizeof(sfile->params->dir)); + if (blendfile_path[0] != '\0') { + BLI_split_dir_part(blendfile_path, sfile->params->dir, sizeof(sfile->params->dir)); } else { const char *doc_path = BKE_appdir_folder_default(); diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index dea1f761073..bfebc850b08 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -226,7 +226,7 @@ static int space_image_file_exists_poll(bContext *C) ibuf = ED_space_image_acquire_buffer(sima, &lock); if (ibuf) { BLI_strncpy(name, ibuf->name, FILE_MAX); - BLI_path_abs(name, bmain->name); + BLI_path_abs(name, BKE_main_blendfile_path(bmain)); if (BLI_exists(name) == false) { CTX_wm_operator_poll_msg_set(C, "image file not found"); @@ -1259,11 +1259,11 @@ static int image_open_exec(bContext *C, wmOperator *op) BLI_strncpy(filepath_range, frame_range->filepath, sizeof(filepath_range)); if (was_relative) { - BLI_path_rel(filepath_range, bmain->name); + BLI_path_rel(filepath_range, BKE_main_blendfile_path(bmain)); } Image *ima_range = image_open_single( - op, filepath_range, bmain->name, + op, filepath_range, BKE_main_blendfile_path(bmain), is_relative_path, use_multiview, frame_range_seq_len); /* take the first image */ @@ -1278,7 +1278,7 @@ static int image_open_exec(bContext *C, wmOperator *op) else { /* for drag & drop etc. */ ima = image_open_single( - op, filepath, bmain->name, + op, filepath, BKE_main_blendfile_path(bmain), is_relative_path, use_multiview, 1); } @@ -1686,12 +1686,12 @@ static int save_image_options_init(Main *bmain, SaveImageOptions *simopts, Space } else { BLI_strncpy(simopts->filepath, "//untitled", sizeof(simopts->filepath)); - BLI_path_abs(simopts->filepath, bmain->name); + BLI_path_abs(simopts->filepath, BKE_main_blendfile_path(bmain)); } } else { BLI_snprintf(simopts->filepath, sizeof(simopts->filepath), "//%s", ima->id.name + 2); - BLI_path_abs(simopts->filepath, is_prev_save ? G.ima : bmain->name); + BLI_path_abs(simopts->filepath, is_prev_save ? G.ima : BKE_main_blendfile_path(bmain)); } } @@ -1715,7 +1715,7 @@ static void save_image_options_from_op(Main *bmain, SaveImageOptions *simopts, w if (RNA_struct_property_is_set(op->ptr, "filepath")) { RNA_string_get(op->ptr, "filepath", simopts->filepath); - BLI_path_abs(simopts->filepath, bmain->name); + BLI_path_abs(simopts->filepath, BKE_main_blendfile_path(bmain)); } } @@ -2296,7 +2296,7 @@ static int image_save_sequence_exec(bContext *C, wmOperator *op) char name[FILE_MAX]; BLI_strncpy(name, ibuf->name, sizeof(name)); - BLI_path_abs(name, bmain->name); + BLI_path_abs(name, BKE_main_blendfile_path(bmain)); if (0 == IMB_saveiff(ibuf, name, IB_rect | IB_zbuf | IB_zbuffloat)) { BKE_reportf(op->reports, RPT_ERROR, "Could not write image: %s", strerror(errno)); diff --git a/source/blender/editors/space_info/info_ops.c b/source/blender/editors/space_info/info_ops.c index 981630e96f6..acd0a856f1a 100644 --- a/source/blender/editors/space_info/info_ops.c +++ b/source/blender/editors/space_info/info_ops.c @@ -364,7 +364,7 @@ static int make_paths_relative_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - BKE_bpath_relative_convert(bmain, bmain->name, op->reports); + BKE_bpath_relative_convert(bmain, BKE_main_blendfile_path(bmain), op->reports); /* redraw everything so any changed paths register */ WM_main_add_notifier(NC_WINDOW, NULL); @@ -397,7 +397,7 @@ static int make_paths_absolute_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - BKE_bpath_absolute_convert(bmain, bmain->name, op->reports); + BKE_bpath_absolute_convert(bmain, BKE_main_blendfile_path(bmain), op->reports); /* redraw everything so any changed paths register */ WM_main_add_notifier(NC_WINDOW, NULL); diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index 0ea69164034..ec7fd99ee5e 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -497,7 +497,7 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname) BKE_library_filepath_set(bmain, lib, lib->name); BLI_strncpy(expanded, lib->name, sizeof(expanded)); - BLI_path_abs(expanded, bmain->name); + BLI_path_abs(expanded, BKE_main_blendfile_path(bmain)); if (!BLI_exists(expanded)) { BKE_reportf(CTX_wm_reports(C), RPT_ERROR, "Library path '%s' does not exist, correct this before saving", expanded); diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index 98370ea9dee..5c332925011 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -117,7 +117,7 @@ static void sequencer_generic_invoke_path__internal(bContext *C, wmOperator *op, Main *bmain = CTX_data_main(C); char path[FILE_MAX]; BLI_strncpy(path, last_seq->strip->dir, sizeof(path)); - BLI_path_abs(path, bmain->name); + BLI_path_abs(path, BKE_main_blendfile_path(bmain)); RNA_string_set(op->ptr, identifier, path); } } @@ -199,7 +199,7 @@ static void seq_load_operator_info(SeqLoadInfo *seq_load, bContext *C, wmOperato } if ((is_file != -1) && relative) - BLI_path_rel(seq_load->path, bmain->name); + BLI_path_rel(seq_load->path, BKE_main_blendfile_path(bmain)); if ((prop = RNA_struct_find_property(op->ptr, "frame_end"))) { diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index 97ff55bf883..e93a18449b0 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -3773,7 +3773,7 @@ static int sequencer_change_path_exec(bContext *C, wmOperator *op) /* TODO, shouldn't this already be relative from the filesel? * (as the 'filepath' is) for now just make relative here, * but look into changing after 2.60 - campbell */ - BLI_path_rel(directory, bmain->name); + BLI_path_rel(directory, BKE_main_blendfile_path(bmain)); } BLI_strncpy(seq->strip->dir, directory, sizeof(seq->strip->dir)); @@ -3889,10 +3889,10 @@ static int sequencer_export_subtitles_invoke(bContext *C, wmOperator *op, const if (!RNA_struct_property_is_set(op->ptr, "filepath")) { char filepath[FILE_MAX]; - if (bmain->name[0] == '\0') + if (BKE_main_blendfile_path(bmain)[0] == '\0') BLI_strncpy(filepath, "untitled", sizeof(filepath)); else - BLI_strncpy(filepath, bmain->name, sizeof(filepath)); + BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath)); BLI_replace_extension(filepath, sizeof(filepath), ".srt"); RNA_string_set(op->ptr, "filepath", filepath); diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 3c2d3c557f6..de5ff36f462 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -234,7 +234,7 @@ static int text_open_exec(bContext *C, wmOperator *op) RNA_string_get(op->ptr, "filepath", str); - text = BKE_text_load_ex(bmain, str, bmain->name, internal); + text = BKE_text_load_ex(bmain, str, BKE_main_blendfile_path(bmain), internal); if (!text) { if (op->customdata) MEM_freeN(op->customdata); @@ -274,7 +274,7 @@ static int text_open_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(e { Main *bmain = CTX_data_main(C); Text *text = CTX_data_edit_text(C); - const char *path = (text && text->name) ? text->name : bmain->name; + const char *path = (text && text->name) ? text->name : BKE_main_blendfile_path(bmain); if (RNA_struct_property_is_set(op->ptr, "filepath")) return text_open_exec(C, op); @@ -465,7 +465,7 @@ static void txt_write_file(Main *bmain, Text *text, ReportList *reports) char filepath[FILE_MAX]; BLI_strncpy(filepath, text->name, FILE_MAX); - BLI_path_abs(filepath, bmain->name); + BLI_path_abs(filepath, BKE_main_blendfile_path(bmain)); fp = BLI_fopen(filepath, "w"); if (fp == NULL) { @@ -562,7 +562,7 @@ static int text_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE else if (text->flags & TXT_ISMEM) str = text->id.name + 2; else - str = bmain->name; + str = BKE_main_blendfile_path(bmain); RNA_string_set(op->ptr, "filepath", str); WM_event_add_fileselect(C, op); diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index 7c3e24c3cc9..8175f494cf0 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -254,7 +254,7 @@ void unpack_menu(bContext *C, const char *opname, const char *id_name, const cha BLI_split_file_part(abs_name, fi, sizeof(fi)); BLI_snprintf(local_name, sizeof(local_name), "//%s/%s", folder, fi); if (!STREQ(abs_name, local_name)) { - switch (checkPackedFile(bmain->name, local_name, pf)) { + switch (checkPackedFile(BKE_main_blendfile_path(bmain), local_name, pf)) { case PF_NOFILE: BLI_snprintf(line, sizeof(line), IFACE_("Create %s"), local_name); uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); @@ -287,7 +287,7 @@ void unpack_menu(bContext *C, const char *opname, const char *id_name, const cha } } - switch (checkPackedFile(bmain->name, abs_name, pf)) { + switch (checkPackedFile(BKE_main_blendfile_path(bmain), abs_name, pf)) { case PF_NOFILE: BLI_snprintf(line, sizeof(line), IFACE_("Create %s"), abs_name); //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL); -- cgit v1.2.3