| 1 | #include <base/dbg.h> |
| 2 | #include <base/fs.h> |
| 3 | #include <base/io.h> |
| 4 | #include <base/str.h> |
| 5 | |
| 6 | #include <engine/shared/datafile.h> |
| 7 | #include <engine/storage.h> |
| 8 | |
| 9 | #include <game/mapitems.h> |
| 10 | |
| 11 | static void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName) |
| 12 | { |
| 13 | CDataFileReader Reader; |
| 14 | if(!Reader.Open(pStorage, pPath: pMapName, StorageType: IStorage::TYPE_ABSOLUTE)) |
| 15 | { |
| 16 | dbg_msg(sys: "config_retrieve" , fmt: "error opening map '%s'" , pMapName); |
| 17 | return; |
| 18 | } |
| 19 | bool ConfigFound = false; |
| 20 | int Start, Num; |
| 21 | Reader.GetType(Type: MAPITEMTYPE_INFO, pStart: &Start, pNum: &Num); |
| 22 | for(int i = Start; i < Start + Num; i++) |
| 23 | { |
| 24 | int Id; |
| 25 | CMapItemInfoSettings *pItem = (CMapItemInfoSettings *)Reader.GetItem(Index: i, pType: nullptr, pId: &Id); |
| 26 | int ItemSize = Reader.GetItemSize(Index: i); |
| 27 | if(!pItem || Id != 0) |
| 28 | continue; |
| 29 | |
| 30 | if(ItemSize < (int)sizeof(CMapItemInfoSettings)) |
| 31 | break; |
| 32 | if(!(pItem->m_Settings > -1)) |
| 33 | break; |
| 34 | |
| 35 | ConfigFound = true; |
| 36 | IOHANDLE Config = pStorage->OpenFile(pFilename: pConfigName, Flags: IOFLAG_WRITE, Type: IStorage::TYPE_ABSOLUTE); |
| 37 | if(!Config) |
| 38 | { |
| 39 | dbg_msg(sys: "config_retrieve" , fmt: "error opening config for writing '%s'" , pConfigName); |
| 40 | Reader.Close(); |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | int Size = Reader.GetDataSize(Index: pItem->m_Settings); |
| 45 | char *pSettings = (char *)Reader.GetData(Index: pItem->m_Settings); |
| 46 | char *pNext = pSettings; |
| 47 | while(pNext < pSettings + Size) |
| 48 | { |
| 49 | int StrSize = str_length(str: pNext) + 1; |
| 50 | io_write(io: Config, buffer: pNext, size: StrSize - 1); |
| 51 | io_write_newline(io: Config); |
| 52 | pNext += StrSize; |
| 53 | } |
| 54 | Reader.UnloadData(Index: pItem->m_Settings); |
| 55 | io_close(io: Config); |
| 56 | break; |
| 57 | } |
| 58 | Reader.Close(); |
| 59 | if(!ConfigFound) |
| 60 | { |
| 61 | fs_remove(filename: pConfigName); |
| 62 | } |
| 63 | } |
| 64 | #include "config_common.h" |
| 65 | |