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/
This commit is contained in:
Campbell Barton 2008-02-13 13:55:22 +00:00
parent e26b5aa9c4
commit bc9848f7e6
16 changed files with 94 additions and 32 deletions

@ -49,6 +49,7 @@
int winqueue_break= 0;
char bprogname[1];
char btempdir[1];
struct IpoCurve;
struct FluidsimSettings;

@ -605,7 +605,7 @@ void BKE_write_undo(char *name)
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 @@ void BKE_undo_save_quit(void)
/* 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) {

@ -51,9 +51,6 @@
#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
@ -79,9 +76,8 @@ static int ptcache_path(char *filename)
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 @@ int BKE_ptcache_id_filename(struct ID *id, char *filename, int cfra, int stack_i
if (do_path) {
len = ptcache_path(filename);
if (len==-1)
return;
return -1;
newname += len;
}
idname = (id->name+2);

@ -70,7 +70,6 @@
#include "DNA_listBase.h"
#include <stdlib.h>
extern ListBase fillfacebase;
extern ListBase fillvertbase;
/**
@ -79,6 +78,8 @@ extern ListBase fillvertbase;
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;
@ -257,6 +258,17 @@ void BLI_free_file_lines(struct LinkNode *lines);
*/
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
*
@ -300,6 +312,7 @@ int BLI_delete(char *file, int dir, int recursive);
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 */
/**

@ -92,6 +92,22 @@ char *BLI_last_slash(const char *string) {
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

@ -44,8 +44,10 @@
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "DNA_listBase.h"
#include "DNA_userdef_types.h"
#include "BLI_blenlib.h"
#include "BLI_storage.h"
#include "BLI_storage_types.h"
#include "BLI_dynamiclist.h"
@ -1605,6 +1607,29 @@ void BLI_where_am_i(char *fullname, const char *name)
}
}
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

@ -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 */

@ -286,6 +286,7 @@ static PyObject *Blender_Set( PyObject * self, PyObject * args )
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 );

@ -403,8 +403,6 @@ static int passtype_from_name(char *str)
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 @@ static void render_unique_exr_name(Render *re, char *str, int sample)
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)

@ -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 @@ typedef struct {
/* ********************** 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 @@ FluidsimSettings *fluidsimSettingsNew(struct Object *srcob)
/* 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;

@ -867,7 +867,7 @@ static void do_info_filemenu(void *arg, int event)
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

@ -569,6 +569,8 @@ static void filesel_u_tempdir(char *name)
BLI_split_dirfile(name, dir, file);
strcpy(U.tempdir, dir);
BLI_where_is_temp( btempdir, 1 );
allqueue(REDRAWALL, 0);
}

@ -3340,10 +3340,18 @@ static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3, sh
}
}
/* setting the temp dir needs to set */
void eval_utemp_dir_callback(void *dummy1, void *dummy2)
{
if (!BLI_exists(U.tempdir))
error("temp directory does not exist, assign a valid directory");
BLI_where_is_temp(btempdir, 1);
}
void drawinfospace(ScrArea *sa, void *spacedata)
{
uiBlock *block;
uiBut *uibut;
static short cur_light=0;
float fac, col[3];
short xpos, ypos, ypostab, buth, rspace, dx, y1, y2, y3, y4, y5, y6, y7;
@ -4225,9 +4233,13 @@ void drawinfospace(ScrArea *sa, void *spacedata)
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefBut(block, TEX, 0, "Temp: ",
uibut = uiDefBut(block, TEX, 0, "Temp: ",
(xpos+edgsp+(3*lpref)+(3*midsp)),y1,(lpref-smfileselbut),buth,
U.tempdir, 1.0, 63.0, 0, 0, "The directory for storing temporary save files");
/* set the btempdir from U.temp */
uiButSetFunc(uibut, eval_utemp_dir_callback, NULL, NULL);
uiDefIconBut(block, BUT, B_TEMPDIRFILESEL, ICON_FILESEL,
(xpos+edgsp+(4*lpref)+(3*midsp)-smfileselbut),y1,smfileselbut,buth,
0, 0, 0, 0, 0, "Select the default temporary save file location");

@ -177,9 +177,7 @@ static void init_userdef_file(void)
}
if(U.mixbufsize==0) U.mixbufsize= 2048;
if (BLI_streq(U.tempdir, "/")) {
char *tmp= getenv("TEMP");
strcpy(U.tempdir, tmp?tmp:"/tmp/");
BLI_where_is_temp(U.tempdir, 0);
}
if (U.savetime <= 0) {
U.savetime = 1;
@ -646,7 +644,7 @@ static void get_autosave_location(char buf[FILE_MAXDIR+FILE_MAXFILE])
sprintf(pidstr, "%d.blend", abs(getpid()));
#ifdef WIN32
if (!BLI_exists(U.tempdir)) {
if (!BLI_exists(btempdir)) {
BLI_strncpy(subdir, "autosave", sizeof(subdir));
BLI_make_file_string("/", savedir, BLI_gethome(), subdir);
@ -659,7 +657,7 @@ static void get_autosave_location(char buf[FILE_MAXDIR+FILE_MAXFILE])
}
#endif
BLI_make_file_string("/", buf, U.tempdir, pidstr);
BLI_make_file_string("/", buf, btempdir, pidstr);
}
void BIF_read_autosavefile(void)
@ -950,7 +948,7 @@ static void delete_autosave(void)
if (BLI_exists(tstr)) {
char str[FILE_MAXDIR+FILE_MAXFILE];
BLI_make_file_string("/", str, U.tempdir, "quit.blend");
BLI_make_file_string("/", str, btempdir, "quit.blend");
if(U.uiflag & USER_GLOBALUNDO) BLI_delete(tstr, 0, 0);
else BLI_rename(tstr, str);

@ -128,7 +128,7 @@ extern void winlay_process_events(int wait_for_event);
extern int pluginapi_force_ref(void); /* from blenpluginapi:pluginapi.c */
char bprogname[FILE_MAXDIR+FILE_MAXFILE]; /* from blenpluginapi:pluginapi.c */
char btempdir[FILE_MAXDIR+FILE_MAXFILE];
/* Initialise callbacks for the modules that need them */
void setCallbacks(void);
@ -317,7 +317,7 @@ int main(int argc, char **argv)
// need this.
BLI_where_am_i(bprogname, argv[0]);
/* Hack - force inclusion of the plugin api functions,
* see blenpluginapi:pluginapi.c
*/
@ -490,12 +490,16 @@ int main(int argc, char **argv)
* added note (ton): i removed it altogether
*/
BIF_init();
BIF_init(); /* loads .B.blend */
BLI_where_is_temp( btempdir, 1 ); /* call after loading the .B.blend so we can read U.tempdir */
}
else {
BPY_start_python(argc, argv);
BLI_where_is_temp( btempdir, 0 ); /* call after loading the .B.blend so we can read U.tempdir */
// (ton) Commented out. I have no idea whats thisfor... will mail around!
// SYS_WriteCommandLineInt(syshandle,"noaudio",1);
// audio = 0;

@ -304,7 +304,6 @@ int main(int argc, char** argv)
#endif /* __alpha__ */
#endif /* __linux__ */
BLI_where_am_i(bprogname, argv[0]);
#ifdef __APPLE__
// Can't use Carbon right now because of double defined type ID (In Carbon.h and DNA_ID.h, sigh)
/*