handle invalid filename for save_replay

This commit is contained in:
dobrykafe 2024-02-26 18:43:51 +01:00
parent 8d2de4b8c2
commit 268b79cb61

View file

@ -3466,9 +3466,6 @@ void CClient::SaveReplay(const int Length, const char *pFilename)
}
else
{
// First we stop the recorder to slice correctly the demo after
DemoRecorder(RECORDER_REPLAYS)->Stop(IDemoRecorder::EStopMode::KEEP_FILE);
char aFilename[IO_MAX_PATH_LENGTH];
if(pFilename[0] == '\0')
{
@ -3479,8 +3476,19 @@ void CClient::SaveReplay(const int Length, const char *pFilename)
else
{
str_format(aFilename, sizeof(aFilename), "demos/replays/%s.demo", pFilename);
IOHANDLE Handle = m_pStorage->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
if(!Handle)
{
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "replay", "ERROR: invalid filename. Try a different one!");
return;
}
io_close(Handle);
m_pStorage->RemoveFile(aFilename, IStorage::TYPE_SAVE);
}
// Stop the recorder to correctly slice the demo after
DemoRecorder(RECORDER_REPLAYS)->Stop(IDemoRecorder::EStopMode::KEEP_FILE);
// Slice the demo to get only the last cl_replay_length seconds
const char *pSrc = m_aDemoRecorder[RECORDER_REPLAYS].CurrentFilename();
const int EndTick = GameTick(g_Config.m_ClDummy);