| 69 | } |
| 70 | |
| 71 | static 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 | |
| 108 | static bool ExtractMap(IStorage *pStorage, const char *pMapName, const char *pPathSave) |
| 109 | { |
no test coverage detected