mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Use the CSV write to write save codes
This commit is contained in:
parent
0db5c51ed9
commit
48e8ba69ca
|
@ -9,6 +9,7 @@
|
||||||
#include <engine/textrender.h>
|
#include <engine/textrender.h>
|
||||||
#include <engine/keys.h>
|
#include <engine/keys.h>
|
||||||
#include <engine/shared/config.h>
|
#include <engine/shared/config.h>
|
||||||
|
#include <engine/shared/csv.h>
|
||||||
|
|
||||||
#include <game/generated/protocol.h>
|
#include <game/generated/protocol.h>
|
||||||
#include <game/generated/client_data.h>
|
#include <game/generated/client_data.h>
|
||||||
|
@ -544,7 +545,12 @@ bool CChat::LineShouldHighlight(const char *pLine, const char *pName)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SAVES_FILE "ddnet-saves.txt"
|
#define SAVES_FILE "ddnet-saves.txt"
|
||||||
const char *SAVES_HEADER = "Time,Player,Map,Code";
|
const char *SAVES_HEADER[] = {
|
||||||
|
"Time",
|
||||||
|
"Player",
|
||||||
|
"Map",
|
||||||
|
"Code",
|
||||||
|
};
|
||||||
|
|
||||||
void CChat::StoreSave(const char *pText)
|
void CChat::StoreSave(const char *pText)
|
||||||
{
|
{
|
||||||
|
@ -576,27 +582,22 @@ void CChat::StoreSave(const char *pText)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char aBuf[256];
|
IOHANDLE File = Storage()->OpenFile(SAVES_FILE, IOFLAG_APPEND, IStorage::TYPE_SAVE);
|
||||||
str_format(aBuf, sizeof(aBuf), "%s,%s,%s,%s", aTimestamp, aName, Client()->GetCurrentMap(), aSaveCode);
|
|
||||||
|
|
||||||
IOHANDLE File = Storage()->OpenFile(SAVES_FILE, IOFLAG_READ, IStorage::TYPE_SAVE);
|
|
||||||
bool FileExists = File;
|
|
||||||
if(File)
|
|
||||||
io_close(File);
|
|
||||||
|
|
||||||
File = Storage()->OpenFile(SAVES_FILE, IOFLAG_APPEND, IStorage::TYPE_SAVE);
|
|
||||||
|
|
||||||
if(!File)
|
if(!File)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!FileExists)
|
const char *apColumns[4] = {
|
||||||
{
|
aTimestamp,
|
||||||
io_write(File, SAVES_HEADER, str_length(SAVES_HEADER));
|
aName,
|
||||||
io_write_newline(File);
|
Client()->GetCurrentMap(),
|
||||||
}
|
aSaveCode,
|
||||||
|
};
|
||||||
|
|
||||||
io_write(File, aBuf, str_length(aBuf));
|
if(io_tell(File) == 0)
|
||||||
io_write_newline(File);
|
{
|
||||||
|
CsvWrite(File, 4, SAVES_HEADER);
|
||||||
|
}
|
||||||
|
CsvWrite(File, 4, apColumns);
|
||||||
io_close(File);
|
io_close(File);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue