From 5e655615cb3f434ea4fe32b219828707d510187d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 25 Jul 2024 20:10:45 +0200 Subject: [PATCH] Fix CSV header being written multiple times to `ddnet-saves.txt` It is implementation-defined whether the file position returned by `ftell` denotes the beginning or the end of the file when opening in append-mode. This was causing the condition `io_tell(File) == 0` to always be true, so the CSV header was also written to `ddnet-saves.txt` every time that a new save code is written. Now, we check if the file already exists before appending and only write the CSV header once when the file does not exist yet. --- src/game/client/components/chat.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index a752fd188..35a7257ad 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -604,6 +604,7 @@ void CChat::StoreSave(const char *pText) } */ + const bool SavesFileExists = Storage()->FileExists(SAVES_FILE, IStorage::TYPE_SAVE); IOHANDLE File = Storage()->OpenFile(SAVES_FILE, IOFLAG_APPEND, IStorage::TYPE_SAVE); if(!File) return; @@ -615,7 +616,7 @@ void CChat::StoreSave(const char *pText) aSaveCode, }; - if(io_tell(File) == 0) + if(!SavesFileExists) { CsvWrite(File, 4, SAVES_HEADER); }