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)
This commit is contained in:
@@ -932,13 +932,28 @@ Main* KX_BlenderSceneConverter::GetMainDynamicPath(const char *path)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, KX_Scene *scene_merge, char **err_str)
|
||||
bool KX_BlenderSceneConverter::LinkBlendFileMemory(void *data, int length, const char *path, char *group, KX_Scene *scene_merge, char **err_str)
|
||||
{
|
||||
BlendHandle *bpy_openlib = BLO_blendhandle_from_memory(data, length);
|
||||
|
||||
// Error checking is done in LinkBlendFile
|
||||
return LinkBlendFile(bpy_openlib, path, group, scene_merge, err_str);
|
||||
}
|
||||
|
||||
bool KX_BlenderSceneConverter::LinkBlendFilePath(const char *path, char *group, KX_Scene *scene_merge, char **err_str)
|
||||
{
|
||||
BlendHandle *bpy_openlib = BLO_blendhandle_from_file( (char *)path );
|
||||
|
||||
// Error checking is done in LinkBlendFile
|
||||
return LinkBlendFile(bpy_openlib, path, group, scene_merge, err_str);
|
||||
}
|
||||
|
||||
bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const char *path, char *group, KX_Scene *scene_merge, char **err_str)
|
||||
{
|
||||
bContext *C;
|
||||
Main *main_newlib; /* stored as a dynamic 'main' until we free it */
|
||||
Main *main_tmp= NULL; /* created only for linking, then freed */
|
||||
LinkNode *names = NULL;
|
||||
BlendHandle *bpy_openlib = NULL; /* ptr to the open .blend file */
|
||||
int idcode= BKE_idcode_from_name(group);
|
||||
short flag= 0; /* dont need any special options */
|
||||
ReportList reports;
|
||||
@@ -956,7 +971,6 @@ bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, KX_S
|
||||
return false;
|
||||
}
|
||||
|
||||
bpy_openlib = BLO_blendhandle_from_file( (char *)path );
|
||||
if(bpy_openlib==NULL) {
|
||||
snprintf(err_local, sizeof(err_local), "could not open blendfile \"%s\"\n", path);
|
||||
*err_str= err_local;
|
||||
|
Reference in New Issue
Block a user