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