Changed dblocator to use json instead of xml, as it is a little easier to use.

This commit is contained in:
Kenneth Skovhede
2013-05-06 20:51:15 +02:00
parent 12b52d8d84
commit bd02336c50
@@ -17,8 +17,8 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Linq;
using System.Xml.Serialization;
using System.Collections.Generic;
using Newtonsoft.Json.Serialization;
namespace Duplicati.Library.Main.ForestHash
{
@@ -46,15 +46,12 @@ namespace Duplicati.Library.Main.ForestHash
if (!System.IO.Directory.Exists(folder))
System.IO.Directory.CreateDirectory(folder);
var file = System.IO.Path.Combine(folder, "dbconfig.xml");
var file = System.IO.Path.Combine(folder, "dbconfig.json");
List<BackendEntry> configs;
if (!System.IO.File.Exists(file))
configs = new List<BackendEntry>();
else
{
using(var fs = System.IO.File.OpenRead(file))
configs = (List<BackendEntry>)new System.Xml.Serialization.XmlSerializer(typeof(List<BackendEntry>)).Deserialize(fs);
}
configs = Newtonsoft.Json.JsonConvert.DeserializeObject<List<BackendEntry>>(System.IO.File.ReadAllText(file, System.Text.Encoding.UTF8));
var uri = new Utility.Uri(backend);
string server = uri.Host;
@@ -139,8 +136,9 @@ namespace Duplicati.Library.Main.ForestHash
ParameterFile = null
});
using(var fs = System.IO.File.OpenWrite(file))
new System.Xml.Serialization.XmlSerializer(typeof(List<BackendEntry>)).Serialize(fs, configs);
var settings = new Newtonsoft.Json.JsonSerializerSettings();
settings.Formatting = Newtonsoft.Json.Formatting.Indented;
System.IO.File.WriteAllText(file, Newtonsoft.Json.JsonConvert.SerializeObject(configs, settings), System.Text.Encoding.UTF8);
return newpath;
}