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.
This commit is contained in:
Bastien Montagne 2018-06-05 15:08:28 +02:00
parent c68429bc03
commit 1d97e948d2
2 changed files with 23 additions and 2 deletions

@ -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);

@ -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);
}
}