mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 14:08:19 +00:00
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.
This commit is contained in:
parent
cd81b1f253
commit
5e655615cb
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue