[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13521] trunk/blender/source/blender/ blenloader/intern/readfile.c: Fix for indirectly linked libs being converted into direct linked libs.

Campbell Barton ideasman42 at gmail.com
Sat Feb 2 12:19:35 CET 2008


Revision: 13521
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13521
Author:   campbellbarton
Date:     2008-02-02 12:19:34 +0100 (Sat, 02 Feb 2008)

Log Message:
-----------
Fix for indirectly linked libs being converted into direct linked libs. (tried to fix this before but didn't work).
fix_relpaths_library() needs to be called after loading libraries but not during recursive library load.

Modified Paths:
--------------
    trunk/blender/source/blender/blenloader/intern/readfile.c

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2008-02-02 10:13:23 UTC (rev 13520)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2008-02-02 11:19:34 UTC (rev 13521)
@@ -4067,14 +4067,24 @@
 	Library *lib;
 	for(lib= main->library.first; lib; lib= lib->id.next) {
 		lib->id.us= 1;
-#if 0		
+	}
+}
+
+/* Always call this once you havbe loaded new library data to set the relative paths correctly in relation to the blend file */
+static void fix_relpaths_library(const char *basepath, Main *main)
+{
+	Library *lib;
+	/* BLO_read_from_memory uses a blank filename */
+	if (basepath==NULL || basepath[0] == '\0')
+		return;
+		
+	for(lib= main->library.first; lib; lib= lib->id.next) {
 		/* Libraries store both relative and abs paths, recreate relative paths,
 		 * relative to the blend file since indirectly linked libs will be relative to their direct linked library */
 		if (strncmp(lib->name, "//", 2)==0) { /* if this is relative to begin with? */
 			strncpy(lib->name, lib->filename, sizeof(lib->name));
-			BLI_makestringcode(fd->filename, lib->name);
+			BLI_makestringcode(basepath, lib->name);
 		}
-#endif
 	}
 }
 
@@ -7499,6 +7509,7 @@
 
 	lib_link_all(fd, bfd->main);
 	lib_verify_nodetree(bfd->main);
+	fix_relpaths_library(fd->filename, bfd->main); /* make all relative paths, relative to the open blend file */
 	
 	if(fg)
 		link_global(fd, bfd, fg);	/* as last */
@@ -8456,6 +8467,7 @@
 
 	lib_link_all(fd, G.main);
 	lib_verify_nodetree(G.main);
+	fix_relpaths_library(G.sce, G.main); /* make all relative paths, relative to the open blend file */
 
 	/* give a base to loose objects. If group append, do it for objects too */
 	if(idcode==ID_GR) {
@@ -8715,10 +8727,10 @@
 		
 		if(mainptr->curlib->filedata) blo_freefiledata(mainptr->curlib->filedata);
 		mainptr->curlib->filedata= NULL;
-
 	}
 }
 
+
 /* reading runtime */
 
 BlendFileData *blo_read_blendafterruntime(int file, int actualsize, BlendReadError *error_r) 





More information about the Bf-blender-cvs mailing list