#include "settings/AdvancedSettings.h"
#include "utils/log.h"
#include "utils/URIUtils.h"
+#include "utils/StringUtils.h"
#include "URL.h"
#include "utils/StringUtils.h"
return s_cache;
}
-CTextureCache::CTextureCache()
+CTextureCache::CTextureCache() : CJobQueue(false, 1, CJob::PRIORITY_LOW_PAUSABLE)
{
}
if (url != "-" && !CURL::IsFullPath(url))
return true;
if (URIUtils::IsInPath(url, "special://skin/") ||
+ URIUtils::IsInPath(url, "special://temp/") ||
URIUtils::IsInPath(url, "androidapp://") ||
URIUtils::IsInPath(url, CProfilesManager::Get().GetThumbnailsFolder()))
return true;
{
CTextureDetails details;
CStdString cachedImage(GetCachedImage(url, details));
- return (!cachedImage.IsEmpty() && cachedImage != url);
+ return (!cachedImage.empty() && cachedImage != url);
}
CStdString CTextureCache::GetCachedImage(const CStdString &image, CTextureDetails &details, bool trackUsage)
{
- CStdString url = UnwrapImageURL(image);
+ CStdString url = CTextureUtils::UnwrapImageURL(image);
if (IsCachedImage(url))
return url;
return "";
}
-CStdString CTextureCache::GetWrappedImageURL(const CStdString &image, const CStdString &type, const CStdString &options)
-{
- if (StringUtils::StartsWith(image, "image://"))
- return image; // already wrapped
-
- CURL url;
- url.SetProtocol("image");
- url.SetUserName(type);
- url.SetHostName(image);
- if (!options.IsEmpty())
- {
- url.SetFileName("transform");
- url.SetOptions("?" + options);
- }
- return url.Get();
-}
-
-CStdString CTextureCache::GetWrappedThumbURL(const CStdString &image)
-{
- return GetWrappedImageURL(image, "", "size=thumb");
-}
-
-CStdString CTextureCache::UnwrapImageURL(const CStdString &image)
-{
- if (StringUtils::StartsWith(image, "image://"))
- {
- CURL url(image);
- if (url.GetUserName().IsEmpty() && url.GetOptions().IsEmpty())
- return url.GetHostName();
- }
- return image;
-}
-
bool CTextureCache::CanCacheImageURL(const CURL &url)
{
return (url.GetUserName().empty() || url.GetUserName() == "music");
CTextureDetails details;
CStdString path(GetCachedImage(url, details, true));
needsRecaching = !details.hash.empty();
- if (!path.IsEmpty())
+ if (!path.empty())
{
if (!needsRecaching && returnDDS && !URIUtils::IsInPath(url, "special://skin/")) // TODO: should skin images be .dds'd (currently they're not necessarily writeable)
{ // check for dds version
{
CTextureDetails details;
CStdString path(GetCachedImage(url, details));
- if (!path.IsEmpty() && details.hash.empty())
+ if (!path.empty() && details.hash.empty())
return; // image is already cached and doesn't need to be checked further
// needs (re)caching
- AddJob(new CTextureCacheJob(UnwrapImageURL(url), details.hash));
+ AddJob(new CTextureCacheJob(CTextureUtils::UnwrapImageURL(url), details.hash));
}
bool CTextureCache::CacheImage(const CStdString &image, CTextureDetails &details)
CStdString CTextureCache::CacheImage(const CStdString &image, CBaseTexture **texture, CTextureDetails *details)
{
- CStdString url = UnwrapImageURL(image);
+ CStdString url = CTextureUtils::UnwrapImageURL(image);
CSingleLock lock(m_processingSection);
- if (m_processing.find(url) == m_processing.end())
+ if (m_processinglist.find(url) == m_processinglist.end())
{
- m_processing.insert(url);
+ m_processinglist.insert(url);
lock.Leave();
// cache the texture directly
CTextureCacheJob job(url);
m_completeEvent.WaitMSec(1000);
{
CSingleLock lock(m_processingSection);
- if (m_processing.find(url) == m_processing.end())
+ if (m_processinglist.find(url) == m_processinglist.end())
break;
}
}
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);
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;
crc.ComputeFromLowerCase(url);
- CStdString hex;
- hex.Format("%08x", (unsigned int)crc);
- CStdString hash;
- hash.Format("%c/%s", hex[0], hex.c_str());
+ CStdString hex = StringUtils::Format("%08x", (unsigned int)crc);
+ CStdString hash = StringUtils::Format("%c/%s", hex[0], hex.c_str());
return hash;
}
{ // remove from our processing list
CSingleLock lock(m_processingSection);
- std::set<CStdString>::iterator i = m_processing.find(job->m_url);
- if (i != m_processing.end())
- m_processing.erase(i);
+ std::set<CStdString>::iterator i = m_processinglist.find(job->m_url);
+ if (i != m_processinglist.end())
+ m_processinglist.erase(i);
}
m_completeEvent.Set();
{
CSingleLock lock(m_processingSection);
const CTextureCacheJob *cacheJob = (CTextureCacheJob *)job;
- std::set<CStdString>::iterator i = m_processing.find(cacheJob->m_url);
- if (i == m_processing.end())
+ std::set<CStdString>::iterator i = m_processinglist.find(cacheJob->m_url);
+ if (i == m_processinglist.end())
{
- m_processing.insert(cacheJob->m_url);
+ m_processinglist.insert(cacheJob->m_url);
return;
}
}
{
CTextureDetails details;
CStdString cachedImage(GetCachedImage(image, details));
- if (!cachedImage.IsEmpty())
+ if (!cachedImage.empty())
{
CStdString dest = destination + URIUtils::GetExtension(cachedImage);
if (overwrite || !CFile::Exists(dest))
{
CTextureDetails details;
CStdString cachedImage(GetCachedImage(image, details));
- if (!cachedImage.IsEmpty())
+ if (!cachedImage.empty())
{
if (CFile::Cache(cachedImage, destination))
return true;