From: Ingo Ruhnke Date: Sat, 23 Aug 2014 19:03:44 +0000 (+0200) Subject: Make sure that duplicate Addon install requests don't lead to duplicates in the insta... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ebfce57cc11bf99e1fe4083fc6c5dfaf6141eafe;p=supertux.git Make sure that duplicate Addon install requests don't lead to duplicates in the installed_addon list --- diff --git a/src/addon/addon_manager.cpp b/src/addon/addon_manager.cpp index 49ce4e42e..515359244 100644 --- a/src/addon/addon_manager.cpp +++ b/src/addon/addon_manager.cpp @@ -181,7 +181,27 @@ AddonManager::check_online() void AddonManager::install_addon(const AddonId& addon_id) { - log_debug << "installing addon " << addon_id << std::endl; + { // remove addon if it already exists + auto it = std::find_if(m_installed_addons.begin(), m_installed_addons.end(), + [&addon_id](const std::unique_ptr& addon) + { + return addon->get_id() == addon_id; + }); + if (it != m_installed_addons.end()) + { + log_debug << "reinstalling addon " << addon_id << std::endl; + if ((*it)->is_enabled()) + { + disable_addon((*it)->get_id()); + } + m_installed_addons.erase(it); + } + else + { + log_debug << "installing addon " << addon_id << std::endl; + } + } + Addon& repository_addon = get_repository_addon(addon_id); std::string install_filename = FileSystem::join(m_addon_directory, repository_addon.get_filename());