[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12547] trunk/blender/source/blender: Bugfix #6797: Relative paths load problem on new file (fix included)

Andrea Weikert elubie at gmx.net
Sat Nov 10 12:45:26 CET 2007


Revision: 12547
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12547
Author:   elubie
Date:     2007-11-10 12:45:25 +0100 (Sat, 10 Nov 2007)

Log Message:
-----------
Bugfix #6797: Relative paths load problem on new file (fix included)
- brought back the check for a valid relative base when selecting.
- kept the check for when file is saved too and warning message is printed to console instead of popping up.
Also fixed BLI_split_filedir overwriting parameter passed as const char*

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/intern/util.c
    trunk/blender/source/blender/src/editimasel.c
    trunk/blender/source/blender/src/filesel.c

Modified: trunk/blender/source/blender/blenlib/intern/util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/util.c	2007-11-10 11:05:44 UTC (rev 12546)
+++ trunk/blender/source/blender/blenlib/intern/util.c	2007-11-10 11:45:25 UTC (rev 12547)
@@ -1275,26 +1275,28 @@
 #ifdef WIN32
 	int sl;
 	short is_relative = 0;
+	char path[FILE_MAX];
 #endif
 
 	dir[0]= 0;
 	file[0]= 0;
 
 #ifdef WIN32
-	BLI_char_switch(string, '/', '\\'); /* make sure we have a valid path format */
-	sl = strlen(string);
+	BLI_strncpy(path, string, FILE_MAX);
+	BLI_char_switch(path, '/', '\\'); /* make sure we have a valid path format */
+	sl = strlen(path);
 	if (sl) {
 		int len;
-		if (string[0] == '/' || string[0] == '\\') { 
-			BLI_strncpy(dir, string, FILE_MAXDIR);
-			if (sl > 1 && string[0] == '\\' && string[1] == '\\') is_relative = 1;
-		} else if (sl > 2 && string[1] == ':' && string[2] == '\\') {
-			BLI_strncpy(dir, string, FILE_MAXDIR);
+		if (path[0] == '/' || path[0] == '\\') { 
+			BLI_strncpy(dir, path, FILE_MAXDIR);
+			if (sl > 1 && path[0] == '\\' && path[1] == '\\') is_relative = 1;
+		} else if (sl > 2 && path[1] == ':' && path[2] == '\\') {
+			BLI_strncpy(dir, path, FILE_MAXDIR);
 		} else {
 			BLI_getwdN(dir);
 			strcat(dir,"\\");
-			strcat(dir,string);
-			BLI_strncpy(string,dir,FILE_MAXDIR+FILE_MAXFILE);
+			strcat(dir,path);
+			BLI_strncpy(path,dir,FILE_MAXDIR+FILE_MAXFILE);
 		}
 		
 		// BLI_exist doesn't recognize a slashed dirname as a dir
@@ -1315,15 +1317,15 @@
 			/* copy from end of string into file, to ensure filename itself isn't truncated 
 			if string is too long. (aphex) */
 
-			len = FILE_MAXFILE - strlen(string);
+			len = FILE_MAXFILE - strlen(path);
 
 			if (len < 0)
-				BLI_strncpy(file,string + abs(len),FILE_MAXFILE);
+				BLI_strncpy(file,path + abs(len),FILE_MAXFILE);
 			else
-				BLI_strncpy(file,string,FILE_MAXFILE);
+				BLI_strncpy(file,path,FILE_MAXFILE);
 		    
-			if (strrchr(string,'\\')) {
-				BLI_strncpy(file,strrchr(string,'\\')+1,FILE_MAXFILE);
+			if (strrchr(path,'\\')) {
+				BLI_strncpy(file,strrchr(path,'\\')+1,FILE_MAXFILE);
 			}
 			
 			if ( (a = strlen(dir)) ) {
@@ -1334,7 +1336,7 @@
 			a = strlen(dir) - 1;
 			while(a>0 && dir[a] != '\\') a--;
 			dir[a + 1] = 0;
-			BLI_strncpy(file, string + strlen(dir),FILE_MAXFILE);
+			BLI_strncpy(file, path + strlen(dir),FILE_MAXFILE);
 		}
 
 	}

Modified: trunk/blender/source/blender/src/editimasel.c
===================================================================
--- trunk/blender/source/blender/src/editimasel.c	2007-11-10 11:05:44 UTC (rev 12546)
+++ trunk/blender/source/blender/src/editimasel.c	2007-11-10 11:45:25 UTC (rev 12547)
@@ -546,16 +546,19 @@
 			strcat(name, simasel->file);
 			
 			if(simasel->flag & FILE_STRINGCODE) {
-				if (!G.relbase_valid) {
-					/* skip save */
-					if(strncmp(simasel->title, "Save", 4)) {
-						okee("You have to save the .blend file before using relative paths! Using absolute path instead.");
-						simasel->flag &= ~FILE_STRINGCODE;
+				/* still weak, but we don't want saving files to make relative paths */
+				if(G.relbase_valid && strncmp(simasel->title, "Save", 4)) {
+					BLI_makestringcode(G.sce, name);
+				} else {
+					/* if we don't have a valid relative base (.blend file hasn't been saved yet)
+					   then we don't save the path as relative (for texture images, background image).	
+					   Warning message not shown when saving files (doesn't make sense there)
+					*/
+					if (strncmp(simasel->title, "Save", 4)) {					
+						printf("Relative path setting has been ignored because .blend file hasn't been saved yet.\n");
 					}
+					simasel->flag &= ~FILE_STRINGCODE;
 				}
-				else {
-					BLI_makestringcode(G.sce, name);
-				}
 			}
 			if(simasel->returnfunc)
 				simasel->returnfunc(name);

Modified: trunk/blender/source/blender/src/filesel.c
===================================================================
--- trunk/blender/source/blender/src/filesel.c	2007-11-10 11:05:44 UTC (rev 12546)
+++ trunk/blender/source/blender/src/filesel.c	2007-11-10 11:45:25 UTC (rev 12547)
@@ -1480,8 +1480,18 @@
 			
 			if(sfile->flag & FILE_STRINGCODE) {
 				/* still weak, but we don't want saving files to make relative paths */
-				if(strncmp(sfile->title, "Save", 4))
+				if(G.relbase_valid && strncmp(sfile->title, "Save", 4)) {
 					BLI_makestringcode(G.sce, name);
+				} else {
+					/* if we don't have a valid relative base (.blend file hasn't been saved yet)
+					   then we don't save the path as relative (for texture images, background image).
+					   Warning message not shown when saving files (doesn't make sense there)
+					*/
+					if (strncmp(sfile->title, "Save", 4)) {
+						printf("Relative path setting has been ignored because .blend file hasn't been saved yet.\n");
+					}
+					sfile->flag &= ~FILE_STRINGCODE;
+				}
 			}
 			if(sfile->returnfunc)
 				sfile->returnfunc(name);





More information about the Bf-blender-cvs mailing list