commit:de68be10ae8d84f85431c704bb06d89e4d93cc98
author:Chip Black
committer:Chip Black
date:Sun Jun 14 22:24:13 2009 -0500
parents:2be31e14fb4593a82a52219e534a61a2613ead34
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).
diff --git a/Config.cs b/Config.cs
line changes: +6/-0
index 7bf9753..b8f04cd
--- a/Config.cs
+++ b/Config.cs
@@ -18,6 +18,7 @@ namespace bytex64.WebThing {
     public class Config {
         public static List<string> ConfigPath;
         public static string ConfigPathOut = null;
+        public static List<string> PluginPath;
 
         public static Dictionary<string,string> Options;
         public static Dictionary<string,Dictionary<string,string>> PluginOptions;
@@ -55,6 +56,11 @@ namespace bytex64.WebThing {
                 if (Directory.Exists(homepath))
                     ConfigPathOut = homepath;
             }
+
+            // Set up PluginPath
+            PluginPath = new List<string>();
+            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
line changes: +5/-1
index d28b428..7d1fe86
--- 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
line changes: +14/-1
index 56bfe55..7ef976c
--- 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/GoogleSearch.cs b/plugins/GoogleSearch.cs
line changes: +0/-10
index 7b1b542..0000000
--- a/plugins/GoogleSearch.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using System;
-using bytex64.WebThing;
-using System.Text.RegularExpressions;
-
-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));
-    }
-}

diff --git a/plugins/Makefile b/plugins/Makefile
line changes: +1/-6
index d09a8c4..77b79a2
--- 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/WikipediaSearch.cs b/plugins/WikipediaSearch.cs
line changes: +0/-10
index 7224396..0000000
--- a/plugins/WikipediaSearch.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using System;
-using bytex64.WebThing;
-using System.Text.RegularExpressions;
-
-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));
-    }
-}

diff --git a/searchplugins/GoogleSearch.cs b/searchplugins/GoogleSearch.cs
line changes: +10/-0
index 0000000..1d345cb
--- /dev/null
+++ b/searchplugins/GoogleSearch.cs
@@ -0,0 +1,10 @@
+using System;
+using System.Web;
+using System.Text.RegularExpressions;
+using bytex64.WebThing;
+
+public class GoogleSearch : WebThingPlugin, ISearchPlugin {
+    public string SearchTransform(string search) {
+        return String.Format("http://google.com/search?q={0}", HttpUtility.UrlEncode(search));
+    }
+}

diff --git a/searchplugins/Makefile b/searchplugins/Makefile
line changes: +10/-0
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/searchplugins/WikipediaSearch.cs b/searchplugins/WikipediaSearch.cs
line changes: +10/-0
index 0000000..85adae4
--- /dev/null
+++ b/searchplugins/WikipediaSearch.cs
@@ -0,0 +1,10 @@
+using System;
+using System.Web;
+using System.Text.RegularExpressions;
+using bytex64.WebThing;
+
+public class WikipediaSearch : WebThingPlugin, ISearchPlugin {
+    public string SearchTransform(string search) {
+        return String.Format("http://www.wikipedia.org/search-redirect.php?search={0}&language=en&go=Go", HttpUtility.UrlEncode(search));
+    }
+}