Fix handling of invalid conf file

Fixes GitHub issue #1068
This commit is contained in:
Grant Limberg 2019-12-17 10:51:01 -08:00
parent 2a7d4fcde5
commit 7696d45093

View File

@ -75,7 +75,15 @@ namespace WinUI
{ {
byte[] tmp = File.ReadAllBytes(centralConfigPath); byte[] tmp = File.ReadAllBytes(centralConfigPath);
string json = Encoding.UTF8.GetString(tmp).Trim(); string json = Encoding.UTF8.GetString(tmp).Trim();
Central = JsonConvert.DeserializeObject<CentralServer>(json); CentralServer ctmp = JsonConvert.DeserializeObject<CentralServer>(json);
if (ctmp != null)
{
Central = ctmp;
}
else
{
Central = new CentralServer();
}
} }
else else
{ {
@ -105,8 +113,11 @@ namespace WinUI
{ {
string json = JsonConvert.SerializeObject(Central); string json = JsonConvert.SerializeObject(Central);
byte[] tmp = Encoding.UTF8.GetBytes(json); byte[] tmp = Encoding.UTF8.GetBytes(json);
if (tmp != null)
{
File.WriteAllBytes(CentralConfigFile(), tmp); File.WriteAllBytes(CentralConfigFile(), tmp);
} }
}
private void UpdateRequestHeaders() private void UpdateRequestHeaders()
{ {