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.
8 #include "ImageResource.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"
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()
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))
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
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
))
66 // translate it into a xbt:// URL
67 xbtUrl
= URIUtils::CreateArchivePath("xbt", CURL(xbtPath
));
72 } /* namespace ADDON */