From 5c23537daa5c669b672528b0ed2bcaef2038f766 Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Sat, 28 Aug 2010 02:07:55 +0000 Subject: Committing patch [#23278] (by me) This patch allows a user to pass binary data to LibLoad() to load a blend file from memory instead of a file path. I don't know how useful this will be for others, but I've used it so far for: * Decrypting .blend files and loading them without having to store the .blend on the hard drive * Pulling .blend data out of an archive and loading it (again skipping the hard drive) So, it seems the biggest use for this is skipping a bit of file IO (and possibly some security problems). Example usage: import bge with f as open('myfile.blend', 'rb'): data = f.read() bge.logic.LibLoad('Name', 'Scene', data) --- source/blender/blenloader/BLO_readfile.h | 13 +++++++++++++ source/blender/blenloader/intern/readblenentry.c | 9 +++++++++ 2 files changed, 22 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h index eeced13b57b..719a3c065ae 100644 --- a/source/blender/blenloader/BLO_readfile.h +++ b/source/blender/blenloader/BLO_readfile.h @@ -122,6 +122,19 @@ BLO_blendfiledata_free( BLO_blendhandle_from_file( char *file); +/** + * Open a blendhandle from memory. + * + * @param mem The data to load from. + * @param memsize The size of the data. + * @return A handle on success, or NULL on failure. + */ + + BlendHandle* +BLO_blendhandle_from_memory( + void *mem, + int memsize); + /** * Gets the names of all the datablocks in a file * of a certain type (ie. All the scene names in diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c index d66d802c8ee..da441214b37 100644 --- a/source/blender/blenloader/intern/readblenentry.c +++ b/source/blender/blenloader/intern/readblenentry.c @@ -76,6 +76,15 @@ BlendHandle *BLO_blendhandle_from_file(char *file) return bh; } +BlendHandle *BLO_blendhandle_from_memory(void *mem, int memsize) +{ + BlendHandle *bh; + + bh= (BlendHandle*)blo_openblendermemory(mem, memsize, NULL); + + return bh; +} + void BLO_blendhandle_print_sizes(BlendHandle *bh, void *fp) { FileData *fd= (FileData*) bh; -- cgit v1.2.3