| 11 | #include <vector> |
| 12 | |
| 13 | static void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName) |
| 14 | { |
| 15 | CLineReader LineReader; |
| 16 | if(!LineReader.OpenFile(pStorage->OpenFile(pConfigName, IOFLAG_READ, IStorage::TYPE_ABSOLUTE))) |
| 17 | { |
| 18 | log_error("config_store", "Failed to import settings from '%s': could not open config for reading", pConfigName); |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | std::vector<const char *> vpLines; |
| 23 | int TotalLength = 0; |
| 24 | while(const char *pLine = LineReader.Get()) |
| 25 | { |
| 26 | vpLines.push_back(pLine); |
| 27 | TotalLength += str_length(pLine) + 1; |
| 28 | } |
| 29 | |
| 30 | CDataFileReader Reader; |
| 31 | if(!Reader.Open(pStorage, pMapName, IStorage::TYPE_ABSOLUTE)) |
| 32 | { |
| 33 | log_error("config_store", "Failed to import settings from '%s': failed to open map '%s' for reading", pConfigName, pMapName); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | char *pSettings = (char *)malloc(maximum(1, TotalLength)); |
| 38 | int Offset = 0; |
| 39 | for(const char *pLine : vpLines) |
| 40 | { |
| 41 | int Length = str_length(pLine) + 1; |
| 42 | mem_copy(pSettings + Offset, pLine, Length); |
| 43 | Offset += Length; |
| 44 | } |
| 45 | |
| 46 | CDataFileWriter Writer; |
| 47 | |
| 48 | int SettingsIndex = Reader.NumData(); |
| 49 | bool FoundInfo = false; |
| 50 | for(int i = 0; i < Reader.NumItems(); i++) |
| 51 | { |
| 52 | int Type, Id; |
| 53 | int *pItem = (int *)Reader.GetItem(i, &Type, &Id); |
| 54 | int Size = Reader.GetItemSize(i); |
| 55 | CMapItemInfoSettings MapInfo; |
| 56 | if(Type == MAPITEMTYPE_INFO && Id == 0) |
| 57 | { |
| 58 | FoundInfo = true; |
| 59 | CMapItemInfoSettings *pInfo = (CMapItemInfoSettings *)pItem; |
| 60 | if(Size >= (int)sizeof(CMapItemInfoSettings)) |
| 61 | { |
| 62 | MapInfo = *pInfo; |
| 63 | pItem = (int *)&MapInfo; |
| 64 | Size = sizeof(MapInfo); |
| 65 | if(pInfo->m_Settings > -1) |
| 66 | { |
| 67 | SettingsIndex = pInfo->m_Settings; |
| 68 | char *pMapSettings = (char *)Reader.GetData(SettingsIndex); |
| 69 | int DataSize = Reader.GetDataSize(SettingsIndex); |
| 70 | if(DataSize == TotalLength && mem_comp(pSettings, pMapSettings, DataSize) == 0) |
nothing calls this directly
no test coverage detected