void AddonManager::check_online() { m_downloader.download(m_repository_url, ADDON_INFO_PATH); m_repository_addons = parse_addon_infos(ADDON_INFO_PATH); m_has_been_updated = true; }
TransferStatusPtr AddonManager::request_check_online() { if (m_transfer_status) { throw std::runtime_error("only async request can be made to AddonManager at a time"); } else { m_transfer_status = m_downloader.request_download(m_repository_url, ADDON_INFO_PATH); m_transfer_status->then( [this](bool success) { m_transfer_status = {}; if (success) { m_repository_addons = parse_addon_infos(ADDON_INFO_PATH); m_has_been_updated = true; } }); return m_transfer_status; } }
AddonManager::AddonManager(const std::string& addon_directory, std::vector<Config::Addon>& addon_config) : m_downloader(), m_addon_directory(addon_directory), m_repository_url("https://raw.githubusercontent.com/SuperTux/addons/master/index-0_5.nfo"), m_addon_config(addon_config), m_installed_addons(), m_repository_addons(), m_has_been_updated(false), m_transfer_status() { if(!PHYSFS_mkdir(m_addon_directory.c_str())) { std::ostringstream msg; msg << "Couldn't create directory for addons '" << m_addon_directory << "': " << PHYSFS_getLastError(); throw std::runtime_error(msg.str()); } add_installed_addons(); // FIXME: We should also restore the order here for(auto& addon : m_addon_config) { if (addon.enabled) { try { enable_addon(addon.id); } catch(const std::exception& err) { log_warning << "failed to enable addon from config: " << err.what() << std::endl; } } } if(PHYSFS_exists(ADDON_INFO_PATH)) { try { m_repository_addons = parse_addon_infos(ADDON_INFO_PATH); } catch(const std::exception& err) { log_warning << "parsing repository.nfo failed: " << err.what() << std::endl; } } else { log_info << "repository.nfo doesn't exist, not loading" << std::endl; } if (!g_config->repository_url.empty() && g_config->repository_url != m_repository_url) { m_repository_url = g_config->repository_url; } }
AddonManager::AddonManager(const std::string& addon_directory, std::vector<Config::Addon>& addon_config) : m_downloader(), m_addon_directory(addon_directory), m_repository_url("https://raw.githubusercontent.com/SuperTux/addons/master/index-0_4_0.nfo"), m_addon_config(addon_config), m_installed_addons(), m_repository_addons(), m_has_been_updated(false), m_transfer_status() { PHYSFS_mkdir(m_addon_directory.c_str()); add_installed_addons(); // FIXME: We should also restore the order here for(auto& addon : m_addon_config) { if (addon.enabled) { try { enable_addon(addon.id); } catch(const std::exception& err) { log_warning << "failed to enable addon from config: " << err.what() << std::endl; } } } if(PHYSFS_exists(ADDON_INFO_PATH)) { try { m_repository_addons = parse_addon_infos(ADDON_INFO_PATH); } catch(const std::exception& err) { log_warning << "parsing repository.nfo failed: " << err.what() << std::endl; } } else { log_info << "repository.nfo doesn't exist, not loading" << std::endl; } }