[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25842] trunk/blender/source/blender: Remap Relative paths save option.

Campbell Barton ideasman42 at gmail.com
Fri Jan 8 18:50:56 CET 2010


Revision: 25842
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25842
Author:   campbellbarton
Date:     2010-01-08 18:50:55 +0100 (Fri, 08 Jan 2010)

Log Message:
-----------
Remap Relative paths save option.
If you have a blend file and want to save in a new directory enabling this will save with the paths corrected relative to the new directory.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_global.h
    trunk/blender/source/blender/blenlib/BLI_bpath.h
    trunk/blender/source/blender/blenlib/intern/bpath.c
    trunk/blender/source/blender/blenloader/intern/writefile.c
    trunk/blender/source/blender/editors/space_info/info_ops.c
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/source/blender/blenkernel/BKE_global.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_global.h	2010-01-08 17:47:27 UTC (rev 25841)
+++ trunk/blender/source/blender/blenkernel/BKE_global.h	2010-01-08 17:50:55 UTC (rev 25842)
@@ -146,6 +146,7 @@
 #define G_FILE_GLSL_NO_EXTRA_TEX (1 << 21)				/* deprecated */
 #define G_FILE_IGNORE_DEPRECATION_WARNINGS	(1 << 22)	/* deprecated */
 #define G_FILE_RECOVER			 (1 << 23)
+#define G_FILE_RELATIVE_REMAP	 (1 << 24)
 
 /* G.windowstate */
 #define G_WINDOWSTATE_USERDEF		0

Modified: trunk/blender/source/blender/blenlib/BLI_bpath.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_bpath.h	2010-01-08 17:47:27 UTC (rev 25841)
+++ trunk/blender/source/blender/blenlib/BLI_bpath.h	2010-01-08 17:50:55 UTC (rev 25842)
@@ -47,11 +47,13 @@
 	void (*setpath_callback)(struct BPathIterator *, char *);
 	void (*getpath_callback)(struct BPathIterator *, char *);
 	
+	char*	base_path; /* base path, the directry the blend file is in - normally G.sce */
+
 	/* only for seq data */
 	struct BPathIteratorSeqData seqdata;
 };
 
-void			BLI_bpathIterator_init				(struct BPathIterator *bpi);
+void			BLI_bpathIterator_init				(struct BPathIterator *bpi, char *base_path);
 void			BLI_bpathIterator_free				(struct BPathIterator *bpi);
 char*			BLI_bpathIterator_getLib			(struct BPathIterator *bpi);
 char*			BLI_bpathIterator_getName			(struct BPathIterator *bpi);
@@ -66,7 +68,7 @@
 /* high level funcs */
 
 /* creates a text file with missing files if there are any */
-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);
+void checkMissingFiles(char *basepath, ReportList *reports);
+void makeFilesRelative(char *basepath, ReportList *reports);
+void makeFilesAbsolute(char *basepath, ReportList *reports);
+void findMissingFiles(char *basepath, char *str);

Modified: trunk/blender/source/blender/blenlib/intern/bpath.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/bpath.c	2010-01-08 17:47:27 UTC (rev 25841)
+++ trunk/blender/source/blender/blenlib/intern/bpath.c	2010-01-08 17:50:55 UTC (rev 25842)
@@ -52,7 +52,7 @@
 #include "DNA_sound_types.h"
 #include "DNA_scene_types.h" /* to get the current frame */
 #include "DNA_sequence_types.h"
-#include "DNA_text_types.h"
+#include "DNA_windowmanager_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_bpath.h"
@@ -61,7 +61,6 @@
 #include "BKE_image.h" /* so we can check the image's type */
 #include "BKE_main.h" /* so we can access G.main->*.first */
 #include "BKE_sequencer.h"
-#include "BKE_text.h" /* for writing to a textblock */
 #include "BKE_utildefines.h"
 
 //XXX #include "BIF_screen.h" /* only for wait cursor */
@@ -86,19 +85,21 @@
  	BPATH_DONE
 };
 
-void BLI_bpathIterator_init( struct BPathIterator *bpi ) {
+void BLI_bpathIterator_init( struct BPathIterator *bpi, char *base_path ) {
 	bpi->type = BPATH_IMAGE;
 	bpi->data = NULL;
 	
 	bpi->getpath_callback = NULL;
 	bpi->setpath_callback = NULL;
 	
-	/* Sequencer spesific */
+	/* Sequencer specific */
 	bpi->seqdata.totseq = 0;
 	bpi->seqdata.seq = 0;
 	bpi->seqdata.seqar = NULL;
 	bpi->seqdata.scene = NULL;
 	
+	bpi->base_path= base_path ? base_path : G.sce;
+
 	BLI_bpathIterator_step(bpi);
 }
 
@@ -134,7 +135,7 @@
 	if (libpath) { /* check the files location relative to its library path */
 		BLI_convertstringcode(path_expanded, libpath);
 	} else { /* local data, use the blend files path */
-		BLI_convertstringcode(path_expanded, G.sce);
+		BLI_convertstringcode(path_expanded, bpi->base_path);
 	}
 }
 char* BLI_bpathIterator_getLib( struct BPathIterator *bpi) {
@@ -413,186 +414,157 @@
 }
 
 /* include the path argument */
-static void bpathToText(Text *btxt, struct BPathIterator *bpi)
+static void bpath_as_report(struct BPathIterator *bpi, const char *message, ReportList *reports)
 {
+	char *prefix;
 	char *name;
 	char path_expanded[FILE_MAXDIR*2];
 	
+	if(reports==NULL)
+		return;
+
 	switch(BLI_bpathIterator_getType(bpi)) {
 	case BPATH_IMAGE:
-		txt_insert_buf( btxt, "Image \"" );
+		prefix= "Image";
 		break;
 	case BPATH_SOUND:
-		txt_insert_buf( btxt, "Sound \"" );
+		prefix= "Sound";
 		break;
 	case BPATH_FONT:
-		txt_insert_buf( btxt, "Font \"" );
+		prefix= "Font";
 		break;
 	case BPATH_LIB:
-		txt_insert_buf( btxt, "Library \"" );
+		prefix= "Library";
 		break;
 	case BPATH_SEQ:
-		txt_insert_buf( btxt, "Sequence \"" );
+		prefix= "Sequence";
 		break;
 	default:
-		txt_insert_buf( btxt, "Unknown \"" );
+		prefix= "Unknown";
 		break;
 	}
 	
 	name = BLI_bpathIterator_getName(bpi);
-	
-	if (name) {
-		txt_insert_buf( btxt, name );
-	}
-	txt_insert_buf( btxt, "\" " );
-	
 	BLI_bpathIterator_getPathExpanded(bpi, path_expanded);
-	
-	txt_insert_buf( btxt, path_expanded );
-	txt_insert_buf( btxt, "\n" );
-	txt_move_eof( btxt, 0 );
+
+	if(reports) {
+		if (name)	BKE_reportf("%s \"%s\", \"%s\": %s", prefix, name, path_expanded, message);
+		else		BKE_reportf("%s \"%s\": %s", prefix, path_expanded, message);
+	}
+
 }
 
 /* high level function */
-void checkMissingFiles( char *txtname ) {
-	Text *btxt = NULL;
+void checkMissingFiles(char *basepath, ReportList *reports) {
 	struct BPathIterator bpi;
 	
 	/* be sure there is low chance of the path being too short */
 	char filepath_expanded[FILE_MAXDIR*2]; 
 	
-	BLI_bpathIterator_init(&bpi);
+	BLI_bpathIterator_init(&bpi, basepath);
 	while (!BLI_bpathIterator_isDone(&bpi)) {
 		BLI_bpathIterator_getPathExpanded( &bpi, filepath_expanded );
 		
-		if (!BLI_exists(filepath_expanded)) {
-			if (!btxt) {
-				btxt = add_empty_text( "missing_files.log" );
-				if (txtname) {
-					BLI_strncpy(txtname, btxt->id.name+2, 24);
-				}
-			}
-			bpathToText(btxt, &bpi);
-		}
+		if (!BLI_exists(filepath_expanded))
+			bpath_as_report(&bpi, "file not found", reports);
+
 		BLI_bpathIterator_step(&bpi);
 	}
 	BLI_bpathIterator_free(&bpi);
 }
 
 /* dont log any errors at the moment, should probably do this */
-void makeFilesRelative(char *txtname, int *tot, int *changed, int *failed, int *linked) {
+void makeFilesRelative(char *basepath, ReportList *reports) {
+	int tot= 0, changed= 0, failed= 0, linked= 0;
 	struct BPathIterator bpi;
 	char filepath[FILE_MAX], *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);
+	BLI_bpathIterator_init(&bpi, basepath);
 	while (!BLI_bpathIterator_isDone(&bpi)) {
 		BLI_bpathIterator_getPath(&bpi, filepath);
 		libpath = BLI_bpathIterator_getLib(&bpi);
 		
 		if(strncmp(filepath, "//", 2)) {
 			if (libpath) { /* cant make relative if we are library - TODO, LOG THIS */
-				(*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);
+				BLI_cleanup_file(bpi.base_path, filepath_relative); /* fix any /foo/../foo/ */
+				BLI_makestringcode(bpi.base_path, 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)++;
+					bpath_as_report(&bpi, "couldn't make path relative (too long)", reports);
+					failed++;
 				} else {
 					if(strncmp(filepath_relative, "//", 2)==0) {
 						BLI_bpathIterator_setPath(&bpi, filepath_relative);
-						(*changed)++;
+						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)++;
+						bpath_as_report(&bpi, "couldn't make path relative", reports);
+						failed++;
 					}
 				}
 			}
 		}
 		BLI_bpathIterator_step(&bpi);
-		(*tot)++;
+		tot++;
 	}
 	BLI_bpathIterator_free(&bpi);
+
+	if(reports)
+		BKE_reportf(reports, failed ? RPT_ERROR : RPT_INFO, "Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
 }
 
 /* dont log any errors at the moment, should probably do this -
  * Verry similar to makeFilesRelative - keep in sync! */
-void makeFilesAbsolute(char *txtname, int *tot, int *changed, int *failed, int *linked) {
+void makeFilesAbsolute(char *basepath, ReportList *reports)
+{
+	int tot= 0, changed= 0, failed= 0, linked= 0;
+
 	struct BPathIterator bpi;
 	char filepath[FILE_MAX], *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);
+	BLI_bpathIterator_init(&bpi, basepath);
 	while (!BLI_bpathIterator_isDone(&bpi)) {
 		BLI_bpathIterator_getPath(&bpi, filepath);
 		libpath = BLI_bpathIterator_getLib(&bpi);
 		
 		if(strncmp(filepath, "//", 2)==0) {
 			if (libpath) { /* cant make absolute if we are library - TODO, LOG THIS */
-				(*linked)++;
+				linked++;
 			} else { /* get the expanded path and check it is relative or too long */
 				BLI_bpathIterator_getPathExpanded( &bpi, filepath_absolute );
-				BLI_cleanup_file(G.sce, filepath_absolute); /* fix any /foo/../foo/ */
+				BLI_cleanup_file(bpi.base_path, 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)++;
+					bpath_as_report(&bpi, "couldn't make absolute (too long)", reports);
+					failed++;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list