diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-02-13 16:55:22 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-02-13 16:55:22 +0300 |
commit | bc9848f7e67c3e695403179f8bcdb78b0e5764a3 (patch) | |
tree | 18561a90fa2660b5227a0c73c1d519d8a58cfab3 /source/blender/blenlib | |
parent | e26b5aa9c47fbc604c23efe9100940ff68d8ddbe (diff) |
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/
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_blenlib.h | 15 | ||||
-rw-r--r-- | source/blender/blenlib/intern/fileops.c | 16 | ||||
-rw-r--r-- | source/blender/blenlib/intern/util.c | 27 |
3 files changed, 56 insertions, 2 deletions
diff --git a/source/blender/blenlib/BLI_blenlib.h b/source/blender/blenlib/BLI_blenlib.h index 4fc4241e6dc..39b679144d5 100644 --- a/source/blender/blenlib/BLI_blenlib.h +++ b/source/blender/blenlib/BLI_blenlib.h @@ -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; @@ -258,6 +259,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 * * @return path to application bundle @@ -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 */ /** diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 2ee42d16176..fa76f2023eb 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.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 diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c index d0f58a50eb9..f849b022e6e 100644 --- a/source/blender/blenlib/intern/util.c +++ b/source/blender/blenlib/intern/util.c @@ -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 |