2.5: Change blenloader module to use the Report system for reporting errors.

This commit is contained in:
Brecht Van Lommel 2008-12-19 00:50:21 +00:00
parent ea81c58429
commit d9de6fca6c
16 changed files with 261 additions and 251 deletions

@ -48,7 +48,8 @@ typedef enum ReportType {
enum ReportListFlags {
RPT_PRINT = 1,
RPT_STORE = 2
RPT_STORE = 2,
RPT_HAS_ERROR = 4
};
typedef struct Report {
@ -60,20 +61,24 @@ typedef struct Report {
typedef struct ReportList {
ListBase list;
ReportType level;
int flags;
ReportType printlevel;
ReportType storelevel;
int flag;
} ReportList;
void BKE_report_list_init(ReportList *reports, int flag);
void BKE_report_list_clear(ReportList *reports);
void BKE_reports_init(ReportList *reports, int flag);
void BKE_reports_clear(ReportList *reports);
void BKE_report(ReportList *reports, ReportType type, const char *message);
void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...);
ReportType BKE_report_level(ReportList *reports);
void BKE_report_level_set(ReportList *reports, ReportType level);
ReportType BKE_report_print_level(ReportList *reports);
void BKE_report_print_level_set(ReportList *reports, ReportType level);
int BKE_report_has_error(ReportList *reports);
ReportType BKE_report_store_level(ReportList *reports);
void BKE_report_store_level_set(ReportList *reports, ReportType level);
void BKE_reports_print(ReportList *reports, ReportType level);
#ifdef __cplusplus
}

@ -77,6 +77,7 @@
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_object.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_sound.h"
@ -435,11 +436,13 @@ static void handle_subversion_warning(Main *main)
int BKE_read_file(bContext *C, char *dir, void *unused)
{
BlendReadError bre;
ReportList reports;
BlendFileData *bfd;
int retval= 1;
bfd= BLO_read_from_file(dir, &bre);
BKE_reports_init(&reports, RPT_STORE);
bfd= BLO_read_from_file(dir, &reports);
if (bfd) {
if(bfd->user) retval= 2;
@ -450,38 +453,48 @@ int BKE_read_file(bContext *C, char *dir, void *unused)
else {
// XXX error("Loading %s failed: %s", dir, BLO_bre_as_string(bre));
}
BKE_reports_clear(&reports);
return (bfd?retval:0);
}
int BKE_read_file_from_memory(bContext *C, char* filebuf, int filelength, void *unused)
{
BlendReadError bre;
ReportList reports;
BlendFileData *bfd;
bfd= BLO_read_from_memory(filebuf, filelength, &bre);
BKE_reports_init(&reports, RPT_STORE);
bfd= BLO_read_from_memory(filebuf, filelength, &reports);
if (bfd) {
setup_app_data(C, bfd, "<memory2>");
} else {
// XXX error("Loading failed: %s", BLO_bre_as_string(bre));
}
BKE_reports_clear(&reports);
return (bfd?1:0);
}
/* memfile is the undo buffer */
int BKE_read_file_from_memfile(bContext *C, MemFile *memfile)
{
BlendReadError bre;
ReportList reports;
BlendFileData *bfd;
bfd= BLO_read_from_memfile(G.sce, memfile, &bre);
BKE_reports_init(&reports, RPT_STORE);
bfd= BLO_read_from_memfile(G.sce, memfile, &reports);
if (bfd) {
setup_app_data(C, bfd, "<memory1>");
} else {
// XXX error("Loading failed: %s", BLO_bre_as_string(bre));
}
BKE_reports_clear(&reports);
return (bfd?1:0);
}
@ -568,8 +581,9 @@ void BKE_write_undo(bContext *C, char *name)
/* disk save version */
if(UNDO_DISK) {
ReportList reports;
static int counter= 0;
char *err, tstr[FILE_MAXDIR+FILE_MAXFILE];
char tstr[FILE_MAXDIR+FILE_MAXFILE];
char numstr[32];
/* calculate current filename */
@ -579,18 +593,22 @@ void BKE_write_undo(bContext *C, char *name)
sprintf(numstr, "%d.blend", counter);
BLI_make_file_string("/", tstr, btempdir, numstr);
success= BLO_write_file(C, tstr, G.fileflags, &err);
BKE_reports_init(&reports, 0);
success= BLO_write_file(C, tstr, G.fileflags, &reports);
BKE_reports_clear(&reports);
strcpy(curundo->str, tstr);
}
else {
ReportList reports;
MemFile *prevfile=NULL;
char *err;
if(curundo->prev) prevfile= &(curundo->prev->memfile);
memused= MEM_get_memory_in_use();
success= BLO_write_file_mem(C, prevfile, &curundo->memfile, G.fileflags, &err);
BKE_reports_init(&reports, 0);
success= BLO_write_file_mem(C, prevfile, &curundo->memfile, G.fileflags, &reports);
BKE_reports_clear(&reports);
curundo->undosize= MEM_get_memory_in_use() - memused;
}

@ -57,15 +57,16 @@ static char *report_type_str(int type)
}
}
void BKE_report_list_init(ReportList *reports, int flags)
void BKE_reports_init(ReportList *reports, int flag)
{
memset(reports, 0, sizeof(ReportList));
reports->level= RPT_WARNING;
reports->flags= flags;
reports->storelevel= RPT_WARNING;
reports->printlevel= RPT_WARNING;
reports->flag= flag;
}
void BKE_report_list_clear(ReportList *reports)
void BKE_reports_clear(ReportList *reports)
{
Report *report;
@ -80,15 +81,18 @@ void BKE_report(ReportList *reports, ReportType type, const char *message)
Report *report;
int len;
if(!reports || type < reports->level)
if(!reports)
return;
if(type >= RPT_ERROR)
reports->flag |= RPT_HAS_ERROR;
if(reports->flags & RPT_PRINT) {
if((reports->flag & RPT_PRINT) && (type >= reports->printlevel)) {
printf("%s: %s\n", report_type_str(type), message);
fflush(stdout); /* this ensures the message is printed before a crash */
}
if(reports->flags & RPT_STORE) {
if((reports->flag & RPT_STORE) && (type >= reports->storelevel)) {
report= MEM_callocN(sizeof(Report), "Report");
report->type= type;
report->typestr= report_type_str(type);
@ -108,17 +112,20 @@ void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...)
char *message;
int len= 256, maxlen= 65536, retval;
if(!reports || type < reports->level)
if(!reports)
return;
if(reports->flags & RPT_PRINT) {
if(type >= RPT_ERROR)
reports->flag |= RPT_HAS_ERROR;
if((reports->flag & RPT_PRINT) && (type >= reports->printlevel)) {
va_start(args, format);
vprintf(format, args);
va_end(args);
fflush(stdout); /* this ensures the message is printed before a crash */
}
if(reports->flags & RPT_STORE) {
if((reports->flag & RPT_STORE) && (type >= reports->storelevel)) {
while(1) {
message= MEM_callocN(sizeof(char)*len+1, "ReportMessage");
@ -160,27 +167,37 @@ void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...)
}
}
ReportType BKE_report_level(ReportList *reports)
ReportType BKE_report_print_level(ReportList *reports)
{
return reports->level;
return reports->printlevel;
}
void BKE_report_level_set(ReportList *reports, ReportType level)
void BKE_report_print_level_set(ReportList *reports, ReportType level)
{
reports->level= level;
reports->printlevel= level;
}
int BKE_report_has_error(ReportList *reports)
ReportType BKE_report_store_level(ReportList *reports)
{
return reports->storelevel;
}
void BKE_report_store_level_set(ReportList *reports, ReportType level)
{
reports->storelevel= level;
}
void BKE_reports_print(ReportList *reports, ReportType level)
{
Report *report;
if(!reports)
return 0;
for(report=reports->list.first; report; report=report->next)
if(report->type >= RPT_ERROR)
return 1;
return;
return 0;
for(report=reports->list.first; report; report=report->next)
if(report->type >= level)
printf("%s: %s\n", report->typestr, report->message);
fflush(stdout);
}

@ -34,16 +34,17 @@
extern "C" {
#endif
struct SpaceFile;
struct SpaceImaSel;
struct bScreen;
struct direntry;
struct FileList;
struct LinkNode;
struct Main;
struct UserDef;
struct bScreen;
struct Scene;
struct MemFile;
struct direntry;
struct ReportList;
struct Scene;
struct SpaceFile;
struct SpaceImaSel;
struct UserDef;
typedef struct BlendHandle BlendHandle;
@ -53,29 +54,6 @@ typedef enum BlenFileType {
BLENFILETYPE_RUNTIME= 3
} BlenFileType;
typedef enum {
BRE_NONE,
BRE_UNABLE_TO_OPEN,
BRE_UNABLE_TO_READ,
BRE_OUT_OF_MEMORY,
BRE_INTERNAL_ERROR,
BRE_NOT_A_BLEND,
BRE_NOT_A_PUBFILE,
BRE_INCOMPLETE,
BRE_CORRUPT,
BRE_TOO_NEW,
BRE_NOT_ALLOWED,
BRE_NO_SCREEN,
BRE_NO_SCENE,
BRE_INVALID
} BlendReadError;
typedef struct BlendFileData {
struct Main* main;
struct UserDef* user;
@ -93,46 +71,33 @@ typedef struct BlendFileData {
/**
* Open a blender file from a pathname. The function
* returns NULL and sets the @a error_r argument if
* returns NULL and sets a report in the list if
* it cannot open the file.
*
* @param file The path of the file to open.
* @param error_r If the return value is NULL, an error
* code indicating the cause of the failure.
* @param reports If the return value is NULL, errors
* indicating the cause of the failure.
* @return The data of the file.
*/
BlendFileData* BLO_read_from_file (char *file, BlendReadError *error_r);
BlendFileData* BLO_read_from_file (char *file, struct ReportList *reports);
/**
* Open a blender file from memory. The function
* returns NULL and sets the @a error_r argument if
* returns NULL and sets a report in the list if
* it cannot open the file.
*
* @param mem The file data.
* @param memsize The length of @a mem.
* @param error_r If the return value is NULL, an error
* code indicating the cause of the failure.
* @param reports If the return value is NULL, errors
* indicating the cause of the failure.
* @return The data of the file.
*/
BlendFileData* BLO_read_from_memory(void *mem, int memsize, BlendReadError *error_r);
BlendFileData* BLO_read_from_memory(void *mem, int memsize, struct ReportList *reports);
/**
* file name is current file, only for retrieving library data */
BlendFileData *BLO_read_from_memfile(const char *filename, struct MemFile *memfile, BlendReadError *error_r);
/**
* Convert a BlendReadError to a human readable string.
* The string is static and does not need to be free'd.
*
* @param error The error to return a string for.
* @return A static human readable string representation
* of @a error.
*/
char*
BLO_bre_as_string(
BlendReadError error);
BlendFileData *BLO_read_from_memfile(const char *filename, struct MemFile *memfile, struct ReportList *reports);
/**
* Free's a BlendFileData structure and _all_ the
@ -239,7 +204,7 @@ void BLO_library_append_(BlendHandle **libfiledata, struct direntry* filelist, i
char *dir, char* file, short flag, int idcode, struct Scene *scene);
void BLO_script_library_append(BlendHandle **bh, char *dir, char *name, int idcode, short flag, struct Scene *scene);
BlendFileData* blo_read_blendafterruntime(int file, char *name, int actualsize, BlendReadError *error_r);
BlendFileData* blo_read_blendafterruntime(int file, char *name, int actualsize, struct ReportList *reports);
#ifdef __cplusplus
}

@ -33,11 +33,12 @@
struct MemFile;
struct bContext;
struct ReportList;
extern int BLO_write_file(struct bContext *C, char *dir, int write_flags, char **error_r);
extern int BLO_write_file(struct bContext *C, char *dir, int write_flags, struct ReportList *reports);
extern int BLO_write_file_mem(struct bContext *C, struct MemFile *compare, struct MemFile *current,
int write_flags, char **error_r);
extern void BLO_write_runtime(struct bContext *C, char *file, char *exename);
int write_flags, struct ReportList *reports);
extern int BLO_write_runtime(struct bContext *C, char *file, char *exename, struct ReportList *reports);
#endif

@ -55,6 +55,7 @@
#include "BKE_main.h"
#include "BKE_global.h"
#include "BKE_library.h" // for free_main
#include "BKE_report.h"
#include "BLO_readfile.h"
#include "BLO_undofile.h"
@ -166,9 +167,14 @@ int BLO_idcode_from_name(char *name)
BlendHandle *BLO_blendhandle_from_file(char *file)
{
BlendReadError err;
ReportList reports;
BlendHandle *bh;
return (BlendHandle*) blo_openblenderfile(file, &err);
BKE_reports_init(&reports, 0);
bh= (BlendHandle*)blo_openblenderfile(file, &reports);
BKE_reports_clear(&reports);
return bh;
}
void BLO_blendhandle_print_sizes(BlendHandle *bh, void *fp)
@ -318,14 +324,14 @@ void BLO_blendhandle_close(BlendHandle *bh) {
/**********/
BlendFileData *BLO_read_from_file(char *file, BlendReadError *error_r)
BlendFileData *BLO_read_from_file(char *file, ReportList *reports)
{
BlendFileData *bfd = NULL;
FileData *fd;
fd = blo_openblenderfile(file, error_r);
fd = blo_openblenderfile(file, reports);
if (fd) {
bfd= blo_read_file_internal(fd, error_r);
bfd= blo_read_file_internal(fd, reports);
if (bfd) {
bfd->type= BLENFILETYPE_BLEND;
strncpy(bfd->main->name, file, sizeof(bfd->main->name)-1);
@ -336,14 +342,14 @@ BlendFileData *BLO_read_from_file(char *file, BlendReadError *error_r)
return bfd;
}
BlendFileData *BLO_read_from_memory(void *mem, int memsize, BlendReadError *error_r)
BlendFileData *BLO_read_from_memory(void *mem, int memsize, ReportList *reports)
{
BlendFileData *bfd = NULL;
FileData *fd;
fd = blo_openblendermemory(mem, memsize, error_r);
fd = blo_openblendermemory(mem, memsize, reports);
if (fd) {
bfd= blo_read_file_internal(fd, error_r);
bfd= blo_read_file_internal(fd, reports);
if (bfd) {
bfd->type= BLENFILETYPE_BLEND;
strcpy(bfd->main->name, "");
@ -354,13 +360,13 @@ BlendFileData *BLO_read_from_memory(void *mem, int memsize, BlendReadError *erro
return bfd;
}
BlendFileData *BLO_read_from_memfile(const char *filename, MemFile *memfile, BlendReadError *error_r)
BlendFileData *BLO_read_from_memfile(const char *filename, MemFile *memfile, ReportList *reports)
{
BlendFileData *bfd = NULL;
FileData *fd;
ListBase mainlist;
fd = blo_openblendermemfile(memfile, error_r);
fd = blo_openblendermemfile(memfile, reports);
if (fd) {
strcpy(fd->filename, filename);
@ -375,7 +381,7 @@ BlendFileData *BLO_read_from_memfile(const char *filename, MemFile *memfile, Ble
/* makes lookup of existing images in G.main */
blo_make_image_pointer_map(fd);
bfd= blo_read_file_internal(fd, error_r);
bfd= blo_read_file_internal(fd, reports);
if (bfd) {
bfd->type= BLENFILETYPE_BLEND;
strcpy(bfd->main->name, "");
@ -416,43 +422,3 @@ void BLO_blendfiledata_free(BlendFileData *bfd)
MEM_freeN(bfd);
}
char *BLO_bre_as_string(BlendReadError error)
{
switch (error) {
case BRE_NONE:
return "No error";
case BRE_UNABLE_TO_OPEN:
return "Unable to open";
case BRE_UNABLE_TO_READ:
return "Unable to read";
case BRE_OUT_OF_MEMORY:
return "Out of memory";
case BRE_INTERNAL_ERROR:
return "<internal error>";
case BRE_NOT_A_BLEND:
return "File is not a Blender file";
case BRE_NOT_A_PUBFILE:
return "File is not a compressed, locked or signed Blender file";
case BRE_INCOMPLETE:
return "File incomplete";
case BRE_CORRUPT:
return "File corrupt";
case BRE_TOO_NEW:
return "File needs newer Blender version, please upgrade";
case BRE_NOT_ALLOWED:
return "File is locked";
case BRE_NO_SCREEN:
return "File has no screen";
case BRE_NO_SCENE:
return "File has no scene";
default:
case BRE_INVALID:
return "<invalid read error>";
}
}

@ -129,6 +129,7 @@
#include "BKE_particle.h"
#include "BKE_pointcache.h"
#include "BKE_property.h" // for get_ob_property
#include "BKE_report.h"
#include "BKE_sca.h" // for init_actuator
#include "BKE_scene.h"
#include "BKE_softbody.h" // sbNew()
@ -925,19 +926,19 @@ static FileData *filedata_new(void)
return fd;
}
static FileData *blo_decode_and_check(FileData *fd, BlendReadError *error_r)
static FileData *blo_decode_and_check(FileData *fd, ReportList *reports)
{
decode_blender_header(fd);
if (fd->flags & FD_FLAGS_FILE_OK) {
if (!read_file_dna(fd)) {
*error_r = BRE_INCOMPLETE;
BKE_report(reports, RPT_ERROR, "File incomplete");
blo_freefiledata(fd);
fd= NULL;
}
}
else {
*error_r = BRE_NOT_A_BLEND;
BKE_report(reports, RPT_ERROR, "File is not a Blender file");
blo_freefiledata(fd);
fd= NULL;
}
@ -947,14 +948,14 @@ static FileData *blo_decode_and_check(FileData *fd, BlendReadError *error_r)
/* cannot be called with relative paths anymore! */
/* on each new library added, it now checks for the current FileData and expands relativeness */
FileData *blo_openblenderfile(char *name, BlendReadError *error_r)
FileData *blo_openblenderfile(char *name, ReportList *reports)
{
gzFile gzfile;
gzfile= gzopen(name, "rb");
if (NULL == gzfile) {
*error_r = BRE_UNABLE_TO_OPEN;
BKE_report(reports, RPT_ERROR, "Unable to open");
return NULL;
} else {
FileData *fd = filedata_new();
@ -964,14 +965,14 @@ FileData *blo_openblenderfile(char *name, BlendReadError *error_r)
/* needed for library_append and read_libraries */
BLI_strncpy(fd->filename, name, sizeof(fd->filename));
return blo_decode_and_check(fd, error_r);
return blo_decode_and_check(fd, reports);
}
}
FileData *blo_openblendermemory(void *mem, int memsize, BlendReadError *error_r)
FileData *blo_openblendermemory(void *mem, int memsize, ReportList *reports)
{
if (!mem || memsize<SIZEOFBLENDERHEADER) {
*error_r = mem?BRE_UNABLE_TO_READ:BRE_UNABLE_TO_OPEN;
BKE_report(reports, RPT_ERROR, (mem)? "Unable to read": "Unable to open");
return NULL;
} else {
FileData *fd= filedata_new();
@ -980,14 +981,14 @@ FileData *blo_openblendermemory(void *mem, int memsize, BlendReadError *error_r)
fd->read= fd_read_from_memory;
fd->flags|= FD_FLAGS_NOT_MY_BUFFER;
return blo_decode_and_check(fd, error_r);
return blo_decode_and_check(fd, reports);
}
}
FileData *blo_openblendermemfile(MemFile *memfile, BlendReadError *error_r)
FileData *blo_openblendermemfile(MemFile *memfile, ReportList *reports)
{
if (!memfile) {
*error_r = BRE_UNABLE_TO_OPEN;
BKE_report(reports, RPT_ERROR, "Unable to open");
return NULL;
} else {
FileData *fd= filedata_new();
@ -996,7 +997,7 @@ FileData *blo_openblendermemfile(MemFile *memfile, BlendReadError *error_r)
fd->read= fd_read_from_memfile;
fd->flags|= FD_FLAGS_NOT_MY_BUFFER;
return blo_decode_and_check(fd, error_r);
return blo_decode_and_check(fd, reports);
}
}
@ -3102,7 +3103,8 @@ static void lib_link_object(FileData *fd, Main *main)
ob= ob->id.next;
}
if(warn); //XXX error("WARNING IN CONSOLE");
if(warn) //XXX error("WARNING IN CONSOLE");
BKE_report(fd->reports, RPT_WARNING, "Warning in console");
}
@ -4323,6 +4325,8 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main)
MEM_freeN(lib);
//XXX error("Library had multiple instances, save and reload!");
BKE_report(fd->reports, RPT_WARNING, "Library had multiple instances, save and reload!");
return;
}
}
@ -8350,7 +8354,7 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead)
return bhead;
}
BlendFileData *blo_read_file_internal(FileData *fd, BlendReadError *error_r)
BlendFileData *blo_read_file_internal(FileData *fd, ReportList *reports)
{
BHead *bhead= blo_firstbhead(fd);
BlendFileData *bfd;
@ -9538,9 +9542,13 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
FileData *fd= mainptr->curlib->filedata;
if(fd==NULL) {
BlendReadError err;
ReportList reports;
printf("read library: lib %s\n", mainptr->curlib->name);
fd= blo_openblenderfile(mainptr->curlib->filename, &err);
BKE_reports_init(&reports, 0);
fd= blo_openblenderfile(mainptr->curlib->filename, &reports);
BKE_reports_clear(&reports);
if (fd) {
if (fd->libmap)
oldnewmap_free(fd->libmap);
@ -9639,7 +9647,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
/* reading runtime */
BlendFileData *blo_read_blendafterruntime(int file, char *name, int actualsize, BlendReadError *error_r)
BlendFileData *blo_read_blendafterruntime(int file, char *name, int actualsize, ReportList *reports)
{
BlendFileData *bfd = NULL;
FileData *fd = filedata_new();
@ -9650,11 +9658,11 @@ BlendFileData *blo_read_blendafterruntime(int file, char *name, int actualsize,
/* needed for library_append and read_libraries */
BLI_strncpy(fd->filename, name, sizeof(fd->filename));
fd = blo_decode_and_check(fd, error_r);
fd = blo_decode_and_check(fd, reports);
if (!fd)
return NULL;
bfd= blo_read_file_internal(fd, error_r);
bfd= blo_read_file_internal(fd, reports);
blo_freefiledata(fd);
return bfd;

@ -35,6 +35,7 @@
struct OldNewMap;
struct MemFile;
struct bheadsort;
struct ReportList;
typedef struct FileData {
// linked list of BHeadN's
@ -83,7 +84,7 @@ typedef struct FileData {
* data through streamglue.
*/
BlendFileData **bfd_r;
BlendReadError *error_r;
struct ReportList *reports;
} FileData;
typedef struct BHeadN {
@ -106,11 +107,11 @@ struct Main;
void blo_join_main(ListBase *mainlist);
void blo_split_main(ListBase *mainlist, struct Main *main);
BlendFileData *blo_read_file_internal( FileData *fd, BlendReadError *error_r);
BlendFileData *blo_read_file_internal( FileData *fd, struct ReportList *reports);
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);
FileData *blo_openblenderfile( char *name, struct ReportList *reports);
FileData *blo_openblendermemory( void *buffer, int buffersize, struct ReportList *reports);
FileData *blo_openblendermemfile(struct MemFile *memfile, struct ReportList *reports);
void blo_clear_proxy_pointers_from_lib(FileData *fd);
void blo_make_image_pointer_map(FileData *fd);

@ -155,6 +155,7 @@ Any case: direct data is ALWAYS after the lib block
#include "BKE_main.h" // G.main
#include "BKE_node.h"
#include "BKE_packedFile.h" // for packAll
#include "BKE_report.h"
#include "BKE_screen.h" // for waitcursor
#include "BKE_sequence.h"
#include "BKE_sound.h" /* ... and for samples */
@ -2110,7 +2111,7 @@ static int write_file_handle(bContext *C, int handle, MemFile *compare, MemFile
}
/* return: success (1) */
int BLO_write_file(bContext *C, char *dir, int write_flags, char **error_r)
int BLO_write_file(bContext *C, char *dir, int write_flags, ReportList *reports)
{
char userfilename[FILE_MAXDIR+FILE_MAXFILE];
char tempname[FILE_MAXDIR+FILE_MAXFILE];
@ -2120,7 +2121,7 @@ int BLO_write_file(bContext *C, char *dir, int write_flags, char **error_r)
file = open(tempname,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
if(file == -1) {
*error_r= "Unable to open";
BKE_report(reports, RPT_ERROR, "Unable to open file for writing.");
return 0;
}
@ -2139,23 +2140,23 @@ int BLO_write_file(bContext *C, char *dir, int write_flags, char **error_r)
int ret = BLI_gzip(tempname, dir);
if(-1==ret) {
*error_r= "Failed opening .gz file";
BKE_report(reports, RPT_ERROR, "Failed opening .gz file.");
return 0;
}
if(-2==ret) {
*error_r= "Failed opening .blend file for compression";
BKE_report(reports, RPT_ERROR, "Failed opening .blend file for compression.");
return 0;
}
}
else
if(BLI_rename(tempname, dir) != 0) {
*error_r= "Can't change old file. File saved with @";
BKE_report(reports, RPT_ERROR, "Can't change old file. File saved with @");
return 0;
}
} else {
*error_r= strerror(errno);
BKE_report(reports, RPT_ERROR, strerror(errno));
remove(tempname);
return 0;
@ -2165,7 +2166,7 @@ int BLO_write_file(bContext *C, char *dir, int write_flags, char **error_r)
}
/* return: success (1) */
int BLO_write_file_mem(bContext *C, MemFile *compare, MemFile *current, int write_flags, char **error_r)
int BLO_write_file_mem(bContext *C, MemFile *compare, MemFile *current, int write_flags, ReportList *reports)
{
int err;
@ -2230,28 +2231,28 @@ static char *get_runtime_path(char *exename) {
#ifdef __APPLE__
static int recursive_copy_runtime(char *outname, char *exename, char **cause_r)
static int recursive_copy_runtime(char *outname, char *exename, ReportList *reports)
{
char *cause = NULL, *runtime = get_runtime_path(exename);
char *runtime = get_runtime_path(exename);
char command[2 * (FILE_MAXDIR+FILE_MAXFILE) + 32];
int progfd = -1;
if (!runtime) {
cause= "Unable to find runtime";
BKE_report(reports, RPT_ERROR, "Unable to find runtime");
goto cleanup;
}
//printf("runtimepath %s\n", runtime);
progfd= open(runtime, O_BINARY|O_RDONLY, 0);
if (progfd==-1) {
cause= "Unable to find runtime";
BKE_report(reports, RPT_ERROR, "Unable to find runtime");
goto cleanup;
}
sprintf(command, "/bin/cp -R \"%s\" \"%s\"", runtime, outname);
//printf("command %s\n", command);
if (system(command) == -1) {
cause = "Couldn't copy runtime";
BKE_report(reports, RPT_ERROR, "Couldn't copy runtime");
}
cleanup:
@ -2260,24 +2261,19 @@ cleanup:
if (runtime)
MEM_freeN(runtime);
if (cause) {
*cause_r= cause;
return 0;
} else
return 1;
return !(reports->flag & RPT_HAS_ERROR);
}
void BLO_write_runtime(bContext *C, char *file, char *exename)
int BLO_write_runtime(bContext *C, char *file, char *exename, ReportList *reports)
{
char gamename[FILE_MAXDIR+FILE_MAXFILE];
int outfd = -1;
char *cause= NULL;
// remove existing file / bundle
//printf("Delete file %s\n", file);
BLI_delete(file, 0, TRUE);
if (!recursive_copy_runtime(file, exename, &cause))
if (!recursive_copy_runtime(file, exename, reports))
goto cleanup;
strcpy(gamename, file);
@ -2289,43 +2285,43 @@ void BLO_write_runtime(bContext *C, char *file, char *exename)
write_file_handle(C, outfd, NULL,NULL, 0, G.fileflags);
if (write(outfd, " ", 1) != 1) {
cause= "Unable to write to output file";
BKE_report(reports, RPT_ERROR, "Unable to write to output file.");
goto cleanup;
}
} else {
cause = "Unable to open blenderfile";
BKE_report(reports, RPT_ERROR, "Unable to open blenderfile.");
}
cleanup:
if (outfd!=-1)
close(outfd);
if (cause)
error("Unable to make runtime: %s", cause);
//XXX error("Unable to make runtime: %s", cause);
return !(reports->flag & RPT_HAS_ERROR);
}
#else /* !__APPLE__ */
static int handle_append_runtime(int handle, char *exename, char **cause_r)
static int handle_append_runtime(int handle, char *exename, ReportList *reports)
{
char *cause= NULL, *runtime= get_runtime_path(exename);
char *runtime= get_runtime_path(exename);
unsigned char buf[1024];
int count, progfd= -1;
if (!BLI_exists(runtime)) {
cause= "Unable to find runtime";
BKE_report(reports, RPT_ERROR, "Unable to find runtime.");
goto cleanup;
}
progfd= open(runtime, O_BINARY|O_RDONLY, 0);
if (progfd==-1) {
cause= "Unable to find runtime";
BKE_report(reports, RPT_ERROR, "Unable to find runtime.@");
goto cleanup;
}
while ((count= read(progfd, buf, sizeof(buf)))>0) {
if (write(handle, buf, count)!=count) {
cause= "Unable to write to output file";
BKE_report(reports, RPT_ERROR, "Unable to write to output file.");
goto cleanup;
}
}
@ -2336,11 +2332,7 @@ cleanup:
if (runtime)
MEM_freeN(runtime);
if (cause) {
*cause_r= cause;
return 0;
} else
return 1;
return !(reports->flag & RPT_HAS_ERROR);
}
static int handle_write_msb_int(int handle, int i)
@ -2354,17 +2346,16 @@ static int handle_write_msb_int(int handle, int i)
return (write(handle, buf, 4)==4);
}
void BLO_write_runtime(bContext *C, char *file, char *exename)
int BLO_write_runtime(bContext *C, char *file, char *exename, ReportList *reports)
{
int outfd= open(file, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, 0777);
char *cause= NULL;
int datastart;
if (!outfd) {
cause= "Unable to open output file";
BKE_report(reports, RPT_ERROR, "Unable to open output file.");
goto cleanup;
}
if (!handle_append_runtime(outfd, exename, &cause))
if (!handle_append_runtime(outfd, exename, reports))
goto cleanup;
datastart= lseek(outfd, 0, SEEK_CUR);
@ -2372,7 +2363,7 @@ void BLO_write_runtime(bContext *C, char *file, char *exename)
write_file_handle(C, outfd, NULL,NULL, 0, G.fileflags);
if (!handle_write_msb_int(outfd, datastart) || (write(outfd, "BRUNTIME", 8)!=8)) {
cause= "Unable to write to output file";
BKE_report(reports, RPT_ERROR, "Unable to write to output file.");
goto cleanup;
}
@ -2380,8 +2371,8 @@ cleanup:
if (outfd!=-1)
close(outfd);
if (cause)
; //XXX error("Unable to make runtime: %s", cause);
//XXX error("Unable to make runtime: %s", cause);
return !(reports->flag & RPT_HAS_ERROR);
}
#endif /* !__APPLE__ */

@ -31,6 +31,9 @@
#ifndef DNA_FILEGLOBAL_TYPES_H
#define DNA_FILEGLOBAL_TYPES_H
struct bScreen;
struct Scene;
/**
* FileGlobal stores a part of the current user-unterface settings at
* the moment of saving, and the file-specific settings.
@ -40,8 +43,8 @@ typedef struct FileGlobal {
short subversion, pads;
short minversion, minsubversion;
short displaymode, winpos;
void *curscreen;
void *curscene;
struct bScreen *curscreen;
struct Scene *curscene;
int fileflags;
int globalf;
} FileGlobal;

@ -35,21 +35,23 @@
extern "C" {
#endif
struct ReportList;
BlendFileData *
BLO_readblenfilename(
char *fileName,
BlendReadError *error_r);
struct ReportList *reports);
BlendFileData *
BLO_readblenfilehandle(
int fileHandle,
BlendReadError *error_r);
struct ReportList *reports);
BlendFileData *
BLO_readblenfilememory(
char *fromBuffer,
int fromBufferSize,
BlendReadError *error_r);
struct ReportList *reports);
void
@ -68,7 +70,7 @@ blo_is_a_runtime(
BlendFileData *
blo_read_runtime(
char *file,
BlendReadError *error_r);
struct ReportList *reports);
#define BLO_RESERVEDSIZE 12
extern char *headerMagic;

@ -51,6 +51,7 @@
#include "BLO_readblenfile.h"
#include "BKE_blender.h"
#include "BKE_report.h"
#include "BLI_blenlib.h"
@ -130,7 +131,7 @@ cleanup:
BlendFileData *
blo_read_runtime(
char *path,
BlendReadError *error_r)
ReportList *reports)
{
BlendFileData *bfd= NULL;
int fd, actualsize, datastart;
@ -138,7 +139,7 @@ blo_read_runtime(
fd= open(path, O_BINARY|O_RDONLY, 0);
if (fd==-1) {
*error_r= BRE_UNABLE_TO_OPEN;
BKE_report(reports, RPT_ERROR, "Unable to open");
goto cleanup;
}
@ -148,18 +149,18 @@ blo_read_runtime(
datastart= handle_read_msb_int(fd);
if (datastart==-1) {
*error_r= BRE_UNABLE_TO_READ;
BKE_report(reports, RPT_ERROR, "Unable to read");
goto cleanup;
} else if (read(fd, buf, 8)!=8) {
*error_r= BRE_UNABLE_TO_READ;
BKE_report(reports, RPT_ERROR, "Unable to read");
goto cleanup;
} else if (memcmp(buf, "BRUNTIME", 8)!=0) {
*error_r= BRE_NOT_A_BLEND;
BKE_report(reports, RPT_ERROR, "File is not a Blender file");
goto cleanup;
} else {
//printf("starting to read runtime from %s at datastart %d\n", path, datastart);
lseek(fd, datastart, SEEK_SET);
bfd = blo_read_blendafterruntime(fd, path, actualsize-datastart, error_r);
bfd = blo_read_blendafterruntime(fd, path, actualsize-datastart, reports);
fd= -1; // file was closed in blo_read_blendafterruntime()
}

@ -65,6 +65,7 @@
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_packedFile.h"
#include "BKE_report.h"
#include "BKE_texture.h"
#include "BKE_utildefines.h"
@ -797,7 +798,7 @@ void WM_write_file(bContext *C, char *target)
Library *li;
int writeflags, len;
char di[FILE_MAX];
char *err;
ReportList reports;
len = strlen(target);
@ -843,8 +844,10 @@ void WM_write_file(bContext *C, char *target)
writeflags= G.fileflags & ~G_FILE_COMPRESS;
if(U.flag & USER_FILECOMPRESS)
writeflags |= G_FILE_COMPRESS;
BKE_reports_init(&reports, RPT_STORE);
if (BLO_write_file(C, di, writeflags, &err)) {
if (BLO_write_file(C, di, writeflags, &reports)) {
strcpy(G.sce, di);
G.relbase_valid = 1;
strcpy(G.main->name, di); /* is guaranteed current file */
@ -858,34 +861,45 @@ void WM_write_file(bContext *C, char *target)
// XXX error("%s", err);
}
BKE_reports_clear(&reports);
// XXX waitcursor(0);
}
/* operator entry */
int WM_write_homefile(bContext *C, wmOperator *op)
{
char *err, tstr[FILE_MAXDIR+FILE_MAXFILE];
ReportList reports;
char tstr[FILE_MAXDIR+FILE_MAXFILE];
int write_flags;
BLI_make_file_string("/", tstr, BLI_gethome(), ".B.blend");
/* force save as regular blend file */
write_flags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_LOCK | G_FILE_SIGN);
BLO_write_file(C, tstr, write_flags, &err);
// XXX error reporting to the user
BKE_reports_init(&reports, RPT_PRINT);
BLO_write_file(C, tstr, write_flags, &reports);
BKE_reports_clear(&reports);
return OPERATOR_FINISHED;
}
void WM_write_autosave(bContext *C)
{
char *err, tstr[FILE_MAXDIR+FILE_MAXFILE];
ReportList reports;
char tstr[FILE_MAXDIR+FILE_MAXFILE];
int write_flags;
get_autosave_location(tstr);
/* force save as regular blend file */
write_flags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_LOCK | G_FILE_SIGN);
BLO_write_file(C, tstr, write_flags, &err);
BKE_reports_init(&reports, RPT_PRINT);
BLO_write_file(C, tstr, write_flags, &reports);
BKE_reports_clear(&reports);
}
/* if global undo; remove tempsave, otherwise rename */

@ -70,6 +70,7 @@
#include "DNA_view3d_types.h"
#include "DNA_screen_types.h"
#include "BKE_global.h"
#include "BKE_report.h"
#include "BKE_utildefines.h"
//XXX #include "BIF_screen.h"
//XXX #include "BIF_scrarea.h"
@ -91,12 +92,21 @@ void update_for_newframe();
}
#endif
static BlendFileData *load_game_data(char *filename) {
BlendReadError error;
BlendFileData *bfd= BLO_read_from_file(filename, &error);
static BlendFileData *load_game_data(char *filename)
{
ReportList reports;
BlendFileData *bfd;
BKE_reports_init(&reports, RPT_STORE);
bfd= BLO_read_from_file(filename, &reports);
if (!bfd) {
printf("Loading %s failed: %s\n", filename, BLO_bre_as_string(error));
printf("Loading %s failed: ", filename);
BKE_reports_print(&reports, RPT_ERROR);
}
BKE_reports_clear(&reports);
return bfd;
}

@ -39,6 +39,7 @@
#include "BKE_blender.h" // initglobals()
#include "BKE_global.h" // Global G
#include "BKE_report.h"
#include "DNA_scene_types.h"
#include "DNA_camera_types.h" // Camera
#include "DNA_object_types.h" // Object
@ -135,15 +136,19 @@ GPC_Engine::~GPC_Engine()
bool GPC_Engine::Start(char *filename)
{
BlendReadError error;
BlendFileData *bfd= BLO_read_from_file(filename, &error);
ReportList reports;
BlendFileData *bfd;
BKE_reports_init(&reports, RPT_STORE);
bfd= BLO_read_from_file(filename, &reports);
BKE_reports_clear(&reports);
if (!bfd) {
// XXX, deal with error here
cout << "Unable to load: " << filename << endl;
return false;
}
StartKetsji();
if(bfd->type == BLENFILETYPE_PUB)
@ -156,8 +161,12 @@ bool GPC_Engine::Start(char *filename)
bool GPC_Engine::Start(unsigned char *blenderDataBuffer,
unsigned int blenderDataBufferSize)
{
BlendReadError error;
BlendFileData *bfd= BLO_read_from_memory(blenderDataBuffer, blenderDataBufferSize, &error);
ReportList reports;
BlendFileData *bfd;
BKE_reports_init(&reports, RPT_STORE);
bfd= BLO_read_from_memory(blenderDataBuffer, blenderDataBufferSize, &reports);
BKE_reports_clear(&reports);
if (!bfd) {
// XXX, deal with error here

@ -58,6 +58,7 @@ extern "C"
#include "BKE_global.h"
#include "BKE_icons.h"
#include "BKE_node.h"
#include "BKE_report.h"
#include "BLI_blenlib.h"
#include "DNA_scene_types.h"
#include "BLO_readfile.h"
@ -251,35 +252,33 @@ static void get_filename(int argc, char **argv, char *filename)
#endif // !_APPLE
}
static BlendFileData *load_game_data(char *progname, char *filename = NULL, char *relativename = NULL) {
BlendReadError error;
static BlendFileData *load_game_data(char *progname, char *filename = NULL, char *relativename = NULL)
{
ReportList reports;
BlendFileData *bfd = NULL;
BKE_reports_init(&reports, RPT_STORE);
/* try to load ourself, will only work if we are a runtime */
if (blo_is_a_runtime(progname)) {
bfd= blo_read_runtime(progname, &error);
bfd= blo_read_runtime(progname, &reports);
if (bfd) {
bfd->type= BLENFILETYPE_RUNTIME;
strcpy(bfd->main->name, progname);
}
} else {
bfd= BLO_read_from_file(progname, &error);
bfd= BLO_read_from_file(progname, &reports);
}
/*
if (bfd && bfd->type == BLENFILETYPE_BLEND) {
BLO_blendfiledata_free(bfd);
bfd = NULL;
error = BRE_NOT_A_PUBFILE;
}
*/
if (!bfd && filename) {
bfd = load_game_data(filename);
if (!bfd) {
printf("Loading %s failed: %s\n", filename, BLO_bre_as_string(error));
printf("Loading %s failed: ", filename);
BKE_reports_print(&reports, RPT_ERROR);
}
}
BKE_reports_clear(&reports);
return bfd;
}