[Bf-blender-cvs] [7cb320e] gooseberry: Ported archive filename constructor from pointcache library to BKE.

Lukas Tönne noreply at git.blender.org
Mon Mar 23 13:02:16 CET 2015


Commit: 7cb320ee610d51924abebd83072cd4737787f20e
Author: Lukas Tönne
Date:   Tue Mar 3 12:54:27 2015 +0100
Branches: gooseberry
https://developer.blender.org/rB7cb320ee610d51924abebd83072cd4737787f20e

Ported archive filename constructor from pointcache library to BKE.

The pointcache library is now pretty much independent from ID blocks and
should not be responsible for handling file paths. The path construction
is also fairly straightforward now compared to the old point cache
system, with only basic conversion of relative to absolute paths for
loading archive files.

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

M	source/blender/blenkernel/BKE_cache_library.h
M	source/blender/blenkernel/intern/cache_library.c

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

diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index 4936368..ebafddd 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -91,6 +91,11 @@ void BKE_cache_library_clear(struct CacheLibrary *cachelib);
 bool BKE_cache_library_validate_item(struct CacheLibrary *cachelib, struct Object *ob, int type, int index);
 void BKE_cache_library_group_update(struct Main *bmain, struct CacheLibrary *cachelib);
 
+/* ========================================================================= */
+
+bool BKE_cache_archive_path_test(const char *path, ID *id, Library *lib);
+void BKE_cache_archive_path(const char *path, ID *id, Library *lib, char *result, int max);
+
 bool BKE_cache_read_derived_mesh(struct Main *bmain, struct Scene *scene, float frame, struct Object *ob, struct DerivedMesh **r_dm);
 bool BKE_cache_read_cloth(struct Main *bmain, struct Scene *scene, float frame, struct Object *ob, struct ClothModifierData *clmd);
 bool BKE_cache_read_hair_dynamics(struct Main *bmain, struct Scene *scene, float frame, struct Object *ob, struct ParticleSystem *psys);
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index a61b49d..af8fb3c 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -32,8 +32,10 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_fileops.h"
 #include "BLI_ghash.h"
 #include "BLI_listbase.h"
+#include "BLI_path_util.h"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
 
@@ -590,6 +592,56 @@ void BKE_cache_library_update_items(CacheLibrary *cachelib)
 
 /* ========================================================================= */
 
+static const char *default_filename = "blendcache";
+
+BLI_INLINE bool path_is_dirpath(const char *path)
+{
+	/* last char is a slash? */
+	return *(BLI_last_slash(path) + 1) == '\0';
+}
+
+bool BKE_cache_archive_path_test(const char *path, ID *UNUSED(id), Library *lib)
+{
+	if (BLI_path_is_rel(path)) {
+		if (!(G.relbase_valid || lib))
+			return false;
+	}
+	
+	return true;
+	
+}
+
+void BKE_cache_archive_path(const char *path, ID *id, Library *lib, char *result, int max)
+{
+	char abspath[FILE_MAX];
+	
+	result[0] = '\0';
+	
+	if (BLI_path_is_rel(path)) {
+		if (G.relbase_valid || lib) {
+			const char *relbase = lib ? lib->filepath : G.main->name;
+			
+			BLI_strncpy(abspath, path, sizeof(abspath));
+			BLI_path_abs(abspath, relbase);
+		}
+		else {
+			/* can't construct a valid path */
+			return;
+		}
+	}
+	else {
+		BLI_strncpy(abspath, path, sizeof(abspath));
+	}
+	
+	if (path_is_dirpath(abspath) || BLI_is_dir(abspath)) {
+		BLI_join_dirfile(result, max, abspath, id ? id->name+2 : default_filename);
+	}
+	else {
+		BLI_strncpy(result, abspath, max);
+	}
+}
+
+
 /* XXX this needs work: the order of cachelibraries in bmain is arbitrary!
  * If there are multiple cachelibs applying data, which should take preference?
  */




More information about the Bf-blender-cvs mailing list