From db8371d3afcdc76756078efe915df22e0d66dc6d Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sun, 23 Feb 2014 10:27:19 +0800 Subject: [PATCH] Fix crash issue when user didn't install python. --- Wox/PluginLoader/PythonPluginLoader.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Wox/PluginLoader/PythonPluginLoader.cs b/Wox/PluginLoader/PythonPluginLoader.cs index 5c7a851ca..d8b2c5db8 100644 --- a/Wox/PluginLoader/PythonPluginLoader.cs +++ b/Wox/PluginLoader/PythonPluginLoader.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading; using Python.Runtime; using Wox.Plugin; +using Wox.Helper; namespace Wox.PluginLoader { @@ -11,6 +12,8 @@ namespace Wox.PluginLoader { public override List LoadPlugin() { + if (!CheckPythonEnvironmentInstalled()) return new List(); + List plugins = new List(); List metadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.Python.ToUpper()).ToList(); foreach (PluginMetadata metadata in metadatas) @@ -26,5 +29,18 @@ namespace Wox.PluginLoader return plugins; } + + private bool CheckPythonEnvironmentInstalled() { + try + { + PythonEngine.Initialize(); + PythonEngine.Shutdown(); + } + catch { + Log.Error("Could't find python environment, all python plugins disabled."); + return false; + } + return true; + } } }