handle writing files better

This commit is contained in:
Lynne Megido 2020-09-06 04:51:47 +10:00
parent 987a28c747
commit 82c666296a
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90

View file

@ -203,11 +203,11 @@ namespace Buypeeb {
if (!Directory.Exists(this.location)) {
Directory.CreateDirectory(this.location);
}
if (!File.Exists(p)) {
var fs = File.CreateText(p);
fs.Close();
using (StreamWriter fs = File.CreateText(p)) {
fs.Write(j);
}
File.WriteAllText(System.IO.Path.Combine(this.location, "userdata.json"), j);
}
private void UpdateThread(string id) {
@ -529,10 +529,10 @@ namespace Buypeeb {
if (sd.Run() == (int)ResponseType.Accept) {
try {
if (!File.Exists(sd.Filename)) {
var fs = File.CreateText(sd.Filename);
fs.Close();
using (StreamWriter fs = File.CreateText(sd.Filename)) {
fs.Write(JsonSerializer.Serialize(this.settings, jsonOptions));
}
}
File.WriteAllText(sd.Filename, JsonSerializer.Serialize(this.settings, jsonOptions));
}
catch (Exception e) {
Console.WriteLine(e);