[textures] adds ClearCachedImage() to clear a texture by id
authorJonathan Marshall <jmarshall@xbmc.org>
Sat, 26 Oct 2013 07:46:53 +0000 (20:46 +1300)
committerJonathan Marshall <jmarshall@xbmc.org>
Sat, 2 Nov 2013 22:40:26 +0000 (11:40 +1300)
xbmc/TextureCache.cpp
xbmc/TextureCache.h
xbmc/TextureDatabase.cpp
xbmc/TextureDatabase.h

index 3b1108d..6fb440f 100644 (file)
@@ -221,6 +221,22 @@ void CTextureCache::ClearCachedImage(const CStdString &url, bool deleteSource /*
     CFile::Delete(path);
 }
 
+bool CTextureCache::ClearCachedImage(int id)
+{
+  CStdString cachedFile;
+  if (ClearCachedTexture(id, cachedFile))
+  {
+    cachedFile = GetCachedPath(cachedFile);
+    if (CFile::Exists(cachedFile))
+      CFile::Delete(cachedFile);
+    cachedFile = URIUtils::ReplaceExtension(cachedFile, ".dds");
+    if (CFile::Exists(cachedFile))
+      CFile::Delete(cachedFile);
+    return true;
+  }
+  return false;
+}
+
 bool CTextureCache::GetCachedTexture(const CStdString &url, CTextureDetails &details)
 {
   CSingleLock lock(m_databaseSection);
@@ -258,6 +274,12 @@ bool CTextureCache::ClearCachedTexture(const CStdString &url, CStdString &cached
   return m_database.ClearCachedTexture(url, cachedURL);
 }
 
+bool CTextureCache::ClearCachedTexture(int id, CStdString &cachedURL)
+{
+  CSingleLock lock(m_databaseSection);
+  return m_database.ClearCachedTexture(id, cachedURL);
+}
+
 CStdString CTextureCache::GetCacheFile(const CStdString &url)
 {
   Crc32 crc;
index f903339..168fb70 100644 (file)
@@ -115,6 +115,12 @@ public:
    */
   void ClearCachedImage(const CStdString &image, bool deleteSource = false);
 
+  /*! \brief clear the cached version of the image with given id
+   \param database id of the image
+   \sa GetCachedImage
+   */
+  bool ClearCachedImage(int textureID);
+
   /*! \brief retrieve a cache file (relative to the cache path) to associate with the given image, excluding extension
    Use GetCachedPath(GetCacheFile(url)+extension) for the full path to the file.
    \param url location of the image
@@ -203,6 +209,7 @@ private:
    \return true if we had a cached version of this image, false otherwise.
    */
   bool ClearCachedTexture(const CStdString &url, CStdString &cacheFile);
+  bool ClearCachedTexture(int textureID, CStdString &cacheFile);
 
   /*! \brief Increment the use count of a texture
    Stores locally before calling CTextureDatabase::IncrementUseCount via a CUseCountJob
index 4006a36..299a2c2 100644 (file)
@@ -212,21 +212,26 @@ bool CTextureDatabase::AddCachedTexture(const CStdString &url, const CTextureDet
 
 bool CTextureDatabase::ClearCachedTexture(const CStdString &url, CStdString &cacheFile)
 {
+  std::string id = GetSingleValue(PrepareSQL("select id from texture where url='%s'", url.c_str()));
+  return !id.empty() ? ClearCachedTexture(strtol(id.c_str(), NULL, 10), cacheFile) : false;
+}
+
+bool CTextureDatabase::ClearCachedTexture(int id, CStdString &cacheFile)
+{
   try
   {
     if (NULL == m_pDB.get()) return false;
     if (NULL == m_pDS.get()) return false;
 
-    CStdString sql = PrepareSQL("select id, cachedurl from texture where url='%s'", url.c_str());
+    CStdString sql = PrepareSQL("select cachedurl from texture where id=%u", id);
     m_pDS->query(sql.c_str());
 
     if (!m_pDS->eof())
     { // have some information
-      int textureID = m_pDS->fv(0).get_asInt();
-      cacheFile = m_pDS->fv(1).get_asString();
+      cacheFile = m_pDS->fv(0).get_asString();
       m_pDS->close();
       // remove it
-      sql = PrepareSQL("delete from texture where id=%u", textureID);
+      sql = PrepareSQL("delete from texture where id=%u", id);
       m_pDS->exec(sql.c_str());
       return true;
     }
@@ -234,7 +239,7 @@ bool CTextureDatabase::ClearCachedTexture(const CStdString &url, CStdString &cac
   }
   catch (...)
   {
-    CLog::Log(LOGERROR, "%s, failed on url '%s'", __FUNCTION__, url.c_str());
+    CLog::Log(LOGERROR, "%s, failed on texture id %u", __FUNCTION__, id);
   }
   return false;
 }
index 34f07bf..985c002 100644 (file)
@@ -34,6 +34,7 @@ public:
   bool AddCachedTexture(const CStdString &originalURL, const CTextureDetails &details);
   bool SetCachedTextureValid(const CStdString &originalURL, bool updateable);
   bool ClearCachedTexture(const CStdString &originalURL, CStdString &cacheFile);
+  bool ClearCachedTexture(int textureID, CStdString &cacheFile);
   bool IncrementUseCount(const CTextureDetails &details);
 
   /*! \brief Invalidate a previously cached texture