diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index c00621686..b38460754 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -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);