bool manage_addons(CVideo& v) { static const int addon_download = 0; // NOTE: the following two values are also known by WML, so don't change them. static const int addon_uninstall = 2; std::string host_name = preferences::campaign_server(); const bool have_addons = !installed_addons().empty(); gui2::dialogs::addon_connect addon_dlg(host_name, have_addons); addon_dlg.show(v); int res = addon_dlg.get_retval(); if(res == gui2::window::OK) { res = addon_download; } switch(res) { case addon_download: return addons_manager_ui(v, host_name); case addon_uninstall: return uninstall_local_addons(v); default: return false; } }
void refresh_addon_version_info_cache() { version_info_cache.clear(); LOG_CFG << "refreshing add-on versions cache\n"; const std::vector<std::string>& addons = installed_addons(); if(addons.empty()) { return; } std::vector<std::string> addon_info_files(addons.size()); std::transform(addons.begin(), addons.end(), addon_info_files.begin(), get_info_file_path); for(size_t i = 0; i < addon_info_files.size(); ++i) { assert(i < addons.size()); const std::string& addon = addons[i]; const std::string& info_file = addon_info_files[i]; if(file_exists(info_file)) { scoped_istream stream = istream_file(info_file); config cfg; read(cfg, *stream); const config& info_cfg = cfg.child("info"); if(!info_cfg) { continue; } const std::string& version = info_cfg["version"].str(); LOG_CFG << "cached add-on version: " << addon << " [" << version << "]\n"; version_info_cache[addon] = version; } else if (!have_addon_pbl_info(addon) && !have_addon_in_vcs_tree(addon)) { // Don't print the warning if the user is clearly the author WRN_CFG << "add-on '" << addon << "' has no _info.cfg; cannot read version info\n"; } } }