From 5e4d32a9ffa7157a40bbd4d1d821c6dad860af0d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 31 Dec 2007 12:03:26 +0000 Subject: 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. --- source/blender/blenlib/BLI_blenlib.h | 3 +- source/blender/blenlib/BLI_bpath.h | 6 ++-- source/blender/blenlib/intern/bpath.c | 55 +++++++++++++++++++++++++++++------ source/blender/blenlib/intern/util.c | 16 ++++++---- source/blender/src/header_info.c | 29 ++++++++++++------ 5 files changed, 82 insertions(+), 27 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenlib/BLI_blenlib.h b/source/blender/blenlib/BLI_blenlib.h index bcb51fa1393..eb13ddc318c 100644 --- a/source/blender/blenlib/BLI_blenlib.h +++ b/source/blender/blenlib/BLI_blenlib.h @@ -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. diff --git a/source/blender/blenlib/BLI_bpath.h b/source/blender/blenlib/BLI_bpath.h index 32d20c4b13e..e932c39eb06 100644 --- a/source/blender/blenlib/BLI_bpath.h +++ b/source/blender/blenlib/BLI_bpath.h @@ -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); diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 2548c059064..a6c71a836f5 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -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)++; } } diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c index 7c94cc80847..d1b2efa28c7 100644 --- a/source/blender/blenlib/intern/util.c +++ b/source/blender/blenlib/intern/util.c @@ -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 } diff --git a/source/blender/src/header_info.c b/source/blender/src/header_info.c index 552201445d1..97b5341fda1 100644 --- a/source/blender/src/header_info.c +++ b/source/blender/src/header_info.c @@ -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'; + + /* run the missing file check */ + checkMissingFiles( txtname ); - if (btxt) { + if (txtname == '\0') { + okee("No external files missing"); + } else { char str[128]; - sprintf(str, "Missing files listed in Text \"%s\"", btxt->name+2); + sprintf(str, "Missing files listed in Text \"%s\"", txtname ); error(str); - } else { - okee("No external files missing"); } } break; -- cgit v1.2.3