| 367 | } |
| 368 | |
| 369 | int 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 | { |
no test coverage detected