38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using System.IO;
|
|
using System.Runtime.Serialization;
|
|
using System.Runtime.Serialization.Json;
|
|
|
|
namespace Katteker
|
|
{
|
|
[DataContract]
|
|
public class KattekerConfig
|
|
{
|
|
[DataMember]
|
|
public string PublishDir { get; set; }
|
|
|
|
[DataMember]
|
|
public string Changelog { get; set; }
|
|
|
|
|
|
public static KattekerConfig ReadFromFile(string path)
|
|
{
|
|
if (!File.Exists(path)) throw new FileNotFoundException();
|
|
var dataContractJsonSerializer = new DataContractJsonSerializer(typeof(KattekerConfig));
|
|
using (var fileStream = File.OpenRead(path))
|
|
{
|
|
var obj = dataContractJsonSerializer.ReadObject(fileStream);
|
|
return (KattekerConfig) obj;
|
|
}
|
|
}
|
|
|
|
public void WriteToFile(string path)
|
|
{
|
|
if (File.Exists(path)) File.Delete(path);
|
|
using (var fileStream = File.OpenWrite(path))
|
|
{
|
|
var dataContractJsonSerializer = new DataContractJsonSerializer(typeof(KattekerConfig));
|
|
dataContractJsonSerializer.WriteObject(fileStream, this);
|
|
}
|
|
}
|
|
}
|
|
} |