From 0399b97672145581adfebcefc79c40f94ae083aa Mon Sep 17 00:00:00 2001 From: RKrom Date: Wed, 11 Dec 2013 21:22:03 +0100 Subject: [PATCH] Fix for #1574, AccessException when loading plugins --- Greenshot/Helpers/PluginHelper.cs | 41 ++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/Greenshot/Helpers/PluginHelper.cs b/Greenshot/Helpers/PluginHelper.cs index 2cefbb29b..b72ff01ce 100644 --- a/Greenshot/Helpers/PluginHelper.cs +++ b/Greenshot/Helpers/PluginHelper.cs @@ -209,25 +209,36 @@ namespace Greenshot.Helpers { return false; } + /// + /// Private helper to find the plugins in the path + /// + /// + /// + private void findPluginsOnPath(List pluginFiles, String path) { + if (Directory.Exists(pafPath)) { + try { + foreach (string pluginFile in Directory.GetFiles(path, "*.gsp", SearchOption.AllDirectories)) { + pluginFiles.Add(pluginFile); + } + } catch (System.UnauthorizedAccessException) { + return; + } catch (Exception ex) { + LOG.Error("Error loading plugin: ", ex); + } + } + } + + /// + /// Load the plugins + /// public void LoadPlugins() { List pluginFiles = new List(); - if (IniConfig.IsPortable && Directory.Exists(pafPath)) { - foreach(string pluginFile in Directory.GetFiles(pafPath, "*.gsp", SearchOption.AllDirectories)) { - pluginFiles.Add(pluginFile); - } + if (IniConfig.IsPortable) { + findPluginsOnPath(pluginFiles, pafPath); } else { - if (Directory.Exists(pluginPath)) { - foreach(string pluginFile in Directory.GetFiles(pluginPath, "*.gsp", SearchOption.AllDirectories)) { - pluginFiles.Add(pluginFile); - } - } - - if (Directory.Exists(applicationPath)) { - foreach(string pluginFile in Directory.GetFiles(applicationPath, "*.gsp", SearchOption.AllDirectories)) { - pluginFiles.Add(pluginFile); - } - } + findPluginsOnPath(pluginFiles, pluginPath); + findPluginsOnPath(pluginFiles, applicationPath); } Dictionary tmpAttributes = new Dictionary();