summaryrefslogtreecommitdiff
path: root/SparkleShare/SparklePlugin.cs
diff options
context:
space:
mode:
authorJo Shields <directhex@apebox.org>2012-03-23 10:41:12 +0000
committerJo Shields <directhex@apebox.org>2012-03-23 10:41:12 +0000
commit9a423cedb3984e73164d70197041eed44e20616d (patch)
tree07f8b719b648d4dac067fbb8d5732b39eacc90cf /SparkleShare/SparklePlugin.cs
parent272b12a0e3dc7079f2594ffa6a24a736827666d4 (diff)
Imported Upstream version 0.8.4
Diffstat (limited to 'SparkleShare/SparklePlugin.cs')
-rw-r--r--SparkleShare/SparklePlugin.cs69
1 files changed, 65 insertions, 4 deletions
diff --git a/SparkleShare/SparklePlugin.cs b/SparkleShare/SparklePlugin.cs
index 3868438..dc32ed6 100644
--- a/SparkleShare/SparklePlugin.cs
+++ b/SparkleShare/SparklePlugin.cs
@@ -16,12 +16,20 @@
using System;
+using System.IO;
using System.Xml;
namespace SparkleShare {
public class SparklePlugin {
+ public static string PluginsPath = "";
+
+ public static string LocalPluginsPath =
+ new string [] { Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
+ "sparkleshare", "plugins" }.Combine ();
+
+
public string Name {
get {
return GetValue ("info", "name");
@@ -36,10 +44,18 @@ namespace SparkleShare {
public string ImagePath {
get {
- return System.IO.Path.Combine (
+ string image_file_name = GetValue ("info", "icon");
+
+ string image_path = System.IO.Path.Combine (
this.plugin_directory,
- GetValue ("info", "icon")
+ image_file_name
);
+
+ if (File.Exists (image_path))
+ return image_path;
+ else
+ return System.IO.Path.Combine (
+ PluginsPath, image_file_name);
}
}
@@ -73,6 +89,12 @@ namespace SparkleShare {
}
}
+ public string AnnouncementsUrl {
+ get {
+ return GetValue ("info", "announcements_url");
+ }
+ }
+
private XmlDocument xml = new XmlDocument ();
private string plugin_directory;
@@ -84,15 +106,54 @@ namespace SparkleShare {
}
+ public static SparklePlugin Create (string name, string description, string address_value,
+ string address_example, string path_value, string path_example)
+ {
+ string plugin_path = System.IO.Path.Combine (LocalPluginsPath, name + ".xml");
+
+ if (File.Exists (plugin_path))
+ return null;
+
+ string plugin_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<sparkleshare>" +
+ " <plugin>" +
+ " <info>" +
+ " <name>" + name + "</name>" +
+ " <description>" + description + "</description>" +
+ " <icon>own-server.png</icon>" +
+ " </info>" +
+ " <address>" +
+ " <value>" + address_value + "</value>" +
+ " <example>" + address_example + "</example>" +
+ " </address>" +
+ " <path>" +
+ " <value>" + path_value + "</value>" +
+ " <example>" + path_example + "</example>" +
+ " </path>" +
+ " </plugin>" +
+ "</sparkleshare>";
+
+ plugin_xml = plugin_xml.Replace ("<value></value>", "<value/>");
+ plugin_xml = plugin_xml.Replace ("<example></example>", "<example/>");
+
+ if (!Directory.Exists (LocalPluginsPath))
+ Directory.CreateDirectory (LocalPluginsPath);
+
+ File.WriteAllText (plugin_path, plugin_xml);
+
+ return new SparklePlugin (plugin_path);
+ }
+
+
private string GetValue (string a, string b)
{
XmlNode node = this.xml.SelectSingleNode (
"/sparkleshare/plugin/" + a + "/" + b + "/text()");
- if (node != null)
+ if (node != null && !string.IsNullOrEmpty (node.Value))
return node.Value;
else
return null;
}
}
-}
+} \ No newline at end of file