diff --git a/source/blender/blenkernel/BKE_blendfile.h b/source/blender/blenkernel/BKE_blendfile.h index 9625a93ed06..75978120051 100644 --- a/source/blender/blenkernel/BKE_blendfile.h +++ b/source/blender/blenkernel/BKE_blendfile.h @@ -51,8 +51,13 @@ bool BKE_blendfile_read_from_memfile( struct bContext *C, struct MemFile *memfile, struct ReportList *reports, int skip_flag); -struct UserDef *BKE_blendfile_userdef_read(const char *filepath, struct ReportList *reports); -int BKE_blendfile_userdef_write(const char *filepath, struct ReportList *reports); +struct UserDef *BKE_blendfile_userdef_read( + const char *filepath, struct ReportList *reports); +struct UserDef *BKE_blendfile_userdef_read_from_memory( + const void *filebuf, int filelength, + struct ReportList *reports); + +int BKE_blendfile_userdef_write(const char *filepath, struct ReportList *reports); /* partial blend file writing */ diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c index c549c138ef2..5725a12e3d4 100644 --- a/source/blender/blenkernel/intern/blendfile.c +++ b/source/blender/blenkernel/intern/blendfile.c @@ -430,7 +430,7 @@ UserDef *BKE_blendfile_userdef_read(const char *filepath, ReportList *reports) BlendFileData *bfd; UserDef *userdef = NULL; - bfd = BLO_read_from_file(filepath, reports, BLO_READ_SKIP_NONE); + bfd = BLO_read_from_file(filepath, reports, BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF); if (bfd) { if (bfd->user) { userdef = bfd->user; @@ -442,6 +442,30 @@ UserDef *BKE_blendfile_userdef_read(const char *filepath, ReportList *reports) return userdef; } + +UserDef *BKE_blendfile_userdef_read_from_memory( + const void *filebuf, int filelength, + ReportList *reports) +{ + BlendFileData *bfd; + UserDef *userdef = NULL; + + bfd = BLO_read_from_memory(filebuf, filelength, reports, BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF); + if (bfd) { + if (bfd->user) { + userdef = bfd->user; + } + BKE_main_free(bfd->main); + MEM_freeN(bfd); + } + else { + BKE_reports_prepend(reports, "Loading failed: "); + } + + return userdef; +} + + /* only write the userdef in a .blend */ int BKE_blendfile_userdef_write(const char *filepath, ReportList *reports) { diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h index 52b8d15b987..e6fc4703248 100644 --- a/source/blender/blenloader/BLO_readfile.h +++ b/source/blender/blenloader/BLO_readfile.h @@ -74,9 +74,12 @@ typedef struct BlendFileData { /* skip reading some data-block types (may want to skip screen data too). */ typedef enum eBLOReadSkip { - BLO_READ_SKIP_NONE = 0, - BLO_READ_SKIP_USERDEF = (1 << 0), + BLO_READ_SKIP_NONE = 0, + BLO_READ_SKIP_USERDEF = (1 << 0), + BLO_READ_SKIP_DATA = (1 << 1), } eBLOReadSkip; +#define BLO_READ_SKIP_ALL \ + (BLO_READ_SKIP_USERDEF | BLO_READ_SKIP_DATA) BlendFileData *BLO_read_from_file( const char *filepath, diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 91c96aef8e8..0aa53dbe633 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -8611,15 +8611,24 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath) case ID_ID: /* Always adds to the most recently loaded ID_LI block, see direct_link_library. * This is part of the file format definition. */ - bhead = read_libblock(fd, mainlist.last, bhead, LIB_TAG_READ | LIB_TAG_EXTERN, NULL); + if (fd->skip_flags & BLO_READ_SKIP_DATA) { + bhead = blo_nextbhead(fd, bhead); + } + else { + bhead = read_libblock(fd, mainlist.last, bhead, LIB_TAG_READ | LIB_TAG_EXTERN, NULL); + } break; - /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ case ID_SCRN: bhead->code = ID_SCR; /* deliberate pass on to default */ default: - bhead = read_libblock(fd, bfd->main, bhead, LIB_TAG_LOCAL, NULL); + if (fd->skip_flags & BLO_READ_SKIP_DATA) { + bhead = blo_nextbhead(fd, bhead); + } + else { + bhead = read_libblock(fd, bfd->main, bhead, LIB_TAG_LOCAL, NULL); + } } }