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:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2008-12-29 16:38:08 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2008-12-29 16:38:08 +0300
commit0a8a00cd1060ee7aa9eae4223fc8c2577533247f (patch)
tree6dc09a68c1d8e35bd807d784f3507b57c9c1f62f /source/blender/blenloader/intern
parentd51bc24384a70f3cdcd4b72091873c96d542d642 (diff)
2.5: Error reporting
* Added a report list to operator, to which they can report errors and warnings. When the operator ends, it will display them with a popup. For python these should become exceptions when calling operators. * Added a function to make a popup menu from a report list. * Also added a utility function to prepend a string before the reports to indicate what they relates to. Also made the report functions used BLI_dynstr to simplify the code. * Made file reading and writing report errors to the user again using this system, also replacing the left over uncommented bad level error() calls.
Diffstat (limited to 'source/blender/blenloader/intern')
-rw-r--r--source/blender/blenloader/intern/readblenentry.c14
-rw-r--r--source/blender/blenloader/intern/readfile.c78
-rw-r--r--source/blender/blenloader/intern/readfile.h6
-rw-r--r--source/blender/blenloader/intern/writefile.c33
4 files changed, 86 insertions, 45 deletions
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index e7e45597887..23e334fbbd1 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -166,12 +166,9 @@ int BLO_idcode_from_name(char *name)
BlendHandle *BLO_blendhandle_from_file(char *file)
{
- ReportList reports;
BlendHandle *bh;
- BKE_reports_init(&reports, 0);
- bh= (BlendHandle*)blo_openblenderfile(file, &reports);
- BKE_reports_clear(&reports);
+ bh= (BlendHandle*)blo_openblenderfile(file, NULL);
return bh;
}
@@ -330,7 +327,8 @@ BlendFileData *BLO_read_from_file(char *file, ReportList *reports)
fd = blo_openblenderfile(file, reports);
if (fd) {
- bfd= blo_read_file_internal(fd, reports);
+ fd->reports= reports;
+ bfd= blo_read_file_internal(fd);
if (bfd) {
bfd->type= BLENFILETYPE_BLEND;
strncpy(bfd->main->name, file, sizeof(bfd->main->name)-1);
@@ -348,7 +346,8 @@ BlendFileData *BLO_read_from_memory(void *mem, int memsize, ReportList *reports)
fd = blo_openblendermemory(mem, memsize, reports);
if (fd) {
- bfd= blo_read_file_internal(fd, reports);
+ fd->reports= reports;
+ bfd= blo_read_file_internal(fd);
if (bfd) {
bfd->type= BLENFILETYPE_BLEND;
strcpy(bfd->main->name, "");
@@ -367,6 +366,7 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain, const char *filename, MemFil
fd = blo_openblendermemfile(memfile, reports);
if (fd) {
+ fd->reports= reports;
strcpy(fd->filename, filename);
/* clear ob->proxy_from pointers in old main */
@@ -380,7 +380,7 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain, const char *filename, MemFil
/* makes lookup of existing images in old main */
blo_make_image_pointer_map(fd, oldmain);
- bfd= blo_read_file_internal(fd, reports);
+ bfd= blo_read_file_internal(fd);
if (bfd) {
bfd->type= BLENFILETYPE_BLEND;
strcpy(bfd->main->name, "");
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 399ce3d6ef8..1de3868a1c9 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -150,8 +150,6 @@
#include "readfile.h"
-//XXX #include "wm_event_types.h"
-
#include <errno.h>
/*
@@ -3111,7 +3109,7 @@ static void lib_link_object(FileData *fd, Main *main)
ob= ob->id.next;
}
- if(warn) //XXX error("WARNING IN CONSOLE");
+ if(warn)
BKE_report(fd->reports, RPT_WARNING, "Warning in console");
}
@@ -3808,7 +3806,7 @@ static void lib_link_windowmanager(FileData *fd, Main *main)
}
}
-/* ************ READ SCREEN ***************** */
+/* ****************** READ GREASE PENCIL ***************** */
/* relinks grease-pencil data for 3d-view(s) - used for direct_link */
static void link_gpencil(FileData *fd, bGPdata *gpd)
@@ -3836,6 +3834,29 @@ static void link_gpencil(FileData *fd, bGPdata *gpd)
}
}
+/* ****************** READ SCREEN ***************** */
+
+static void butspace_version_132(SpaceButs *buts)
+{
+ buts->v2d.tot.xmin= 0.0f;
+ buts->v2d.tot.ymin= 0.0f;
+ buts->v2d.tot.xmax= 1279.0f;
+ buts->v2d.tot.ymax= 228.0f;
+
+ buts->v2d.min[0]= 256.0f;
+ buts->v2d.min[1]= 42.0f;
+
+ buts->v2d.max[0]= 2048.0f;
+ buts->v2d.max[1]= 450.0f;
+
+ buts->v2d.minzoom= 0.5f;
+ buts->v2d.maxzoom= 1.21f;
+
+ buts->v2d.scroll= 0;
+ buts->v2d.keepzoom= 1;
+ buts->v2d.keeptot= 1;
+}
+
/* note: file read without screens option G_FILE_NO_UI;
check lib pointers in call below */
static void lib_link_screen(FileData *fd, Main *main)
@@ -3887,7 +3908,8 @@ static void lib_link_screen(FileData *fd, Main *main)
SpaceButs *sbuts= (SpaceButs *)sl;
sbuts->lockpoin= NULL;
sbuts->ri= NULL;
-// XXX if(main->versionfile<132) set_rects_butspace(sbuts);
+ if(main->versionfile<132)
+ butspace_version_132(sbuts);
}
else if(sl->spacetype==SPACE_FILE) {
SpaceFile *sfile= (SpaceFile *)sl;
@@ -4189,6 +4211,7 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
link_list(fd, &(sc->edgebase));
link_list(fd, &(sc->areabase));
sc->regionbase.first= sc->regionbase.last= NULL;
+ sc->context= NULL;
sc->mainwin= sc->subwinactive= 0; /* indices */
@@ -4340,7 +4363,6 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main)
BLI_remlink(&main->library, lib);
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;
@@ -5602,8 +5624,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
SpaceLink *sl= sa->spacedata.first;
while(sl) {
if(sl->spacetype==SPACE_BUTS) {
- //SpaceButs *sbuts= (SpaceButs*) sl;
- //XXX sbuts->scaflag= BUTS_SENS_LINK|BUTS_SENS_ACT|BUTS_CONT_ACT|BUTS_ACT_ACT|BUTS_ACT_LINK;
+ SpaceButs *sbuts= (SpaceButs*) sl;
+ sbuts->scaflag= BUTS_SENS_LINK|BUTS_SENS_ACT|BUTS_CONT_ACT|BUTS_ACT_ACT|BUTS_ACT_LINK;
}
sl= sl->next;
}
@@ -6254,8 +6276,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
sbuts->v2d.maxzoom= 1.2f;
sbuts->align= 1; /* horizontal default */
- //XXX
-#if 0
if(sbuts->mainb==BUTS_LAMP) {
sbuts->mainb= CONTEXT_SHADING;
sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_LAMP;
@@ -6299,7 +6319,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
sbuts->mainb= CONTEXT_EDITING;
}
else sbuts->mainb= CONTEXT_SCENE;
-#endif
}
}
}
@@ -8424,7 +8443,7 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead)
return bhead;
}
-BlendFileData *blo_read_file_internal(FileData *fd, ReportList *reports)
+BlendFileData *blo_read_file_internal(FileData *fd)
{
BHead *bhead= blo_firstbhead(fd);
BlendFileData *bfd;
@@ -9480,26 +9499,33 @@ static Library* library_append(Main *mainvar, Scene *scene, char* file, char *di
/* this should probably be moved into the Python code anyway */
void BLO_script_library_append(BlendHandle **bh, char *dir, char *name,
- int idcode, short flag, Main *mainvar, Scene *scene)
+ int idcode, short flag, Main *mainvar, Scene *scene, ReportList *reports)
{
+ FileData *fd= (FileData*)(*bh);
+
/* try to append the requested object */
- library_append(mainvar, scene, name, dir, idcode, 0, (FileData **)bh, NULL, 0, flag );
+ fd->reports= reports;
+ library_append(mainvar, scene, name, dir, idcode, 0, &fd, NULL, 0, flag );
+ if(fd) fd->reports= NULL;
/* do we need to do this? */
DAG_scene_sort(scene);
+
+ *bh= (BlendHandle*)fd;
}
/* append to scene */
/* dir is a full path */
-void BLO_library_append(SpaceFile *sfile, char *dir, int idcode, Main *mainvar, Scene *scene)
+void BLO_library_append(SpaceFile *sfile, char *dir, int idcode, Main *mainvar, Scene *scene, ReportList *reports)
{
BLO_library_append_(&sfile->libfiledata, sfile->filelist, sfile->totfile,
- dir, sfile->file, sfile->flag, idcode, mainvar, scene);
+ dir, sfile->file, sfile->flag, idcode, mainvar, scene, reports);
}
-void BLO_library_append_(BlendHandle** libfiledata, struct direntry* filelist, int totfile,
- char *dir, char* file, short flag, int idcode, Main *mainvar, Scene *scene)
+void BLO_library_append_(BlendHandle** bh, struct direntry* filelist, int totfile,
+ char *dir, char* file, short flag, int idcode, Main *mainvar, Scene *scene, ReportList *reports)
{
+ FileData *fd= (FileData*)(*bh);
Library *curlib;
Base *centerbase;
Object *ob;
@@ -9519,12 +9545,12 @@ void BLO_library_append_(BlendHandle** libfiledata, struct direntry* filelist, i
if( strcmp(filelist[a].relname, file)==0) break;
}
if(a==totfile) {
- //XXX error("Wrong indicated name");
+ BKE_report(reports, RPT_ERROR, "Wrong indicated name");
return;
}
}
else {
- //XXX error("Nothing indicated");
+ BKE_report(reports, RPT_ERROR, "Nothing indicated");
return;
}
}
@@ -9532,7 +9558,11 @@ void BLO_library_append_(BlendHandle** libfiledata, struct direntry* filelist, i
if(flag & FILE_AUTOSELECT) scene_deselect_all(scene);
- curlib = library_append(mainvar, scene, file, dir, idcode, totsel, (FileData**) libfiledata, filelist, totfile,flag );
+ fd->reports= reports;
+ curlib = library_append(mainvar, scene, file, dir, idcode, totsel, &fd, filelist, totfile,flag );
+ if(fd) fd->reports= NULL;
+
+ *bh= (BlendHandle*)fd;
/* when not linking (appending)... */
if((flag & FILE_LINK)==0) {
@@ -9614,9 +9644,8 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
ReportList reports;
printf("read library: lib %s\n", mainptr->curlib->name);
- BKE_reports_init(&reports, 0);
fd= blo_openblenderfile(mainptr->curlib->filename, &reports);
- BKE_reports_clear(&reports);
+ fd->reports= basefd->reports;
if (fd) {
if (fd->libmap)
@@ -9731,7 +9760,8 @@ BlendFileData *blo_read_blendafterruntime(int file, char *name, int actualsize,
if (!fd)
return NULL;
- bfd= blo_read_file_internal(fd, reports);
+ fd->reports= reports;
+ bfd= blo_read_file_internal(fd);
blo_freefiledata(fd);
return bfd;
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 08797d36084..b084e377d19 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -107,10 +107,10 @@ struct Main;
void blo_join_main(ListBase *mainlist);
void blo_split_main(ListBase *mainlist, struct Main *main);
-BlendFileData *blo_read_file_internal( FileData *fd, struct ReportList *reports);
+BlendFileData *blo_read_file_internal(FileData *fd);
-FileData *blo_openblenderfile( char *name, struct ReportList *reports);
-FileData *blo_openblendermemory( void *buffer, int buffersize, struct ReportList *reports);
+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, Main *oldmain);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 7c7325ab8fa..1b8db72f4ec 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2265,20 +2265,22 @@ cleanup:
if (runtime)
MEM_freeN(runtime);
- return !(reports->flag & RPT_HAS_ERROR);
+ return !BKE_reports_have_error(reports);
}
int BLO_write_runtime(Main *mainvar, char *file, char *exename, ReportList *reports)
{
char gamename[FILE_MAXDIR+FILE_MAXFILE];
- int outfd = -1;
+ int outfd = -1, error= 0;
// remove existing file / bundle
//printf("Delete file %s\n", file);
BLI_delete(file, 0, TRUE);
- if (!recursive_copy_runtime(file, exename, reports))
+ if (!recursive_copy_runtime(file, exename, reports)) {
+ error= 1;
goto cleanup;
+ }
strcpy(gamename, file);
strcat(gamename, "/Contents/Resources/game.blend");
@@ -2290,18 +2292,20 @@ int BLO_write_runtime(Main *mainvar, char *file, char *exename, ReportList *repo
if (write(outfd, " ", 1) != 1) {
BKE_report(reports, RPT_ERROR, "Unable to write to output file.");
+ error= 1;
goto cleanup;
}
} else {
BKE_report(reports, RPT_ERROR, "Unable to open blenderfile.");
+ error= 1;
}
cleanup:
if (outfd!=-1)
close(outfd);
- //XXX error("Unable to make runtime: %s", cause);
- return !(reports->flag & RPT_HAS_ERROR);
+ BKE_reports_prepend(reports, "Unable to make runtime: ");
+ return !error;
}
#else /* !__APPLE__ */
@@ -2310,22 +2314,25 @@ static int handle_append_runtime(int handle, char *exename, ReportList *reports)
{
char *runtime= get_runtime_path(exename);
unsigned char buf[1024];
- int count, progfd= -1;
+ int count, progfd= -1, error= 0;
if (!BLI_exists(runtime)) {
BKE_report(reports, RPT_ERROR, "Unable to find runtime.");
+ error= 1;
goto cleanup;
}
progfd= open(runtime, O_BINARY|O_RDONLY, 0);
if (progfd==-1) {
BKE_report(reports, RPT_ERROR, "Unable to find runtime.@");
+ error= 1;
goto cleanup;
}
while ((count= read(progfd, buf, sizeof(buf)))>0) {
if (write(handle, buf, count)!=count) {
BKE_report(reports, RPT_ERROR, "Unable to write to output file.");
+ error= 1;
goto cleanup;
}
}
@@ -2336,7 +2343,7 @@ cleanup:
if (runtime)
MEM_freeN(runtime);
- return !(reports->flag & RPT_HAS_ERROR);
+ return !error;
}
static int handle_write_msb_int(int handle, int i)
@@ -2353,14 +2360,17 @@ static int handle_write_msb_int(int handle, int i)
int BLO_write_runtime(Main *mainvar, char *file, char *exename, ReportList *reports)
{
int outfd= open(file, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, 0777);
- int datastart;
+ int datastart, error= 0;
if (!outfd) {
BKE_report(reports, RPT_ERROR, "Unable to open output file.");
+ error= 1;
goto cleanup;
}
- if (!handle_append_runtime(outfd, exename, reports))
+ if (!handle_append_runtime(outfd, exename, reports)) {
+ error= 1;
goto cleanup;
+ }
datastart= lseek(outfd, 0, SEEK_CUR);
@@ -2368,6 +2378,7 @@ int BLO_write_runtime(Main *mainvar, char *file, char *exename, ReportList *repo
if (!handle_write_msb_int(outfd, datastart) || (write(outfd, "BRUNTIME", 8)!=8)) {
BKE_report(reports, RPT_ERROR, "Unable to write to output file.");
+ error= 1;
goto cleanup;
}
@@ -2375,8 +2386,8 @@ cleanup:
if (outfd!=-1)
close(outfd);
- //XXX error("Unable to make runtime: %s", cause);
- return !(reports->flag & RPT_HAS_ERROR);
+ BKE_reports_prepend(reports, "Unable to make runtime: ");
+ return !error;
}
#endif /* !__APPLE__ */