[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13072] trunk/blender/source/blender: Improvements to File->External Data-> Make Paths Relative & Make Paths Absolute,

Campbell Barton ideasman42 at gmail.com
Mon Dec 31 13:03:26 CET 2007


Revision: 13072
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13072
Author:   campbellbarton
Date:     2007-12-31 13:03:26 +0100 (Mon, 31 Dec 2007)

Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_blenlib.h
    trunk/blender/source/blender/blenlib/BLI_bpath.h
    trunk/blender/source/blender/blenlib/intern/bpath.c
    trunk/blender/source/blender/blenlib/intern/util.c
    trunk/blender/source/blender/src/header_info.c

Modified: trunk/blender/source/blender/blenlib/BLI_blenlib.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_blenlib.h	2007-12-31 10:18:26 UTC (rev 13071)
+++ trunk/blender/source/blender/blenlib/BLI_blenlib.h	2007-12-31 12:03:26 UTC (rev 13072)
@@ -135,7 +135,8 @@
 	 * 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.

Modified: trunk/blender/source/blender/blenlib/BLI_bpath.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_bpath.h	2007-12-31 10:18:26 UTC (rev 13071)
+++ trunk/blender/source/blender/blenlib/BLI_bpath.h	2007-12-31 12:03:26 UTC (rev 13072)
@@ -54,7 +54,7 @@
 /* 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);

Modified: trunk/blender/source/blender/blenlib/intern/bpath.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/bpath.c	2007-12-31 10:18:26 UTC (rev 13071)
+++ trunk/blender/source/blender/blenlib/intern/bpath.c	2007-12-31 12:03:26 UTC (rev 13072)
@@ -303,7 +303,7 @@
 }
 
 /* high level function */
-Text *checkMissingFiles(void) {
+void checkMissingFiles( char *txtname ) {
 	Text *btxt = NULL;
 	struct BPathIterator bpi;
 	
@@ -320,25 +320,29 @@
 		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 @@
 				(*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 @@
 
 /* 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 @@
 				(*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)++;
 					}
 				}

Modified: trunk/blender/source/blender/blenlib/intern/util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/util.c	2007-12-31 10:18:26 UTC (rev 13071)
+++ trunk/blender/source/blender/blenlib/intern/util.c	2007-12-31 12:03:26 UTC (rev 13072)
@@ -777,6 +777,16 @@
 
 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 @@
 			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 @@
 			if (a<=0) break;
 		}
 	}
-
-	strcat(dir, "/");
 #endif
 }
 

Modified: trunk/blender/source/blender/src/header_info.c
===================================================================
--- trunk/blender/source/blender/src/header_info.c	2007-12-31 10:18:26 UTC (rev 13071)
+++ trunk/blender/source/blender/src/header_info.c	2007-12-31 12:03:26 UTC (rev 13072)
@@ -956,8 +956,11 @@
 		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 @@
 		{
 			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) {
+			/* 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\"", btxt->name+2);
+				sprintf(str, "Missing files listed in Text \"%s\"", txtname );
 				error(str);
-			} else {
-				okee("No external files missing");
 			}
 		}
 		break;





More information about the Bf-blender-cvs mailing list