std::set<std::string> getAvailableGameIds() { std::set<std::string> gameids; std::set<std::string> gamespaths; gamespaths.insert(porting::path_share + DIR_DELIM + "games"); gamespaths.insert(porting::path_user + DIR_DELIM + "games"); Strfnd search_paths(getSubgamePathEnv()); while (!search_paths.at_end()) gamespaths.insert(search_paths.next(PATH_DELIM)); for (std::set<std::string>::const_iterator i = gamespaths.begin(); i != gamespaths.end(); ++i){ std::vector<fs::DirListNode> dirlist = fs::GetDirListing(*i); for(u32 j=0; j<dirlist.size(); j++){ if(!dirlist[j].dir) continue; // If configuration file is not found or broken, ignore game Settings conf; if(!getGameConfig(*i + DIR_DELIM + dirlist[j].name, conf)) continue; // Add it to result const char *ends[] = {"_game", NULL}; std::string shorter = removeStringEnd(dirlist[j].name, ends); if(shorter != "") gameids.insert(shorter); else gameids.insert(dirlist[j].name); } } return gameids; }
SubgameSpec findSubgame(const std::string &id) { if(id == "") return SubgameSpec(); std::string share = porting::path_share; std::string user = porting::path_user; std::vector<GameFindPath> find_paths; Strfnd search_paths(getSubgamePathEnv()); while (!search_paths.at_end()) { std::string path = search_paths.next(PATH_DELIM); find_paths.push_back(GameFindPath( path + DIR_DELIM + id, false)); find_paths.push_back(GameFindPath( path + DIR_DELIM + id + "_game", false)); } find_paths.push_back(GameFindPath( user + DIR_DELIM + "games" + DIR_DELIM + id + "_game", true)); find_paths.push_back(GameFindPath( user + DIR_DELIM + "games" + DIR_DELIM + id, true)); find_paths.push_back(GameFindPath( share + DIR_DELIM + "games" + DIR_DELIM + id + "_game", false)); find_paths.push_back(GameFindPath( share + DIR_DELIM + "games" + DIR_DELIM + id, false)); // Find game directory std::string game_path; bool user_game = true; // Game is in user's directory for(u32 i=0; i<find_paths.size(); i++){ const std::string &try_path = find_paths[i].path; if(fs::PathExists(try_path)){ game_path = try_path; user_game = find_paths[i].user_specific; break; } } if(game_path == "") return SubgameSpec(); std::string gamemod_path = game_path + DIR_DELIM + "files"; // Find mod directories std::set<std::string> mods_paths; if(!user_game) mods_paths.insert(share + DIR_DELIM + "files"); if(user != share || user_game) mods_paths.insert(user + DIR_DELIM + "files"); std::string game_name = getGameName(game_path); if(game_name == "") game_name = id; std::string menuicon_path; #ifndef SERVER menuicon_path = getImagePath(game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png"); #endif return SubgameSpec(id, game_path, gamemod_path, mods_paths, game_name, menuicon_path); }
std::set<std::string> getAvailableGameIds() { std::set<std::string> gameids; std::set<std::string> gamespaths; gamespaths.insert(porting::path_share + DIR_DELIM + "games"); gamespaths.insert(porting::path_user + DIR_DELIM + "games"); Strfnd search_paths(getSubgamePathEnv()); while (!search_paths.at_end()) gamespaths.insert(search_paths.next(PATH_DELIM)); for (const std::string &gamespath : gamespaths) { std::vector<fs::DirListNode> dirlist = fs::GetDirListing(gamespath); for (const fs::DirListNode &dln : dirlist) { if (!dln.dir) continue; // If configuration file is not found or broken, ignore game Settings conf; std::string conf_path = gamespath + DIR_DELIM + dln.name + DIR_DELIM + "game.conf"; if (!conf.readConfigFile(conf_path.c_str())) continue; // Add it to result const char *ends[] = {"_game", NULL}; std::string shorter = removeStringEnd(dln.name, ends); if (!shorter.empty()) gameids.insert(shorter); else gameids.insert(dln.name); } } return gameids; }
SubgameSpec findSubgame(const std::string &id) { if (id.empty()) return SubgameSpec(); std::string share = porting::path_share; std::string user = porting::path_user; // Get games install locations Strfnd search_paths(getSubgamePathEnv()); // Get all possible paths fo game std::vector<GameFindPath> find_paths; while (!search_paths.at_end()) { std::string path = search_paths.next(PATH_DELIM); find_paths.emplace_back(path + DIR_DELIM + id, false); find_paths.emplace_back(path + DIR_DELIM + id + "_game", false); } find_paths.emplace_back( user + DIR_DELIM + "games" + DIR_DELIM + id + "_game", true); find_paths.emplace_back(user + DIR_DELIM + "games" + DIR_DELIM + id, true); find_paths.emplace_back( share + DIR_DELIM + "games" + DIR_DELIM + id + "_game", false); find_paths.emplace_back(share + DIR_DELIM + "games" + DIR_DELIM + id, false); // Find game directory std::string game_path; bool user_game = true; // Game is in user's directory for (const GameFindPath &find_path : find_paths) { const std::string &try_path = find_path.path; if (fs::PathExists(try_path)) { game_path = try_path; user_game = find_path.user_specific; break; } } if (game_path.empty()) return SubgameSpec(); std::string gamemod_path = game_path + DIR_DELIM + "mods"; // Find mod directories std::set<std::string> mods_paths; if (!user_game) mods_paths.insert(share + DIR_DELIM + "mods"); if (user != share || user_game) mods_paths.insert(user + DIR_DELIM + "mods"); // Get meta std::string conf_path = game_path + DIR_DELIM + "game.conf"; Settings conf; conf.readConfigFile(conf_path.c_str()); std::string game_name; if (conf.exists("name")) game_name = conf.get("name"); else game_name = id; std::string game_author; if (conf.exists("author")) game_author = conf.get("author"); int game_release = 0; if (conf.exists("release")) game_release = conf.getS32("release"); std::string menuicon_path; #ifndef SERVER menuicon_path = getImagePath( game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png"); #endif return SubgameSpec(id, game_path, gamemod_path, mods_paths, game_name, menuicon_path, game_author, game_release); }