Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2011-10-21 21:37:38 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2011-10-21 21:37:38 +0400
commit00735ed9e49d2103e06b0e25513b5b880f0db226 (patch)
treec7138c391136a658698b3195635d6d2298ecb51f /source
parent4d48dbe5fd553ab149abd1f062eec08ae813060a (diff)
Code cleanup: don't use btempdir/bprogdir/bprogname globals anymore, but wrap
in BLI_ functions.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/blender.c4
-rw-r--r--source/blender/blenkernel/intern/pointcache.c4
-rw-r--r--source/blender/blenlib/BLI_blenlib.h2
-rw-r--r--source/blender/blenlib/BLI_path_util.h37
-rw-r--r--source/blender/blenlib/intern/path_util.c72
-rw-r--r--source/blender/editors/interface/resources.c2
-rw-r--r--source/blender/makesrna/intern/rna_userdef.c3
-rw-r--r--source/blender/modifiers/intern/MOD_fluidsim_util.c2
-rw-r--r--source/blender/python/BPY_extern.h2
-rw-r--r--source/blender/python/intern/bpy_app.c7
-rw-r--r--source/blender/python/intern/bpy_interface.c6
-rw-r--r--source/blender/render/intern/source/pipeline.c2
-rw-r--r--source/blender/windowmanager/intern/wm_files.c9
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c2
-rw-r--r--source/blenderplayer/bad_level_call_stubs/stubs.c1
-rw-r--r--source/creator/creator.c18
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_ghost.cpp12
17 files changed, 105 insertions, 80 deletions
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index 5358a26e660..7a675dc64c3 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -549,7 +549,7 @@ void BKE_write_undo(bContext *C, const char *name)
counter= counter % U.undosteps;
BLI_snprintf(numstr, sizeof(numstr), "%d.blend", counter);
- BLI_make_file_string("/", filepath, btempdir, numstr);
+ BLI_make_file_string("/", filepath, BLI_temporary_dir(), numstr);
/* success= */ /* UNUSED */ BLO_write_file(CTX_data_main(C), filepath, fileflags, NULL, NULL);
@@ -719,7 +719,7 @@ void BKE_undo_save_quit(void)
/* no undo state to save */
if(undobase.first==undobase.last) return;
- BLI_make_file_string("/", str, btempdir, "quit.blend");
+ BLI_make_file_string("/", str, BLI_temporary_dir(), "quit.blend");
file = open(str,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
if(file == -1) {
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index bd5e5dc6049..f12e9698810 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -923,8 +923,8 @@ static int ptcache_path(PTCacheID *pid, char *filename)
}
/* use the temp path. this is weak but better then not using point cache at all */
- /* btempdir is assumed to exist and ALWAYS has a trailing slash */
- BLI_snprintf(filename, MAX_PTCACHE_PATH, "%s"PTCACHE_PATH"%d", btempdir, abs(getpid()));
+ /* temporary directory is assumed to exist and ALWAYS has a trailing slash */
+ BLI_snprintf(filename, MAX_PTCACHE_PATH, "%s"PTCACHE_PATH"%d", BLI_temporary_dir(), abs(getpid()));
return BLI_add_slash(filename); /* new strlen() */
}
diff --git a/source/blender/blenlib/BLI_blenlib.h b/source/blender/blenlib/BLI_blenlib.h
index cda7a51c47f..4eb4b71da12 100644
--- a/source/blender/blenlib/BLI_blenlib.h
+++ b/source/blender/blenlib/BLI_blenlib.h
@@ -64,8 +64,6 @@ struct ListBase;
#include <stdlib.h>
-extern char btempdir[]; /* creator.c temp dir used instead of U.tempdir, set with BLI_where_is_temp( btempdir, 1 ); */
-
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index 9ccdc37c353..56ecec042f2 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -181,29 +181,20 @@ void BLI_path_rel(char *file, const char *relfile);
*/
void BLI_char_switch(char *string, char from, char to);
-/**
- * Checks if name is a fully qualified filename to an executable.
- * If not it searches $PATH for the file. On Windows it also
- * adds the correct extension (.com .exe etc) from
- * $PATHEXT if necessary. Also on Windows it translates
- * the name to its 8.3 version to prevent problems with
- * spaces and stuff. Final result is returned in fullname.
- *
- * @param fullname The full path and full name of the executable
- * @param name The name of the executable (usually argv[0]) to be checked
- */
-void BLI_where_am_i(char *fullname, const size_t maxlen, 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, const size_t maxlen, int usertemp);
-
+ /* Initialize path to program executable */
+void BLI_init_program_path(const char *argv0);
+ /* Initialize path to temporary directory.
+ * NOTE: On Window userdir will be set to the temporary directory! */
+void BLI_init_temporary_dir(char *userdir);
+
+ /* Path to executable */
+const char *BLI_program_path(void);
+ /* Path to directory of executable */
+const char *BLI_program_dir(void);
+ /* Path to temporary directory (with trailing slash) */
+const char *BLI_temporary_dir(void);
+ /* Path to the system temporary directory (with trailing slash) */
+void BLI_system_temporary_dir(char *dir);
#ifdef WITH_ICONV
void BLI_string_to_utf8(char *original, char *utf_8, const char *code);
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index b338bfcbc50..f57ac09c9b9 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -41,7 +41,7 @@
#include "MEM_guardedalloc.h"
-#include "DNA_userdef_types.h"
+#include "DNA_listBase.h"
#include "BLI_fileops.h"
#include "BLI_path_util.h"
@@ -87,8 +87,9 @@
/* local */
#define UNIQUE_NAME_MAX 128
-extern char bprogname[];
-extern char bprogdir[];
+static char bprogname[FILE_MAX]; /* path to program executable */
+static char bprogdir[FILE_MAX]; /* path in which executable is located */
+static char btempdir[FILE_MAX]; /* temporary directory */
static int add_win32_extension(char *name);
static char *blender_version_decimal(const int ver);
@@ -1670,8 +1671,19 @@ static int add_win32_extension(char *name)
return (retval);
}
-/* filename must be FILE_MAX length minimum */
-void BLI_where_am_i(char *fullname, const size_t maxlen, const char *name)
+/*
+* Checks if name is a fully qualified filename to an executable.
+* If not it searches $PATH for the file. On Windows it also
+* adds the correct extension (.com .exe etc) from
+* $PATHEXT if necessary. Also on Windows it translates
+* the name to its 8.3 version to prevent problems with
+* spaces and stuff. Final result is returned in fullname.
+*
+* @param fullname The full path and full name of the executable
+* (must be FILE_MAX minimum)
+* @param name The name of the executable (usually argv[0]) to be checked
+*/
+static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name)
{
char filename[FILE_MAXDIR+FILE_MAXFILE];
const char *path = NULL, *temp;
@@ -1751,12 +1763,37 @@ void BLI_where_am_i(char *fullname, const size_t maxlen, const char *name)
}
}
-void BLI_where_is_temp(char *fullname, const size_t maxlen, int usertemp)
+void BLI_init_program_path(const char *argv0)
+{
+ bli_where_am_i(bprogname, sizeof(bprogname), argv0);
+ BLI_split_dir_part(bprogname, bprogdir, sizeof(bprogdir));
+}
+
+const char *BLI_program_path(void)
+{
+ return bprogname;
+}
+
+const char *BLI_program_dir(void)
+{
+ return bprogdir;
+}
+
+/**
+* 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
+* @param userdir Directory specified in user preferences
+*/
+void BLI_where_is_temp(char *fullname, const size_t maxlen, char *userdir)
{
fullname[0] = '\0';
- if (usertemp && BLI_is_dir(U.tempdir)) {
- BLI_strncpy(fullname, U.tempdir, maxlen);
+ if (userdir && BLI_is_dir(userdir)) {
+ BLI_strncpy(fullname, userdir, maxlen);
}
@@ -1790,13 +1827,28 @@ void BLI_where_is_temp(char *fullname, const size_t maxlen, int usertemp)
/* add a trailing slash if needed */
BLI_add_slash(fullname);
#ifdef WIN32
- if(U.tempdir != fullname) {
- BLI_strncpy(U.tempdir, fullname, maxlen); /* also set user pref to show %TEMP%. /tmp/ is just plain confusing for Windows users. */
+ if(userdir != fullname) {
+ BLI_strncpy(userdir, fullname, maxlen); /* also set user pref to show %TEMP%. /tmp/ is just plain confusing for Windows users. */
}
#endif
}
}
+void BLI_init_temporary_dir(char *userdir)
+{
+ BLI_where_is_temp(btempdir, FILE_MAX, userdir);
+}
+
+const char *BLI_temporary_dir(void)
+{
+ return btempdir;
+}
+
+void BLI_system_temporary_dir(char *dir)
+{
+ BLI_where_is_temp(dir, FILE_MAX, NULL);
+}
+
#ifdef WITH_ICONV
void BLI_string_to_utf8(char *original, char *utf_8, const char *code)
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index fd511948bac..61936fba931 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -1127,7 +1127,7 @@ void init_userdef_do_versions(void)
}
if(U.mixbufsize==0) U.mixbufsize= 2048;
if (strcmp(U.tempdir, "/") == 0) {
- BLI_where_is_temp(U.tempdir, sizeof(U.tempdir), FALSE);
+ BLI_system_temporary_dir(U.tempdir);
}
if (U.autokey_mode == 0) {
/* 'add/replace' but not on */
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index d579d00f6ce..c6a76cf42b9 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -295,8 +295,7 @@ static void rna_userdef_addon_remove(bAddon *bext)
static void rna_userdef_temp_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
{
- extern char btempdir[];
- BLI_where_is_temp(btempdir, FILE_MAX, 1);
+ BLI_init_temporary_dir(U.tempdir);
}
static void rna_userdef_text_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c
index 277f0852f90..a2f62d55d69 100644
--- a/source/blender/modifiers/intern/MOD_fluidsim_util.c
+++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c
@@ -105,7 +105,7 @@ void fluidsim_init(FluidsimModifierData *fluidmd)
/* elubie: changed this to default to the same dir as the render output
to prevent saving to C:\ on Windows */
- BLI_strncpy(fss->surfdataPath, btempdir, FILE_MAX);
+ BLI_strncpy(fss->surfdataPath, BLI_temporary_dir(), FILE_MAX);
// first init of bounding box
// no bounding box needed
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h
index cd5c8e53ef7..ae82dac7f14 100644
--- a/source/blender/python/BPY_extern.h
+++ b/source/blender/python/BPY_extern.h
@@ -36,8 +36,6 @@
#ifndef BPY_EXTERN_H
#define BPY_EXTERN_H
-extern char bprogname[]; /* holds a copy of argv[0], from creator.c */
-
struct Text; /* defined in DNA_text_types.h */
struct ID; /* DNA_ID.h */
struct Object; /* DNA_object_types.h */
diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c
index bd7be8dd9c5..c3d60bc353d 100644
--- a/source/blender/python/intern/bpy_app.c
+++ b/source/blender/python/intern/bpy_app.c
@@ -93,8 +93,6 @@ static PyStructSequence_Desc app_info_desc= {
static PyObject *make_app_info(void)
{
- extern char bprogname[]; /* argv[0] from creator.c */
-
PyObject *app_info;
int pos= 0;
@@ -118,7 +116,7 @@ static PyObject *make_app_info(void)
SetStrItem("");
#endif
SetStrItem(STRINGIFY(BLENDER_VERSION_CYCLE));
- SetStrItem(bprogname);
+ SetStrItem(BLI_program_path());
SetObjItem(PyBool_FromLong(G.background));
/* build info */
@@ -200,8 +198,7 @@ static int bpy_app_debug_value_set(PyObject *UNUSED(self), PyObject *value, void
static PyObject *bpy_app_tempdir_get(PyObject *UNUSED(self), void *UNUSED(closure))
{
- extern char btempdir[];
- return PyC_UnicodeFromByte(btempdir);
+ return PyC_UnicodeFromByte(BLI_temporary_dir());
}
static PyObject *bpy_app_driver_dict_get(PyObject *UNUSED(self), void *UNUSED(closure))
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index ddbd557375c..90156a9cb3e 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -193,9 +193,9 @@ void BPY_python_start(int argc, const char **argv)
PyThreadState *py_tstate= NULL;
/* not essential but nice to set our name */
- static wchar_t bprogname_wchar[FILE_MAXDIR+FILE_MAXFILE]; /* python holds a reference */
- BLI_strncpy_wchar_from_utf8(bprogname_wchar, bprogname, sizeof(bprogname_wchar) / sizeof(wchar_t));
- Py_SetProgramName(bprogname_wchar);
+ static wchar_t program_path_wchar[FILE_MAXDIR+FILE_MAXFILE]; /* python holds a reference */
+ BLI_strncpy_wchar_from_utf8(program_path_wchar, BLI_program_path(), sizeof(program_path_wchar) / sizeof(wchar_t));
+ Py_SetProgramName(program_path_wchar);
/* must run before python initializes */
PyImport_ExtendInittab(bpy_internal_modules);
diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c
index 3db73816025..405779c360f 100644
--- a/source/blender/render/intern/source/pipeline.c
+++ b/source/blender/render/intern/source/pipeline.c
@@ -478,7 +478,7 @@ static void scene_unique_exr_name(Scene *scene, char *str, int sample)
else
BLI_snprintf(name, sizeof(name), "%s_%s%d.exr", fi, scene->id.name+2, sample);
- BLI_make_file_string("/", str, btempdir, name);
+ BLI_make_file_string("/", str, BLI_temporary_dir(), name);
}
static void render_unique_exr_name(Render *re, char *str, int sample)
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 9b2d7026a46..4cd31b8d894 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -289,8 +289,9 @@ static void wm_init_userdef(bContext *C)
if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) G.f |= G_SCRIPT_AUTOEXEC;
else G.f &= ~G_SCRIPT_AUTOEXEC;
}
+
/* update tempdir from user preferences */
- BLI_where_is_temp(btempdir, FILE_MAX, 1);
+ BLI_init_temporary_dir(U.tempdir);
}
@@ -856,14 +857,14 @@ void wm_autosave_location(char *filepath)
* BLI_make_file_string will create string that has it most likely on C:\
* through get_default_root().
* If there is no C:\tmp autosave fails. */
- if (!BLI_exists(btempdir)) {
+ if (!BLI_exists(BLI_temporary_dir())) {
savedir = BLI_get_folder_create(BLENDER_USER_AUTOSAVE, NULL);
BLI_make_file_string("/", filepath, savedir, pidstr);
return;
}
#endif
- BLI_make_file_string("/", filepath, btempdir, pidstr);
+ BLI_make_file_string("/", filepath, BLI_temporary_dir(), pidstr);
}
void WM_autosave_init(wmWindowManager *wm)
@@ -921,7 +922,7 @@ void wm_autosave_delete(void)
if(BLI_exists(filename)) {
char str[FILE_MAXDIR+FILE_MAXFILE];
- BLI_make_file_string("/", str, btempdir, "quit.blend");
+ BLI_make_file_string("/", str, BLI_temporary_dir(), "quit.blend");
/* if global undo; remove tempsave, otherwise rename */
if(U.uiflag & USER_GLOBALUNDO) BLI_delete(filename, 0, 0);
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index a06da3941af..5fee5fb2a57 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -1807,7 +1807,7 @@ static int wm_recover_last_session_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_WINDOW, NULL);
/* load file */
- BLI_make_file_string("/", filename, btempdir, "quit.blend");
+ BLI_make_file_string("/", filename, BLI_temporary_dir(), "quit.blend");
WM_read_file(C, filename, op->reports);
G.fileflags &= ~G_FILE_RECOVER;
diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c
index fe53937ec5a..788b4e40eb2 100644
--- a/source/blenderplayer/bad_level_call_stubs/stubs.c
+++ b/source/blenderplayer/bad_level_call_stubs/stubs.c
@@ -129,7 +129,6 @@ struct RenderResult *RE_GetResult(struct Render *re){return (struct RenderResult
struct Render *RE_GetRender(const char *name){return (struct Render *) NULL;}
/* blenkernel */
-char btempdir[] = "";
void RE_FreeRenderResult(struct RenderResult *res){}
struct RenderResult *RE_MultilayerConvert(void *exrhandle, int rectx, int recty){return (struct RenderResult *) NULL;}
void RE_GetResultImage(struct Render *re, struct RenderResult *rr){}
diff --git a/source/creator/creator.c b/source/creator/creator.c
index 24f2d22a029..cdbc21337e6 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -62,6 +62,7 @@
#include "DNA_ID.h"
#include "DNA_scene_types.h"
+#include "DNA_userdef_types.h"
#include "BLI_blenlib.h"
@@ -141,10 +142,6 @@ static int print_version(int argc, const char **argv, void *data);
extern int pluginapi_force_ref(void); /* from blenpluginapi:pluginapi.c */
-char bprogname[FILE_MAX];
-char bprogdir[FILE_MAX];
-char btempdir[FILE_MAX];
-
#define BLEND_VERSION_STRING_FMT "Blender %d.%02d (sub %d)\n", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION
/* Initialize callbacks for the modules that need them */
@@ -1154,11 +1151,8 @@ int main(int argc, const char **argv)
fpsetmask(0);
#endif
- // copy path to executable in bprogname. playanim and creting runtimes
- // need this.
-
- BLI_where_am_i(bprogname, sizeof(bprogname), argv[0]);
- BLI_split_dir_part(bprogname, bprogdir, sizeof(bprogdir));
+ // initialize path to executable
+ BLI_init_program_path(argv[0]);
BLI_threadapi_init();
@@ -1213,7 +1207,8 @@ int main(int argc, const char **argv)
WM_init(C, argc, argv);
/* this is properly initialized with user defs, but this is default */
- BLI_where_is_temp(btempdir, FILE_MAX, 1); /* call after loading the startup.blend so we can read U.tempdir */
+ /* call after loading the startup.blend so we can read U.tempdir */
+ BLI_init_temporary_dir(U.tempdir);
#ifdef WITH_SDL
BLI_setenv("SDL_VIDEODRIVER", "dummy");
@@ -1224,7 +1219,8 @@ int main(int argc, const char **argv)
WM_init(C, argc, argv);
- BLI_where_is_temp(btempdir, FILE_MAX, 0); /* call after loading the startup.blend so we can read U.tempdir */
+ /* don't use user preferences temp dir */
+ BLI_init_temporary_dir(NULL);
}
#ifdef WITH_PYTHON
/**
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
index 78ea2aac8ce..f5439ba4f64 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
@@ -76,9 +76,6 @@ extern "C"
int GHOST_HACK_getFirstFile(char buf[]);
-extern char bprogname[]; /* holds a copy of argv[0], from creator.c */
-extern char btempdir[]; /* use this to store a valid temp directory */
-
// For BLF
#include "BLF_api.h"
#include "BLF_translation.h"
@@ -116,9 +113,6 @@ extern char datatoc_bfont_ttf[];
const int kMinWindowWidth = 100;
const int kMinWindowHeight = 100;
-char bprogname[FILE_MAX];
-char bprogdir[FILE_MAX];
-
static void mem_error_cb(const char *errorStr)
{
fprintf(stderr, "%s", errorStr);
@@ -380,8 +374,8 @@ int main(int argc, char** argv)
signal (SIGFPE, SIG_IGN);
#endif /* __alpha__ */
#endif /* __linux__ */
- BLI_where_am_i(bprogname, sizeof(bprogname), argv[0]);
- BLI_split_dir_part(bprogname, bprogdir, sizeof(bprogdir));
+ BLI_init_program_path(argv[0]);
+ BLI_init_temporary_dir(NULL);
#ifdef __APPLE__
// Can't use Carbon right now because of double defined type ID (In Carbon.h and DNA_ID.h, sigh)
/*
@@ -786,7 +780,7 @@ int main(int argc, char** argv)
}
else
{
- bfd = load_game_data(bprogname, filename[0]? filename: NULL);
+ bfd = load_game_data(BLI_program_path(), filename[0]? filename: NULL);
}
//::printf("game data loaded from %s\n", filename);