If an addon icon can not be shown, delete the image file (which will

trigger a re-download on the next start).
This commit is contained in:
hiker 2014-07-28 21:07:39 +10:00
parent f6fcb9d8da
commit dbe722316a
4 changed files with 29 additions and 1 deletions

View File

@ -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

View File

@ -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. */

View File

@ -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; }
};
}

View File

@ -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