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

Method Start

src/engine/shared/demo.cpp:60–220  ·  view source on GitHub ↗

Record

Source from the content-addressed store, hash-verified

58
59// Record
60int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetVersion, const char *pMap, const SHA256_DIGEST &Sha256, unsigned Crc, const char *pType, unsigned MapSize, unsigned char *pMapData, IOHANDLE MapFile, DEMOFUNC_FILTER pfnFilter, void *pUser)
61{
62 dbg_assert(m_File == 0, "Demo recorder already recording");
63
64 m_pConsole = pConsole;
65 m_pStorage = pStorage;
66
67 if(!str_valid_filename(fs_filename(pFilename)))
68 {
69 log_error_color(DEMO_PRINT_COLOR, "demo_recorder", "The name '%s' cannot be used for demos because not all platforms support it", pFilename);
70 return -1;
71 }
72
73 IOHANDLE DemoFile = pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
74 if(!DemoFile)
75 {
76 if(m_pConsole)
77 {
78 char aBuf[64 + IO_MAX_PATH_LENGTH];
79 str_format(aBuf, sizeof(aBuf), "Unable to open '%s' for recording", pFilename);
80 m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", aBuf, gs_DemoPrintColor);
81 }
82 return -1;
83 }
84
85 bool CloseMapFile = false;
86
87 if(MapFile)
88 io_seek(MapFile, 0, IOSEEK_START);
89
90 char aSha256[SHA256_MAXSTRSIZE];
91 sha256_str(Sha256, aSha256, sizeof(aSha256));
92
93 if(!pMapData && !MapFile)
94 {
95 // open mapfile
96 char aMapFilename[IO_MAX_PATH_LENGTH];
97 // try the downloaded maps
98 str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%s.map", pMap, aSha256);
99 MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ, IStorage::TYPE_ALL);
100 if(!MapFile)
101 {
102 // try the normal maps folder
103 str_format(aMapFilename, sizeof(aMapFilename), "maps/%s.map", pMap);
104 MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ, IStorage::TYPE_ALL);
105 }
106 if(!MapFile)
107 {
108 // search for the map within subfolders
109 char aBuf[IO_MAX_PATH_LENGTH];
110 str_format(aMapFilename, sizeof(aMapFilename), "%s.map", pMap);
111 if(pStorage->FindFile(aMapFilename, "maps", IStorage::TYPE_ALL, aBuf, sizeof(aBuf)))
112 MapFile = pStorage->OpenFile(aBuf, IOFLAG_READ, IStorage::TYPE_ALL);
113 }
114 if(!MapFile)
115 {
116 if(m_pConsole)
117 {

Callers 3

AddInfosMethod · 0.45
SaveGhostMethod · 0.45
SliceMethod · 0.45

Calls 15

str_valid_filenameFunction · 0.85
fs_filenameFunction · 0.85
str_formatFunction · 0.85
io_seekFunction · 0.85
sha256_strFunction · 0.85
io_lengthFunction · 0.85
io_closeFunction · 0.85
mem_zeroFunction · 0.85
mem_copyFunction · 0.85
uint_to_bytes_beFunction · 0.85
str_timestampFunction · 0.85
io_writeFunction · 0.85

Tested by

no test coverage detected