BGE LibLoad: Allow the user to disable loading text datablocks if they want to attemp...
authorMitchell Stokes <mogurijin@gmail.com>
Sun, 22 Jul 2012 22:58:12 +0000 (22:58 +0000)
committerMitchell Stokes <mogurijin@gmail.com>
Sun, 22 Jul 2012 22:58:12 +0000 (22:58 +0000)
doc/python_api/rst/bge.logic.rst
source/gameengine/Converter/KX_BlenderSceneConverter.cpp
source/gameengine/Converter/KX_BlenderSceneConverter.h
source/gameengine/Ketsji/KX_PythonInit.cpp

index d071984b14b7da0e4bfafc60d371f848839cd6f9..0d1d0df88c39d49e4aab235993d877a728018cd8 100644 (file)
@@ -172,7 +172,7 @@ General functions
 
    Restarts the current game by reloading the .blend file (the last saved version, not what is currently running).
    
 
    Restarts the current game by reloading the .blend file (the last saved version, not what is currently running).
    
-.. function:: LibLoad(blend, type, data, load_actions=False, verbose=False)
+.. function:: LibLoad(blend, type, data, load_actions=False, verbose=False, load_scripts=True)
    
    Converts the all of the datablocks of the given type from the given blend.
    
    
    Converts the all of the datablocks of the given type from the given blend.
    
@@ -186,6 +186,8 @@ General functions
    :type load_actions: bool
    :arg verbose: Whether or not to print debugging information (e.g., "SceneName: Scene")
    :type verbose: bool
    :type load_actions: bool
    :arg verbose: Whether or not to print debugging information (e.g., "SceneName: Scene")
    :type verbose: bool
+   :arg load_scripts: Whether or not to load text datablocks as well (can be disabled for some extra security)
+   :type load_scripts: bool
    
 .. function:: LibNew(name, type, data)
 
    
 .. function:: LibNew(name, type, data)
 
index 3961e6554a724bfe620d5b8f652639d6af0ad51c..651c1a70f45e8454feee6bd26ddff0696e2f6b9d 100644 (file)
@@ -988,8 +988,7 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha
 
        load_datablocks(main_newlib, bpy_openlib, path, idcode);
 
 
        load_datablocks(main_newlib, bpy_openlib, path, idcode);
 
-       if (idcode==ID_SCE) {
-               /* assume we want text blocks too */
+       if (idcode==ID_SCE && options & LIB_LOAD_LOAD_SCRIPTS) {
                load_datablocks(main_newlib, bpy_openlib, path, ID_TXT);
        }
 
                load_datablocks(main_newlib, bpy_openlib, path, ID_TXT);
        }
 
@@ -1045,8 +1044,8 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha
                }
 
                /* Handle any text datablocks */
                }
 
                /* Handle any text datablocks */
-
-               addImportMain(main_newlib);
+               if (options & LIB_LOAD_LOAD_SCRIPTS)
+                       addImportMain(main_newlib);
 
                /* Now handle all the actions */
                if (options & LIB_LOAD_LOAD_ACTIONS) {
 
                /* Now handle all the actions */
                if (options & LIB_LOAD_LOAD_ACTIONS) {
index 906e3fed111b7435bc8c48084d33bc028e974bb8..b51c2f21ca7917b26127f8ccdf6752a7c014c509 100644 (file)
@@ -182,6 +182,7 @@ public:
        {
                LIB_LOAD_LOAD_ACTIONS = 1,
                LIB_LOAD_VERBOSE = 2,
        {
                LIB_LOAD_LOAD_ACTIONS = 1,
                LIB_LOAD_VERBOSE = 2,
+               LIB_LOAD_LOAD_SCRIPTS = 4,
        };
 
 
        };
 
 
index 823363dfd110f141822055f9b32ac2e828ce4c16..536b32cbd77448d3114a224d777e1316528a5c6c 100644 (file)
@@ -676,12 +676,12 @@ static PyObject *gLibLoad(PyObject*, PyObject* args, PyObject* kwds)
        char *err_str= NULL;
 
        short options=0;
        char *err_str= NULL;
 
        short options=0;
-       int load_actions=0, verbose=0;
+       int load_actions=0, verbose=0, load_scripts=1;
 
 
-       static const char *kwlist[] = {"path", "group", "buffer", "load_actions", "verbose", NULL};
+       static const char *kwlist[] = {"path", "group", "buffer", "load_actions", "verbose", "load_scripts", NULL};
        
        
-       if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|y*ii:LibLoad", const_cast<char**>(kwlist),
-                                                                       &path, &group, &py_buffer, &load_actions, &verbose))
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|y*iii:LibLoad", const_cast<char**>(kwlist),
+                                                                       &path, &group, &py_buffer, &load_actions, &verbose, &load_scripts))
                return NULL;
 
        /* setup options */
                return NULL;
 
        /* setup options */
@@ -689,6 +689,8 @@ static PyObject *gLibLoad(PyObject*, PyObject* args, PyObject* kwds)
                options |= KX_BlenderSceneConverter::LIB_LOAD_LOAD_ACTIONS;
        if (verbose != 0)
                options |= KX_BlenderSceneConverter::LIB_LOAD_VERBOSE;
                options |= KX_BlenderSceneConverter::LIB_LOAD_LOAD_ACTIONS;
        if (verbose != 0)
                options |= KX_BlenderSceneConverter::LIB_LOAD_VERBOSE;
+       if (load_scripts != 0)
+               options |= KX_BlenderSceneConverter::LIB_LOAD_LOAD_SCRIPTS;
 
        if (!py_buffer.buf)
        {
 
        if (!py_buffer.buf)
        {