properly truncate file before writing

This commit is contained in:
Florian Stinglmayr 2022-01-09 11:33:09 +01:00
parent e2d59a54b7
commit 617ade0163

View File

@ -66,9 +66,13 @@ namespace EliteBGS.Util {
public void SaveObjectives(Report report) { public void SaveObjectives(Report report) {
var serializer = JsonSerializer.CreateDefault(); var serializer = JsonSerializer.CreateDefault();
using (var file = new StreamWriter(File.OpenWrite(objectives_file), Encoding.UTF8)) { using (FileStream filestream = File.OpenWrite(objectives_file)) {
var stream = new JsonTextWriter(file); filestream.SetLength(0);
serializer.Serialize(stream, report.Objectives); filestream.Flush();
using (StreamWriter file = new StreamWriter(filestream, Encoding.UTF8)) {
JsonTextWriter stream = new JsonTextWriter(file);
serializer.Serialize(stream, report.Objectives);
}
} }
} }