From: Ingo Ruhnke Date: Sat, 23 Aug 2014 19:07:25 +0000 (+0200) Subject: Keep proper track of MD5 checksums of addons X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=417d2f8152e495270d3e1dc78be0a573d6bad20b;p=supertux.git Keep proper track of MD5 checksums of addons --- diff --git a/src/addon/addon.cpp b/src/addon/addon.cpp index b4536973c..4683b0369 100644 --- a/src/addon/addon.cpp +++ b/src/addon/addon.cpp @@ -159,9 +159,10 @@ Addon::is_enabled() const } void -Addon::set_install_filename(const std::string& absolute_filename) +Addon::set_install_filename(const std::string& absolute_filename, const std::string& md5) { m_install_filename = absolute_filename; + m_md5 = md5; } void diff --git a/src/addon/addon.hpp b/src/addon/addon.hpp index 81cf34909..34e49aabd 100644 --- a/src/addon/addon.hpp +++ b/src/addon/addon.hpp @@ -70,7 +70,7 @@ public: bool is_installed() const; bool is_enabled() const; - void set_install_filename(const std::string& absolute_filename); + void set_install_filename(const std::string& absolute_filename, const std::string& md5); void set_enabled(bool v); private: diff --git a/src/addon/addon_manager.cpp b/src/addon/addon_manager.cpp index 515359244..acd983fa2 100644 --- a/src/addon/addon_manager.cpp +++ b/src/addon/addon_manager.cpp @@ -227,7 +227,7 @@ AddonManager::install_addon(const AddonId& addon_id) } else { - add_installed_archive(install_filename); + add_installed_archive(install_filename, md5.hex_digest()); } } } @@ -358,7 +358,7 @@ AddonManager::scan_for_info(const std::string& archive_os_path) const } void -AddonManager::add_installed_archive(const std::string& archive) +AddonManager::add_installed_archive(const std::string& archive, const std::string& md5) { const char* realdir = PHYSFS_getRealDir(archive.c_str()); if (!realdir) @@ -383,7 +383,7 @@ AddonManager::add_installed_archive(const std::string& archive) try { std::unique_ptr addon = Addon::parse(nfo_filename); - addon->set_install_filename(os_path); + addon->set_install_filename(os_path, md5); m_installed_addons.push_back(std::move(addon)); } catch (const std::runtime_error& e) @@ -403,7 +403,8 @@ AddonManager::add_installed_addons() for(auto archive : archives) { - add_installed_archive(archive); + MD5 md5 = md5_from_file(archive); + add_installed_archive(archive, md5.hex_digest()); } } diff --git a/src/addon/addon_manager.hpp b/src/addon/addon_manager.hpp index cd1167165..68e1953c4 100644 --- a/src/addon/addon_manager.hpp +++ b/src/addon/addon_manager.hpp @@ -73,7 +73,7 @@ private: /** add \a archive, given as physfs path, to the list of installed archives */ - void add_installed_archive(const std::string& archive); + void add_installed_archive(const std::string& archive, const std::string& md5); /** search for an .nfo file in the top level directory that originates from \a archive, \a archive is a OS path */ diff --git a/src/supertux/menu/addon_menu.cpp b/src/supertux/menu/addon_menu.cpp index d2e6c5bc5..704d1d2c7 100644 --- a/src/supertux/menu/addon_menu.cpp +++ b/src/supertux/menu/addon_menu.cpp @@ -109,7 +109,7 @@ AddonMenu::rebuild_menu() add_label(_("Add-ons")); add_hl(); - + if (!m_installed_addons.empty()) { int idx = 0; @@ -117,7 +117,7 @@ AddonMenu::rebuild_menu() { const Addon& addon = m_addon_manager.get_installed_addon(addon_id); std::string text = generate_menu_item_text(addon); - add_toggle(MAKE_INSTALLED_MENU_ID(idx), text, addon.is_enabled()); + add_toggle(MAKE_INSTALLED_MENU_ID(idx), text, addon.is_enabled()); idx += 1; } @@ -145,12 +145,16 @@ AddonMenu::rebuild_menu() if (installed_addon.get_md5() == addon.get_md5() || installed_addon.get_version() > addon.get_version()) { - // addon alredy present, ignore it + log_debug << "ignoring already installed addon " << installed_addon.get_id() << std::endl; } else { + log_debug << installed_addon.get_id() << " is installed, but updated: '" + << installed_addon.get_md5() << "' vs '" << addon.get_md5() << "' '" + << installed_addon.get_version() << "' vs '" << addon.get_version() << "'" + << std::endl; std::string text = generate_menu_item_text(addon); - add_entry(MAKE_REPOSITORY_MENU_ID(idx), "Install " + text + "*NEW*"); + add_entry(MAKE_REPOSITORY_MENU_ID(idx), "Install " + text + " *NEW*"); idx += 1; } } @@ -193,7 +197,7 @@ AddonMenu::menu_action(MenuItem* item) const Addon& addon = m_addon_manager.get_installed_addon(m_installed_addons[idx]); if(addon.is_enabled()) { - m_addon_manager.enable_addon(addon.get_id()); + m_addon_manager.disable_addon(addon.get_id()); set_toggled(item->id, addon.is_enabled()); } else