Improvements to File->External Data->Make Paths Relative & Make Paths Absolute,

made when testing peach blend files wont have path issues when sent to the renderfarm.
* log failed path conversions
* clean the path so //foo/../foo/ is removed (not sure why but some peach files had this problem)
Also added a function to util.c 
BLI_cleanup_file, same as BLI_cleanup_dir but dosnt add a slash at the end.
This commit is contained in:
Campbell Barton
2007-12-31 12:03:26 +00:00
parent d00d1f1c89
commit 5e4d32a9ff
5 changed files with 83 additions and 28 deletions

View File

@@ -135,7 +135,8 @@ void BLI_dlist_reinit(struct DynamicList *dlist);
* converts it to a regular full path.
* Also removes garbage from directory paths, like /../ or double slashes etc
*/
void BLI_cleanup_dir(const char *relabase, char *dir);
void BLI_cleanup_file(const char *relabase, char *dir);
void BLI_cleanup_dir(const char *relabase, char *dir); /* same as above but adds a trailing slash */
/**
* Blender's path code replacement function.

View File

@@ -54,7 +54,7 @@ void BLI_bpathIterator_copyPathExpanded( struct BPathIterator *bpi, char *path
/* high level funcs */
/* creates a text file with missing files if there are any */
struct Text * checkMissingFiles(void);
void makeFilesRelative(int *tot, int *changed, int *failed, int *linked);
void makeFilesAbsolute(int *tot, int *changed, int *failed, int *linked);
void checkMissingFiles(char *txtname );
void makeFilesRelative(char *txtname, int *tot, int *changed, int *failed, int *linked);
void makeFilesAbsolute(char *txtname, int *tot, int *changed, int *failed, int *linked);
void findMissingFiles(char *str);

View File

@@ -303,7 +303,7 @@ static void bpathToText(Text *btxt, struct BPathIterator *bpi)
}
/* high level function */
Text *checkMissingFiles(void) {
void checkMissingFiles( char *txtname ) {
Text *btxt = NULL;
struct BPathIterator bpi;
@@ -320,25 +320,29 @@ Text *checkMissingFiles(void) {
BLI_bpathIterator_copyPathExpanded( &bpi, filepath_expanded );
if (!BLI_exists(filepath_expanded)) {
if (!btxt)
btxt = add_empty_text( "missing_files.txt" );
if (!btxt) {
btxt = add_empty_text( "missing_files.log" );
if (txtname) {
BLI_strncpy(txtname, btxt->id.name+2, 24);
}
}
bpathToText(btxt, &bpi);
files_missing = 1;
}
BLI_bpathIterator_step(&bpi);
}
return btxt;
}
/* dont log any errors at the moment, should probably do this */
void makeFilesRelative(int *tot, int *changed, int *failed, int *linked) {
void makeFilesRelative(char *txtname, int *tot, int *changed, int *failed, int *linked) {
struct BPathIterator bpi;
char *filepath, *libpath;
/* be sure there is low chance of the path being too short */
char filepath_relative[(FILE_MAXDIR * 2) + FILE_MAXFILE];
Text *btxt = NULL;
*tot = *changed = *failed = *linked = 0;
BLI_bpathIterator_init(&bpi);
@@ -351,15 +355,32 @@ void makeFilesRelative(int *tot, int *changed, int *failed, int *linked) {
(*linked)++;
} else { /* local data, use the blend files path */
BLI_strncpy(filepath_relative, filepath, sizeof(filepath_relative));
/* Important BLI_cleanup_dir runs before the path is made relative
* because it wont work for paths that start with "//../" */
BLI_cleanup_file(G.sce, filepath_relative); /* fix any /foo/../foo/ */
BLI_makestringcode(G.sce, filepath_relative);
/* be safe and check the length */
if (BLI_bpathIterator_getPathMaxLen(&bpi) <= strlen(filepath_relative)) {
if (!btxt) {
btxt = add_empty_text( "missing_no_rel.log" );
if (txtname) {
BLI_strncpy(txtname, btxt->id.name+2, 24);
}
}
bpathToText(btxt, &bpi);
(*failed)++;
} else {
if(strncmp(filepath_relative, "//", 2)==0) {
strcpy(filepath, filepath_relative);
(*changed)++;
} else {
if (!btxt) {
btxt = add_empty_text( "missing_no_rel.log" );
if (txtname) {
BLI_strncpy(txtname, btxt->id.name+2, 24);
}
}
bpathToText(btxt, &bpi);
(*failed)++;
}
}
@@ -372,13 +393,15 @@ void makeFilesRelative(int *tot, int *changed, int *failed, int *linked) {
/* dont log any errors at the moment, should probably do this -
* Verry similar to makeFilesRelative - keep in sync! */
void makeFilesAbsolute(int *tot, int *changed, int *failed, int *linked) {
void makeFilesAbsolute(char *txtname, int *tot, int *changed, int *failed, int *linked) {
struct BPathIterator bpi;
char *filepath, *libpath;
/* be sure there is low chance of the path being too short */
char filepath_absolute[(FILE_MAXDIR * 2) + FILE_MAXFILE];
Text *btxt = NULL;
*tot = *changed = *failed = *linked = 0;
BLI_bpathIterator_init(&bpi);
@@ -391,15 +414,29 @@ void makeFilesAbsolute(int *tot, int *changed, int *failed, int *linked) {
(*linked)++;
} else { /* get the expanded path and check it is relative or too long */
BLI_bpathIterator_copyPathExpanded( &bpi, filepath_absolute );
/* safe be safe, check the length */
BLI_cleanup_file(G.sce, filepath_absolute); /* fix any /foo/../foo/ */
/* to be safe, check the length */
if (BLI_bpathIterator_getPathMaxLen(&bpi) <= strlen(filepath_absolute)) {
if (!btxt) {
btxt = add_empty_text( "missing_no_abs.log" );
if (txtname) {
BLI_strncpy(txtname, btxt->id.name+2, 24);
}
}
bpathToText(btxt, &bpi);
(*failed)++;
} else {
if(strncmp(filepath_absolute, "//", 2)) {
strcpy(filepath, filepath_absolute);
(*changed)++;
} else {
if (!btxt) {
btxt = add_empty_text( "missing_no_abs.log" );
if (txtname) {
BLI_strncpy(txtname, btxt->id.name+2, 24);
}
}
bpathToText(btxt, &bpi);
(*failed)++;
}
}

View File

@@ -776,6 +776,16 @@ int BLI_strcaseeq(char *a, char *b) {
*/
void BLI_cleanup_dir(const char *relabase, char *dir)
{
BLI_cleanup_file(relabase, dir);
#ifdef WIN32
strcat(dir, "\\");
#else
strcat(dir, "/");
#endif
}
void BLI_cleanup_file(const char *relabase, char *dir)
{
short a;
char *start, *eind;
@@ -814,9 +824,7 @@ void BLI_cleanup_dir(const char *relabase, char *dir)
dir[a] = 0;
}
}
strcat(dir, "\\");
#else
#else
if(dir[0]=='.') { /* happens, for example in FILE_MAIN */
dir[0]= '/';
dir[1]= 0;
@@ -850,8 +858,6 @@ void BLI_cleanup_dir(const char *relabase, char *dir)
if (a<=0) break;
}
}
strcat(dir, "/");
#endif
}

View File

@@ -956,8 +956,11 @@ static void do_info_externalfiles(void *arg, int event)
if (G.relbase_valid) {
int tot,changed,failed,linked;
char str[512];
makeFilesRelative(&tot, &changed, &failed, &linked);
sprintf(str, "Make Relative%%t|Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
char txtname[24]; /* text block name */
txtname[0] = '\0';
makeFilesRelative(txtname, &tot, &changed, &failed, &linked);
if (failed) sprintf(str, "Make Relative%%t|Total files %i|Changed %i|Failed %i, See Text \"%s\"|Linked %i", tot, changed, failed, txtname, linked);
else sprintf(str, "Make Relative%%t|Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
pupmenu(str);
} else {
pupmenu("Can't set relative paths with an unsaved blend file");
@@ -967,22 +970,30 @@ static void do_info_externalfiles(void *arg, int event)
{
int tot,changed,failed,linked;
char str[512];
makeFilesAbsolute(&tot, &changed, &failed, &linked);
char txtname[24]; /* text block name */
txtname[0] = '\0';
makeFilesAbsolute(txtname, &tot, &changed, &failed, &linked);
sprintf(str, "Make Absolute%%t|Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
if (failed) sprintf(str, "Make Absolute%%t|Total files %i|Changed %i|Failed %i, See Text \"%s\"|Linked %i", tot, changed, failed, txtname, linked);
else sprintf(str, "Make Absolute%%t|Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
pupmenu(str);
}
break;
case 12: /* check images exist */
{
/* Its really text but only care about the name */
ID *btxt = (ID *)checkMissingFiles();
char txtname[24]; /* text block name */
txtname[0] = '\0';
if (btxt) {
char str[128];
sprintf(str, "Missing files listed in Text \"%s\"", btxt->name+2);
error(str);
} else {
/* run the missing file check */
checkMissingFiles( txtname );
if (txtname == '\0') {
okee("No external files missing");
} else {
char str[128];
sprintf(str, "Missing files listed in Text \"%s\"", txtname );
error(str);
}
}
break;