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
diff options
context:
space:
mode:
-rw-r--r--source/blender/blenloader/intern/readblenentry.c10
-rw-r--r--source/blender/blenloader/intern/readfile.c87
-rw-r--r--source/blender/blenloader/intern/readfile.h6
3 files changed, 41 insertions, 62 deletions
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index 182bbe2f1a1..ceb226f67fb 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -163,7 +163,9 @@ int BLO_idcode_from_name(char *name)
BlendHandle *BLO_blendhandle_from_file(char *file)
{
- return (BlendHandle*) blo_openblenderfile(file);
+ BlendReadError err;
+
+ return (BlendHandle*) blo_openblenderfile(file, &err);
}
void BLO_blendhandle_print_sizes(BlendHandle *bh, void *fp)
@@ -254,7 +256,7 @@ BlendFileData *BLO_read_from_file(char *file, BlendReadError *error_r)
BlendFileData *bfd = NULL;
FileData *fd;
- fd = blo_openblenderfile(file);
+ fd = blo_openblenderfile(file, error_r);
if (fd) {
bfd= blo_read_file_internal(fd, error_r);
if (bfd) {
@@ -272,7 +274,7 @@ BlendFileData *BLO_read_from_memory(void *mem, int memsize, BlendReadError *erro
BlendFileData *bfd = NULL;
FileData *fd;
- fd = blo_openblendermemory(mem, memsize);
+ fd = blo_openblendermemory(mem, memsize, error_r);
if (fd) {
bfd= blo_read_file_internal(fd, error_r);
if (bfd) {
@@ -290,7 +292,7 @@ BlendFileData *BLO_read_from_memfile(MemFile *memfile, BlendReadError *error_r)
BlendFileData *bfd = NULL;
FileData *fd;
- fd = blo_openblendermemfile(memfile);
+ fd = blo_openblendermemfile(memfile, error_r);
if (fd) {
bfd= blo_read_file_internal(fd, error_r);
if (bfd) {
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 93a67a591db..39a9f9456d4 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -854,7 +854,26 @@ static FileData *filedata_new(void)
return fd;
}
-FileData *blo_openblenderfile(char *name)
+static FileData *blo_decode_and_check(FileData *fd, BlendReadError *error_r)
+{
+ decode_blender_header(fd);
+
+ if (fd->flags & FD_FLAGS_FILE_OK) {
+ if (!read_file_dna(fd)) {
+ *error_r = BRE_INCOMPLETE;
+ blo_freefiledata(fd);
+ fd= NULL;
+ }
+ } else {
+ *error_r = BRE_NOT_A_BLEND;
+ blo_freefiledata(fd);
+ fd= NULL;
+ }
+
+ return fd;
+}
+
+FileData *blo_openblenderfile(char *name, BlendReadError *error_r)
{
int file;
char name1[FILE_MAXDIR+FILE_MAXFILE];
@@ -869,6 +888,7 @@ FileData *blo_openblenderfile(char *name)
file= open(name1, O_BINARY|O_RDONLY);
if (file == -1) {
+ *error_r = BRE_UNABLE_TO_OPEN;
return NULL;
} else {
FileData *fd = filedata_new();
@@ -877,25 +897,14 @@ FileData *blo_openblenderfile(char *name)
fd->buffersize = BLI_filesize(file);
fd->read = fd_read_from_file;
- decode_blender_header(fd);
-
- if (fd->flags & FD_FLAGS_FILE_OK) {
- if (!read_file_dna(fd)) {
- blo_freefiledata(fd);
- fd= NULL;
- }
- } else {
- blo_freefiledata(fd);
- fd= NULL;
- }
-
- return fd;
+ return blo_decode_and_check(fd, error_r);
}
}
-FileData *blo_openblendermemory(void *mem, int memsize)
+FileData *blo_openblendermemory(void *mem, int memsize, BlendReadError *error_r)
{
if (!mem || memsize<SIZEOFBLENDERHEADER) {
+ *error_r = mem?BRE_UNABLE_TO_READ:BRE_UNABLE_TO_OPEN;
return NULL;
} else {
FileData *fd= filedata_new();
@@ -904,25 +913,14 @@ FileData *blo_openblendermemory(void *mem, int memsize)
fd->read= fd_read_from_memory;
fd->flags|= FD_FLAGS_NOT_MY_BUFFER;
- decode_blender_header(fd);
-
- if (fd->flags & FD_FLAGS_FILE_OK) {
- if (!read_file_dna(fd)) {
- blo_freefiledata(fd);
- fd= NULL;
- }
- } else {
- blo_freefiledata(fd);
- fd= NULL;
- }
-
- return fd;
+ return blo_decode_and_check(fd, error_r);
}
}
-FileData *blo_openblendermemfile(MemFile *memfile)
+FileData *blo_openblendermemfile(MemFile *memfile, BlendReadError *error_r)
{
if (!memfile) {
+ *error_r = BRE_UNABLE_TO_OPEN;
return NULL;
} else {
FileData *fd= filedata_new();
@@ -931,19 +929,7 @@ FileData *blo_openblendermemfile(MemFile *memfile)
fd->read= fd_read_from_memfile;
fd->flags|= FD_FLAGS_NOT_MY_BUFFER;
- decode_blender_header(fd);
-
- if (fd->flags & FD_FLAGS_FILE_OK) {
- if (!read_file_dna(fd)) {
- blo_freefiledata(fd);
- fd= NULL;
- }
- } else {
- blo_freefiledata(fd);
- fd= NULL;
- }
-
- return fd;
+ return blo_decode_and_check(fd, error_r);
}
}
@@ -5759,8 +5745,9 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
FileData *fd= mainptr->curlib->filedata;
if(fd==NULL) {
+ BlendReadError err;
printf("read lib %s\n", mainptr->curlib->name);
- fd= blo_openblenderfile(mainptr->curlib->name);
+ fd= blo_openblenderfile(mainptr->curlib->name, &err);
if (fd) {
if (fd->libmap)
oldnewmap_free(fd->libmap);
@@ -5859,19 +5846,9 @@ BlendFileData *blo_read_blendafterruntime(int file, int actualsize, BlendReadErr
fd->buffersize = actualsize;
fd->read = fd_read_from_file;
- decode_blender_header(fd);
-
- if (fd->flags & FD_FLAGS_FILE_OK) {
- if (!read_file_dna(fd)) {
- blo_freefiledata(fd);
- fd= NULL;
- return NULL;
- }
- } else {
- blo_freefiledata(fd);
- fd= NULL;
+ fd = blo_decode_and_check(fd, error_r);
+ if (!fd)
return NULL;
- }
bfd= blo_read_file_internal(fd, error_r);
blo_freefiledata(fd);
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 19534095f98..6389cfaa6f5 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -100,9 +100,9 @@ void blo_split_main(ListBase *mainlist);
BlendFileData *blo_read_file_internal( FileData *fd, BlendReadError *error_r);
-FileData *blo_openblenderfile( char *name);
-FileData *blo_openblendermemory( void *buffer, int buffersize);
-FileData *blo_openblendermemfile(struct MemFile *memfile);
+FileData *blo_openblenderfile( char *name, BlendReadError *error_r);
+FileData *blo_openblendermemory( void *buffer, int buffersize, BlendReadError *error_r);
+FileData *blo_openblendermemfile(struct MemFile *memfile, BlendReadError *error_r);
void blo_freefiledata( FileData *fd);