From cddaa86dba6de562d67e4c8c26b69691e8b21507 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 18 Feb 2018 14:16:33 +0000 Subject: [PATCH] presets: Use Xml.Linq to write XML --- Sparkles/Preset.cs | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/Sparkles/Preset.cs b/Sparkles/Preset.cs index 86d68fca..0828c926 100644 --- a/Sparkles/Preset.cs +++ b/Sparkles/Preset.cs @@ -17,6 +17,7 @@ using System; using System.Xml; +using System.Xml.Linq; using IO = System.IO; @@ -80,33 +81,31 @@ namespace Sparkles { if (IO.File.Exists (preset_path)) return null; - // TODO: Don't write manually - string preset_xml = "" + - "" + - " " + - " " + - " " + name + "" + - " " + description + "" + - " own-server.png" + - " " + - "
" + - " " + address_value + "" + - " " + address_example + "" + - "
" + - " " + - " " + path_value + "" + - " " + path_example + "" + - " " + - "
" + - "
"; + string icon_name = "own-server.png"; - preset_xml = preset_xml.Replace ("", ""); - preset_xml = preset_xml.Replace ("", ""); + XElement xml = + new XElement ("sparkleshare", + new XElement ("preset", + new XElement ("info", + new XElement ("name", name), + new XElement ("description", description), + new XElement ("icon", icon_name) + ), + new XElement ("address", + new XElement ("value", address_value), + new XElement ("example", address_example) + ), + new XElement ("path", + new XElement ("value", path_value), + new XElement ("example", path_example) + ) + ) + ); if (!IO.Directory.Exists (LocalPresetsPath)) IO.Directory.CreateDirectory (LocalPresetsPath); - IO.File.WriteAllText (preset_path, preset_xml); + IO.File.WriteAllText (preset_path, xml.ToString ()); return new Preset (preset_path); }