From eb9375fb562cccdccb7062ed1f3d26cd7973bb88 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 2 Feb 2008 11:19:34 +0000 Subject: 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. --- source/blender/blenloader/intern/readfile.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 769ff541ea4..a382fa17fa5 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4067,14 +4067,24 @@ static void lib_link_library(FileData *fd, Main *main) 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 @@ BlendFileData *blo_read_file_internal(FileData *fd, BlendReadError *error_r) 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 @@ static Library* library_append( Scene *scene, char* file, char *dir, int idcode, 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 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) 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) -- cgit v1.2.3