bool buildMapList() { if (!loadLevFile("gamedesc.lev", mod_campaign, false, NULL)) { return false; } loadLevFile("addon.lev", mod_multiplay, false, NULL); WZ_Maps.clear(); MapFileList realFileNames = listMapFiles(); for (MapFileList::iterator realFileName = realFileNames.begin(); realFileName != realFileNames.end(); ++realFileName) { bool mapmod = false; struct WZmaps CurrentMap; std::string realFilePathAndName = PHYSFS_getRealDir(realFileName->c_str()) + *realFileName; PHYSFS_addToSearchPath(realFilePathAndName.c_str(), PHYSFS_APPEND); char **filelist = PHYSFS_enumerateFiles(""); for (char **file = filelist; *file != NULL; ++file) { std::string checkfile = *file; size_t len = strlen(*file); if (len > 10 && !strcasecmp(*file + (len - 10), ".addon.lev")) // Do not add addon.lev again { loadLevFile(*file, mod_multiplay, true, realFileName->c_str()); } // add support for X player maps using a new name to prevent conflicts. if (len > 13 && !strcasecmp(*file + (len - 13), ".xplayers.lev")) { loadLevFile(*file, mod_multiplay, true, realFileName->c_str()); } } PHYSFS_freeList(filelist); if (PHYSFS_removeFromSearchPath(realFilePathAndName.c_str()) == 0) { debug(LOG_ERROR, "Could not unmount %s, %s", realFilePathAndName.c_str(), PHYSFS_getLastError()); } mapmod = CheckInMap(realFilePathAndName.c_str(), "WZMap", "WZMap"); if (!mapmod) { mapmod = CheckInMap(realFilePathAndName.c_str(), "WZMap", "WZMap/multiplay"); } CurrentMap.MapName = realFileName->c_str(); CurrentMap.isMapMod = mapmod; WZ_Maps.push_back(CurrentMap); } return true; }
bool buildMapList() { if (!loadLevFile("gamedesc.lev", mod_campaign, false, NULL)) { return false; } loadLevFile("addon.lev", mod_multiplay, false, NULL); MapFileList realFileNames = listMapFiles(); for (MapFileList::iterator realFileName = realFileNames.begin(); realFileName != realFileNames.end(); ++realFileName) { std::string realFilePathAndName = PHYSFS_getRealDir(realFileName->c_str()) + *realFileName; PHYSFS_addToSearchPath(realFilePathAndName.c_str(), PHYSFS_APPEND); char **filelist = PHYSFS_enumerateFiles(""); for (char **file = filelist; *file != NULL; ++file) { size_t len = strlen(*file); if (len > 10 && !strcasecmp(*file + (len - 10), ".addon.lev")) // Do not add addon.lev again { loadLevFile(*file, mod_multiplay, true, realFileName->c_str()); } // add support for X player maps using a new name to prevent conflicts. if (len > 13 && !strcasecmp(*file + (len - 13), ".xplayers.lev")) { loadLevFile(*file, mod_multiplay, true, realFileName->c_str()); } } PHYSFS_freeList(filelist); PHYSFS_removeFromSearchPath(realFilePathAndName.c_str()); } return true; }
static MapFileList listMapFiles() { MapFileList ret, filtered, oldSearchPath; char **subdirlist = PHYSFS_enumerateFiles("maps"); for (char **i = subdirlist; *i != NULL; ++i) { std::string wzfile = *i; if (*i[0] == '.' || wzfile.substr(wzfile.find_last_of(".")+1) != "wz") { continue; } std::string realFileName = std::string("maps/") + *i; ret.push_back(realFileName); } PHYSFS_freeList(subdirlist); // save our current search path(s) debug(LOG_WZ, "Map search paths:"); char **searchPath = PHYSFS_getSearchPath(); for (char **i = searchPath; *i != NULL; i++) { debug(LOG_WZ, " [%s]", *i); oldSearchPath.push_back(*i); PHYSFS_removeFromSearchPath(*i); } PHYSFS_freeList(searchPath); for (MapFileList::iterator realFileName = ret.begin(); realFileName != ret.end(); ++realFileName) { std::string realFilePathAndName = PHYSFS_getWriteDir() + *realFileName; PHYSFS_addToSearchPath(realFilePathAndName.c_str(), PHYSFS_APPEND); int unsafe = 0; char **filelist = PHYSFS_enumerateFiles("multiplay/maps"); for (char **file = filelist; *file != NULL; ++file) { std::string isDir = std::string("multiplay/maps/") + *file; if (PHYSFS_isDirectory(isDir.c_str())) continue; std::string checkfile = *file; debug(LOG_WZ,"checking ... %s", *file); if (checkfile.substr(checkfile.find_last_of(".")+ 1) == "gam") { if (unsafe++ > 1) { debug(LOG_ERROR, "Map packs are not supported! %s NOT added.", realFilePathAndName.c_str()); break; } } } PHYSFS_freeList(filelist); if (unsafe < 2) { filtered.push_back(realFileName->c_str()); } PHYSFS_removeFromSearchPath(realFilePathAndName.c_str()); } // restore our search path(s) again for (MapFileList::iterator restorePaths = oldSearchPath.begin(); restorePaths != oldSearchPath.end(); ++restorePaths) { PHYSFS_addToSearchPath(restorePaths->c_str(), PHYSFS_APPEND); } debug(LOG_WZ, "Search paths restored"); printSearchPath(); return filtered; }
bool buildMapList() { if (!loadLevFile("gamedesc.lev", mod_campaign, false, NULL)) { return false; } loadLevFile("addon.lev", mod_multiplay, false, NULL); WZ_Maps.clear(); MapFileList realFileNames = listMapFiles(); for (MapFileList::iterator realFileName = realFileNames.begin(); realFileName != realFileNames.end(); ++realFileName) { bool mapmod = false; struct WZmaps CurrentMap; std::string realFilePathAndName = PHYSFS_getRealDir(realFileName->c_str()) + *realFileName; PHYSFS_addToSearchPath(realFilePathAndName.c_str(), PHYSFS_APPEND); char **filelist = PHYSFS_enumerateFiles(""); for (char **file = filelist; *file != NULL; ++file) { std::string checkfile = *file; size_t len = strlen(*file); if (len > 10 && !strcasecmp(*file + (len - 10), ".addon.lev")) // Do not add addon.lev again { loadLevFile(*file, mod_multiplay, true, realFileName->c_str()); } // add support for X player maps using a new name to prevent conflicts. if (len > 13 && !strcasecmp(*file + (len - 13), ".xplayers.lev")) { loadLevFile(*file, mod_multiplay, true, realFileName->c_str()); } } PHYSFS_freeList(filelist); if (PHYSFS_removeFromSearchPath(realFilePathAndName.c_str()) == 0) { debug(LOG_ERROR, "Could not unmount %s", PHYSFS_getLastError()); } // check what kind of map it is if (!PHYSFS_mount(realFilePathAndName.c_str(), "WZMap", PHYSFS_APPEND)) { debug(LOG_FATAL, "Could not mount %s, because: %s. Please delete the file, and run the game again. Game will now exit.", realFilePathAndName.c_str(), PHYSFS_getLastError()); exit(-1); } filelist = PHYSFS_enumerateFiles("WZMap"); for (char **file = filelist; *file != NULL; ++file) { if (PHYSFS_isDirectory(*file)) { std::string checkfile = *file; if (checkfile.compare("wrf")==0 || checkfile.compare("stats")==0 ||checkfile.compare("components")==0 || checkfile.compare("anims")==0 || checkfile.compare("effects")==0 ||checkfile.compare("messages")==0 || checkfile.compare("audio")==0 || checkfile.compare("sequenceaudio")==0 ||checkfile.compare("misc")==0 || checkfile.compare("features")==0 || checkfile.compare("script")==0 ||checkfile.compare("structs")==0 || checkfile.compare("tileset")==0 || checkfile.compare("images")==0 || checkfile.compare("texpages")==0 ) { mapmod = true; break; } } } PHYSFS_freeList(filelist); CurrentMap.MapName = realFileName->c_str(); CurrentMap.isMapMod = mapmod; WZ_Maps.push_back(CurrentMap); if (PHYSFS_removeFromSearchPath(realFilePathAndName.c_str()) == 0) { debug(LOG_ERROR, "Could not unmount %s", PHYSFS_getLastError()); } } return true; }