void mod_manager::load_mods_list(WORLDPTR world) const { if (world == NULL) { return; } std::vector<std::string> &amo = world->active_mod_order; amo.clear(); bool obsolete_mod_found = false; read_from_file_optional_json( get_mods_list_file( world ), [&]( JsonIn &jsin ) { JsonArray ja = jsin.get_array(); while (ja.has_more()) { const std::string mod = ja.next_string(); if( mod.empty() || std::find(amo.begin(), amo.end(), mod) != amo.end() ) { continue; } if( mod_replacements.count( mod ) ) { amo.push_back( mod_replacements[ mod ] ); obsolete_mod_found = true; } else { amo.push_back(mod); } } } ); if( obsolete_mod_found ) { // If we found an obsolete mod, overwrite the mod list without the obsolete one. save_mods_list(world); } }
void mod_manager::load_mods_list(WORLDPTR world) const { if (world == NULL) { return; } std::vector<std::string> &amo = world->active_mod_order; amo.clear(); std::ifstream mods_list_file( get_mods_list_file(world).c_str(), std::ios::in | std::ios::binary ); if (!mods_list_file) { return; } bool obsolete_mod_found = false; try { JsonIn jsin(mods_list_file); JsonArray ja = jsin.get_array(); while (ja.has_more()) { const std::string mod = ja.next_string(); if( mod.empty() || std::find(amo.begin(), amo.end(), mod) != amo.end() ) { continue; } if( obsolete_mod_list.count( mod ) ) { obsolete_mod_found = true; continue; } amo.push_back(mod); } } catch (std::string e) { DebugLog( D_ERROR, DC_ALL ) << "worldfactory: loading mods list failed: " << e; } if( obsolete_mod_found ) { // If we found an obsolete mod, overwrite the mod list without the obsolete one. save_mods_list(world); } }