MCPcopy Create free account
hub / github.com/ddnet/ddnet / Process

Function Process

src/tools/config_retrieve.cpp:8–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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, 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"

Callers

nothing calls this directly

Calls 15

dbg_msgFunction · 0.85
str_lengthFunction · 0.85
io_writeFunction · 0.85
io_write_newlineFunction · 0.85
io_closeFunction · 0.85
fs_removeFunction · 0.85
OpenMethod · 0.45
GetTypeMethod · 0.45
GetItemMethod · 0.45
GetItemSizeMethod · 0.45
OpenFileMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected