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; } 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; } amo.push_back(mod); } } catch (std::string e) { DebugLog( D_ERROR, DC_ALL ) << "worldfactory: loading mods list failed: " << e; } }
void mod_manager::save_mods_list(WORLDPTR world) const { if( world == NULL ) { return; } const std::string path = get_mods_list_file(world); if( world->active_mod_order.empty() ) { // If we were called from load_mods_list to prune the list, // and it's empty now, delete the file. if( file_exist(path) ) { remove_file(path); } return; } std::ofstream mods_list_file(path.c_str(), std::ios::out | std::ios::binary); if(!mods_list_file) { popup(_("Can not open %s for writing"), path.c_str()); } try { mods_list_file.exceptions(std::ios::failbit | std::ios::badbit); JsonOut json(mods_list_file, true); // pretty-print json.write(world->active_mod_order); } catch(std::ios::failure &) { // this might happen and indicates an I/O-error popup(_("Failed to write to %s"), path.c_str()); } catch (std::string e) { popup( _( "Failed to write list of mods to %s: %s" ), path.c_str(), e.c_str() ); } }
void mod_manager::save_mods_list(WORLDPTR world) const { if( world == NULL ) { return; } const std::string path = get_mods_list_file(world); if( world->active_mod_order.empty() ) { // If we were called from load_mods_list to prune the list, // and it's empty now, delete the file. remove_file(path); return; } write_to_file( path, [&]( std::ostream &fout ) { JsonOut json( fout, true ); // pretty-print json.write(world->active_mod_order); }, _( "list of mods" ) ); }
void mod_manager::save_mods_list(WORLDPTR world) const { if (world == NULL || world->active_mod_order.empty()) { return; } const std::string path = get_mods_list_file(world); std::ofstream mods_list_file(path.c_str(), std::ios::out | std::ios::binary); if(!mods_list_file) { popup(_("Can not open %s for writing"), path.c_str()); } try { mods_list_file.exceptions(std::ios::failbit | std::ios::badbit); JsonOut json(mods_list_file, true); // pretty-print json.write(world->active_mod_order); } catch(std::ios::failure &) { // this might happen and indicates an I/O-error popup(_("Failed to write to %s"), path.c_str()); } catch (std::string e) { DebugLog() << "worldfactory: failed to write list of mods to world folder\n"; } }
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); } }