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

Function ExtractMapSounds

src/tools/map_extract.cpp:71–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71static void ExtractMapSounds(CDataFileReader &Reader, const char *pPathSave)
72{
73 int Start, Num;
74 Reader.GetType(MAPITEMTYPE_SOUND, &Start, &Num);
75 for(int i = 0; i < Num; i++)
76 {
77 const CMapItemSound *pItem = static_cast<CMapItemSound *>(Reader.GetItem(Start + i));
78 if(pItem->m_External)
79 continue;
80
81 const char *pName = Reader.GetDataString(pItem->m_SoundName);
82 if(pName == nullptr || pName[0] == '\0')
83 {
84 log_error("map_extract", "failed to load name of sound %d", i);
85 continue;
86 }
87
88 const int SoundDataSize = Reader.GetDataSize(pItem->m_SoundData);
89 char aBuf[IO_MAX_PATH_LENGTH];
90 str_format(aBuf, sizeof(aBuf), "%s/%s.opus", pPathSave, pName);
91 Reader.UnloadData(pItem->m_SoundName);
92
93 IOHANDLE Opus = io_open(aBuf, IOFLAG_WRITE);
94 if(Opus)
95 {
96 log_info("map_extract", "writing sound: %s (%d B)", aBuf, SoundDataSize);
97 io_write(Opus, Reader.GetData(pItem->m_SoundData), SoundDataSize);
98 io_close(Opus);
99 Reader.UnloadData(pItem->m_SoundData);
100 }
101 else
102 {
103 log_error("map_extract", "failed to open sound file for writing. filename='%s'", aBuf);
104 }
105 }
106}
107
108static bool ExtractMap(IStorage *pStorage, const char *pMapName, const char *pPathSave)
109{

Callers 1

ExtractMapFunction · 0.85

Calls 10

str_formatFunction · 0.85
io_openFunction · 0.85
io_writeFunction · 0.85
io_closeFunction · 0.85
GetTypeMethod · 0.45
GetItemMethod · 0.45
GetDataStringMethod · 0.45
GetDataSizeMethod · 0.45
UnloadDataMethod · 0.45
GetDataMethod · 0.45

Tested by

no test coverage detected