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:
@@ -626,13 +626,28 @@ static PyObject *gLibLoad(PyObject*, PyObject* args)
|
||||
KX_Scene *kx_scene= gp_KetsjiScene;
|
||||
char *path;
|
||||
char *group;
|
||||
Py_buffer py_buffer;
|
||||
py_buffer.buf = NULL;
|
||||
char *err_str= NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args,"ss:LibLoad",&path, &group))
|
||||
if (!PyArg_ParseTuple(args,"ss|y*:LibLoad",&path, &group, &py_buffer))
|
||||
return NULL;
|
||||
|
||||
if(kx_scene->GetSceneConverter()->LinkBlendFile(path, group, kx_scene, &err_str)) {
|
||||
Py_RETURN_TRUE;
|
||||
if (!py_buffer.buf)
|
||||
{
|
||||
if(kx_scene->GetSceneConverter()->LinkBlendFilePath(path, group, kx_scene, &err_str)) {
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if(kx_scene->GetSceneConverter()->LinkBlendFileMemory(py_buffer.buf, py_buffer.len, path, group, kx_scene, &err_str)) {
|
||||
PyBuffer_Release(&py_buffer);
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
|
||||
PyBuffer_Release(&py_buffer);
|
||||
}
|
||||
|
||||
if(err_str) {
|
||||
|
||||
Reference in New Issue
Block a user