From de68be10ae8d84f85431c704bb06d89e4d93cc98 Mon Sep 17 00:00:00 2001 From: Chip Black Date: Sun, 14 Jun 2009 22:24:13 -0500 Subject: [PATCH] Add plugin path, separate search plugins Added plugin path to Config, used to search for plugins. Moved search plugins into their own directory, with a slightly different makefile. Modified PluginManager to search for assemblies on the search path. Search plugins have been modified to do proper url escaping (which, incidentally, makes them even simpler). --- Config.cs | 6 ++++++ Makefile | 6 +++++- PluginManager.cs | 15 ++++++++++++++- plugins/Makefile | 7 +------ {plugins => searchplugins}/GoogleSearch.cs | 6 +++--- searchplugins/Makefile | 10 ++++++++++ {plugins => searchplugins}/WikipediaSearch.cs | 6 +++--- 7 files changed, 42 insertions(+), 14 deletions(-) rename {plugins => searchplugins}/GoogleSearch.cs (57%) create mode 100644 searchplugins/Makefile rename {plugins => searchplugins}/WikipediaSearch.cs (67%) diff --git a/Config.cs b/Config.cs index 7bf9753..b8f04cd 100644 --- a/Config.cs +++ b/Config.cs @@ -18,6 +18,7 @@ namespace bytex64.WebThing { public class Config { public static List ConfigPath; public static string ConfigPathOut = null; + public static List PluginPath; public static Dictionary Options; public static Dictionary> PluginOptions; @@ -55,6 +56,11 @@ namespace bytex64.WebThing { if (Directory.Exists(homepath)) ConfigPathOut = homepath; } + + // Set up PluginPath + PluginPath = new List(); + PluginPath.Add(Environment.GetEnvironmentVariable("WEBTHING_HOME") + "/plugins"); + PluginPath.Add(Environment.GetEnvironmentVariable("WEBTHING_HOME") + "/searchplugins"); } private static void ParseOption(string key, string val) { diff --git a/Makefile b/Makefile index d28b428..7d1fe86 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ LDFLAGS = `pkg-config glib-2.0 libsoup-2.4 webkit-1.0 --libs` CSFLAGS = -debug references = -r:webkit-sharp.dll -pkg:gtk-sharp-2.0 -all: WebThingMain.exe plugins +all: WebThingMain.exe plugins searchplugins .PHONY: tags tags: @@ -22,3 +22,7 @@ SoupSettings.so: SoupSettings.c plugins: make -C plugins .PHONY: plugins + +searchplugins: + make -C searchplugins +.PHONY: searchplugins diff --git a/PluginManager.cs b/PluginManager.cs index 56bfe55..7ef976c 100644 --- a/PluginManager.cs +++ b/PluginManager.cs @@ -23,8 +23,10 @@ namespace bytex64.WebThing { } public void LoadPlugin(string assemblyname) { - Assembly a = Assembly.LoadFile(Environment.GetEnvironmentVariable("WEBTHING_HOME") + "/plugins/" + assemblyname + ".dll"); + Assembly a = FindAssembly(assemblyname); + if (a == null) return; Type[] types = a.GetTypes(); + foreach (Type t in types) { if (t.IsSubclassOf(typeof(WebThingPlugin))) { if (Plugins.ContainsKey(t.FullName)) @@ -38,6 +40,17 @@ namespace bytex64.WebThing { } } + private Assembly FindAssembly(string assemblyname) { + foreach (string path in Config.PluginPath) { + try { + return Assembly.LoadFile(path + "/" + assemblyname + ".dll"); + } catch { + } + } + Console.WriteLine("Could not find {0}", assemblyname); + return null; + } + public void WebViewSetup(WebView view) { foreach (string key in PluginOrder) { Plugins[key].InitWebView(view); diff --git a/plugins/Makefile b/plugins/Makefile index d09a8c4..77b79a2 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -1,15 +1,10 @@ CSFLAGS = -debug references = -r:../webkit-sharp.dll -pkg:gtk-sharp-2.0 -all: Vimish.dll FFNav.dll DefaultPage.dll LoadProgress.dll MiddleClickOpen.dll QuickSearch.dll Session.dll Fullscreen.dll GoogleSearch.dll WikipediaSearch.dll +all: Vimish.dll FFNav.dll DefaultPage.dll LoadProgress.dll MiddleClickOpen.dll QuickSearch.dll Session.dll Fullscreen.dll clean: rm -f *.dll *.mdb *.so - make -C SoupSettings clean - -.PHONY: SoupSettings.dll -SoupSettings.dll: - make -C SoupSettings %.dll: %.cs ../WebThing.dll gmcs $(CSFLAGS) $(references) -r:../WebThing.dll -target:library -out:$@ $< diff --git a/plugins/GoogleSearch.cs b/searchplugins/GoogleSearch.cs similarity index 57% rename from plugins/GoogleSearch.cs rename to searchplugins/GoogleSearch.cs index 7b1b542..1d345cb 100644 --- a/plugins/GoogleSearch.cs +++ b/searchplugins/GoogleSearch.cs @@ -1,10 +1,10 @@ using System; -using bytex64.WebThing; +using System.Web; using System.Text.RegularExpressions; +using bytex64.WebThing; public class GoogleSearch : WebThingPlugin, ISearchPlugin { public string SearchTransform(string search) { - string[] words = Regex.Split(search, @"\s+"); - return String.Format("http://google.com/search?q={0}", String.Join("%20", words)); + return String.Format("http://google.com/search?q={0}", HttpUtility.UrlEncode(search)); } } diff --git a/searchplugins/Makefile b/searchplugins/Makefile new file mode 100644 index 0000000..41b3880 --- /dev/null +++ b/searchplugins/Makefile @@ -0,0 +1,10 @@ +CSFLAGS = -debug +references = -r:../WebThing.dll -r:System.Web + +all: GoogleSearch.dll WikipediaSearch.dll + +clean: + rm -f *.dll *.mdb *.so + +%.dll: %.cs ../WebThing.dll + gmcs $(CSFLAGS) $(references) -target:library -out:$@ $< diff --git a/plugins/WikipediaSearch.cs b/searchplugins/WikipediaSearch.cs similarity index 67% rename from plugins/WikipediaSearch.cs rename to searchplugins/WikipediaSearch.cs index 7224396..85adae4 100644 --- a/plugins/WikipediaSearch.cs +++ b/searchplugins/WikipediaSearch.cs @@ -1,10 +1,10 @@ using System; -using bytex64.WebThing; +using System.Web; using System.Text.RegularExpressions; +using bytex64.WebThing; public class WikipediaSearch : WebThingPlugin, ISearchPlugin { public string SearchTransform(string search) { - string[] words = Regex.Split(search, @"\s+"); - return String.Format("http://www.wikipedia.org/search-redirect.php?search={0}&language=en&go=Go", String.Join("%20", words)); + return String.Format("http://www.wikipedia.org/search-redirect.php?search={0}&language=en&go=Go", HttpUtility.UrlEncode(search)); } } -- 2.25.1