| 6 | #include <game/mapitems.h> |
| 7 | |
| 8 | static void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName) |
| 9 | { |
| 10 | CDataFileReader Reader; |
| 11 | if(!Reader.Open(pStorage, pMapName, IStorage::TYPE_ABSOLUTE)) |
| 12 | { |
| 13 | dbg_msg("config_retrieve", "error opening map '%s'", pMapName); |
| 14 | return; |
| 15 | } |
| 16 | bool ConfigFound = false; |
| 17 | int Start, Num; |
| 18 | Reader.GetType(MAPITEMTYPE_INFO, &Start, &Num); |
| 19 | for(int i = Start; i < Start + Num; i++) |
| 20 | { |
| 21 | int Id; |
| 22 | CMapItemInfoSettings *pItem = (CMapItemInfoSettings *)Reader.GetItem(i, nullptr, &Id); |
| 23 | int ItemSize = Reader.GetItemSize(i); |
| 24 | if(!pItem || Id != 0) |
| 25 | continue; |
| 26 | |
| 27 | if(ItemSize < (int)sizeof(CMapItemInfoSettings)) |
| 28 | break; |
| 29 | if(!(pItem->m_Settings > -1)) |
| 30 | break; |
| 31 | |
| 32 | ConfigFound = true; |
| 33 | IOHANDLE Config = pStorage->OpenFile(pConfigName, IOFLAG_WRITE, IStorage::TYPE_ABSOLUTE); |
| 34 | if(!Config) |
| 35 | { |
| 36 | dbg_msg("config_retrieve", "error opening config for writing '%s'", pConfigName); |
| 37 | Reader.Close(); |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | int Size = Reader.GetDataSize(pItem->m_Settings); |
| 42 | char *pSettings = (char *)Reader.GetData(pItem->m_Settings); |
| 43 | char *pNext = pSettings; |
| 44 | while(pNext < pSettings + Size) |
| 45 | { |
| 46 | int StrSize = str_length(pNext) + 1; |
| 47 | io_write(Config, pNext, StrSize - 1); |
| 48 | io_write_newline(Config); |
| 49 | pNext += StrSize; |
| 50 | } |
| 51 | Reader.UnloadData(pItem->m_Settings); |
| 52 | io_close(Config); |
| 53 | break; |
| 54 | } |
| 55 | Reader.Close(); |
| 56 | if(!ConfigFound) |
| 57 | { |
| 58 | fs_remove(pConfigName); |
| 59 | } |
| 60 | } |
| 61 | #include "config_common.h" |
nothing calls this directly
no test coverage detected