From 2a72c0b38b8c2610001f24340097ad3a1b052263 Mon Sep 17 00:00:00 2001 From: oy Date: Thu, 31 Mar 2011 15:13:49 +0200 Subject: added a mechanism to check for a valid standard map. Closes #132 --- src/tools/map_version.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/tools/map_version.cpp (limited to 'src/tools/map_version.cpp') diff --git a/src/tools/map_version.cpp b/src/tools/map_version.cpp new file mode 100644 index 00000000..d995f478 --- /dev/null +++ b/src/tools/map_version.cpp @@ -0,0 +1,66 @@ +/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ +/* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include +#include + +#include +#include +#include + + +static IOHANDLE s_File = 0; +static IStorage *s_pStorage = 0; +static IEngineMap *s_pEngineMap = 0; + +int MaplistCallback(const char *pName, int IsDir, int DirType, void *pUser) +{ + int l = str_length(pName); + if(l < 4 || IsDir || str_comp(pName+l-4, ".map") != 0) + return 0; + + char aBuf[128]; + str_format(aBuf, sizeof(aBuf), "maps/%s", pName); + if(!s_pEngineMap->Load(aBuf)) + return 0; + + unsigned MapCrc = s_pEngineMap->Crc(); + s_pEngineMap->Unload(); + + IOHANDLE MapFile = s_pStorage->OpenFile(aBuf, IOFLAG_READ, DirType); + unsigned MapSize = io_length(MapFile); + io_close(MapFile); + + char aMapName[8]; + str_copy(aMapName, pName, min((int)sizeof(aMapName),l-3)); + + str_format(aBuf, sizeof(aBuf), "\t{\"%s\", {0x%02x, 0x%02x, 0x%02x, 0x%02x}, {0x%02x, 0x%02x, 0x%02x, 0x%02x}},\n", aMapName, + (MapCrc>>24)&0xff, (MapCrc>>16)&0xff, (MapCrc>>8)&0xff, MapCrc&0xff, + (MapSize>>24)&0xff, (MapSize>>16)&0xff, (MapSize>>8)&0xff, MapSize&0xff); + io_write(s_File, aBuf, str_length(aBuf)); + + return 0; +} + +int main(int argc, const char **argv) // ignore_convention +{ + IKernel *pKernel = IKernel::Create(); + s_pStorage = CreateStorage("Teeworlds", argc, argv); + s_pEngineMap = CreateEngineMap(); + + bool RegisterFail = !pKernel->RegisterInterface(s_pStorage); + RegisterFail |= !pKernel->RegisterInterface(s_pEngineMap); + + if(RegisterFail) + return -1; + + s_File = s_pStorage->OpenFile("map_version.txt", IOFLAG_WRITE, 1); + if(s_File) + { + io_write(s_File, "static CMapVersion s_aMapVersionList[] = {\n", str_length("static CMapVersion s_aMapVersionList[] = {\n")); + s_pStorage->ListDirectory(1, "maps", MaplistCallback, 0); + io_write(s_File, "};\n", str_length("};\n")); + io_close(s_File); + } + + return 0; +} -- cgit 1.4.1