diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-10-21 21:37:38 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-10-21 21:37:38 +0400 |
commit | 00735ed9e49d2103e06b0e25513b5b880f0db226 (patch) | |
tree | c7138c391136a658698b3195635d6d2298ecb51f /source/blender/blenlib | |
parent | 4d48dbe5fd553ab149abd1f062eec08ae813060a (diff) |
Code cleanup: don't use btempdir/bprogdir/bprogname globals anymore, but wrap
in BLI_ functions.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_blenlib.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_path_util.h | 37 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 72 |
3 files changed, 76 insertions, 35 deletions
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) |