Improvements to File->External Data->Make Paths Relative & Make Paths Absolute,
authorCampbell Barton <ideasman42@gmail.com>
Mon, 31 Dec 2007 12:03:26 +0000 (12:03 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 31 Dec 2007 12:03:26 +0000 (12:03 +0000)
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
source/blender/blenlib/BLI_bpath.h
source/blender/blenlib/intern/bpath.c
source/blender/blenlib/intern/util.c
source/blender/src/header_info.c

index bcb51fa1393de0445a04631dda641aa858fcddc5..eb13ddc318cdfdbd1765596fda744b9bcf91f0e5 100644 (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.
index 32d20c4b13e3500ac4c7c7194e7ea3016dc996a0..e932c39eb06a52fa071a7f5ee746fdd1ec2d6ed0 100644 (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);
index 2548c059064f1e1d2116c4437ed95c79c6ee57d3..a6c71a836f59d9f3aa0944feaaa04fbb0b8b6c09 100644 (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)++;
                                        }
                                }
index 7c94cc80847284b426281cdfe5627fcb8948a25c..d1b2efa28c72bf2954fff85dc038e72d08672b0f 100644 (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
 }
 
index 552201445d164398d6d163f09924e8b7f98de48b..97b5341fda1f647a5f107ad5477b46d5e05f2169 100644 (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';
+                       
+                       /* 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;