[Bf-blender-cvs] [e210a50] alembic_basic_io: Fix for library cache paths not using library as relative basis

Campbell Barton noreply at git.blender.org
Wed Jul 20 22:43:17 CEST 2016


Commit: e210a5073dff42817011e6f2a72c369c54c61873
Author: Campbell Barton
Date:   Thu Jul 21 06:43:56 2016 +1000
Branches: alembic_basic_io
https://developer.blender.org/rBe210a5073dff42817011e6f2a72c369c54c61873

Fix for library cache paths not using library as relative basis

Also rename BKE_cachefile_load -> reload since load is typically use to load a new datablock from a path.

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

M	source/blender/blenkernel/BKE_cachefile.h
M	source/blender/blenkernel/intern/cachefile.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/io/io_cache.c
M	source/blender/makesrna/intern/rna_cachefile.c

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

diff --git a/source/blender/blenkernel/BKE_cachefile.h b/source/blender/blenkernel/BKE_cachefile.h
index 2626a11..c3f1781 100644
--- a/source/blender/blenkernel/BKE_cachefile.h
+++ b/source/blender/blenkernel/BKE_cachefile.h
@@ -44,13 +44,13 @@ void BKE_cachefile_free(struct CacheFile *cache_file);
 
 struct CacheFile *BKE_cachefile_copy(struct Main *bmain, struct CacheFile *cache_file);
 
-void BKE_cachefile_load(struct CacheFile *cache_file, const char *relabase);
+void BKE_cachefile_reload(const struct Main *bmain, struct CacheFile *cache_file);
 
 void BKE_cachefile_update_frame(struct Main *bmain, struct Scene *scene, float ctime, const float fps);
 
 bool BKE_cachefile_filepath_get(
-        const struct CacheFile *cache_file, float frame,
-        char *r_filename);
+        const struct Main *bmain, const struct CacheFile *cache_file, float frame,
+        char r_filename[1024]);
 
 float BKE_cachefile_time_offset(struct CacheFile *cache_file, const float time, const float fps);
 
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index effbecb..1c0d740 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -48,15 +48,6 @@
 #  include "ABC_alembic.h"
 #endif
 
-static void get_absolute_path(char *r_absolute, const char *relative, const char *base)
-{
-	BLI_strncpy(r_absolute, relative, FILE_MAX);
-
-	if (BLI_path_is_rel(r_absolute)) {
-		BLI_path_abs(r_absolute, base);
-	}
-}
-
 void *BKE_cachefile_add(Main *bmain, const char *name)
 {
 	CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, name);
@@ -95,7 +86,7 @@ CacheFile *BKE_cachefile_copy(Main *bmain, CacheFile *cache_file)
 	new_cache_file->scale = cache_file->scale;
 
 	if (cache_file->handle) {
-		BKE_cachefile_load(new_cache_file, bmain->name);
+		BKE_cachefile_reload(bmain, new_cache_file);
 	}
 
 	if (ID_IS_LINKED_DATABLOCK(cache_file)) {
@@ -105,17 +96,19 @@ CacheFile *BKE_cachefile_copy(Main *bmain, CacheFile *cache_file)
 	return new_cache_file;
 }
 
-void BKE_cachefile_load(CacheFile *cache_file, const char *relabase)
+void BKE_cachefile_reload(const Main *bmain, CacheFile *cache_file)
 {
-	char filename[FILE_MAX];
-	get_absolute_path(filename, cache_file->filepath, relabase);
+	char filepath[FILE_MAX];
+
+	BLI_strncpy(filepath, cache_file->filepath, sizeof(filepath));
+	BLI_path_abs(filepath, ID_BLEND_PATH(bmain, &cache_file->id));
 
 #ifdef WITH_ALEMBIC
 	if (cache_file->handle) {
 		ABC_free_handle(cache_file->handle);
 	}
 
-	cache_file->handle = ABC_create_handle(filename, &cache_file->object_paths);
+	cache_file->handle = ABC_create_handle(filepath, &cache_file->object_paths);
 #endif
 }
 
@@ -134,7 +127,7 @@ void BKE_cachefile_update_frame(Main *bmain, Scene *scene, const float ctime, co
 
 		const float time = BKE_cachefile_time_offset(cache_file, ctime, fps);
 
-		if (BKE_cachefile_filepath_get(cache_file, time, filename)) {
+		if (BKE_cachefile_filepath_get(bmain, cache_file, time, filename)) {
 #ifdef WITH_ALEMBIC
 			ABC_free_handle(cache_file->handle);
 			cache_file->handle = ABC_create_handle(filename, NULL);
@@ -143,9 +136,12 @@ void BKE_cachefile_update_frame(Main *bmain, Scene *scene, const float ctime, co
 	}
 }
 
-bool BKE_cachefile_filepath_get(const CacheFile *cache_file, float frame, char *r_filepath)
+bool BKE_cachefile_filepath_get(
+        const Main *bmain, const CacheFile *cache_file, float frame,
+        char r_filepath[FILE_MAX])
 {
-	get_absolute_path(r_filepath, cache_file->filepath, G.main->name);
+	BLI_strncpy(r_filepath, cache_file->filepath, FILE_MAX);
+	BLI_path_abs(r_filepath, ID_BLEND_PATH(bmain, &cache_file->id));
 
 	int fframe;
 	int frame_len;
@@ -154,7 +150,7 @@ bool BKE_cachefile_filepath_get(const CacheFile *cache_file, float frame, char *
 		char ext[32];
 		BLI_path_frame_strip(r_filepath, true, ext);
 		BLI_path_frame(r_filepath, frame, frame_len);
-		BLI_ensure_extension(r_filepath, 1024, ext);
+		BLI_ensure_extension(r_filepath, FILE_MAX, ext);
 
 		/* TODO(kevin): store sequence range? */
 		return BLI_exists(r_filepath);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 08d3473..5d6fbe9 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2695,18 +2695,18 @@ static void direct_link_animdata(FileData *fd, AnimData *adt)
 
 /* ************ READ CACHEFILES *************** */
 
-static void lib_link_cachefiles(FileData *fd, Main *main)
+static void lib_link_cachefiles(FileData *fd, Main *bmain)
 {
 	CacheFile *cache_file;
 
 	/* only link ID pointers */
-	for (cache_file = main->cachefiles.first; cache_file; cache_file = cache_file->id.next) {
+	for (cache_file = bmain->cachefiles.first; cache_file; cache_file = cache_file->id.next) {
 		if (cache_file->id.tag & LIB_TAG_NEED_LINK) {
 			cache_file->id.tag &= ~LIB_TAG_NEED_LINK;
 		}
 
 		BLI_listbase_clear(&cache_file->object_paths);
-		BKE_cachefile_load(cache_file, fd->relabase);
+		BKE_cachefile_reload(bmain, cache_file);
 
 		if (cache_file->adt) {
 			lib_link_animdata(fd, &cache_file->id, cache_file->adt);
diff --git a/source/blender/editors/io/io_cache.c b/source/blender/editors/io/io_cache.c
index 74b24b1..d6e2c1a 100644
--- a/source/blender/editors/io/io_cache.c
+++ b/source/blender/editors/io/io_cache.c
@@ -93,7 +93,7 @@ static int cachefile_open_exec(bContext *C, wmOperator *op)
 
 	CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, BLI_path_basename(filename));
 	BLI_strncpy(cache_file->filepath, filename, FILE_MAX);
-	BKE_cachefile_load(cache_file, bmain->name);
+	BKE_cachefile_reload(bmain, cache_file);
 
 	/* hook into UI */
 	PropertyPointerRNA *pprop = op->customdata;
@@ -141,7 +141,7 @@ static int cachefile_reload_exec(bContext *C, wmOperator *op)
 	Main *bmain = CTX_data_main(C);
 
 	BLI_listbase_clear(&cache_file->object_paths);
-	BKE_cachefile_load(cache_file, bmain->name);
+	BKE_cachefile_reload(bmain, cache_file);
 
 	return OPERATOR_FINISHED;
 
diff --git a/source/blender/makesrna/intern/rna_cachefile.c b/source/blender/makesrna/intern/rna_cachefile.c
index cc20f38..37cfe01 100644
--- a/source/blender/makesrna/intern/rna_cachefile.c
+++ b/source/blender/makesrna/intern/rna_cachefile.c
@@ -66,9 +66,9 @@ static void rna_CacheFile_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 
 static void rna_CacheFile_update_handle(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
-	CacheFile *cache_file = (CacheFile *)ptr->data;
+	CacheFile *cache_file = ptr->data;
 
-	BKE_cachefile_load(cache_file, bmain->name);
+	BKE_cachefile_reload(bmain, cache_file);
 
 	rna_CacheFile_update(bmain, scene, ptr);
 }




More information about the Bf-blender-cvs mailing list