From 1d97e948d2c4867306e7fb5ce5fccf8b72c13391 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 5 Jun 2018 15:08:28 +0200 Subject: Cleanup: add hleper functions to get filepath from Main. This helps making things clearer and cleaner. Func returning filepath of G.main is separate, so that we can easily track its usages, and hopefully deprecate it at some point. Though that usage of G.main is likely the less evil one, you nearly always want current blendfile path in those cases anyway. --- source/blender/blenkernel/BKE_library.h | 3 +++ source/blender/blenkernel/intern/library.c | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index ad97eb62773..1c64aa63917 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -174,6 +174,9 @@ struct BlendThumbnail *BKE_main_thumbnail_from_imbuf(struct Main *bmain, struct struct ImBuf *BKE_main_thumbnail_to_imbuf(struct Main *bmain, struct BlendThumbnail *data); void BKE_main_thumbnail_create(struct Main *bmain); +const char *BKE_main_blendfile_path(struct Main *bmain) ATTR_NONNULL(); +const char *BKE_main_blendfile_path_from_global(void); + void BKE_main_id_tag_idcode(struct Main *mainvar, const short type, const int tag, const bool value); void BKE_main_id_tag_listbase(struct ListBase *lb, const int tag, const bool value); void BKE_main_id_tag_all(struct Main *mainvar, const int tag, const bool value); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 70ee3cbe5f3..1caa0f381c5 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -152,7 +152,7 @@ * also note that the id _must_ have a library - campbell */ void BKE_id_lib_local_paths(Main *bmain, Library *lib, ID *id) { - const char *bpath_user_data[2] = {bmain->name, lib->filepath}; + const char *bpath_user_data[2] = {BKE_main_blendfile_path(bmain), lib->filepath}; BKE_bpath_traverse_id(bmain, id, BKE_bpath_relocate_visitor, @@ -1593,6 +1593,24 @@ void BKE_main_thumbnail_create(struct Main *bmain) bmain->blen_thumb->height = BLEN_THUMB_SIZE; } +/** + * Return filepath of given \a main. + */ +const char *BKE_main_blendfile_path(Main *bmain) +{ + return bmain->name; +} + +/** + * Return filepath of global main (G.main). + * + * \warning Usage is not recommended, you should always try to get a velid Main pointer from context... + */ +const char *BKE_main_blendfile_path_from_global(void) +{ + return BKE_main_blendfile_path(G.main); +} + /* ***************** ID ************************ */ ID *BKE_libblock_find_name(struct Main *bmain, const short type, const char *name) { @@ -2381,7 +2399,7 @@ void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath) */ /* Never make paths relative to parent lib - reading code (blenloader) always set *all* lib->name relative to * current main, not to their parent for indirectly linked ones. */ - const char *basepath = bmain->name; + const char *basepath = BKE_main_blendfile_path(bmain); BLI_path_abs(lib->filepath, basepath); } } -- cgit v1.2.3 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/blenkernel/BKE_library.h | 2 +- source/blender/blenkernel/BKE_movieclip.h | 2 +- source/blender/blenkernel/intern/blender_undo.c | 7 +++-- source/blender/blenkernel/intern/blendfile.c | 42 +++++++++++++------------ source/blender/blenkernel/intern/bpath.c | 2 +- source/blender/blenkernel/intern/dynamicpaint.c | 2 +- source/blender/blenkernel/intern/font.c | 6 ++-- source/blender/blenkernel/intern/image.c | 9 +++--- source/blender/blenkernel/intern/library.c | 2 +- source/blender/blenkernel/intern/movieclip.c | 18 +++++------ source/blender/blenkernel/intern/packedFile.c | 14 ++++----- source/blender/blenkernel/intern/pointcache.c | 2 +- source/blender/blenkernel/intern/scene.c | 4 +-- source/blender/blenkernel/intern/sequencer.c | 21 +++++++------ source/blender/blenkernel/intern/sound.c | 4 +-- source/blender/blenkernel/intern/text.c | 6 ++-- source/blender/blenkernel/intern/writeavi.c | 2 +- source/blender/blenkernel/intern/writeffmpeg.c | 2 +- 18 files changed, 76 insertions(+), 71 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 1c64aa63917..935e90d7ed0 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -174,7 +174,7 @@ struct BlendThumbnail *BKE_main_thumbnail_from_imbuf(struct Main *bmain, struct struct ImBuf *BKE_main_thumbnail_to_imbuf(struct Main *bmain, struct BlendThumbnail *data); void BKE_main_thumbnail_create(struct Main *bmain); -const char *BKE_main_blendfile_path(struct Main *bmain) ATTR_NONNULL(); +const char *BKE_main_blendfile_path(const struct Main *bmain) ATTR_NONNULL(); const char *BKE_main_blendfile_path_from_global(void); void BKE_main_id_tag_idcode(struct Main *mainvar, const short type, const int tag, const bool value); diff --git a/source/blender/blenkernel/BKE_movieclip.h b/source/blender/blenkernel/BKE_movieclip.h index 818f79ad8ac..b79f37fd040 100644 --- a/source/blender/blenkernel/BKE_movieclip.h +++ b/source/blender/blenkernel/BKE_movieclip.h @@ -49,7 +49,7 @@ void BKE_movieclip_make_local(struct Main *bmain, struct MovieClip *clip, const struct MovieClip *BKE_movieclip_file_add(struct Main *bmain, const char *name); struct MovieClip *BKE_movieclip_file_add_exists_ex(struct Main *bmain, const char *name, bool *r_exists); struct MovieClip *BKE_movieclip_file_add_exists(struct Main *bmain, const char *name); -void BKE_movieclip_reload(struct MovieClip *clip); +void BKE_movieclip_reload(struct Main *bmain, struct MovieClip *clip); void BKE_movieclip_clear_cache(struct MovieClip *clip); void BKE_movieclip_clear_proxy_cache(struct MovieClip *clip); diff --git a/source/blender/blenkernel/intern/blender_undo.c b/source/blender/blenkernel/intern/blender_undo.c index 6b31c8c96f9..c3306b16041 100644 --- a/source/blender/blenkernel/intern/blender_undo.c +++ b/source/blender/blenkernel/intern/blender_undo.c @@ -66,10 +66,11 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu, bContext *C) { - char mainstr[sizeof(G.main->name)]; + Main *bmain = CTX_data_main(C); + char mainstr[sizeof(bmain->name)]; int success = 0, fileflags; - BLI_strncpy(mainstr, G.main->name, sizeof(mainstr)); /* temporal store */ + BLI_strncpy(mainstr, BKE_main_blendfile_path(bmain), sizeof(mainstr)); /* temporal store */ fileflags = G.fileflags; G.fileflags |= G_FILE_NO_UI; @@ -82,7 +83,7 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu, bContext *C) } /* restore */ - BLI_strncpy(G.main->name, mainstr, sizeof(G.main->name)); /* restore */ + BLI_strncpy(bmain->name, mainstr, sizeof(bmain->name)); /* restore */ G.fileflags = fileflags; if (success) { diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c index cc992a4a520..935000e3b8e 100644 --- a/source/blender/blenkernel/intern/blendfile.c +++ b/source/blender/blenkernel/intern/blendfile.c @@ -113,6 +113,7 @@ static void setup_app_data( bContext *C, BlendFileData *bfd, const char *filepath, ReportList *reports) { + Main *bmain = G.main; /* Valid usage */ Scene *curscene = NULL; const bool is_startup = (bfd->filename[0] == '\0'); const bool recover = (G.fileflags & G_FILE_RECOVER) != 0; @@ -167,8 +168,8 @@ static void setup_app_data( bool track_undo_scene; /* comes from readfile.c */ - SWAP(ListBase, G.main->wm, bfd->main->wm); - SWAP(ListBase, G.main->screen, bfd->main->screen); + SWAP(ListBase, bmain->wm, bfd->main->wm); + SWAP(ListBase, bmain->screen, bfd->main->screen); /* we re-use current screen */ curscreen = CTX_wm_screen(C); @@ -221,9 +222,9 @@ static void setup_app_data( /* clear old property update cache, in case some old references are left dangling */ RNA_property_update_cache_free(); - G.main = bfd->main; + bmain = G.main = bfd->main; - CTX_data_main_set(C, G.main); + CTX_data_main_set(C, bmain); if (bfd->user) { /* only here free userdef themes... */ @@ -250,7 +251,7 @@ static void setup_app_data( /* Keep state from preferences. */ const int fileflags_skip = G_FILE_FLAGS_RUNTIME; G.fileflags = (G.fileflags & fileflags_skip) | (bfd->fileflags & ~fileflags_skip); - CTX_wm_manager_set(C, G.main->wm.first); + CTX_wm_manager_set(C, bmain->wm.first); CTX_wm_screen_set(C, bfd->curscreen); CTX_data_scene_set(C, bfd->curscene); CTX_wm_area_set(C, NULL); @@ -262,10 +263,10 @@ static void setup_app_data( /* this can happen when active scene was lib-linked, and doesn't exist anymore */ if (CTX_data_scene(C) == NULL) { /* in case we don't even have a local scene, add one */ - if (!G.main->scene.first) - BKE_scene_add(G.main, "Empty"); + if (!bmain->scene.first) + BKE_scene_add(bmain, "Empty"); - CTX_data_scene_set(C, G.main->scene.first); + CTX_data_scene_set(C, bmain->scene.first); CTX_wm_screen(C)->scene = CTX_data_scene(C); curscene = CTX_data_scene(C); } @@ -289,30 +290,30 @@ static void setup_app_data( /* FIXME: this version patching should really be part of the file-reading code, * but we still get too many unrelated data-corruption crashes otherwise... */ - if (G.main->versionfile < 250) - do_versions_ipos_to_animato(G.main); + if (bmain->versionfile < 250) + do_versions_ipos_to_animato(bmain); - G.main->recovered = 0; + bmain->recovered = 0; /* startup.blend or recovered startup */ if (bfd->filename[0] == 0) { - G.main->name[0] = 0; + bmain->name[0] = '\0'; } else if (recover && G.relbase_valid) { /* in case of autosave or quit.blend, use original filename instead * use relbase_valid to make sure the file is saved, else we get in the filename */ filepath = bfd->filename; - G.main->recovered = 1; + bmain->recovered = 1; /* these are the same at times, should never copy to the same location */ - if (G.main->name != filepath) - BLI_strncpy(G.main->name, filepath, FILE_MAX); + if (bmain->name != filepath) + BLI_strncpy(bmain->name, filepath, FILE_MAX); } /* baseflags, groups, make depsgraph, etc */ /* first handle case if other windows have different scenes visible */ if (mode == LOAD_UI) { - wmWindowManager *wm = G.main->wm.first; + wmWindowManager *wm = bmain->wm.first; if (wm) { wmWindow *win; @@ -320,15 +321,15 @@ static void setup_app_data( for (win = wm->windows.first; win; win = win->next) { if (win->screen && win->screen->scene) /* zealous check... */ if (win->screen->scene != curscene) - BKE_scene_set_background(G.main, win->screen->scene); + BKE_scene_set_background(bmain, win->screen->scene); } } } - BKE_scene_set_background(G.main, curscene); + BKE_scene_set_background(bmain, curscene); if (mode != LOAD_UNDO) { RE_FreeAllPersistentData(); - IMB_colormanagement_check_file_config(G.main); + IMB_colormanagement_check_file_config(bmain); } MEM_freeN(bfd); @@ -406,9 +407,10 @@ bool BKE_blendfile_read_from_memfile( bContext *C, struct MemFile *memfile, ReportList *reports, int skip_flags) { + Main *bmain = CTX_data_main(C); BlendFileData *bfd; - bfd = BLO_read_from_memfile(CTX_data_main(C), G.main->name, memfile, reports, skip_flags); + bfd = BLO_read_from_memfile(bmain, BKE_main_blendfile_path(bmain), memfile, reports, skip_flags); if (bfd) { /* remove the unused screens and wm */ while (bfd->main->wm.first) diff --git a/source/blender/blenkernel/intern/bpath.c b/source/blender/blenkernel/intern/bpath.c index 2e8c369451b..e6be42088db 100644 --- a/source/blender/blenkernel/intern/bpath.c +++ b/source/blender/blenkernel/intern/bpath.c @@ -325,7 +325,7 @@ void BKE_bpath_missing_files_find(Main *bmain, const char *searchpath, ReportLis struct BPathFind_Data data = {NULL}; const int flag = BKE_BPATH_TRAVERSE_ABS | BKE_BPATH_TRAVERSE_RELOAD_EDITED; - data.basedir = bmain->name; + data.basedir = BKE_main_blendfile_path(bmain); data.reports = reports; data.searchdir = searchpath; data.find_all = find_all; diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 954bfc90eda..87fd10c7e7d 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -3232,7 +3232,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char *filenam BKE_image_path_ensure_ext_from_imtype(output_file, format); /* Validate output file path */ - BLI_path_abs(output_file, G.main->name); + BLI_path_abs(output_file, BKE_main_blendfile_path_from_global()); BLI_make_existing_file(output_file); /* Init image buffer */ diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 5545eba8764..39be0f67c93 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -255,8 +255,8 @@ VFont *BKE_vfont_load(Main *bmain, const char *filepath) } else { BLI_split_file_part(filepath, filename, sizeof(filename)); - pf = newPackedFile(NULL, filepath, bmain->name); - temp_pf = newPackedFile(NULL, filepath, bmain->name); + pf = newPackedFile(NULL, filepath, BKE_main_blendfile_path(bmain)); + temp_pf = newPackedFile(NULL, filepath, BKE_main_blendfile_path(bmain)); is_builtin = false; } @@ -301,7 +301,7 @@ VFont *BKE_vfont_load_exists_ex(struct Main *bmain, const char *filepath, bool * char str[FILE_MAX], strtest[FILE_MAX]; BLI_strncpy(str, filepath, sizeof(str)); - BLI_path_abs(str, bmain->name); + BLI_path_abs(str, BKE_main_blendfile_path(bmain)); /* first search an identical filepath */ for (vfont = bmain->vfont.first; vfont; vfont = vfont->id.next) { diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 8fd672963c7..1d909ba1a76 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -594,7 +594,7 @@ Image *BKE_image_load(Main *bmain, const char *filepath) char str[FILE_MAX]; STRNCPY(str, filepath); - BLI_path_abs(str, bmain->name); + BLI_path_abs(str, BKE_main_blendfile_path(bmain)); /* exists? */ file = BLI_open(str, O_BINARY | O_RDONLY, 0); @@ -623,7 +623,7 @@ Image *BKE_image_load_exists_ex(const char *filepath, bool *r_exists) char str[FILE_MAX], strtest[FILE_MAX]; STRNCPY(str, filepath); - BLI_path_abs(str, G.main->name); + BLI_path_abs(str, BKE_main_blendfile_path_from_global()); /* first search an identical filepath */ for (ima = G.main->image.first; ima; ima = ima->id.next) { @@ -1652,7 +1652,8 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d time_t t; if (scene->r.stamp & R_STAMP_FILENAME) { - SNPRINTF(stamp_data->file, do_prefix ? "File %s" : "%s", G.relbase_valid ? G.main->name : ""); + SNPRINTF(stamp_data->file, do_prefix ? "File %s" : "%s", + G.relbase_valid ? BKE_main_blendfile_path_from_global() : ""); } else { stamp_data->file[0] = '\0'; @@ -4702,7 +4703,7 @@ static void image_update_views_format(Image *ima, ImageUser *iuser) char str[FILE_MAX]; STRNCPY(str, iv->filepath); - BLI_path_abs(str, G.main->name); + BLI_path_abs(str, BKE_main_blendfile_path_from_global()); /* exists? */ file = BLI_open(str, O_BINARY | O_RDONLY, 0); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 1caa0f381c5..4982c9a2f61 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -1596,7 +1596,7 @@ void BKE_main_thumbnail_create(struct Main *bmain) /** * Return filepath of given \a main. */ -const char *BKE_main_blendfile_path(Main *bmain) +const char *BKE_main_blendfile_path(const Main *bmain) { return bmain->name; } diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 9ed715d7591..65768372a28 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -199,7 +199,7 @@ static void get_proxy_fname(const MovieClip *clip, else BLI_snprintf(name, FILE_MAX, "%s/%s/proxy_%d/%08d", dir, clipfile, size, proxynr); - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, BKE_main_blendfile_path_from_global()); BLI_path_frame(name, 1, 0); strcat(name, ".jpg"); @@ -270,7 +270,7 @@ static void movieclip_open_anim_file(MovieClip *clip) if (clip->flag & MCLIP_USE_PROXY_CUSTOM_DIR) { char dir[FILE_MAX]; BLI_strncpy(dir, clip->proxy.dir, sizeof(dir)); - BLI_path_abs(dir, G.main->name); + BLI_path_abs(dir, BKE_main_blendfile_path_from_global()); IMB_anim_set_index_dir(clip->anim, dir); } } @@ -627,13 +627,13 @@ static void movieclip_load_get_size(MovieClip *clip) } } -static void detect_clip_source(MovieClip *clip) +static void detect_clip_source(Main *bmain, MovieClip *clip) { ImBuf *ibuf; char name[FILE_MAX]; BLI_strncpy(name, clip->name, sizeof(name)); - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, BKE_main_blendfile_path(bmain)); ibuf = IMB_testiffname(name, IB_rect | IB_multilayer); if (ibuf) { @@ -656,7 +656,7 @@ MovieClip *BKE_movieclip_file_add(Main *bmain, const char *name) char str[FILE_MAX]; BLI_strncpy(str, name, sizeof(str)); - BLI_path_abs(str, bmain->name); + BLI_path_abs(str, BKE_main_blendfile_path(bmain)); /* exists? */ file = BLI_open(str, O_BINARY | O_RDONLY, 0); @@ -670,7 +670,7 @@ MovieClip *BKE_movieclip_file_add(Main *bmain, const char *name) clip = movieclip_alloc(bmain, BLI_path_basename(name)); BLI_strncpy(clip->name, name, sizeof(clip->name)); - detect_clip_source(clip); + detect_clip_source(bmain, clip); movieclip_load_get_size(clip); if (clip->lastsize[0]) { @@ -690,7 +690,7 @@ MovieClip *BKE_movieclip_file_add_exists_ex(Main *bmain, const char *filepath, b char str[FILE_MAX], strtest[FILE_MAX]; BLI_strncpy(str, filepath, sizeof(str)); - BLI_path_abs(str, bmain->name); + BLI_path_abs(str, BKE_main_blendfile_path(bmain)); /* first search an identical filepath */ for (clip = bmain->movieclip.first; clip; clip = clip->id.next) { @@ -1282,13 +1282,13 @@ void BKE_movieclip_clear_proxy_cache(MovieClip *clip) } } -void BKE_movieclip_reload(MovieClip *clip) +void BKE_movieclip_reload(Main *bmain, MovieClip *clip) { /* clear cache */ free_buffers(clip); /* update clip source */ - detect_clip_source(clip); + detect_clip_source(bmain, clip); clip->lastsize[0] = clip->lastsize[1] = 0; movieclip_load_get_size(clip); diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index afb155f7646..baa88f00985 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -246,14 +246,14 @@ void packAll(Main *bmain, ReportList *reports, bool verbose) for (vfont = bmain->vfont.first; vfont; vfont = vfont->id.next) { if (vfont->packedfile == NULL && !ID_IS_LINKED(vfont) && BKE_vfont_is_builtin(vfont) == false) { - vfont->packedfile = newPackedFile(reports, vfont->name, bmain->name); + vfont->packedfile = newPackedFile(reports, vfont->name, BKE_main_blendfile_path(bmain)); tot ++; } } for (sound = bmain->sound.first; sound; sound = sound->id.next) { if (sound->packedfile == NULL && !ID_IS_LINKED(sound)) { - sound->packedfile = newPackedFile(reports, sound->name, bmain->name); + sound->packedfile = newPackedFile(reports, sound->name, BKE_main_blendfile_path(bmain)); tot++; } } @@ -542,7 +542,7 @@ int unpackVFont(Main *bmain, ReportList *reports, VFont *vfont, int how) if (vfont != NULL) { unpack_generate_paths(vfont->name, (ID *)vfont, absname, localname, sizeof(absname), sizeof(localname)); - newname = unpackFile(reports, bmain->name, absname, localname, vfont->packedfile, how); + newname = unpackFile(reports, BKE_main_blendfile_path(bmain), absname, localname, vfont->packedfile, how); if (newname != NULL) { ret_value = RET_OK; freePackedFile(vfont->packedfile); @@ -563,7 +563,7 @@ int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how) if (sound != NULL) { unpack_generate_paths(sound->name, (ID *)sound, absname, localname, sizeof(absname), sizeof(localname)); - newname = unpackFile(reports, bmain->name, absname, localname, sound->packedfile, how); + newname = unpackFile(reports, BKE_main_blendfile_path(bmain), absname, localname, sound->packedfile, how); if (newname != NULL) { BLI_strncpy(sound->name, newname, sizeof(sound->name)); MEM_freeN(newname); @@ -591,7 +591,7 @@ int unpackImage(Main *bmain, ReportList *reports, Image *ima, int how) ImagePackedFile *imapf = ima->packedfiles.last; unpack_generate_paths(imapf->filepath, (ID *)ima, absname, localname, sizeof(absname), sizeof(localname)); - newname = unpackFile(reports, bmain->name, absname, localname, imapf->packedfile, how); + newname = unpackFile(reports, BKE_main_blendfile_path(bmain), absname, localname, imapf->packedfile, how); if (newname != NULL) { ImageView *iv; @@ -637,7 +637,7 @@ int unpackLibraries(Main *bmain, ReportList *reports) for (lib = bmain->library.first; lib; lib = lib->id.next) { if (lib->packedfile && lib->name[0]) { - newname = unpackFile(reports, bmain->name, lib->filepath, lib->filepath, lib->packedfile, PF_WRITE_ORIGINAL); + newname = unpackFile(reports, BKE_main_blendfile_path(bmain), lib->filepath, lib->filepath, lib->packedfile, PF_WRITE_ORIGINAL); if (newname != NULL) { ret_value = RET_OK; @@ -670,7 +670,7 @@ void packLibraries(Main *bmain, ReportList *reports) for (lib = bmain->library.first; lib; lib = lib->id.next) if (lib->packedfile == NULL) - lib->packedfile = newPackedFile(reports, lib->name, bmain->name); + lib->packedfile = newPackedFile(reports, lib->name, BKE_main_blendfile_path(bmain)); } void unpackAll(Main *bmain, ReportList *reports, int how) diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index b6d9ba71c2c..c7dacf97624 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -1782,7 +1782,7 @@ static int ptcache_frame_from_filename(const char *filename, const char *ext) static int ptcache_path(PTCacheID *pid, char *filename) { Library *lib = (pid->ob) ? pid->ob->id.lib : NULL; - const char *blendfilename= (lib && (pid->cache->flag & PTCACHE_IGNORE_LIBPATH)==0) ? lib->filepath: G.main->name; + const char *blendfilename= (lib && (pid->cache->flag & PTCACHE_IGNORE_LIBPATH)==0) ? lib->filepath: BKE_main_blendfile_path_from_global(); size_t i; if (pid->cache->flag & PTCACHE_EXTERNAL) { diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 15ba5079ab5..8fd88b12974 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -963,11 +963,11 @@ Scene *BKE_scene_set_name(Main *bmain, const char *name) Scene *sce = (Scene *)BKE_libblock_find_name(bmain, ID_SCE, name); if (sce) { BKE_scene_set_background(bmain, sce); - printf("Scene switch for render: '%s' in file: '%s'\n", name, bmain->name); + printf("Scene switch for render: '%s' in file: '%s'\n", name, BKE_main_blendfile_path(bmain)); return sce; } - printf("Can't find scene: '%s' in file: '%s'\n", name, bmain->name); + printf("Can't find scene: '%s' in file: '%s'\n", name, BKE_main_blendfile_path(bmain)); return NULL; } diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 1b747c4a24f..f817ba7fc37 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -893,7 +893,7 @@ void BKE_sequence_reload_new_file(Scene *scene, Sequence *seq, const bool lock_r BLI_join_dirfile(path, sizeof(path), seq->strip->dir, seq->strip->stripdata->name); - BLI_path_abs(path, G.main->name); + BLI_path_abs(path, BKE_main_blendfile_path_from_global()); BKE_sequence_free_anim(seq); @@ -1540,7 +1540,7 @@ static void seq_open_anim_file(Scene *scene, Sequence *seq, bool openfile) BLI_join_dirfile(name, sizeof(name), seq->strip->dir, seq->strip->stripdata->name); - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, BKE_main_blendfile_path_from_global()); proxy = seq->strip->proxy; @@ -1557,7 +1557,7 @@ static void seq_open_anim_file(Scene *scene, Sequence *seq, bool openfile) else { BLI_strncpy(dir, seq->strip->proxy->dir, sizeof(dir)); } - BLI_path_abs(dir, G.main->name); + BLI_path_abs(dir, BKE_main_blendfile_path_from_global()); } if (is_multiview && seq->views_format == R_IMF_VIEWS_INDIVIDUAL) { @@ -1685,7 +1685,7 @@ static bool seq_proxy_get_fname(Editing *ed, Sequence *seq, int cfra, int render return false; } BLI_path_append(dir, sizeof(dir), fname); - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, BKE_main_blendfile_path_from_global()); } else if ((proxy->storage & SEQ_STORAGE_PROXY_CUSTOM_DIR) && (proxy->storage & SEQ_STORAGE_PROXY_CUSTOM_FILE)) { BLI_strncpy(dir, seq->strip->proxy->dir, sizeof(dir)); @@ -1717,7 +1717,7 @@ static bool seq_proxy_get_fname(Editing *ed, Sequence *seq, int cfra, int render { char fname[FILE_MAXFILE]; BLI_join_dirfile(fname, PROXY_MAXFILE, dir, proxy->file); - BLI_path_abs(fname, G.main->name); + BLI_path_abs(fname, BKE_main_blendfile_path_from_global()); if (suffix[0] != '\0') { /* TODO(sergey): This will actually append suffix after extension * which is weird but how was originally coded in multiview branch. @@ -1743,7 +1743,7 @@ static bool seq_proxy_get_fname(Editing *ed, Sequence *seq, int cfra, int render BLI_snprintf(name, PROXY_MAXFILE, "%s/proxy_misc/%d/####%s", dir, render_size, suffix); } - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, BKE_main_blendfile_path_from_global()); BLI_path_frame(name, frameno, 0); strcat(name, ".jpg"); @@ -1888,7 +1888,7 @@ static bool seq_proxy_multiview_context_invalid(Sequence *seq, Scene *scene, con char path[FILE_MAX]; BLI_join_dirfile(path, sizeof(path), seq->strip->dir, seq->strip->stripdata->name); - BLI_path_abs(path, G.main->name); + BLI_path_abs(path, BKE_main_blendfile_path_from_global()); BKE_scene_multiview_view_prefix_get(scene, path, prefix, &ext); } else { @@ -2841,7 +2841,7 @@ static ImBuf *seq_render_image_strip(const SeqRenderData *context, Sequence *seq if (s_elem) { BLI_join_dirfile(name, sizeof(name), seq->strip->dir, s_elem->name); - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, BKE_main_blendfile_path_from_global()); } flag = IB_rect | IB_metadata; @@ -5138,7 +5138,7 @@ void BKE_sequence_init_colorspace(Sequence *seq) ImBuf *ibuf; BLI_join_dirfile(name, sizeof(name), seq->strip->dir, seq->strip->stripdata->name); - BLI_path_abs(name, G.main->name); + BLI_path_abs(name, BKE_main_blendfile_path_from_global()); /* initialize input color space */ if (seq->type == SEQ_TYPE_IMAGE) { @@ -5306,6 +5306,7 @@ static void seq_anim_add_suffix(Scene *scene, struct anim *anim, const int view_ Sequence *BKE_sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo *seq_load) { + Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); /* only for sound */ char path[sizeof(seq_load->path)]; @@ -5320,7 +5321,7 @@ Sequence *BKE_sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoad int i; BLI_strncpy(path, seq_load->path, sizeof(path)); - BLI_path_abs(path, G.main->name); + BLI_path_abs(path, BKE_main_blendfile_path(bmain)); anim_arr = MEM_callocN(sizeof(struct anim *) * totfiles, "Video files"); diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 45d1f969d64..7ad8f03dfee 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -79,7 +79,7 @@ bSound *BKE_sound_new_file(struct Main *bmain, const char *filepath) BLI_strncpy(str, filepath, sizeof(str)); - path = /*bmain ? bmain->name :*/ G.main->name; + path = BKE_main_blendfile_path(bmain); BLI_path_abs(str, path); @@ -98,7 +98,7 @@ bSound *BKE_sound_new_file_exists_ex(struct Main *bmain, const char *filepath, b char str[FILE_MAX], strtest[FILE_MAX]; BLI_strncpy(str, filepath, sizeof(str)); - BLI_path_abs(str, bmain->name); + BLI_path_abs(str, BKE_main_blendfile_path(bmain)); /* first search an identical filepath */ for (sound = bmain->sound.first; sound; sound = sound->id.next) { diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index b650b6e9fb8..bd2afd0c512 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -391,7 +391,7 @@ bool BKE_text_reload(Text *text) } BLI_strncpy(filepath_abs, text->name, FILE_MAX); - BLI_path_abs(filepath_abs, G.main->name); + BLI_path_abs(filepath_abs, BKE_main_blendfile_path_from_global()); buffer = BLI_file_read_text_as_mem(filepath_abs, 0, &buffer_len); if (buffer == NULL) { @@ -560,7 +560,7 @@ int BKE_text_file_modified_check(Text *text) return 0; BLI_strncpy(file, text->name, FILE_MAX); - BLI_path_abs(file, G.main->name); + BLI_path_abs(file, BKE_main_blendfile_path_from_global()); if (!BLI_exists(file)) return 2; @@ -588,7 +588,7 @@ void BKE_text_file_modified_ignore(Text *text) if (!text->name) return; BLI_strncpy(file, text->name, FILE_MAX); - BLI_path_abs(file, G.main->name); + BLI_path_abs(file, BKE_main_blendfile_path_from_global()); if (!BLI_exists(file)) return; diff --git a/source/blender/blenkernel/intern/writeavi.c b/source/blender/blenkernel/intern/writeavi.c index 2fb4ed03603..02940723520 100644 --- a/source/blender/blenkernel/intern/writeavi.c +++ b/source/blender/blenkernel/intern/writeavi.c @@ -159,7 +159,7 @@ static void filepath_avi(char *string, RenderData *rd, bool preview, const char } strcpy(string, rd->pic); - BLI_path_abs(string, G.main->name); + BLI_path_abs(string, BKE_main_blendfile_path_from_global()); BLI_make_existing_file(string); diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index eb7ad38c456..bf702aa95b9 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -1138,7 +1138,7 @@ static void ffmpeg_filepath_get(FFMpegContext *context, char *string, RenderData } strcpy(string, rd->pic); - BLI_path_abs(string, G.main->name); + BLI_path_abs(string, BKE_main_blendfile_path_from_global()); BLI_make_existing_file(string); -- cgit v1.2.3