[Bf-blender-cvs] [1d97e948d2c] master: Cleanup: add hleper functions to get filepath from Main.

Bastien Montagne noreply at git.blender.org
Tue Jun 5 16:33:52 CEST 2018


Commit: 1d97e948d2c4867306e7fb5ce5fccf8b72c13391
Author: Bastien Montagne
Date:   Tue Jun 5 15:08:28 2018 +0200
Branches: master
https://developer.blender.org/rB1d97e948d2c4867306e7fb5ce5fccf8b72c13391

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.

===================================================================

M	source/blender/blenkernel/BKE_library.h
M	source/blender/blenkernel/intern/library.c

===================================================================

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



More information about the Bf-blender-cvs mailing list