From 9845d757ef2a11f4fc37f0f438bca9adb47cacaf Mon Sep 17 00:00:00 2001 From: oy Date: Thu, 9 Jun 2011 22:44:22 +0200 Subject: removed file extension from the demo name in the demo player --- src/engine/shared/demo.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/engine/shared/demo.cpp') diff --git a/src/engine/shared/demo.cpp b/src/engine/shared/demo.cpp index e48c2f1e..51dd51d9 100644 --- a/src/engine/shared/demo.cpp +++ b/src/engine/shared/demo.cpp @@ -1,13 +1,16 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include #include + #include #include + +#include "compression.h" #include "demo.h" #include "memheap.h" -#include "snapshot.h" -#include "compression.h" #include "network.h" +#include "snapshot.h" static const unsigned char gs_aHeaderMarker[7] = {'T', 'W', 'D', 'E', 'M', 'O', 0}; static const unsigned char gs_ActVersion = 3; @@ -760,16 +763,21 @@ int CDemoPlayer::Stop() return 0; } -char *CDemoPlayer::GetDemoName() +void CDemoPlayer::GetDemoName(char *pBuffer, int BufferSize) const { - // get the name of the demo without its path - char *pDemoShortName = &m_aFilename[0]; - for(int i = 0; i < str_length(m_aFilename)-1; i++) + const char *pFileName = m_aFilename; + const char *pExtractedName = pFileName; + const char *pEnd = 0; + for(; *pFileName; ++pFileName) { - if(m_aFilename[i] == '/' || m_aFilename[i] == '\\') - pDemoShortName = &m_aFilename[i+1]; + if(*pFileName == '/' || *pFileName == '\\') + pExtractedName = pFileName+1; + else if(*pFileName == '.') + pEnd = pFileName; } - return pDemoShortName; + + int Length = pEnd > pExtractedName ? min(BufferSize, (int)(pEnd-pExtractedName+1)) : BufferSize; + str_copy(pBuffer, pExtractedName, Length); } bool CDemoPlayer::GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader) const -- cgit 1.4.1