Refactor GetDemoName using IStorage::StripPathAndExtension

The functions were effectively identical already.
This commit is contained in:
Robert Müller 2023-10-16 21:52:56 +02:00
parent c3b8c94212
commit 82d94faf28
3 changed files with 4 additions and 16 deletions

View file

@ -106,7 +106,7 @@ public:
virtual void Unpause() = 0;
virtual bool IsPlaying() const = 0;
virtual const CInfo *BaseInfo() const = 0;
virtual void GetDemoName(char *pBuffer, int BufferSize) const = 0;
virtual void GetDemoName(char *pBuffer, size_t BufferSize) const = 0;
virtual bool GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader, CTimelineMarkers *pTimelineMarkers, CMapInfo *pMapInfo) const = 0;
virtual int GetDemoType() const = 0;
};

View file

@ -1064,21 +1064,9 @@ int CDemoPlayer::Stop()
return 0;
}
void CDemoPlayer::GetDemoName(char *pBuffer, int BufferSize) const
void CDemoPlayer::GetDemoName(char *pBuffer, size_t BufferSize) const
{
const char *pFileName = m_aFilename;
const char *pExtractedName = pFileName;
const char *pEnd = 0;
for(; *pFileName; ++pFileName)
{
if(*pFileName == '/' || *pFileName == '\\')
pExtractedName = pFileName + 1;
else if(*pFileName == '.')
pEnd = pFileName;
}
int Length = pEnd > pExtractedName ? minimum(BufferSize, (int)(pEnd - pExtractedName + 1)) : BufferSize;
str_copy(pBuffer, pExtractedName, Length);
IStorage::StripPathAndExtension(m_aFilename, pBuffer, BufferSize);
}
bool CDemoPlayer::GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader, CTimelineMarkers *pTimelineMarkers, CMapInfo *pMapInfo) const

View file

@ -154,7 +154,7 @@ public:
int SeekTick(ETickOffset TickOffset) override;
int SetPos(int WantedTick) override;
const CInfo *BaseInfo() const override { return &m_Info.m_Info; }
void GetDemoName(char *pBuffer, int BufferSize) const override;
void GetDemoName(char *pBuffer, size_t BufferSize) const override;
bool GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader, CTimelineMarkers *pTimelineMarkers, CMapInfo *pMapInfo) const override;
const char *GetDemoFileName() { return m_aFilename; }
int GetDemoType() const override;