Sparkles.Preset.Create C# (CSharp) Method

Create() public static method

public static Create ( string name, string description, string address_value, string address_example, string path_value, string path_example ) : Preset
name string
description string
address_value string
address_example string
path_value string
path_example string
return Preset
        public static Preset Create(string name, string description, string address_value,
            string address_example, string path_value, string path_example)
        {
            string preset_path = IO.Path.Combine (LocalPresetsPath, name + ".xml");

            if (IO.File.Exists (preset_path))
                return null;

            // TODO: Don't write manually
            string preset_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<sparkleshare>" +
                "  <preset>" +
                "    <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>" +
                "  </preset>" +
                "</sparkleshare>";

            preset_xml = preset_xml.Replace ("<value></value>", "<value/>");
            preset_xml = preset_xml.Replace ("<example></example>", "<example/>");

            if (!IO.Directory.Exists (LocalPresetsPath))
                IO.Directory.CreateDirectory (LocalPresetsPath);

            IO.File.WriteAllText (preset_path, preset_xml);
            return new Preset (preset_path);
        }