From 617ade0163df4bc5d026d39252166a3c7a9d72af Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Sun, 9 Jan 2022 11:33:09 +0100 Subject: [PATCH] properly truncate file before writing --- Util/Config.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Util/Config.cs b/Util/Config.cs index 575fbeb..8ac0ace 100644 --- a/Util/Config.cs +++ b/Util/Config.cs @@ -66,9 +66,13 @@ namespace EliteBGS.Util { public void SaveObjectives(Report report) { var serializer = JsonSerializer.CreateDefault(); - using (var file = new StreamWriter(File.OpenWrite(objectives_file), Encoding.UTF8)) { - var stream = new JsonTextWriter(file); - serializer.Serialize(stream, report.Objectives); + using (FileStream filestream = File.OpenWrite(objectives_file)) { + filestream.SetLength(0); + filestream.Flush(); + using (StreamWriter file = new StreamWriter(filestream, Encoding.UTF8)) { + JsonTextWriter stream = new JsonTextWriter(file); + serializer.Serialize(stream, report.Objectives); + } } }