Merge pull request #24470 from fuzzard/release_20.3
[xbmc.git] / xbmc / addons / ImageResource.cpp
blob06eada3b1aabbb109ee5841ffe8789ea94c7a603
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8 #include "ImageResource.h"
10 #include "URL.h"
11 #include "addons/addoninfo/AddonType.h"
12 #include "filesystem/XbtManager.h"
13 #include "utils/FileUtils.h"
14 #include "utils/StringUtils.h"
15 #include "utils/URIUtils.h"
17 namespace ADDON
20 CImageResource::CImageResource(const AddonInfoPtr& addonInfo)
21 : CResource(addonInfo, AddonType::RESOURCE_IMAGES)
23 m_type = Type(AddonType::RESOURCE_IMAGES)->GetValue("@type").asString();
26 void CImageResource::OnPreUnInstall()
28 CURL xbtUrl;
29 if (!HasXbt(xbtUrl))
30 return;
32 // if there's an XBT we need to remove it from the XBT manager
33 XFILE::CXbtManager::GetInstance().Release(xbtUrl);
36 bool CImageResource::IsAllowed(const std::string &file) const
38 // check if the file path points to a directory
39 if (URIUtils::HasSlashAtEnd(file, true))
40 return true;
42 std::string ext = URIUtils::GetExtension(file);
43 return file.empty() ||
44 StringUtils::EqualsNoCase(ext, ".png") ||
45 StringUtils::EqualsNoCase(ext, ".jpg");
48 std::string CImageResource::GetFullPath(const std::string &filePath) const
50 // check if there's an XBT file which might contain the file. if not just return the usual full path
51 CURL xbtUrl;
52 if (!HasXbt(xbtUrl))
53 return CResource::GetFullPath(filePath);
55 // append the file path to the xbt:// URL
56 return URIUtils::AddFileToFolder(xbtUrl.Get(), filePath);
59 bool CImageResource::HasXbt(CURL& xbtUrl) const
61 std::string resourcePath = GetResourcePath();
62 std::string xbtPath = URIUtils::AddFileToFolder(resourcePath, "Textures.xbt");
63 if (!CFileUtils::Exists(xbtPath))
64 return false;
66 // translate it into a xbt:// URL
67 xbtUrl = URIUtils::CreateArchivePath("xbt", CURL(xbtPath));
69 return true;
72 } /* namespace ADDON */