From 4e931482f48feab644b74308be92c385b8ebf3ec Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 27 Feb 2010 01:27:22 +0000 Subject: [PATCH] option to set the blend file as from a 'Trusted Source' on load. --- source/blender/python/intern/bpy_driver.c | 6 ++++++ source/blender/python/intern/bpy_interface.c | 18 ++++++++++++------ .../windowmanager/intern/wm_operators.c | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c index 3c204bab9be..24b8c0dc522 100644 --- a/source/blender/python/intern/bpy_driver.c +++ b/source/blender/python/intern/bpy_driver.c @@ -30,6 +30,7 @@ #include "BPY_extern.h" #include "BKE_fcurve.h" +#include "BKE_global.h" #include @@ -165,6 +166,11 @@ float BPY_pydriver_eval (ChannelDriver *driver) if ((expr == NULL) || (expr[0]=='\0')) return result; + if(!(G.fileflags & G_DOSCRIPTLINKS)) { + printf("skipping driver '%s', automatic scripts are disabled\n", driver->expression); + return result; + } + gilstate = PyGILState_Ensure(); /* init global dictionary for py-driver evaluation settings */ diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 0b7c8759b5c..4ad06e83e9f 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -62,6 +62,7 @@ #include "BKE_text.h" #include "BKE_context.h" #include "BKE_main.h" +#include "BKE_global.h" /* only for script checking */ #include "BPY_extern.h" @@ -630,14 +631,19 @@ void BPY_load_user_modules(bContext *C) for(text=CTX_data_main(C)->text.first; text; text= text->id.next) { if(text->flags & TXT_ISSCRIPT && BLI_testextensie(text->id.name+2, ".py")) { - PyObject *module= bpy_text_import(text); - - if (module==NULL) { - PyErr_Print(); - PyErr_Clear(); + if(!(G.fileflags & G_DOSCRIPTLINKS)) { + printf("scripts disabled for \"%s\", skipping '%s'\n", bmain->name, text->id.name+2); } else { - Py_DECREF(module); + PyObject *module= bpy_text_import(text); + + if (module==NULL) { + PyErr_Print(); + PyErr_Clear(); + } + else { + Py_DECREF(module); + } } } } diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 14fe5a4a2e1..eea33423d2b 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1326,10 +1326,17 @@ static void open_set_load_ui(wmOperator *op) RNA_boolean_set(op->ptr, "load_ui", !(U.flag & USER_FILENOUI)); } +static void open_set_use_scripts(wmOperator *op) +{ + if(!RNA_property_is_set(op->ptr, "use_scripts")) + RNA_boolean_set(op->ptr, "use_scripts", (U.flag & USER_DONT_DOSCRIPTLINKS)); +} + static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event) { RNA_string_set(op->ptr, "path", G.sce); open_set_load_ui(op); + open_set_use_scripts(op); WM_event_add_fileselect(C, op); @@ -1342,11 +1349,17 @@ static int wm_open_mainfile_exec(bContext *C, wmOperator *op) RNA_string_get(op->ptr, "path", path); open_set_load_ui(op); + open_set_use_scripts(op); if(RNA_boolean_get(op->ptr, "load_ui")) G.fileflags &= ~G_FILE_NO_UI; else G.fileflags |= G_FILE_NO_UI; + + if(RNA_boolean_get(op->ptr, "use_scripts")) + G.fileflags |= G_DOSCRIPTLINKS; + else + G.fileflags &= ~G_DOSCRIPTLINKS; // XXX wm in context is not set correctly after WM_read_file -> crash // do it before for now, but is this correct with multiple windows? @@ -1370,6 +1383,7 @@ static void WM_OT_open_mainfile(wmOperatorType *ot) WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER, FILE_OPENFILE); RNA_def_boolean(ot->srna, "load_ui", 1, "Load UI", "Load user interface setup in the .blend file"); + RNA_def_boolean(ot->srna, "use_scripts", 1, "Trusted Source", "Allow blend file execute scripts automatically, default available from system preferences"); } /* **************** link/append *************** */