return -1;
}
+AddonVersion CAddonDatabase::GetAddonVersion(const std::string &id)
+{
+ AddonVersion maxversion("0.0.0");
+ try
+ {
+ if (NULL == m_pDB.get()) return maxversion;
+ if (NULL == m_pDS2.get()) return maxversion;
+
+ // there may be multiple addons with this id (eg from different repositories) in the database,
+ // so we want to retrieve the latest version. Order by version won't work as the database
+ // won't know that 1.10 > 1.2, so grab them all and order outside
+ CStdString sql = PrepareSQL("select version from addon where addonID='%s'",id.c_str());
+ m_pDS2->query(sql.c_str());
+
+ if (m_pDS2->eof())
+ return maxversion;
+
+ while (!m_pDS2->eof())
+ {
+ AddonVersion version(m_pDS2->fv(0).get_asString());
+ if (version > maxversion)
+ maxversion = version;
+ m_pDS2->next();
+ }
+ return maxversion;
+ }
+ catch (...)
+ {
+ CLog::Log(LOGERROR, "%s failed on addon %s", __FUNCTION__, id.c_str());
+ }
+ return maxversion;
+}
+
bool CAddonDatabase::GetAddon(const CStdString& id, AddonPtr& addon)
{
try
bool GetAddon(const CStdString& addonID, ADDON::AddonPtr& addon);
bool GetAddons(ADDON::VECADDONS& addons);
+ /*! \brief grab the (largest) add-on version for an add-on */
+ ADDON::AddonVersion GetAddonVersion(const std::string &id);
+
/*! \brief Grab the repository from which a given addon came
\param addonID - the id of the addon in question
\param repo [out] - the id of the repository
// Check if we should mark the add-on as broken. We may have a newer version
// of this add-on in the database or installed - if so, we keep it unbroken.
- bool haveNewer = addon && addon->Version() > newAddon->Version();
- if (!haveNewer)
- {
- AddonPtr dbAddon;
- haveNewer = database.GetAddon(newAddon->ID(), dbAddon) && dbAddon->Version() > newAddon->Version();
- }
+ bool haveNewer = (addon && addon->Version() > newAddon->Version()) ||
+ database.GetAddonVersion(newAddon->ID()) > newAddon->Version();
if (!haveNewer)
{
if (!newAddon->Props().broken.empty())