From 4eecf93bc80c35586cab13d29213cfd3d2fd1069 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 8 Feb 2012 14:51:07 +0100 Subject: [PATCH] plugin: cleanup --- SparkleShare/SparklePlugin.cs | 95 ++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 36 deletions(-) diff --git a/SparkleShare/SparklePlugin.cs b/SparkleShare/SparklePlugin.cs index e77fc15d..d25a7cd1 100644 --- a/SparkleShare/SparklePlugin.cs +++ b/SparkleShare/SparklePlugin.cs @@ -16,56 +16,79 @@ using System; -using System.IO; using System.Xml; namespace SparkleShare { public class SparklePlugin { - public string Name; - public string Description; - public string ImagePath; - public string Backend; + public string Name { + get { + return GetValue ("info", "name"); + } + } - public string Address; - public string AddressExample; - public string Path; - public string PathExample; + public string Description { + get { + return GetValue ("info", "description"); + } + } + public string ImagePath { + get { + return System.IO.Path.Combine (this.plugin_directory, GetValue ("info", "icon")); + } + } + + public string Backend { + get { + return GetValue ("info", "backend"); + } + } + + public string Address { + get { + return GetValue ("address", "value"); + } + } + + public string AddressExample { + get { + return GetValue ("address", "example"); + } + } + + public string Path { + get { + return GetValue ("path", "value"); + } + } + + public string PathExample { + get { + return GetValue ("path", "example"); + } + } + + + private XmlDocument xml = new XmlDocument (); + private string plugin_directory; public SparklePlugin (string plugin_path) { - string plugin_directory = System.IO.Path.GetDirectoryName (plugin_path); + this.plugin_directory = System.IO.Path.GetDirectoryName (plugin_path); + this.xml.Load (plugin_path); + } - XmlDocument xml = new XmlDocument (); - xml.Load (plugin_path); - XmlNode node; + private string GetValue (string a, string b) + { + XmlNode node = this.xml.SelectSingleNode ("/sparkleshare/plugin/" + a + "/" + b + "/text()"); - node = xml.SelectSingleNode ("/sparkleshare/plugin/info/name/text()"); - if (node != null) { Name = node.Value; } - - node = xml.SelectSingleNode ("/sparkleshare/plugin/info/description/text()"); - if (node != null) { Description = node.Value; } - - node = xml.SelectSingleNode ("/sparkleshare/plugin/info/icon/text()"); - if (node != null) { ImagePath = System.IO.Path.Combine (plugin_directory, node.Value); } - - node = xml.SelectSingleNode ("/sparkleshare/plugin/info/backend/text()"); - if (node != null) { Backend = node.Value; } - - node = xml.SelectSingleNode ("/sparkleshare/plugin/address/value/text()"); - if (node != null) { Address = node.Value; } - - node = xml.SelectSingleNode ("/sparkleshare/plugin/address/example/text()"); - if (node != null) { AddressExample = node.Value; } - - node = xml.SelectSingleNode ("/sparkleshare/plugin/path/value/text()"); - if (node != null) { Path = node.Value; } - - node = xml.SelectSingleNode ("/sparkleshare/plugin/path/example/text()"); - if (node != null) { PathExample = node.Value; } + if (node != null) + return node.Value; + else + return null; } } }