From: Ingo Ruhnke Date: Tue, 26 Aug 2014 10:55:14 +0000 (+0200) Subject: Implemented non-blocking download for the repository index list X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f30bc1786951b8be5c3888c87e5eae00f3b136a5;p=supertux.git Implemented non-blocking download for the repository index list --- diff --git a/src/addon/addon_manager.cpp b/src/addon/addon_manager.cpp index c20764f36..1db62a815 100644 --- a/src/addon/addon_manager.cpp +++ b/src/addon/addon_manager.cpp @@ -203,11 +203,40 @@ AddonManager::has_been_updated() const return m_has_been_updated; } +AddonManager::InstallStatusPtr +AddonManager::request_check_online() +{ + if (m_install_status) + { + throw std::runtime_error("only one addon install request allowed at a time"); + } + else + { + 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; + + if (m_install_status->callback) + { + m_install_status->callback(); + } + + m_install_status = {}; + m_transfer_status = {}; + }); + + m_install_status = std::make_shared(); + return m_install_status; + } +} + void AddonManager::check_online() { - std::string addoninfos = m_downloader.download(m_repository_url); - m_repository_addons = parse_addon_infos(addoninfos); + m_downloader.download(m_repository_url, "/addons/repository.nfo"); + m_repository_addons = parse_addon_infos("/addons/repository.nfo"); m_has_been_updated = true; } @@ -527,15 +556,14 @@ AddonManager::add_installed_addons() } AddonManager::AddonList -AddonManager::parse_addon_infos(const std::string& addoninfos) const +AddonManager::parse_addon_infos(const std::string& filename) const { AddonList m_addons; try { lisp::Parser parser; - std::stringstream addoninfos_stream(addoninfos); - const lisp::Lisp* root = parser.parse(addoninfos_stream, "supertux-addons"); + const lisp::Lisp* root = parser.parse(filename); const lisp::Lisp* addons_lisp = root->get_lisp("supertux-addons"); if(!addons_lisp) { diff --git a/src/addon/addon_manager.hpp b/src/addon/addon_manager.hpp index cd23e619e..713d70db4 100644 --- a/src/addon/addon_manager.hpp +++ b/src/addon/addon_manager.hpp @@ -97,6 +97,7 @@ public: bool has_online_support() const; bool has_been_updated() const; void check_online(); + InstallStatusPtr request_check_online(); std::vector get_repository_addons() const; std::vector get_installed_addons() const; @@ -117,7 +118,7 @@ public: private: std::vector scan_for_archives() const; void add_installed_addons(); - AddonList parse_addon_infos(const std::string& addoninfos) const; + AddonList parse_addon_infos(const std::string& filename) const; /** add \a archive, given as physfs path, to the list of installed archives */ diff --git a/src/supertux/menu/addon_menu.cpp b/src/supertux/menu/addon_menu.cpp index 86776f550..5011e9557 100644 --- a/src/supertux/menu/addon_menu.cpp +++ b/src/supertux/menu/addon_menu.cpp @@ -184,8 +184,14 @@ AddonMenu::menu_action(MenuItem* item) { try { - m_addon_manager.check_online(); - refresh(); + AddonManager::InstallStatusPtr status = m_addon_manager.request_check_online(); + status->then([this]{ + MenuManager::instance().set_dialog({}); + refresh(); + }); + std::unique_ptr dialog(new AddonDialog(status)); + dialog->set_title("Downloading Add-On Repository Index"); + MenuManager::instance().set_dialog(std::move(dialog)); } catch (std::exception& e) {