[Bf-blender-cvs] [d4d8da28fc] master: Add BKE_blendfile_userdef_read_from_memory

Campbell Barton noreply at git.blender.org
Thu Mar 16 20:57:15 CET 2017


Commit: d4d8da28fce479d01d2910f4acc9e849621807d9
Author: Campbell Barton
Date:   Fri Mar 17 07:01:11 2017 +1100
Branches: master
https://developer.blender.org/rBd4d8da28fce479d01d2910f4acc9e849621807d9

Add BKE_blendfile_userdef_read_from_memory

Needed to read user-preferences from in-memory startup.blend

Also skip data-blocks when reading preferences.

===================================================================

M	source/blender/blenkernel/BKE_blendfile.h
M	source/blender/blenkernel/intern/blendfile.c
M	source/blender/blenloader/BLO_readfile.h
M	source/blender/blenloader/intern/readfile.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_blendfile.h b/source/blender/blenkernel/BKE_blendfile.h
index 9625a93ed0..7597812005 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 c549c138ef..5725a12e3d 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 52b8d15b98..e6fc470324 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 91c96aef8e..0aa53dbe63 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);
+			}
 		}
 	}




More information about the Bf-blender-cvs mailing list