From d5a76206835fc09ab70a0f35162a4d8018598dbd Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 18 Feb 2018 14:06:14 +0000 Subject: [PATCH] config: Use Xml.Linq for writing XML --- SparkleShare/Common/SetupController.cs | 1 - Sparkles/ChangeSet.cs | 4 ++-- Sparkles/Configuration.cs | 31 ++++++++++++-------------- Sparkles/Sparkles.csproj | 1 + 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/SparkleShare/Common/SetupController.cs b/SparkleShare/Common/SetupController.cs index 289bf1c8..8a9f72d9 100644 --- a/SparkleShare/Common/SetupController.cs +++ b/SparkleShare/Common/SetupController.cs @@ -536,7 +536,6 @@ namespace SparkleShare { string folder_name = Path.GetFileName (PreviousPath); folder_name = folder_name.ReplaceUnderscoreWithSpace (); - // TODO: Open SparkleShare/$HOST SparkleShare.Controller.OpenSparkleShareFolder (folder_name); FinishPageCompleted (); } diff --git a/Sparkles/ChangeSet.cs b/Sparkles/ChangeSet.cs index 7a98e7b8..8358012f 100644 --- a/Sparkles/ChangeSet.cs +++ b/Sparkles/ChangeSet.cs @@ -44,7 +44,7 @@ namespace Sparkles { public string ToMessage () { string message = "added: {0}"; - + switch (Changes [0].Type) { case ChangeType.Edited: message = "edited: {0}"; break; case ChangeType.Deleted: message = "deleted: {0}"; break; @@ -64,7 +64,7 @@ namespace Sparkles { public ChangeType Type; public DateTime Timestamp; public bool IsFolder; - + public string Path; public string MovedToPath; } diff --git a/Sparkles/Configuration.cs b/Sparkles/Configuration.cs index e29c4403..e0b46bae 100644 --- a/Sparkles/Configuration.cs +++ b/Sparkles/Configuration.cs @@ -16,9 +16,10 @@ using System; -using System.IO; using System.Collections.Generic; +using System.IO; using System.Xml; +using System.Xml.Linq; namespace Sparkles { @@ -42,6 +43,7 @@ namespace Sparkles { public readonly string FilePath; public readonly string TmpPath; public readonly string BinPath; + public readonly string LogFilePath; @@ -115,11 +117,10 @@ namespace Sparkles { CreateInitialConfig (); } else { - throw new XmlException (FilePath + " does not contain a valid config XML structure."); + throw; } } finally { - Load (FilePath); TmpPath = Path.Combine (DirectoryPath, "tmp"); Directory.CreateDirectory (TmpPath); } @@ -138,17 +139,16 @@ namespace Sparkles { user_name = user_name.TrimEnd (','); } - // TODO: Don't do this manually - string n = Environment.NewLine; - File.WriteAllText (FilePath, - "" + n + - "" + n + - " " + n + - " " + user_name + "" + n + - " Unknown" + n + - " " + n + - " True" + n + - ""); + XElement xml = + new XElement ("sparkleshare", + new XElement ("user", + new XElement ("name", user_name), + new XElement ("email", "Unknown") + ), + new XElement ("notifications", bool.TrueString) + ); + + LoadXml (xml.ToString ()); } @@ -351,9 +351,6 @@ namespace Sparkles { void Save () { - if (!File.Exists (FilePath)) - throw new FileNotFoundException (FilePath + " does not exist"); - Save (FilePath); Logger.LogInfo ("Config", "Wrote to '" + FilePath + "'"); } diff --git a/Sparkles/Sparkles.csproj b/Sparkles/Sparkles.csproj index 3ff026fa..b7cb50a2 100644 --- a/Sparkles/Sparkles.csproj +++ b/Sparkles/Sparkles.csproj @@ -60,6 +60,7 @@ +