Protect against blank settings.json
This commit is contained in:
parent
283a46e1e2
commit
9a458bf3dc
@ -30,8 +30,7 @@ namespace FileManager
|
|||||||
if (IsReadOnly)
|
if (IsReadOnly)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
File.WriteAllText(Filepath, "{}");
|
createNewFile();
|
||||||
System.Threading.Thread.Sleep(100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetString(string propertyName)
|
public string GetString(string propertyName)
|
||||||
@ -214,6 +213,13 @@ namespace FileManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
var settingsJsonContents = File.ReadAllText(Filepath);
|
var settingsJsonContents = File.ReadAllText(Filepath);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(settingsJsonContents))
|
||||||
|
{
|
||||||
|
createNewFile();
|
||||||
|
settingsJsonContents = File.ReadAllText(Filepath);
|
||||||
|
}
|
||||||
|
|
||||||
var jObject = JsonConvert.DeserializeObject<JObject>(settingsJsonContents);
|
var jObject = JsonConvert.DeserializeObject<JObject>(settingsJsonContents);
|
||||||
|
|
||||||
if (jObject is null)
|
if (jObject is null)
|
||||||
@ -226,5 +232,11 @@ namespace FileManager
|
|||||||
|
|
||||||
return jObject;
|
return jObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createNewFile()
|
||||||
|
{
|
||||||
|
File.WriteAllText(Filepath, "{}");
|
||||||
|
System.Threading.Thread.Sleep(100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user