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

Method Init

src/engine/shared/filecollection.cpp:12–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include <algorithm>
11
12void CFileCollection::Init(IStorage *pStorage, const char *pPath, const char *pFileDesc, const char *pFileExt, int MaxEntries)
13{
14 m_vFileEntries.clear();
15 str_copy(m_aFileDesc, pFileDesc);
16 m_FileDescLength = str_length(m_aFileDesc);
17 str_copy(m_aFileExt, pFileExt);
18 m_FileExtLength = str_length(m_aFileExt);
19 str_copy(m_aPath, pPath);
20 m_pStorage = pStorage;
21
22 m_pStorage->ListDirectory(IStorage::TYPE_SAVE, m_aPath, FilelistCallback, this);
23 std::sort(m_vFileEntries.begin(), m_vFileEntries.end(), [](const CFileEntry &Lhs, const CFileEntry &Rhs) { return Lhs.m_Timestamp < Rhs.m_Timestamp; });
24
25 int FilesDeleted = 0;
26 for(auto FileEntry : m_vFileEntries)
27 {
28 if((int)m_vFileEntries.size() - FilesDeleted <= MaxEntries)
29 break;
30
31 char aBuf[IO_MAX_PATH_LENGTH];
32 if(m_aFileDesc[0] == '\0')
33 {
34 str_format(aBuf, sizeof(aBuf), "%s/%s", m_aPath, FileEntry.m_aFilename);
35 }
36 else
37 {
38 char aTimestring[TIMESTAMP_LENGTH];
39 str_timestamp_ex(FileEntry.m_Timestamp, aTimestring, sizeof(aTimestring), FORMAT_NOSPACE);
40 str_format(aBuf, sizeof(aBuf), "%s/%s_%s%s", m_aPath, m_aFileDesc, aTimestring, m_aFileExt);
41 }
42
43 m_pStorage->RemoveFile(aBuf, IStorage::TYPE_SAVE);
44 FilesDeleted++;
45 }
46}
47
48bool CFileCollection::ExtractTimestamp(const char *pTimestring, time_t *pTimestamp)
49{

Callers

nothing calls this directly

Calls 8

str_lengthFunction · 0.85
str_formatFunction · 0.85
str_timestamp_exFunction · 0.85
ListDirectoryMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
RemoveFileMethod · 0.80
str_copyFunction · 0.50

Tested by

no test coverage detected