summaryrefslogtreecommitdiffstats
path: root/xbmc/pvr/PVRCachedImages.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
commitc04dcc2e7d834218ef2d4194331e383402495ae1 (patch)
tree7333e38d10d75386e60f336b80c2443c1166031d /xbmc/pvr/PVRCachedImages.cpp
parentInitial commit. (diff)
downloadkodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz
kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/pvr/PVRCachedImages.cpp')
-rw-r--r--xbmc/pvr/PVRCachedImages.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/xbmc/pvr/PVRCachedImages.cpp b/xbmc/pvr/PVRCachedImages.cpp
new file mode 100644
index 0000000..ea17fd7
--- /dev/null
+++ b/xbmc/pvr/PVRCachedImages.cpp
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2005-2021 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "PVRCachedImages.h"
+
+#include "ServiceBroker.h"
+#include "TextureCache.h"
+#include "TextureDatabase.h"
+#include "URL.h"
+#include "utils/StringUtils.h"
+#include "utils/Variant.h"
+#include "utils/log.h"
+
+#include <algorithm>
+
+using namespace PVR;
+
+int CPVRCachedImages::Cleanup(const std::vector<PVRImagePattern>& urlPatterns,
+ const std::vector<std::string>& urlsToCheck,
+ bool clearTextureForPath /* = false */)
+{
+ int iCleanedImages = 0;
+
+ if (urlPatterns.empty())
+ {
+ CLog::LogFC(LOGERROR, LOGPVR, "No URL patterns given");
+ return iCleanedImages;
+ }
+
+ CTextureDatabase db;
+ if (!db.Open())
+ {
+ CLog::LogFC(LOGERROR, LOGPVR, "Failed to open texture database");
+ return iCleanedImages;
+ }
+
+ CDatabase::Filter filter;
+
+ for (const auto& pattern : urlPatterns)
+ {
+ const std::string encodedPattern =
+ StringUtils::Format("{}@{}", pattern.owner, CURL::Encode(pattern.path));
+
+ std::string escapedPattern;
+ for (size_t i = 0; i < encodedPattern.size(); ++i)
+ {
+ if (encodedPattern[i] == '%' || encodedPattern[i] == '^')
+ escapedPattern += '^';
+
+ escapedPattern += encodedPattern[i];
+ }
+
+ const std::string where =
+ StringUtils::Format("url LIKE 'image://{}%' ESCAPE '^'", escapedPattern);
+ filter.AppendWhere(where, false); // logical OR
+ }
+
+ CVariant items;
+ if (!db.GetTextures(items, filter))
+ {
+ CLog::LogFC(LOGERROR, LOGPVR, "Failed to get items from texture database");
+ return iCleanedImages;
+ }
+
+ for (unsigned int i = 0; i < items.size(); ++i)
+ {
+ // Unwrap the image:// URL returned from texture db.
+ const std::string textureURL = UnwrapImageURL(items[i]["url"].asString());
+
+ if (std::none_of(urlsToCheck.cbegin(), urlsToCheck.cend(),
+ [&textureURL](const std::string& url) { return url == textureURL; }))
+ {
+ CLog::LogFC(LOGDEBUG, LOGPVR, "Removing stale cached image: '{}'", textureURL);
+ CServiceBroker::GetTextureCache()->ClearCachedImage(items[i]["textureid"].asInteger());
+
+ if (clearTextureForPath)
+ db.ClearTextureForPath(textureURL, "thumb");
+
+ iCleanedImages++;
+ }
+ }
+
+ return iCleanedImages;
+}
+
+std::string CPVRCachedImages::UnwrapImageURL(const std::string& url)
+{
+ return StringUtils::StartsWith(url, "image://") ? CURL(url).GetHostName() : url;
+}