From dbe722316a82ba965c20b6afceff4ad751594511 Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 28 Jul 2014 21:07:39 +1000 Subject: [PATCH] If an addon icon can not be shown, delete the image file (which will trigger a re-download on the next start). --- src/addons/addon.cpp | 12 ++++++++++++ src/addons/addon.hpp | 2 ++ src/guiengine/widgets/icon_button_widget.hpp | 9 ++++++++- src/states_screens/dialogs/addons_loading.cpp | 7 +++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/addons/addon.cpp b/src/addons/addon.cpp index 96523a32b..052d532a1 100644 --- a/src/addons/addon.cpp +++ b/src/addons/addon.cpp @@ -216,3 +216,15 @@ bool Addon::filterByWords(const core::stringw words) const return false; } // filterByWords + +// ---------------------------------------------------------------------------- +/** Deletes the icon file of this addon, and marks it to be re-downloaded (next + * time AddonsManager::downloadIcons() is called. + */ +void Addon::deleteInvalidIconFile() +{ + m_icon_ready = false; + std::string icon = file_manager->getAddonsFile("icons/"+m_icon_basename); + file_manager->removeFile(icon); + m_installed = false; +} // redownloadIcon diff --git a/src/addons/addon.hpp b/src/addons/addon.hpp index b834b6b4c..4a8b166e8 100644 --- a/src/addons/addon.hpp +++ b/src/addons/addon.hpp @@ -130,6 +130,8 @@ public: Addon() {}; /** Initialises the object from an XML node. */ Addon(const XMLNode &xml); + + void deleteInvalidIconFile(); // ------------------------------------------------------------------------ /** Sets the sort order used in the comparison function. It is static, so * that each instance can access the sort order. */ diff --git a/src/guiengine/widgets/icon_button_widget.hpp b/src/guiengine/widgets/icon_button_widget.hpp index 6a429d105..b64375a34 100644 --- a/src/guiengine/widgets/icon_button_widget.hpp +++ b/src/guiengine/widgets/icon_button_widget.hpp @@ -109,7 +109,7 @@ namespace GUIEngine */ void setImage(const char* path_to_texture, IconPathType path_type=ICON_PATH_TYPE_NO_CHANGE); - + // -------------------------------------------------------------------- /** Convenience function taking std::string. */ void setImage(const std::string &path_to_texture, IconPathType path_type=ICON_PATH_TYPE_NO_CHANGE) @@ -117,6 +117,7 @@ namespace GUIEngine setImage(path_to_texture.c_str(), path_type); } + // -------------------------------------------------------------------- /** * Change the texture used for this icon. * \pre At the moment, the new texture must have the same aspct ratio @@ -126,16 +127,22 @@ namespace GUIEngine */ void setImage(irr::video::ITexture* texture); + // -------------------------------------------------------------------- void setHighlightedImage(irr::video::ITexture* texture) { m_highlight_texture = texture; } + // -------------------------------------------------------------------- /** \brief override from base class */ virtual EventPropagation focused(const int playerID); + // -------------------------------------------------------------------- /** \brief override from base class */ virtual void unfocused(const int playerID, Widget* new_focus); + // -------------------------------------------------------------------- + /** Returns the texture of this button. */ + const video::ITexture* getTexture() const { return m_texture; } }; } diff --git a/src/states_screens/dialogs/addons_loading.cpp b/src/states_screens/dialogs/addons_loading.cpp index 1d82e4b13..1ebf2f3ad 100644 --- a/src/states_screens/dialogs/addons_loading.cpp +++ b/src/states_screens/dialogs/addons_loading.cpp @@ -294,6 +294,13 @@ void AddonsLoading::onUpdate(float delta) const std::string icon = "icons/"+m_addon.getIconBasename(); m_icon->setImage( file_manager->getAddonsFile(icon).c_str(), IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE ); + // Check if there was an error displaying the icon. If so, the icon + // file is (likely) corrupt, and the file needs to be downloaded again. + std::string s = m_icon->getTexture()->getName().getPath().c_str(); + if(StringUtils::getBasename(s)!=StringUtils::getBasename(icon)) + { + m_addon.deleteInvalidIconFile(); + } m_icon_shown = true; } } // onUpdate