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