diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-07-03 21:47:06 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-07-03 21:47:06 +0400 |
commit | 80f6102629b746ea520d3ec54aaa6414c669a998 (patch) | |
tree | 8d254cc92120eca8be6ef5b92af7be3c3626f202 /source/blender/makesrna/intern/rna_main_api.c | |
parent | 9a85435e96af9933b282594b6ad8b23ca598d8bc (diff) |
better reporting for file i/o failier, use system error message in more places: Permission Denied, No space left, File not found etc.
- blend load/save uses os message.
- image load gives os message. (remove check for slash at end of line, just let the os report an error)
- python api load image/font/text raise errors with message (was just retuning None for image and font)
- minor edits to py api errors.
Diffstat (limited to 'source/blender/makesrna/intern/rna_main_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_main_api.c | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index 4564ecd586b..6c74ff2fefa 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -28,6 +28,7 @@ #include <stdlib.h> #include <stdio.h> +#include <errno.h> #include "RNA_define.h" #include "RNA_access.h" @@ -260,9 +261,17 @@ Image *rna_Main_images_new(Main *bmain, char* name, int width, int height, int a image->id.us--; return image; } -Image *rna_Main_images_load(Main *bmain, char *filepath) +Image *rna_Main_images_load(Main *bmain, ReportList *reports, char *filepath) { - return BKE_add_image_file(filepath, 0); + Image *ima; + + errno= 0; + ima= BKE_add_image_file(filepath, 0); + + if(!ima) + BKE_reportf(reports, RPT_ERROR, "Can't read: \"%s\", %s.", filepath, errno ? strerror(errno) : "Unsupported image format"); + + return ima; } void rna_Main_images_remove(Main *bmain, ReportList *reports, Image *image) { @@ -316,9 +325,18 @@ void rna_Main_metaballs_remove(Main *bmain, ReportList *reports, struct MetaBall BKE_reportf(reports, RPT_ERROR, "MetaBall \"%s\" must have zero users to be removed, found %d.", mb->id.name+2, ID_REAL_USERS(mb)); } -VFont *rna_Main_fonts_load(Main *bmain, char *filepath) +VFont *rna_Main_fonts_load(Main *bmain, ReportList *reports, char *filepath) { - return load_vfont(filepath); + VFont *font; + + errno= 0; + font= load_vfont(filepath); + + if(!font) + BKE_reportf(reports, RPT_ERROR, "Can't read: \"%s\", %s.", filepath, errno ? strerror(errno) : "Unsupported font format"); + + return font; + } void rna_Main_fonts_remove(Main *bmain, ReportList *reports, VFont *vfont) { @@ -394,11 +412,16 @@ void rna_Main_texts_remove(Main *bmain, ReportList *reports, Text *text) free_libblock(&bmain->text, text); /* XXX python now has invalid pointer? */ } -Text *rna_Main_texts_load(Main *bmain, ReportList *reports, char* path) + +Text *rna_Main_texts_load(Main *bmain, ReportList *reports, char* filepath) { - Text *txt= add_text(path, bmain->name); - if(txt==NULL) - BKE_reportf(reports, RPT_ERROR, "Couldn't load text from path \"%s\".", path); + Text *txt; + + errno= 0; + txt= add_text(filepath, bmain->name); + + if(!txt) + BKE_reportf(reports, RPT_ERROR, "Can't read: \"%s\", %s.", filepath, errno ? strerror(errno) : "Unable to load text"); return txt; } @@ -692,6 +715,7 @@ void RNA_def_main_images(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_return(func, parm); func= RNA_def_function(srna, "load", "rna_Main_images_load"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Load a new image into the main database"); parm= RNA_def_string(func, "filepath", "File Path", 0, "", "path of the file to load."); RNA_def_property_flag(parm, PROP_REQUIRED); @@ -791,6 +815,7 @@ void RNA_def_main_fonts(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_struct_ui_text(srna, "Main Fonts", "Collection of fonts"); func= RNA_def_function(srna, "load", "rna_Main_fonts_load"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Load a new font into the main database"); parm= RNA_def_string(func, "filepath", "File Path", 0, "", "path of the font to load."); RNA_def_property_flag(parm, PROP_REQUIRED); |