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:
authorCampbell Barton <ideasman42@gmail.com>2008-02-29 18:50:28 +0300
committerCampbell Barton <ideasman42@gmail.com>2008-02-29 18:50:28 +0300
commit96247ce19ca08a9db3da83148851e897f725cb1b (patch)
tree47ac3326ec9d40add038246bc54af39f174e23b3 /source
parent95b0176fdedd4ac4b891563fd88161d4213a0cc2 (diff)
* Made BLI_join_dirfile() check before adding a slash between dir and file so as not to get /foo///bar.blend
* Pointcache now uses the process id to construct the path for unsaved files. (so 2 or more blender's open wont try to read/write the same pointcache) * Temp pointcache is cleared when existing blender, added BIF_clear_tempfiles() for this. Should also be usedto clear EXR's in the temp dir (TODO), BIF_clear_tempfiles also needs to be added in more places. (On file load for instace)
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_pointcache.h5
-rw-r--r--source/blender/blenkernel/intern/pointcache.c63
-rw-r--r--source/blender/blenlib/intern/util.c14
-rw-r--r--source/blender/include/BIF_usiblender.h1
-rw-r--r--source/blender/src/usiblender.c18
5 files changed, 84 insertions, 17 deletions
diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index 52cc0ddcaa7..12068f7dedf 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -40,11 +40,10 @@
/* Add the blendfile name after blendcache_ */
#define PTCACHE_EXT ".bphys"
-#define PTCACHE_PATH "//blendcache_"
+#define PTCACHE_PATH "blendcache_"
/* Global funcs */
-/* void BKE_ptcache_clean(void); - not implimented yet! */
-
+void BKE_ptcache_remove(void);
/* Object spesific funcs */
int BKE_ptcache_id_filename(struct ID *id, char *filename, int cfra, int stack_index, short do_path, short do_ext);
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 7d3b6ca0569..cdb95e2f015 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -51,6 +51,12 @@
#include "BLI_winstuff.h"
#endif
+/* untitled blend's need getpid for a unique name */
+#ifdef WIN32
+#include <process.h>
+#else
+#include <unistd.h>
+#endif
/* Takes an Object ID and returns a unique name
- id: object id
@@ -71,15 +77,14 @@ static int ptcache_path(char *filename)
if (i > 6)
file[i-6] = '\0';
- sprintf(filename, PTCACHE_PATH"%s/", file); /* add blend file name to pointcache dir */
+ sprintf(filename, "//"PTCACHE_PATH"%s/", file); /* add blend file name to pointcache dir */
BLI_convertstringcode(filename, G.sce, 0);
return strlen(filename);
- } else {
- /* 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 */
- return sprintf(filename, "%s"PTCACHE_PATH"untitled/", btempdir);
}
- return -1;
+
+ /* 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 */
+ return sprintf(filename, "%s"PTCACHE_PATH"%d/", btempdir, abs(getpid()));
}
int BKE_ptcache_id_filename(struct ID *id, char *filename, int cfra, int stack_index, short do_path, short do_ext)
@@ -95,8 +100,6 @@ int BKE_ptcache_id_filename(struct ID *id, char *filename, int cfra, int stack_i
/* start with temp dir */
if (do_path) {
len = ptcache_path(filename);
- if (len==-1)
- return -1;
newname += len;
}
idname = (id->name+2);
@@ -144,7 +147,7 @@ FILE *BKE_ptcache_id_fopen(struct ID *id, char mode, int cfra, int stack_index)
}
/* youll need to close yourself after!
- * mode,
+ * mode - PTCACHE_CLEAR_ALL,
*/
@@ -166,8 +169,7 @@ void BKE_ptcache_id_clear(struct ID *id, char mode, int cfra, int stack_index)
case PTCACHE_CLEAR_ALL:
case PTCACHE_CLEAR_BEFORE:
case PTCACHE_CLEAR_AFTER:
- if (ptcache_path(path)==-1)
- return;
+ ptcache_path(path);
len = BKE_ptcache_id_filename(id, filename, cfra, stack_index, 0, 0); /* no path */
@@ -219,3 +221,42 @@ int BKE_ptcache_id_exist(struct ID *id, int cfra, int stack_index)
return BLI_exists(filename);
}
+
+/* Use this when quitting blender, with unsaved files */
+void BKE_ptcache_remove(void)
+{
+ char path[FILE_MAX];
+ char path_full[FILE_MAX];
+ int rmdir = 1;
+
+ ptcache_path(path);
+
+ if (BLI_exists(path)) {
+ /* TODO, Check with win32, probably needs last slash removed */
+ /* The pointcache dir exists? - remove all pointcache */
+
+ DIR *dir;
+ struct dirent *de;
+
+ dir = opendir(path);
+ if (dir==NULL)
+ return;
+
+ while ((de = readdir(dir)) != NULL) {
+ if( strcmp(de->d_name, ".")==0 || strcmp(de->d_name, "..")==0) {
+ /* do nothing */
+ } else if (strstr(de->d_name, PTCACHE_EXT)) { /* do we have the right extension?*/
+ BLI_join_dirfile(path_full, path, de->d_name);
+ BLI_delete(path_full, 0, 0);
+ } else {
+ rmdir = 0; /* unknown file, dont remove the dir */
+ }
+ }
+ } else {
+ rmdir = 0; /* path dosnt exist */
+ }
+
+ if (rmdir) {
+ BLI_delete(path, 1, 0);
+ }
+}
diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c
index 8480a9d6e06..4610c887476 100644
--- a/source/blender/blenlib/intern/util.c
+++ b/source/blender/blenlib/intern/util.c
@@ -1471,12 +1471,20 @@ void BLI_join_dirfile(char *string, const char *dir, const char *file)
int sl_dir = strlen(dir);
BLI_strncpy(string, dir, FILE_MAX);
if (sl_dir > FILE_MAX-1) sl_dir = FILE_MAX-1;
+
+ /* only add seperator if needed */
#ifdef WIN32
- string[sl_dir] = '\\';
+ if (string[sl_dir-1] != '\\') {
+ string[sl_dir] = '\\';
+ sl_dir++;
+ }
#else
- string[sl_dir] = '/';
+ if (string[sl_dir-1] != '/') {
+ string[sl_dir] = '/';
+ sl_dir++;
+ }
#endif
- sl_dir++;
+
if (sl_dir <FILE_MAX) {
BLI_strncpy(string + sl_dir, file, FILE_MAX-sl_dir);
}
diff --git a/source/blender/include/BIF_usiblender.h b/source/blender/include/BIF_usiblender.h
index e7475af3ab7..42261ce09d3 100644
--- a/source/blender/include/BIF_usiblender.h
+++ b/source/blender/include/BIF_usiblender.h
@@ -49,6 +49,7 @@ void BIF_read_autosavefile(void);
void BIF_write_file(char *target);
void BIF_write_homefile(void);
void BIF_write_autosave(void);
+void BIF_clear_tempfiles(void);
#endif
diff --git a/source/blender/src/usiblender.c b/source/blender/src/usiblender.c
index 68981583358..4a791ddfb79 100644
--- a/source/blender/src/usiblender.c
+++ b/source/blender/src/usiblender.c
@@ -84,6 +84,7 @@
#include "BKE_packedFile.h"
#include "BKE_texture.h"
#include "BKE_utildefines.h"
+#include "BKE_pointcache.h"
#ifdef WITH_VERSE
#include "BKE_verse.h"
@@ -541,6 +542,8 @@ void BIF_read_file(char *name)
retval= BKE_read_exotic(name);
if (retval== 0) {
+ BIF_clear_tempfiles();
+
/* we didn't succeed, now try to read Blender file */
retval= BKE_read_file(name, NULL);
@@ -591,6 +594,8 @@ int BIF_read_homefile(int from_memory)
int success;
struct TmpFont *tf;
+ BIF_clear_tempfiles();
+
BLI_clean(home);
tf= G.ttfdata.first;
@@ -939,6 +944,16 @@ void BIF_write_autosave(void)
BLO_write_file(tstr, write_flags, &err);
}
+/* remove temp files assosiated with this blend file when quitting, loading or saving in a new path */
+void BIF_clear_tempfiles( void )
+{
+ /* TODO - remove exr files from the temp dir */
+
+ if (!G.relbase_valid) { /* We could have pointcache saved in tyhe temp dir, if its there */
+ BKE_ptcache_remove();
+ }
+}
+
/* if global undo; remove tempsave, otherwise rename */
static void delete_autosave(void)
{
@@ -1019,6 +1034,9 @@ extern ListBase editelems;
void exit_usiblender(void)
{
struct TmpFont *tf;
+
+ BIF_clear_tempfiles();
+
tf= G.ttfdata.first;
while(tf)
{