MCPcopy Create free account
hub / github.com/ddnet/ddnet / Stop

Method Stop

src/engine/shared/demo.cpp:369–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367}
368
369int CDemoRecorder::Stop(IDemoRecorder::EStopMode Mode, const char *pTargetFilename)
370{
371 if(!m_File)
372 return -1;
373
374 if(Mode == IDemoRecorder::EStopMode::KEEP_FILE)
375 {
376 // add the demo length to the header
377 io_seek(m_File, offsetof(CDemoHeader, m_aLength), IOSEEK_START);
378 unsigned char aLength[sizeof(int32_t)];
379 uint_to_bytes_be(aLength, Length());
380 io_write(m_File, aLength, sizeof(aLength));
381
382 // add the timeline markers to the header
383 io_seek(m_File, sizeof(CDemoHeader) + offsetof(CTimelineMarkers, m_aNumTimelineMarkers), IOSEEK_START);
384 unsigned char aNumMarkers[sizeof(int32_t)];
385 uint_to_bytes_be(aNumMarkers, m_NumTimelineMarkers);
386 io_write(m_File, aNumMarkers, sizeof(aNumMarkers));
387 for(int i = 0; i < m_NumTimelineMarkers; i++)
388 {
389 unsigned char aMarker[sizeof(int32_t)];
390 uint_to_bytes_be(aMarker, m_aTimelineMarkers[i]);
391 io_write(m_File, aMarker, sizeof(aMarker));
392 }
393 }
394
395 io_close(m_File);
396 m_File = nullptr;
397
398 if(Mode == IDemoRecorder::EStopMode::REMOVE_FILE)
399 {
400 if(!m_pStorage->RemoveFile(m_aCurrentFilename, IStorage::TYPE_SAVE))
401 {
402 if(m_pConsole)
403 {
404 char aBuf[64 + IO_MAX_PATH_LENGTH];
405 str_format(aBuf, sizeof(aBuf), "Could not remove demo file '%s'.", m_aCurrentFilename);
406 m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", aBuf, gs_DemoPrintColor);
407 }
408 return -1;
409 }
410 }
411 else if(pTargetFilename[0] != '\0')
412 {
413 if(!m_pStorage->RenameFile(m_aCurrentFilename, pTargetFilename, IStorage::TYPE_SAVE))
414 {
415 if(m_pConsole)
416 {
417 char aBuf[64 + 2 * IO_MAX_PATH_LENGTH];
418 str_format(aBuf, sizeof(aBuf), "Could not move demo file '%s' to '%s'.", m_aCurrentFilename, pTargetFilename);
419 m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", aBuf, gs_DemoPrintColor);
420 }
421 return -1;
422 }
423 }
424
425 if(m_pConsole)
426 {

Callers 7

ExtractDemoChatFunction · 0.45
SliceMethod · 0.45
SaveDemoMethod · 0.45
StopRecordMethod · 0.45
StopDemosMethod · 0.45
ConStopRecordMethod · 0.45

Calls 9

io_seekFunction · 0.85
uint_to_bytes_beFunction · 0.85
io_writeFunction · 0.85
io_closeFunction · 0.85
str_formatFunction · 0.85
RemoveFileMethod · 0.80
RenameFileMethod · 0.80
str_copyFunction · 0.50
PrintMethod · 0.45

Tested by

no test coverage detected