fix [#27405] Append objects with linked materials they dissapears after save

when linking in files to an unsaved blend file, make all library paths absolute.
This commit is contained in:
Campbell Barton 2011-05-18 05:21:44 +00:00
parent dc50003824
commit edb9045824
2 changed files with 24 additions and 11 deletions

@ -750,7 +750,9 @@ void makeFilesAbsolute(Main *bmain, const char *basedir, ReportList *reports)
/* be sure there is low chance of the path being too short */
char filepath_absolute[(FILE_MAXDIR * 2) + FILE_MAXFILE];
BLI_assert(basedir[0] != '\0');
BLI_bpathIterator_init(&bpi, bmain, basedir, 0);
while (!BLI_bpathIterator_isDone(bpi)) {
BLI_bpathIterator_getPath(bpi, filepath);

@ -5511,20 +5511,31 @@ static void lib_link_library(FileData *UNUSED(fd), Main *main)
}
}
/* Always call this once you havbe loaded new library data to set the relative paths correctly in relation to the blend file */
/* Always call this once you have 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->filepath, sizeof(lib->name));
BLI_path_rel(lib->name, basepath);
if (basepath==NULL || basepath[0] == '\0') {
for(lib= main->library.first; lib; lib= lib->id.next) {
/* when loading a linked lib into a file which has not been saved,
* there is nothing we can be relative to, so instead we need to make
* it absolute. This can happen when appending an object with a relative
* link into an unsaved blend file. See [#27405].
* The remap relative option will make it relative again on save - campbell */
if (strncmp(lib->name, "//", 2)==0) {
strncpy(lib->name, lib->filepath, sizeof(lib->name));
}
}
}
else {
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->filepath, sizeof(lib->name));
BLI_path_rel(lib->name, basepath);
}
}
}
}