Fix for [#7866] Relative Path to library from command line

http://projects.blender.org/tracker/index.php?func=detail&aid=7866&group_id=9&atid=125

where linked relative blend files would not load when the absolute path was not given.
Solved by constructing the absolute path from the command line argument given.
This commit is contained in:
Campbell Barton 2007-12-28 21:16:00 +00:00
parent 6a5ce69a16
commit 81cdf24284

@ -688,8 +688,49 @@ int main(int argc, char **argv)
} }
} }
else { else {
/* Make the path absolute because its needed for relative linked blends to be found */
int abs = 0;
int filelen;
char cwd[FILE_MAXDIR + FILE_MAXFILE];
char filename[FILE_MAXDIR + FILE_MAXFILE];
cwd[0] = filename[0] = '\0';
BLI_strncpy(filename, argv[a], sizeof(filename));
filelen = strlen(filename);
/* relative path checks, could do more tests here... */
#ifdef WIN32
/* Account for X:/ and X:\ - should be enough */
if (filelen >= 3 && filename[1] == ':' && (filename[2] == '\\' || filename[2] == '/'))
abs = 1;
#else
if (filelen >= 2 && filename[0] == '/')
abs = 1 ;
#endif
if (!abs) {
BLI_getwdN(cwd); /* incase the full path to the blend isnt used */
if (cwd[0] == '\0') {
printf(
"Could not get the current working directory - $PWD for an unknown reason.\n\t"
"Relative linked files will not load if the entire blend path is not used.\n\t"
"The 'Play' button may also fail.\n"
);
} else {
/* uses the blend path relative to cwd important for loading relative linked files.
*
* cwd should contain c:\ etc on win32 so the relbase can be NULL
* relbase being NULL also prevents // being misunderstood as relative to the current
* blend file which isnt a feature we want to use in this case since were dealing
* with a path from the command line, rather then from inside Blender */
BLI_make_file_string(NULL, filename, cwd, argv[a]);
}
}
if (G.background) { if (G.background) {
BKE_read_file(argv[a], NULL); BKE_read_file(filename, NULL);
sound_initialize_sounds(); sound_initialize_sounds();
/* happens for the UI on file reading too */ /* happens for the UI on file reading too */
@ -698,7 +739,7 @@ int main(int argc, char **argv)
} else { } else {
/* we are not running in background mode here, but start blender in UI mode with /* we are not running in background mode here, but start blender in UI mode with
a file - this should do everything a 'load file' does */ a file - this should do everything a 'load file' does */
BIF_read_file(argv[a]); BIF_read_file(filename);
} }
} }
} }