[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41180] trunk/blender/source: Code cleanup : don't use btempdir/bprogdir/bprogname globals anymore, but wrap
Brecht Van Lommel
brechtvanlommel at pandora.be
Fri Oct 21 19:37:39 CEST 2011
Revision: 41180
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41180
Author: blendix
Date: 2011-10-21 17:37:38 +0000 (Fri, 21 Oct 2011)
Log Message:
-----------
Code cleanup: don't use btempdir/bprogdir/bprogname globals anymore, but wrap
in BLI_ functions.
Modified Paths:
--------------
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/BLI_path_util.h
trunk/blender/source/blender/blenlib/intern/path_util.c
trunk/blender/source/blender/editors/interface/resources.c
trunk/blender/source/blender/makesrna/intern/rna_userdef.c
trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c
trunk/blender/source/blender/python/BPY_extern.h
trunk/blender/source/blender/python/intern/bpy_app.c
trunk/blender/source/blender/python/intern/bpy_interface.c
trunk/blender/source/blender/render/intern/source/pipeline.c
trunk/blender/source/blender/windowmanager/intern/wm_files.c
trunk/blender/source/blender/windowmanager/intern/wm_operators.c
trunk/blender/source/blenderplayer/bad_level_call_stubs/stubs.c
trunk/blender/source/creator/creator.c
trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
Modified: trunk/blender/source/blender/blenkernel/intern/blender.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/blender.c 2011-10-21 17:10:59 UTC (rev 41179)
+++ trunk/blender/source/blender/blenkernel/intern/blender.c 2011-10-21 17:37:38 UTC (rev 41180)
@@ -549,7 +549,7 @@
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 @@
/* 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) {
Modified: trunk/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/pointcache.c 2011-10-21 17:10:59 UTC (rev 41179)
+++ trunk/blender/source/blender/blenkernel/intern/pointcache.c 2011-10-21 17:37:38 UTC (rev 41180)
@@ -923,8 +923,8 @@
}
/* 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() */
}
Modified: trunk/blender/source/blender/blenlib/BLI_blenlib.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_blenlib.h 2011-10-21 17:10:59 UTC (rev 41179)
+++ trunk/blender/source/blender/blenlib/BLI_blenlib.h 2011-10-21 17:37:38 UTC (rev 41180)
@@ -64,8 +64,6 @@
#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
Modified: trunk/blender/source/blender/blenlib/BLI_path_util.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_path_util.h 2011-10-21 17:10:59 UTC (rev 41179)
+++ trunk/blender/source/blender/blenlib/BLI_path_util.h 2011-10-21 17:37:38 UTC (rev 41180)
@@ -181,30 +181,21 @@
*/
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);
+ /* 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);
- /**
- * 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);
+ /* 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);
#endif
Modified: trunk/blender/source/blender/blenlib/intern/path_util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/path_util.c 2011-10-21 17:10:59 UTC (rev 41179)
+++ trunk/blender/source/blender/blenlib/intern/path_util.c 2011-10-21 17:37:38 UTC (rev 41180)
@@ -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 @@
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_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 @@
/* 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)
Modified: trunk/blender/source/blender/editors/interface/resources.c
===================================================================
--- trunk/blender/source/blender/editors/interface/resources.c 2011-10-21 17:10:59 UTC (rev 41179)
+++ trunk/blender/source/blender/editors/interface/resources.c 2011-10-21 17:37:38 UTC (rev 41180)
@@ -1127,7 +1127,7 @@
}
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 */
Modified: trunk/blender/source/blender/makesrna/intern/rna_userdef.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_userdef.c 2011-10-21 17:10:59 UTC (rev 41179)
+++ trunk/blender/source/blender/makesrna/intern/rna_userdef.c 2011-10-21 17:37:38 UTC (rev 41180)
@@ -295,8 +295,7 @@
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))
Modified: trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c 2011-10-21 17:10:59 UTC (rev 41179)
+++ trunk/blender/source/blender/modifiers/intern/MOD_fluidsim_util.c 2011-10-21 17:37:38 UTC (rev 41180)
@@ -105,7 +105,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, btempdir, FILE_MAX);
+ BLI_strncpy(fss->surfdataPath, BLI_temporary_dir(), FILE_MAX);
// first init of bounding box
// no bounding box needed
Modified: trunk/blender/source/blender/python/BPY_extern.h
===================================================================
--- trunk/blender/source/blender/python/BPY_extern.h 2011-10-21 17:10:59 UTC (rev 41179)
+++ trunk/blender/source/blender/python/BPY_extern.h 2011-10-21 17:37:38 UTC (rev 41180)
@@ -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 output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list