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

Function ResaveMap

src/tools/map_resave.cpp:13–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11static const char *TOOL_NAME = "map_resave";
12
13static int ResaveMap(const char *pSourceMap, const char *pDestinationMap, IStorage *pStorage)
14{
15 CDataFileReader Reader;
16 if(!Reader.Open(pStorage, pSourceMap, IStorage::TYPE_ABSOLUTE))
17 {
18 log_error(TOOL_NAME, "Failed to open source map '%s' for reading", pSourceMap);
19 return -1;
20 }
21
22 CDataFileWriter Writer;
23 if(!Writer.Open(pStorage, pDestinationMap))
24 {
25 log_error(TOOL_NAME, "Failed to open destination map '%s' for writing", pDestinationMap);
26 Reader.Close();
27 return -1;
28 }
29
30 // add all items
31 for(int Index = 0; Index < Reader.NumItems(); Index++)
32 {
33 int Type, Id;
34 CUuid Uuid;
35 const void *pPtr = Reader.GetItem(Index, &Type, &Id, &Uuid);
36
37 // Filter ITEMTYPE_EX items, they will be automatically added again.
38 if(Type == ITEMTYPE_EX)
39 {
40 continue;
41 }
42
43 int Size = Reader.GetItemSize(Index);
44 Writer.AddItem(Type, Id, Size, pPtr, &Uuid);
45 }
46
47 // add all data
48 for(int Index = 0; Index < Reader.NumData(); Index++)
49 {
50 const void *pPtr = Reader.GetData(Index);
51 int Size = Reader.GetDataSize(Index);
52 Writer.AddData(Size, pPtr);
53 }
54
55 Reader.Close();
56 Writer.Finish();
57 log_info(TOOL_NAME, "Resaved '%s' to '%s'", pSourceMap, pDestinationMap);
58 return 0;
59}
60
61int main(int argc, const char **argv)
62{

Callers 1

mainFunction · 0.85

Calls 11

AddItemMethod · 0.80
AddDataMethod · 0.80
OpenMethod · 0.45
CloseMethod · 0.45
NumItemsMethod · 0.45
GetItemMethod · 0.45
GetItemSizeMethod · 0.45
NumDataMethod · 0.45
GetDataMethod · 0.45
GetDataSizeMethod · 0.45
FinishMethod · 0.45

Tested by

no test coverage detected