X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Faddon%2Faddon_manager.cpp;h=60099bf4c4747d69ff0ff74c6270fc132a73bc81;hb=2b7cf1bf8c85a4df1d2a02ddcad8723b40f8efff;hp=87ff4cbb10a2184caa28eb4a0e63fb90de5fe2eb;hpb=74773542651d1f9dd3ee8fc78a7fbf0e0ac3fe10;p=supertux.git diff --git a/src/addon/addon_manager.cpp b/src/addon/addon_manager.cpp index 87ff4cbb1..60099bf4c 100644 --- a/src/addon/addon_manager.cpp +++ b/src/addon/addon_manager.cpp @@ -89,7 +89,6 @@ AddonManager::AddonManager(const std::string& addon_directory, m_installed_addons(), m_repository_addons(), m_has_been_updated(false), - m_install_request(), m_transfer_status() { PHYSFS_mkdir(m_addon_directory.c_str()); @@ -111,6 +110,15 @@ AddonManager::AddonManager(const std::string& addon_directory, } } } + + try + { + m_repository_addons = parse_addon_infos("/addons/repository.nfo"); + } + catch(const std::exception& err) + { + log_warning << "parsing repository.nfo failed: " << err.what() << std::endl; + } } AddonManager::~AddonManager() @@ -213,11 +221,16 @@ AddonManager::request_check_online() { m_transfer_status = m_downloader.request_download(m_repository_url, "/addons/repository.nfo"); - m_transfer_status->then([this]{ - m_repository_addons = parse_addon_infos("/addons/repository.nfo"); - m_has_been_updated = true; - + m_transfer_status->then( + [this](bool success) + { m_transfer_status = {}; + + if (success) + { + m_repository_addons = parse_addon_infos("/addons/repository.nfo"); + m_has_been_updated = true; + } }); return m_transfer_status; @@ -262,48 +275,45 @@ AddonManager::request_install_addon(const AddonId& addon_id) } } - { - Addon& repository_addon = get_repository_addon(addon_id); + Addon& addon = get_repository_addon(addon_id); - m_install_request = std::make_shared(); - m_install_request->install_filename = FileSystem::join(m_addon_directory, repository_addon.get_filename()); - m_install_request->addon_id = addon_id; + std::string install_filename = FileSystem::join(m_addon_directory, addon.get_filename()); - m_transfer_status = m_downloader.request_download(repository_addon.get_url(), - m_install_request->install_filename); - } + m_transfer_status = m_downloader.request_download(addon.get_url(), install_filename); m_transfer_status->then( - [this] + [this, install_filename, addon_id](bool success) { - // complete the addon install - Addon& repository_addon = get_repository_addon(m_install_request->addon_id); + m_transfer_status = {}; - MD5 md5 = md5_from_file(m_install_request->install_filename); - if (repository_addon.get_md5() != md5.hex_digest()) + if (success) { - if (PHYSFS_delete(m_install_request->install_filename.c_str()) == 0) - { - log_warning << "PHYSFS_delete failed: " << PHYSFS_getLastError() << std::endl; - } + // complete the addon install + Addon& repository_addon = get_repository_addon(addon_id); - throw std::runtime_error("Downloading Add-on failed: MD5 checksums differ"); - } - else - { - const char* realdir = PHYSFS_getRealDir(m_install_request->install_filename.c_str()); - if (!realdir) + MD5 md5 = md5_from_file(install_filename); + if (repository_addon.get_md5() != md5.hex_digest()) { - throw std::runtime_error("PHYSFS_getRealDir failed: " + m_install_request->install_filename); + if (PHYSFS_delete(install_filename.c_str()) == 0) + { + log_warning << "PHYSFS_delete failed: " << PHYSFS_getLastError() << std::endl; + } + + throw std::runtime_error("Downloading Add-on failed: MD5 checksums differ"); } else { - add_installed_archive(m_install_request->install_filename, md5.hex_digest()); + const char* realdir = PHYSFS_getRealDir(install_filename.c_str()); + if (!realdir) + { + throw std::runtime_error("PHYSFS_getRealDir failed: " + install_filename); + } + else + { + add_installed_archive(install_filename, md5.hex_digest()); + } } } - - m_install_request = {}; - m_transfer_status = {}; }); return m_transfer_status; @@ -588,15 +598,4 @@ AddonManager::update() m_downloader.update(); } -void -AddonManager::abort_install() -{ - log_info << "addon install aborted" << std::endl; - - m_downloader.abort(m_transfer_status->id); - - m_install_request = {}; - m_transfer_status = {}; -} - /* EOF */