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<InstallStatus>();
+ 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;
}
}
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)
{
bool has_online_support() const;
bool has_been_updated() const;
void check_online();
+ InstallStatusPtr request_check_online();
std::vector<AddonId> get_repository_addons() const;
std::vector<AddonId> get_installed_addons() const;
private:
std::vector<std::string> 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 */
{
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<AddonDialog> dialog(new AddonDialog(status));
+ dialog->set_title("Downloading Add-On Repository Index");
+ MenuManager::instance().set_dialog(std::move(dialog));
}
catch (std::exception& e)
{