| 11 | static const char *TOOL_NAME = "map_resave"; |
| 12 | |
| 13 | static 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 | |
| 61 | int main(int argc, const char **argv) |
| 62 | { |