[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13671] trunk/blender/source: Added a global string to be used for the tempdir.

Campbell Barton ideasman42 at gmail.com
Wed Feb 13 14:55:23 CET 2008


Revision: 13671
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13671
Author:   campbellbarton
Date:     2008-02-13 14:55:22 +0100 (Wed, 13 Feb 2008)

Log Message:
-----------
Added a global string to be used for the tempdir. since the user preference is not loaded in background mode and the user preference is not validated and has no fallback.
'btempdir' is set with BLI_where_is_temp() - This tries to use U.tempdir but falls back to $TEMP or /tmp/

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c
    trunk/blender/source/blender/blenkernel/intern/blender.c
    trunk/blender/source/blender/blenkernel/intern/pointcache.c
    trunk/blender/source/blender/blenlib/BLI_blenlib.h
    trunk/blender/source/blender/blenlib/intern/fileops.c
    trunk/blender/source/blender/blenlib/intern/util.c
    trunk/blender/source/blender/python/BPY_extern.h
    trunk/blender/source/blender/python/api2_2x/Blender.c
    trunk/blender/source/blender/render/intern/source/pipeline.c
    trunk/blender/source/blender/src/fluidsim.c
    trunk/blender/source/blender/src/header_info.c
    trunk/blender/source/blender/src/headerbuttons.c
    trunk/blender/source/blender/src/space.c
    trunk/blender/source/blender/src/usiblender.c
    trunk/blender/source/creator/creator.c
    trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp

Modified: trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c
===================================================================
--- trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c	2008-02-13 13:36:35 UTC (rev 13670)
+++ trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c	2008-02-13 13:55:22 UTC (rev 13671)
@@ -49,6 +49,7 @@
 int winqueue_break= 0;
 
 char bprogname[1];
+char btempdir[1];
 
 struct IpoCurve;
 struct FluidsimSettings;

Modified: trunk/blender/source/blender/blenkernel/intern/blender.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/blender.c	2008-02-13 13:36:35 UTC (rev 13670)
+++ trunk/blender/source/blender/blenkernel/intern/blender.c	2008-02-13 13:55:22 UTC (rev 13671)
@@ -605,7 +605,7 @@
 		counter= counter % U.undosteps;	
 	
 		sprintf(numstr, "%d.blend", counter);
-		BLI_make_file_string("/", tstr, U.tempdir, numstr);
+		BLI_make_file_string("/", tstr, btempdir, numstr);
 	
 		success= BLO_write_file(tstr, G.fileflags, &err);
 		
@@ -716,7 +716,7 @@
 	/* no undo state to save */
 	if(undobase.first==undobase.last) return;
 		
-	BLI_make_file_string("/", str, U.tempdir, "quit.blend");
+	BLI_make_file_string("/", str, btempdir, "quit.blend");
 
 	file = open(str,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
 	if(file == -1) {

Modified: trunk/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/pointcache.c	2008-02-13 13:36:35 UTC (rev 13670)
+++ trunk/blender/source/blender/blenkernel/intern/pointcache.c	2008-02-13 13:55:22 UTC (rev 13671)
@@ -51,10 +51,7 @@
   #include "BLI_winstuff.h"
 #endif
 
-/* for U.tempdir */
-#include "DNA_userdef_types.h"
 
-
 /*	Takes an Object ID and returns a unique name
 	- id: object id
 	- cfra: frame for the cache, can be negative
@@ -79,9 +76,8 @@
 		return strlen(filename);
 	} else {
 		/* use the temp path. this is weak but better then not using point cache at all */
-		if (U.tempdir[0] != '\0' && BLI_exists(U.tempdir)) {
-			return sprintf(filename, "%s/"PTCACHE_PATH"untitled/", U.tempdir);
-		}
+		/* btempdir is assumed to exist and ALWAYS has a trailing slash */
+		return sprintf(filename, "%s"PTCACHE_PATH"untitled/", btempdir);
 	}
 	return -1;
 }
@@ -100,7 +96,7 @@
 	if (do_path) {
 		len = ptcache_path(filename);
 		if (len==-1)
-			return;
+			return -1;
 		newname += len;
 	}
 	idname = (id->name+2);

Modified: trunk/blender/source/blender/blenlib/BLI_blenlib.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_blenlib.h	2008-02-13 13:36:35 UTC (rev 13670)
+++ trunk/blender/source/blender/blenlib/BLI_blenlib.h	2008-02-13 13:55:22 UTC (rev 13671)
@@ -70,7 +70,6 @@
 #include "DNA_listBase.h" 
 
 #include <stdlib.h>
-
 extern ListBase fillfacebase;
 extern ListBase fillvertbase;
 /**
@@ -79,6 +78,8 @@
 extern ListBase filledgebase;
 extern int totblock;
 
+extern char btempdir[]; /* creator.c temp dir used instead of U.tempdir, set with BLI_where_is_temp( btempdir, 1 ); */
+
 struct chardesc;
 struct direntry;
 struct rctf;
@@ -258,6 +259,17 @@
 void BLI_where_am_i(char *fullname, const char *name);
 
 	/**
+	 * Gets the temp directory when blender first runs.
+	 * If the default path is not found, use try $TEMP
+	 * 
+	 * Also make sure the temp dir has a trailing slash
+	 *
+	 * @param fullname The full path to the temp directory
+	 */
+void BLI_where_is_temp(char *fullname, int usertemp);
+
+
+	/**
 	 * determines the full path to the application bundle on OS X
 	 *
 	 * @return path to application bundle
@@ -300,6 +312,7 @@
 int   BLI_move(char *file, char *to);
 int   BLI_touch(const char *file);
 char *BLI_last_slash(const char *string);
+void  BLI_add_slash(char *string);
 
 /* BLI_rct.c */
 /**

Modified: trunk/blender/source/blender/blenlib/intern/fileops.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/fileops.c	2008-02-13 13:36:35 UTC (rev 13670)
+++ trunk/blender/source/blender/blenlib/intern/fileops.c	2008-02-13 13:55:22 UTC (rev 13671)
@@ -92,6 +92,22 @@
 	else return lfslash;
 }
 
+/* adds a slash if there isnt one there alredy */
+void BLI_add_slash(char *string) {
+	int len = strlen(string);
+#ifdef WIN32
+	if (string[len-1]!='\\') {
+		string[len] = '\\';
+		string[len+1] = '\0';
+	}
+#else
+	if (string[len-1]!='/') {
+		string[len] = '/';
+		string[len+1] = '\0';
+	}
+#endif
+}
+
 /* gzip the file in from and write it to "to". 
  return -1 if zlib fails, -2 if the originating file does not exist
  note: will remove the "from" file

Modified: trunk/blender/source/blender/blenlib/intern/util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/util.c	2008-02-13 13:36:35 UTC (rev 13670)
+++ trunk/blender/source/blender/blenlib/intern/util.c	2008-02-13 13:55:22 UTC (rev 13671)
@@ -44,8 +44,10 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_listBase.h"
+#include "DNA_userdef_types.h"
+
 #include "BLI_blenlib.h"
-#include "DNA_listBase.h"
 #include "BLI_storage.h"
 #include "BLI_storage_types.h"
 #include "BLI_dynamiclist.h"
@@ -1605,6 +1607,29 @@
 	}
 }
 
+void BLI_where_is_temp(char *fullname, int usertemp)
+{
+	fullname[0] = '\0';
+	
+	if (usertemp && BLI_exists(U.tempdir)) {
+		strcpy(fullname, U.tempdir);
+	}
+	
+	if (fullname[0] == '\0') {
+		char *tmp = getenv("TEMP");
+		if (tmp && BLI_exists(tmp)) {
+			strcpy(fullname, tmp);
+		}
+	}
+	
+	if (fullname[0] == '\0') {
+		strcpy(fullname, "/tmp/");
+	} else {
+		/* add a trailing slash if needed */
+		BLI_add_slash(fullname);
+	}
+}
+
 /* 
  * returns absolute path to the app bundle
  * only useful on OS X 

Modified: trunk/blender/source/blender/python/BPY_extern.h
===================================================================
--- trunk/blender/source/blender/python/BPY_extern.h	2008-02-13 13:36:35 UTC (rev 13670)
+++ trunk/blender/source/blender/python/BPY_extern.h	2008-02-13 13:55:22 UTC (rev 13671)
@@ -34,6 +34,7 @@
 #define BPY_EXTERN_H
 
 extern char bprogname[];	/* holds a copy of argv[0], from creator.c */
+extern char btempdir[];		/* use this to store a valid temp directory */
 
 struct Text; /* defined in DNA_text_types.h */
 struct ID; /* DNA_ID.h */

Modified: trunk/blender/source/blender/python/api2_2x/Blender.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Blender.c	2008-02-13 13:36:35 UTC (rev 13670)
+++ trunk/blender/source/blender/python/api2_2x/Blender.c	2008-02-13 13:55:22 UTC (rev 13671)
@@ -286,6 +286,7 @@
 		if ( !PyArg_Parse( arg , "s" , &dir ))
 			return EXPP_ReturnPyObjError( PyExc_ValueError, "expected a string" );
 		BLI_strncpy(U.tempdir, dir, FILE_MAXDIR);
+		BLI_where_is_temp( btempdir, 1 );
 	} else if (StringEqual( name , "compressfile" ) ) {
 		int value = PyObject_IsTrue( arg );
 		

Modified: trunk/blender/source/blender/render/intern/source/pipeline.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/pipeline.c	2008-02-13 13:36:35 UTC (rev 13670)
+++ trunk/blender/source/blender/render/intern/source/pipeline.c	2008-02-13 13:55:22 UTC (rev 13671)
@@ -403,8 +403,6 @@
 	return 0;
 }
 
-
-
 static void render_unique_exr_name(Render *re, char *str, int sample)
 {
 	char di[FILE_MAX], name[FILE_MAXFILE], fi[FILE_MAXFILE];
@@ -417,11 +415,7 @@
 	else
 		sprintf(name, "%s_%s%d.exr", fi, re->scene->id.name+2, sample);
 
-	if(G.background)
-		BLI_make_file_string("/", str, "/tmp/", name);
-	else
-		BLI_make_file_string("/", str, U.tempdir, name);
-		
+	BLI_make_file_string("/", str, btempdir, name);
 }
 
 static void render_layer_add_pass(RenderResult *rr, RenderLayer *rl, int channels, int passtype)

Modified: trunk/blender/source/blender/src/fluidsim.c
===================================================================
--- trunk/blender/source/blender/src/fluidsim.c	2008-02-13 13:36:35 UTC (rev 13670)
+++ trunk/blender/source/blender/src/fluidsim.c	2008-02-13 13:55:22 UTC (rev 13671)
@@ -70,7 +70,6 @@
 #include "BKE_scene.h"
 #include "BKE_object.h"
 #include "BKE_softbody.h"
-#include "BKE_utildefines.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_ipo.h"
 #include "LBM_fluidsim.h"
@@ -151,6 +150,7 @@
 /* ********************** fluid sim settings struct functions ********************** */
 
 /* allocates and initializes general main data */
+
 FluidsimSettings *fluidsimSettingsNew(struct Object *srcob)
 {
 	//char blendDir[FILE_MAXDIR], blendFile[FILE_MAXFILE];
@@ -189,7 +189,7 @@
 
 	/*  elubie: changed this to default to the same dir as the render output
 		to prevent saving to C:\ on Windows */
-	BLI_strncpy(fss->surfdataPath, U.tempdir, FILE_MAX); 
+	BLI_strncpy(fss->surfdataPath, btempdir, FILE_MAX); 
 	fss->orgMesh = (Mesh *)srcob->data;
 	fss->meshSurface = NULL;
 	fss->meshBB = NULL;

Modified: trunk/blender/source/blender/src/header_info.c
===================================================================
--- trunk/blender/source/blender/src/header_info.c	2008-02-13 13:36:35 UTC (rev 13670)
+++ trunk/blender/source/blender/src/header_info.c	2008-02-13 13:55:22 UTC (rev 13671)
@@ -867,7 +867,7 @@
 			
 			strcpy(scestr, G.sce);	/* temporal store */
 			save_over = G.save_over;
-			BLI_make_file_string("/", str, U.tempdir, "quit.blend");
+			BLI_make_file_string("/", str, btempdir, "quit.blend");
 			retval = BKE_read_file(str, NULL);
 			
 			/*we successfully loaded a blend file, get sure that

Modified: trunk/blender/source/blender/src/headerbuttons.c
===================================================================
--- trunk/blender/source/blender/src/headerbuttons.c	2008-02-13 13:36:35 UTC (rev 13670)
+++ trunk/blender/source/blender/src/headerbuttons.c	2008-02-13 13:55:22 UTC (rev 13671)
@@ -569,6 +569,8 @@
 	BLI_split_dirfile(name, dir, file);
 
 	strcpy(U.tempdir, dir);
+	BLI_where_is_temp( btempdir, 1 );
+	
 	allqueue(REDRAWALL, 0);
 }
 

Modified: trunk/blender/source/blender/src/space.c
===================================================================
--- trunk/blender/source/blender/src/space.c	2008-02-13 13:36:35 UTC (rev 13670)
+++ trunk/blender/source/blender/src/space.c	2008-02-13 13:55:22 UTC (rev 13671)
@@ -3340,10 +3340,18 @@
 	}
 }
 
+/* setting the temp dir needs to set */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list