diff options
author | Kai Sommerfeld <kai.sommerfeld@gmx.com> | 2022-10-18 08:51:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-18 08:51:06 +0200 |
commit | 07c0601ee8c3db81c0561f79a4f92d770ec9346b (patch) | |
tree | 8b672d0f9e877712eead4df93a724783fa30aecd | |
parent | 678e3f80cbbfeecbef56e0b0a3d7db4334920f21 (diff) | |
parent | dabf32d27b79e2bdf39ff2623a66518677eb9669 (diff) |
Merge pull request #22033 from ksooo/addons-optimize-headers-2
[addons] Optimize compile time dependencies, round 2
154 files changed, 2010 insertions, 1761 deletions
diff --git a/xbmc/ContextMenuItem.cpp b/xbmc/ContextMenuItem.cpp index e032f2ddb4..9191cb1770 100644 --- a/xbmc/ContextMenuItem.cpp +++ b/xbmc/ContextMenuItem.cpp @@ -53,8 +53,7 @@ bool CContextMenuItem::Execute(const std::shared_ptr<CFileItem>& item) const return false; ADDON::AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(m_addonId, addon, ADDON::ADDON_UNKNOWN, - ADDON::OnlyEnabled::CHOICE_YES)) + if (!CServiceBroker::GetAddonMgr().GetAddon(m_addonId, addon, ADDON::OnlyEnabled::CHOICE_YES)) return false; bool reuseLanguageInvoker = false; diff --git a/xbmc/ContextMenuManager.cpp b/xbmc/ContextMenuManager.cpp index 00229b125f..154f4c85c0 100644 --- a/xbmc/ContextMenuManager.cpp +++ b/xbmc/ContextMenuManager.cpp @@ -18,11 +18,13 @@ #include "addons/ContextMenuAddon.h" #include "addons/ContextMenus.h" #include "addons/IAddon.h" +#include "addons/addoninfo/AddonType.h" #include "dialogs/GUIDialogContextMenu.h" #include "favourites/ContextMenus.h" #include "messaging/ApplicationMessenger.h" #include "music/ContextMenus.h" #include "pvr/PVRContextMenus.h" +#include "utils/StringUtils.h" #include "utils/log.h" #include "video/ContextMenus.h" @@ -98,7 +100,7 @@ void CContextMenuManager::Init() void CContextMenuManager::ReloadAddonItems() { VECADDONS addons; - m_addonMgr.GetAddons(addons, ADDON_CONTEXT_ITEM); + m_addonMgr.GetAddons(addons, AddonType::CONTEXTMENU_ITEM); std::vector<CContextMenuItem> addonItems; for (const auto& addon : addons) @@ -128,7 +130,8 @@ void CContextMenuManager::OnEvent(const ADDON::AddonEvent& event) else if (typeid(event) == typeid(AddonEvents::Enabled)) { AddonPtr addon; - if (m_addonMgr.GetAddon(event.addonId, addon, ADDON_CONTEXT_ITEM, OnlyEnabled::CHOICE_YES)) + if (m_addonMgr.GetAddon(event.addonId, addon, AddonType::CONTEXTMENU_ITEM, + OnlyEnabled::CHOICE_YES)) { std::unique_lock<CCriticalSection> lock(m_criticalSection); auto items = std::static_pointer_cast<CContextMenuAddon>(addon)->GetItems(); @@ -143,7 +146,7 @@ void CContextMenuManager::OnEvent(const ADDON::AddonEvent& event) } else if (typeid(event) == typeid(AddonEvents::Disabled)) { - if (m_addonMgr.HasType(event.addonId, ADDON_CONTEXT_ITEM)) + if (m_addonMgr.HasType(event.addonId, AddonType::CONTEXTMENU_ITEM)) { ReloadAddonItems(); } diff --git a/xbmc/LangInfo.cpp b/xbmc/LangInfo.cpp index 1db7f79084..db85aa555e 100644 --- a/xbmc/LangInfo.cpp +++ b/xbmc/LangInfo.cpp @@ -9,10 +9,12 @@ #include "LangInfo.h" #include "ServiceBroker.h" +#include "XBDateTime.h" #include "addons/AddonInstaller.h" #include "addons/AddonManager.h" #include "addons/LanguageResource.h" #include "addons/RepositoryUpdater.h" +#include "addons/addoninfo/AddonType.h" #include "guilib/LocalizeStrings.h" #include "messaging/ApplicationMessenger.h" #include "pvr/PVRManager.h" @@ -651,7 +653,7 @@ std::string CLangInfo::GetSubtitleCharSet() const void CLangInfo::GetAddonsLanguageCodes(std::map<std::string, std::string>& languages) { ADDON::VECADDONS addons; - CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON::ADDON_RESOURCE_LANGUAGE); + CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON::AddonType::RESOURCE_LANGUAGE); for (const auto& addon : addons) { const LanguageResourcePtr langAddon = @@ -673,7 +675,7 @@ LanguageResourcePtr CLangInfo::GetLanguageAddon(const std::string& locale /* = " addonId = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_LOCALE_LANGUAGE); ADDON::AddonPtr addon; - if (CServiceBroker::GetAddonMgr().GetAddon(addonId, addon, ADDON::ADDON_RESOURCE_LANGUAGE, + if (CServiceBroker::GetAddonMgr().GetAddon(addonId, addon, ADDON::AddonType::RESOURCE_LANGUAGE, ADDON::OnlyEnabled::CHOICE_YES) && addon != NULL) return std::dynamic_pointer_cast<ADDON::CLanguageResource>(addon); @@ -684,7 +686,7 @@ LanguageResourcePtr CLangInfo::GetLanguageAddon(const std::string& locale /* = " std::string CLangInfo::ConvertEnglishNameToAddonLocale(const std::string& langName) { ADDON::VECADDONS addons; - CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON::ADDON_RESOURCE_LANGUAGE); + CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON::AddonType::RESOURCE_LANGUAGE); for (const auto& addon : addons) { if (StringUtils::CompareNoCase(addon->Name(), langName) == 0) @@ -717,7 +719,7 @@ bool CLangInfo::SetLanguage(std::string language /* = "" */, bool reloadServices ADDON::AddonPtr addon; // Find the chosen language add-on if it's enabled - if (!addonMgr.GetAddon(language, addon, ADDON::ADDON_RESOURCE_LANGUAGE, + if (!addonMgr.GetAddon(language, addon, ADDON::AddonType::RESOURCE_LANGUAGE, ADDON::OnlyEnabled::CHOICE_YES)) { if (!addonMgr.IsAddonInstalled(language) || @@ -731,7 +733,7 @@ bool CLangInfo::SetLanguage(std::string language /* = "" */, bool reloadServices CSettings::SETTING_LOCALE_LANGUAGE)) ->GetDefault(); - if (!addonMgr.GetAddon(language, addon, ADDON::ADDON_RESOURCE_LANGUAGE, + if (!addonMgr.GetAddon(language, addon, ADDON::AddonType::RESOURCE_LANGUAGE, ADDON::OnlyEnabled::CHOICE_NO)) { CLog::Log(LOGFATAL, "CLangInfo::{}: could not find default language add-on '{}'", __func__, @@ -1185,7 +1187,7 @@ void CLangInfo::SettingOptionsLanguageNamesFiller(const SettingConstPtr& setting { // find languages... ADDON::VECADDONS addons; - if (!CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON::ADDON_RESOURCE_LANGUAGE)) + if (!CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON::AddonType::RESOURCE_LANGUAGE)) return; for (const auto &addon : addons) diff --git a/xbmc/NfoFile.cpp b/xbmc/NfoFile.cpp index 84318d18f1..98a49b5091 100644 --- a/xbmc/NfoFile.cpp +++ b/xbmc/NfoFile.cpp @@ -15,6 +15,7 @@ #include "ServiceBroker.h" #include "addons/AddonManager.h" #include "addons/AddonSystemSettings.h" +#include "addons/addoninfo/AddonType.h" #include "filesystem/File.h" #include "music/Album.h" #include "music/Artist.h" @@ -37,23 +38,23 @@ CInfoScanner::INFO_TYPE CNfoFile::Create(const std::string& strPath, CFileItemList items; bool bNfo=false; - if (m_type == ADDON_SCRAPER_ALBUMS) + if (m_type == AddonType::SCRAPER_ALBUMS) { CAlbum album; bNfo = GetDetails(album); } - else if (m_type == ADDON_SCRAPER_ARTISTS) + else if (m_type == AddonType::SCRAPER_ARTISTS) { CArtist artist; bNfo = GetDetails(artist); } - else if (m_type == ADDON_SCRAPER_TVSHOWS || m_type == ADDON_SCRAPER_MOVIES - || m_type == ADDON_SCRAPER_MUSICVIDEOS) + else if (m_type == AddonType::SCRAPER_TVSHOWS || m_type == AddonType::SCRAPER_MOVIES || + m_type == AddonType::SCRAPER_MUSICVIDEOS) { // first check if it's an XML file with the info we need CVideoInfoTag details; bNfo = GetDetails(details); - if (episode > -1 && bNfo && m_type == ADDON_SCRAPER_TVSHOWS) + if (episode > -1 && bNfo && m_type == AddonType::SCRAPER_TVSHOWS) { int infos=0; while (m_headPos != std::string::npos && details.m_iEpisode != episode) @@ -149,7 +150,7 @@ void CNfoFile::Close() m_scurl.Clear(); } -std::vector<ScraperPtr> CNfoFile::GetScrapers(TYPE type, const ScraperPtr& selectedScraper) +std::vector<ScraperPtr> CNfoFile::GetScrapers(AddonType type, const ScraperPtr& selectedScraper) { AddonPtr addon; ScraperPtr defaultScraper; diff --git a/xbmc/NfoFile.h b/xbmc/NfoFile.h index de81ab0a54..9b97f2a3ab 100644 --- a/xbmc/NfoFile.h +++ b/xbmc/NfoFile.h @@ -20,6 +20,11 @@ #include <utility> #include <vector> +namespace ADDON +{ +enum class AddonType; +} + class CNfoFile { public: @@ -50,14 +55,14 @@ public: static int Scrape(ADDON::ScraperPtr& scraper, CScraperUrl& url, const std::string& content); - static std::vector<ADDON::ScraperPtr> GetScrapers(ADDON::TYPE type, + static std::vector<ADDON::ScraperPtr> GetScrapers(ADDON::AddonType type, const ADDON::ScraperPtr& selectedScraper); private: std::string m_doc; size_t m_headPos = 0; ADDON::ScraperPtr m_info; - ADDON::TYPE m_type = ADDON::ADDON_UNKNOWN; + ADDON::AddonType m_type{}; CScraperUrl m_scurl; int Load(const std::string&); diff --git a/xbmc/Util.cpp b/xbmc/Util.cpp index 8ee176ebc6..fabfd1b071 100644 --- a/xbmc/Util.cpp +++ b/xbmc/Util.cpp @@ -1167,8 +1167,7 @@ std::string CUtil::GetExecProviderLabelFromPath(const std::string& path) const std::string plugin = pathIsAddonID ? path : CURL(path).GetHostName(); ADDON::AddonPtr addon; - CServiceBroker::GetAddonMgr().GetAddon(plugin, addon, ADDON::ADDON_UNKNOWN, - ADDON::OnlyEnabled::CHOICE_NO); + CServiceBroker::GetAddonMgr().GetAddon(plugin, addon, ADDON::OnlyEnabled::CHOICE_NO); if (addon) provider = addon->Name(); } diff --git a/xbmc/addons/Addon.cpp b/xbmc/addons/Addon.cpp index eb1d0e2b68..90669bb10e 100644 --- a/xbmc/addons/Addon.cpp +++ b/xbmc/addons/Addon.cpp @@ -8,10 +8,11 @@ #include "Addon.h" -#include "AddonManager.h" -#include "RepositoryUpdater.h" #include "ServiceBroker.h" +#include "addons/AddonManager.h" +#include "addons/RepositoryUpdater.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "addons/settings/AddonSettings.h" #include "filesystem/Directory.h" #include "filesystem/File.h" @@ -38,27 +39,28 @@ using XFILE::CFile; namespace ADDON { -CAddon::CAddon(const AddonInfoPtr& addonInfo, TYPE addonType) - : m_addonInfo(addonInfo), m_type(addonType == ADDON_UNKNOWN ? addonInfo->MainType() : addonType) +CAddon::CAddon(const AddonInfoPtr& addonInfo, AddonType addonType) + : m_addonInfo(addonInfo), + m_type(addonType == AddonType::UNKNOWN ? addonInfo->MainType() : addonType) { } -TYPE CAddon::MainType() const +AddonType CAddon::MainType() const { return m_addonInfo->MainType(); } -bool CAddon::HasType(TYPE type) const +bool CAddon::HasType(AddonType type) const { return m_addonInfo->HasType(type); } -bool CAddon::HasMainType(TYPE type) const +bool CAddon::HasMainType(AddonType type) const { return m_addonInfo->HasType(type, true); } -const CAddonType* CAddon::Type(TYPE type) const +const CAddonType* CAddon::Type(AddonType type) const { return m_addonInfo->Type(type); } @@ -78,12 +80,12 @@ bool CAddon::IsBinary() const return m_addonInfo->IsBinary(); } -AddonVersion CAddon::Version() const +CAddonVersion CAddon::Version() const { return m_addonInfo->Version(); } -AddonVersion CAddon::MinVersion() const +CAddonVersion CAddon::MinVersion() const { return m_addonInfo->MinVersion(); } @@ -194,7 +196,7 @@ std::string CAddon::FanArt() const return it != m_addonInfo->Art().end() ? it->second : ""; } -bool CAddon::MeetsVersion(const AddonVersion& versionMin, const AddonVersion& version) const +bool CAddon::MeetsVersion(const CAddonVersion& versionMin, const CAddonVersion& version) const { return m_addonInfo->MeetsVersion(versionMin, version); } @@ -647,7 +649,7 @@ std::string CAddon::LibPath() const return URIUtils::AddFileToFolder(m_addonInfo->Path(), libName); } -AddonVersion CAddon::GetDependencyVersion(const std::string& dependencyID) const +CAddonVersion CAddon::GetDependencyVersion(const std::string& dependencyID) const { return m_addonInfo->DependencyVersion(dependencyID); } diff --git a/xbmc/addons/Addon.h b/xbmc/addons/Addon.h index e9c21387de..a09b8db80f 100644 --- a/xbmc/addons/Addon.h +++ b/xbmc/addons/Addon.h @@ -20,14 +20,12 @@ class CXBMCTinyXML; namespace ADDON { -typedef std::vector<AddonPtr> VECADDONS; -typedef std::vector<AddonPtr>::iterator IVECADDONS; +enum class AddonType; +class CAddonType; class CAddonInfo; using AddonInfoPtr = std::shared_ptr<CAddonInfo>; -const char* const ORIGIN_SYSTEM = "b6a50484-93a0-4afb-a01c-8d17e059feda"; - void OnPreInstall(const AddonPtr& addon); void OnPostInstall(const AddonPtr& addon, bool update, bool modal); void OnPreUnInstall(const AddonPtr& addon); @@ -36,7 +34,7 @@ void OnPostUnInstall(const AddonPtr& addon); class CAddon : public IAddon { public: - explicit CAddon(const AddonInfoPtr& addonInfo, TYPE addonType); + explicit CAddon(const AddonInfoPtr& addonInfo, AddonType addonType); ~CAddon() override = default; /** @@ -47,14 +45,14 @@ public: * * @return The used main type of addon */ - TYPE MainType() const override; + AddonType MainType() const override; /** * @brief To get the on this CAddon class processed addon type * * @return For this class used addon type */ - TYPE Type() const override { return m_type; } + AddonType Type() const override { return m_type; } /** * @brief To check complete addon (not only this) contains a type @@ -65,7 +63,7 @@ public: * @param[in] type The to checked type identifier * @return true in case the wanted type is supported, false if not */ - bool HasType(TYPE type) const override; + bool HasType(AddonType type) const override; /** * @brief To check complete addon (not only this) has a specific type @@ -75,7 +73,7 @@ public: * @param[in] type Type identifier to be checked * @return true in case the wanted type is the main type, false if not */ - bool HasMainType(TYPE type) const override; + bool HasMainType(AddonType type) const override; /** * @brief The get for given addon type information and extension data @@ -95,14 +93,14 @@ public: * ~~~~~~~~~~~~~ * */ - const CAddonType* Type(TYPE type) const; + const CAddonType* Type(AddonType type) const; std::string ID() const override; std::string Name() const override; bool IsInUse() const override { return false; } bool IsBinary() const override; - AddonVersion Version() const override; - AddonVersion MinVersion() const override; + CAddonVersion Version() const override; + CAddonVersion MinVersion() const override; std::string Summary() const override; std::string Description() const override; std::string Path() const override; @@ -368,13 +366,13 @@ public: \param dependencyID the addon ID of the dependency. \return the version this addon requires. */ - AddonVersion GetDependencyVersion(const std::string& dependencyID) const override; + CAddonVersion GetDependencyVersion(const std::string& dependencyID) const override; /*! \brief return whether or not this addon satisfies the given version requirements \param version the version to meet. \return true if min_version <= version <= current_version, false otherwise. */ - bool MeetsVersion(const AddonVersion& versionMin, const AddonVersion& version) const override; + bool MeetsVersion(const CAddonVersion& versionMin, const CAddonVersion& version) const override; bool ReloadSettings(AddonInstanceId id = ADDON_SETTINGS_ID) override; @@ -486,7 +484,7 @@ private: std::shared_ptr<CAddonSettings> FindInstanceSettings(AddonInstanceId id) const; mutable std::unordered_map<AddonInstanceId, CSettingsData> m_settings; - const TYPE m_type; + const AddonType m_type; }; }; // namespace ADDON diff --git a/xbmc/addons/AddonBuilder.cpp b/xbmc/addons/AddonBuilder.cpp index 3ca26536c9..7d52ee0431 100644 --- a/xbmc/addons/AddonBuilder.cpp +++ b/xbmc/addons/AddonBuilder.cpp @@ -22,6 +22,7 @@ #include "addons/UISoundsResource.h" #include "addons/Webinterface.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "games/addons/GameClient.h" #include "games/controllers/Controller.h" #include "pvr/addons/PVRClient.h" @@ -32,18 +33,18 @@ using namespace KODI; namespace ADDON { -AddonPtr CAddonBuilder::Generate(const AddonInfoPtr& info, TYPE type) +AddonPtr CAddonBuilder::Generate(const AddonInfoPtr& info, AddonType type) { if (!info || info->ID().empty()) return AddonPtr(); - if (type == ADDON_UNKNOWN) + if (type == AddonType::UNKNOWN) type = info->MainType(); - if (type == ADDON_UNKNOWN) - return std::make_shared<CAddon>(info, ADDON_UNKNOWN); + if (type == AddonType::UNKNOWN) + return std::make_shared<CAddon>(info, AddonType::UNKNOWN); // Handle screensaver special cases - if (type == ADDON_SCREENSAVER) + if (type == AddonType::SCREENSAVER) { // built in screensaver or python screensaver if (StringUtils::StartsWithNoCase(info->ID(), "screensaver.xbmc.builtin.") || @@ -52,7 +53,7 @@ AddonPtr CAddonBuilder::Generate(const AddonInfoPtr& info, TYPE type) } // Handle audio encoder special cases - if (type == ADDON_AUDIOENCODER) + if (type == AddonType::AUDIOENCODER) { // built in audio encoder if (StringUtils::StartsWithNoCase(info->ID(), "audioencoder.kodi.builtin.")) @@ -61,58 +62,58 @@ AddonPtr CAddonBuilder::Generate(const AddonInfoPtr& info, TYPE type) switch (type) { - case ADDON_AUDIODECODER: - case ADDON_AUDIOENCODER: - case ADDON_IMAGEDECODER: - case ADDON_INPUTSTREAM: - case ADDON_PERIPHERALDLL: - case ADDON_PVRDLL: - case ADDON_VFS: - case ADDON_VIZ: - case ADDON_SCREENSAVER: - return std::make_shared<CAddonDll>(info, type); - case ADDON_GAMEDLL: - return std::make_shared<GAME::CGameClient>(info); - case ADDON_PLUGIN: - case ADDON_SCRIPT: - return std::make_shared<CPluginSource>(info, type); - case ADDON_SCRIPT_LIBRARY: - case ADDON_SCRIPT_LYRICS: - case ADDON_SCRIPT_MODULE: - case ADDON_SUBTITLE_MODULE: - case ADDON_SCRIPT_WEATHER: - return std::make_shared<CAddon>(info, type); - case ADDON_WEB_INTERFACE: - return std::make_shared<CWebinterface>(info); - case ADDON_SERVICE: - return std::make_shared<CService>(info); - case ADDON_SCRAPER_ALBUMS: - case ADDON_SCRAPER_ARTISTS: - case ADDON_SCRAPER_MOVIES: - case ADDON_SCRAPER_MUSICVIDEOS: - case ADDON_SCRAPER_TVSHOWS: - case ADDON_SCRAPER_LIBRARY: - return std::make_shared<CScraper>(info, type); - case ADDON_SKIN: - return std::make_shared<CSkinInfo>(info); - case ADDON_RESOURCE_FONT: - return std::make_shared<CFontResource>(info); - case ADDON_RESOURCE_IMAGES: - return std::make_shared<CImageResource>(info); - case ADDON_RESOURCE_GAMES: - return std::make_shared<CGameResource>(info); - case ADDON_RESOURCE_LANGUAGE: - return std::make_shared<CLanguageResource>(info); - case ADDON_RESOURCE_UISOUNDS: - return std::make_shared<CUISoundsResource>(info); - case ADDON_REPOSITORY: - return std::make_shared<CRepository>(info); - case ADDON_CONTEXT_ITEM: - return std::make_shared<CContextMenuAddon>(info); - case ADDON_GAME_CONTROLLER: - return std::make_shared<GAME::CController>(info); - default: - break; + case AddonType::AUDIODECODER: + case AddonType::AUDIOENCODER: + case AddonType::IMAGEDECODER: + case AddonType::INPUTSTREAM: + case AddonType::PERIPHERALDLL: + case AddonType::PVRDLL: + case AddonType::VFS: + case AddonType::VISUALIZATION: + case AddonType::SCREENSAVER: + return std::make_shared<CAddonDll>(info, type); + case AddonType::GAMEDLL: + return std::make_shared<GAME::CGameClient>(info); + case AddonType::PLUGIN: + case AddonType::SCRIPT: + return std::make_shared<CPluginSource>(info, type); + case AddonType::SCRIPT_LIBRARY: + case AddonType::SCRIPT_LYRICS: + case AddonType::SCRIPT_MODULE: + case AddonType::SUBTITLE_MODULE: + case AddonType::SCRIPT_WEATHER: + return std::make_shared<CAddon>(info, type); + case AddonType::WEB_INTERFACE: + return std::make_shared<CWebinterface>(info); + case AddonType::SERVICE: + return std::make_shared<CService>(info); + case AddonType::SCRAPER_ALBUMS: + case AddonType::SCRAPER_ARTISTS: + case AddonType::SCRAPER_MOVIES: + case AddonType::SCRAPER_MUSICVIDEOS: + case AddonType::SCRAPER_TVSHOWS: + case AddonType::SCRAPER_LIBRARY: + return std::make_shared<CScraper>(info, type); + case AddonType::SKIN: + return std::make_shared<CSkinInfo>(info); + case AddonType::RESOURCE_FONT: + return std::make_shared<CFontResource>(info); + case AddonType::RESOURCE_IMAGES: + return std::make_shared<CImageResource>(info); + case AddonType::RESOURCE_GAMES: + return std::make_shared<CGameResource>(info); + case AddonType::RESOURCE_LANGUAGE: + return std::make_shared<CLanguageResource>(info); + case AddonType::RESOURCE_UISOUNDS: + return std::make_shared<CUISoundsResource>(info); + case AddonType::REPOSITORY: + return std::make_shared<CRepository>(info); + case AddonType::CONTEXTMENU_ITEM: + return std::make_shared<CContextMenuAddon>(info); + case AddonType::GAME_CONTROLLER: + return std::make_shared<GAME::CController>(info); + default: + break; } return AddonPtr(); } diff --git a/xbmc/addons/AddonBuilder.h b/xbmc/addons/AddonBuilder.h index 374e609b43..dfc486548d 100644 --- a/xbmc/addons/AddonBuilder.h +++ b/xbmc/addons/AddonBuilder.h @@ -8,12 +8,11 @@ #pragma once -#include "addons/addoninfo/AddonType.h" - #include <memory> namespace ADDON { +enum class AddonType; class IAddon; using AddonPtr = std::shared_ptr<IAddon>; @@ -24,7 +23,7 @@ using AddonInfoPtr = std::shared_ptr<CAddonInfo>; class CAddonBuilder { public: - static AddonPtr Generate(const AddonInfoPtr& info, TYPE type); + static AddonPtr Generate(const AddonInfoPtr& info, AddonType type); }; } // namespace ADDON diff --git a/xbmc/addons/AddonDatabase.cpp b/xbmc/addons/AddonDatabase.cpp index ca2fa813a4..dbbf204322 100644 --- a/xbmc/addons/AddonDatabase.cpp +++ b/xbmc/addons/AddonDatabase.cpp @@ -12,6 +12,7 @@ #include "addons/AddonBuilder.h" #include "addons/addoninfo/AddonInfo.h" #include "addons/addoninfo/AddonInfoBuilder.h" +#include "addons/addoninfo/AddonType.h" #include "dbwrappers/dataset.h" #include "filesystem/SpecialProtocol.h" #include "utils/JSONVariantParser.h" @@ -109,7 +110,7 @@ CVariant CAddonDatabaseSerializer::SerializeExtensions(const CAddonExtensions& a } void CAddonDatabaseSerializer::DeserializeMetadata(const std::string& document, - CAddonInfoBuilder::CFromDB& builder) + CAddonInfoBuilderFromDB& builder) { CVariant variant; if (!CJSONVariantParser::Parse(document, variant)) @@ -144,8 +145,8 @@ void CAddonDatabaseSerializer::DeserializeMetadata(const std::string& document, std::vector<DependencyInfo> deps; for (auto it = variant["dependencies"].begin_array(); it != variant["dependencies"].end_array(); ++it) { - deps.emplace_back((*it)["addonId"].asString(), AddonVersion((*it)["minversion"].asString()), - AddonVersion((*it)["version"].asString()), (*it)["optional"].asBoolean()); + deps.emplace_back((*it)["addonId"].asString(), CAddonVersion((*it)["minversion"].asString()), + CAddonVersion((*it)["version"].asString()), (*it)["optional"].asBoolean()); } builder.SetDependencies(std::move(deps)); } @@ -546,9 +547,9 @@ bool CAddonDatabase::FindByAddonId(const std::string& addonId, ADDON::VECADDONS& while (!m_pDS->eof()) { - CAddonInfoBuilder::CFromDB builder; + CAddonInfoBuilderFromDB builder; builder.SetId(addonId); - builder.SetVersion(AddonVersion(m_pDS->fv("version").get_asString())); + builder.SetVersion(CAddonVersion(m_pDS->fv("version").get_asString())); builder.SetName(m_pDS->fv("name").get_asString()); builder.SetSummary(m_pDS->fv("summary").get_asString()); builder.SetDescription(m_pDS->fv("description").get_asString()); @@ -556,7 +557,7 @@ bool CAddonDatabase::FindByAddonId(const std::string& addonId, ADDON::VECADDONS& builder.SetChangelog(m_pDS->fv("news").get_asString()); builder.SetOrigin(m_pDS->fv("repoID").get_asString()); - auto addon = CAddonBuilder::Generate(builder.get(), ADDON_UNKNOWN); + auto addon = CAddonBuilder::Generate(builder.get(), AddonType::UNKNOWN); if (addon) addons.push_back(std::move(addon)); else @@ -574,7 +575,10 @@ bool CAddonDatabase::FindByAddonId(const std::string& addonId, ADDON::VECADDONS& return false; } -bool CAddonDatabase::GetAddon(const std::string& addonID, const AddonVersion& version, const std::string& repoId, AddonPtr& addon) +bool CAddonDatabase::GetAddon(const std::string& addonID, + const CAddonVersion& version, + const std::string& repoId, + AddonPtr& addon) { try { @@ -621,16 +625,16 @@ bool CAddonDatabase::GetAddon(int id, AddonPtr &addon) if (m_pDS2->eof()) return false; - CAddonInfoBuilder::CFromDB builder; + CAddonInfoBuilderFromDB builder; builder.SetId(m_pDS2->fv("addonID").get_asString()); builder.SetOrigin(m_pDS2->fv("origin").get_asString()); - builder.SetVersion(AddonVersion(m_pDS2->fv("version").get_asString())); + builder.SetVersion(CAddonVersion(m_pDS2->fv("version").get_asString())); builder.SetName(m_pDS2->fv("name").get_asString()); builder.SetSummary(m_pDS2->fv("summary").get_asString()); builder.SetDescription(m_pDS2->fv("description").get_asString()); CAddonDatabaseSerializer::DeserializeMetadata(m_pDS2->fv("metadata").get_asString(), builder); - addon = CAddonBuilder::Generate(builder.get(), ADDON_UNKNOWN); + addon = CAddonBuilder::Generate(builder.get(), AddonType::UNKNOWN); return addon != nullptr; } @@ -710,9 +714,9 @@ bool CAddonDatabase::GetRepositoryContent(const std::string& id, VECADDONS& addo while (!m_pDS->eof()) { std::string addonId = m_pDS->fv("addonID").get_asString(); - AddonVersion version(m_pDS->fv("version").get_asString()); + CAddonVersion version(m_pDS->fv("version").get_asString()); - CAddonInfoBuilder::CFromDB builder; + CAddonInfoBuilderFromDB builder; builder.SetId(addonId); builder.SetVersion(version); builder.SetName(m_pDS->fv("name").get_asString()); @@ -721,7 +725,7 @@ bool CAddonDatabase::GetRepositoryContent(const std::string& id, VECADDONS& addo builder.SetOrigin(m_pDS->fv("repoID").get_asString()); CAddonDatabaseSerializer::DeserializeMetadata(m_pDS->fv("metadata").get_asString(), builder); - auto addon = CAddonBuilder::Generate(builder.get(), ADDON_UNKNOWN); + auto addon = CAddonBuilder::Generate(builder.get(), AddonType::UNKNOWN); if (addon) { result.emplace_back(std::move(addon)); @@ -804,7 +808,7 @@ int CAddonDatabase::GetRepositoryId(const std::string& addonId) } bool CAddonDatabase::UpdateRepositoryContent(const std::string& repository, - const AddonVersion& version, + const CAddonVersion& version, const std::string& checksum, const std::vector<AddonInfoPtr>& addons) { @@ -893,7 +897,7 @@ CAddonDatabase::RepoUpdateData CAddonDatabase::GetRepoUpdateData(const std::stri if (!m_pDS->eof()) { result.lastCheckedAt.SetFromDBDateTime(m_pDS->fv("lastcheck").get_asString()); - result.lastCheckedVersion = AddonVersion(m_pDS->fv("version").get_asString()); + result.lastCheckedVersion = CAddonVersion(m_pDS->fv("version").get_asString()); result.nextCheckAt.SetFromDBDateTime(m_pDS->fv("nextcheck").get_asString()); } } @@ -970,7 +974,8 @@ bool CAddonDatabase::Search(const std::string& search, VECADDONS& addons) { AddonPtr addon; GetAddon(m_pDS->fv("id").get_asInt(), addon); - if (addon->Type() >= ADDON_UNKNOWN+1 && addon->Type() < ADDON_SCRAPER_LIBRARY) + if (static_cast<int>(addon->Type()) >= static_cast<int>(AddonType::UNKNOWN) + 1 && + static_cast<int>(addon->Type()) < static_cast<int>(AddonType::SCRAPER_LIBRARY)) addons.push_back(addon); m_pDS->next(); } diff --git a/xbmc/addons/AddonDatabase.h b/xbmc/addons/AddonDatabase.h index 76750440dd..72caa8564b 100644 --- a/xbmc/addons/AddonDatabase.h +++ b/xbmc/addons/AddonDatabase.h @@ -10,9 +10,11 @@ #include "XBDateTime.h" #include "addons/AddonVersion.h" -#include "addons/addoninfo/AddonInfoBuilder.h" #include "dbwrappers/Database.h" +#include <map> +#include <memory> +#include <set> #include <string> #include <vector> @@ -24,6 +26,16 @@ namespace ADDON enum class AddonDisabledReason; enum class AddonUpdateRule; +class CAddonExtensions; +class CAddonInfoBuilderFromDB; + +class CAddonInfo; +using AddonInfoPtr = std::shared_ptr<CAddonInfo>; + +class IAddon; +using AddonPtr = std::shared_ptr<IAddon>; +using VECADDONS = std::vector<AddonPtr>; + /*! * @brief Addon content serializer/deserializer. * @@ -39,7 +51,7 @@ class CAddonDatabaseSerializer public: static std::string SerializeMetadata(const CAddonInfo& addon); - static void DeserializeMetadata(const std::string& document, CAddonInfoBuilder::CFromDB& builder); + static void DeserializeMetadata(const std::string& document, CAddonInfoBuilderFromDB& builder); private: static CVariant SerializeExtensions(const CAddonExtensions& addonType); @@ -54,7 +66,10 @@ public: bool Open() override; /*! \brief Get an addon with a specific version and repository. */ - bool GetAddon(const std::string& addonID, const ADDON::AddonVersion& version, const std::string& repoId, ADDON::AddonPtr& addon); + bool GetAddon(const std::string& addonID, + const ADDON::CAddonVersion& version, + const std::string& repoId, + ADDON::AddonPtr& addon); /*! Get the addon IDs that have been set to disabled */ bool GetDisabled(std::map<std::string, ADDON::AddonDisabledReason>& addons); @@ -63,7 +78,7 @@ public: bool FindByAddonId(const std::string& addonId, ADDON::VECADDONS& addons) const; bool UpdateRepositoryContent(const std::string& repositoryId, - const ADDON::AddonVersion& version, + const ADDON::CAddonVersion& version, const std::string& checksum, const std::vector<AddonInfoPtr>& addons); @@ -84,14 +99,14 @@ public: /*! \brief last time the repo was checked, or invalid CDateTime if never checked */ CDateTime lastCheckedAt; /*! \brief last version of the repo add-on that was checked, or empty if never checked */ - ADDON::AddonVersion lastCheckedVersion{""}; + ADDON::CAddonVersion lastCheckedVersion{""}; /*! \brief next time the repo should be checked, or invalid CDateTime if unknown */ CDateTime nextCheckAt; RepoUpdateData() = default; RepoUpdateData(const CDateTime& lastCheckedAt, - const ADDON::AddonVersion& lastCheckedVersion, + const ADDON::CAddonVersion& lastCheckedVersion, const CDateTime& nextCheckAt) : lastCheckedAt{lastCheckedAt}, lastCheckedVersion{lastCheckedVersion}, diff --git a/xbmc/addons/AddonEvents.h b/xbmc/addons/AddonEvents.h index 0d9d4ce7ee..8db032c78c 100644 --- a/xbmc/addons/AddonEvents.h +++ b/xbmc/addons/AddonEvents.h @@ -8,7 +8,7 @@ #pragma once -#include "IAddon.h" +#include "addons/IAddon.h" #include <string> diff --git a/xbmc/addons/AddonInstaller.cpp b/xbmc/addons/AddonInstaller.cpp index 92a8213403..0a0d1694dd 100644 --- a/xbmc/addons/AddonInstaller.cpp +++ b/xbmc/addons/AddonInstaller.cpp @@ -12,14 +12,15 @@ #include "FilesystemInstaller.h" #include "GUIPassword.h" #include "GUIUserMessages.h" // for callback -#include "RepositoryUpdater.h" #include "ServiceBroker.h" #include "URL.h" #include "Util.h" #include "addons/AddonManager.h" #include "addons/AddonRepos.h" #include "addons/Repository.h" +#include "addons/RepositoryUpdater.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "dialogs/GUIDialogExtendedProgressBar.h" #include "events/AddonManagementEvent.h" #include "events/EventLog.h" @@ -250,7 +251,7 @@ bool CAddonInstaller::InstallModal(const std::string& addonID, return false; // we assume that addons that are enabled don't get to this routine (i.e. that GetAddon() has been called) - if (CServiceBroker::GetAddonMgr().GetAddon(addonID, addon, ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO)) + if (CServiceBroker::GetAddonMgr().GetAddon(addonID, addon, OnlyEnabled::CHOICE_NO)) return false; // addon is installed but disabled, and the user has specifically activated something that needs // the addon - should we enable it? @@ -271,8 +272,7 @@ bool CAddonInstaller::InstallModal(const std::string& addonID, if (!InstallOrUpdate(addonID, BackgroundJob::CHOICE_NO, ModalJob::CHOICE_YES)) return false; - return CServiceBroker::GetAddonMgr().GetAddon(addonID, addon, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_YES); + return CServiceBroker::GetAddonMgr().GetAddon(addonID, addon, OnlyEnabled::CHOICE_YES); } @@ -333,7 +333,7 @@ std::vector<std::string> CAddonInstaller::RemoveOrphanedDepsRecursively() const } bool CAddonInstaller::Install(const std::string& addonId, - const AddonVersion& version, + const CAddonVersion& version, const std::string& repoId) { CLog::Log(LOGDEBUG, "CAddonInstaller: installing '{}' version '{}' from repository '{}'", addonId, @@ -346,7 +346,7 @@ bool CAddonInstaller::Install(const std::string& addonId, return false; AddonPtr repo; - if (!CServiceBroker::GetAddonMgr().GetAddon(repoId, repo, ADDON_REPOSITORY, + if (!CServiceBroker::GetAddonMgr().GetAddon(repoId, repo, AddonType::REPOSITORY, OnlyEnabled::CHOICE_YES)) return false; @@ -481,12 +481,12 @@ bool CAddonInstaller::CheckDependencies(const AddonPtr &addon, for (const auto& it : addon->GetDependencies()) { const std::string &addonID = it.id; - const AddonVersion& versionMin = it.versionMin; - const AddonVersion& version = it.version; + const CAddonVersion& versionMin = it.versionMin; + const CAddonVersion& version = it.version; bool optional = it.optional; AddonPtr dep; const bool haveInstalledAddon = - CServiceBroker::GetAddonMgr().GetAddon(addonID, dep, ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO); + CServiceBroker::GetAddonMgr().GetAddon(addonID, dep, OnlyEnabled::CHOICE_NO); if ((haveInstalledAddon && !dep->MeetsVersion(versionMin, version)) || (!haveInstalledAddon && !optional)) { @@ -623,7 +623,7 @@ int64_t CAddonInstaller::EnumeratePackageFolder( size += items[i]->m_dwSize; std::string pack,dummy; - AddonVersion::SplitFileName(pack, dummy, items[i]->GetLabel()); + CAddonVersion::SplitFileName(pack, dummy, items[i]->GetLabel()); if (result.find(pack) == result.end()) result[pack] = std::make_unique<CFileItemList>(); result[pack]->Add(CFileItemPtr(new CFileItem(*items[i]))); @@ -638,8 +638,7 @@ CAddonInstallJob::CAddonInstallJob(const AddonPtr& addon, : m_addon(addon), m_repo(repo), m_isAutoUpdate(isAutoUpdate) { AddonPtr dummy; - m_isUpdate = CServiceBroker::GetAddonMgr().GetAddon(addon->ID(), dummy, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_NO); + m_isUpdate = CServiceBroker::GetAddonMgr().GetAddon(addon->ID(), dummy, OnlyEnabled::CHOICE_NO); } bool CAddonInstallJob::GetAddon(const std::string& addonID, RepositoryPtr& repo, @@ -649,7 +648,7 @@ bool CAddonInstallJob::GetAddon(const std::string& addonID, RepositoryPtr& repo, return false; AddonPtr tmp; - if (!CServiceBroker::GetAddonMgr().GetAddon(addon->Origin(), tmp, ADDON_REPOSITORY, + if (!CServiceBroker::GetAddonMgr().GetAddon(addon->Origin(), tmp, AddonType::REPOSITORY, OnlyEnabled::CHOICE_YES)) return false; @@ -809,8 +808,7 @@ bool CAddonInstallJob::DoWork() // Load new installed and if successed replace defined m_addon here with new one if (!CServiceBroker::GetAddonMgr().LoadAddon(m_addon->ID(), m_addon->Origin(), m_addon->Version()) || - !CServiceBroker::GetAddonMgr().GetAddon(m_addon->ID(), m_addon, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_YES)) + !CServiceBroker::GetAddonMgr().GetAddon(m_addon->ID(), m_addon, OnlyEnabled::CHOICE_YES)) { CLog::Log(LOGERROR, "CAddonInstallJob[{}]: failed to reload addon", m_addon->ID()); return false; @@ -829,7 +827,7 @@ bool CAddonInstallJob::DoWork() { origin = ORIGIN_SYSTEM; // keep system add-on origin as ORIGIN_SYSTEM } - else if (m_addon->HasMainType(ADDON_REPOSITORY)) + else if (m_addon->HasMainType(AddonType::REPOSITORY)) { origin = m_addon->ID(); // use own id as origin if repository @@ -878,7 +876,7 @@ bool CAddonInstallJob::DoWork() // handle add-ons that originate from a repository // find the latest version for the origin we installed from - AddonVersion latestVersion; + CAddonVersion latestVersion; for (const auto& compatibleVersion : compatibleVersions) { if (compatibleVersion->Origin() == m_addon->Origin() && @@ -910,7 +908,7 @@ bool CAddonInstallJob::DoWork() // handle manually installed add-ons // find the latest version of any origin/repository - AddonVersion latestVersion; + CAddonVersion latestVersion; for (const auto& compatibleVersion : compatibleVersions) { if (compatibleVersion->Version() > latestVersion) @@ -1026,7 +1024,7 @@ bool CAddonInstallJob::Install(const std::string &installFrom, const RepositoryP { const auto& deps = m_addon->GetDependencies(); - if (!deps.empty() && m_addon->HasType(ADDON_REPOSITORY)) + if (!deps.empty() && m_addon->HasType(AddonType::REPOSITORY)) { bool notSystemAddon = std::none_of(deps.begin(), deps.end(), [](const DependencyInfo& dep) { return CServiceBroker::GetAddonMgr().IsSystemAddon(dep.id); @@ -1058,12 +1056,12 @@ bool CAddonInstallJob::Install(const std::string &installFrom, const RepositoryP if (it->id != "xbmc.metadata") { const std::string &addonID = it->id; - const AddonVersion& versionMin = it->versionMin; - const AddonVersion& version = it->version; + const CAddonVersion& versionMin = it->versionMin; + const CAddonVersion& version = it->version; bool optional = it->optional; AddonPtr dependency; - const bool haveInstalledAddon = CServiceBroker::GetAddonMgr().GetAddon( - addonID, dependency, ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO); + const bool haveInstalledAddon = + CServiceBroker::GetAddonMgr().GetAddon(addonID, dependency, OnlyEnabled::CHOICE_NO); if ((haveInstalledAddon && !dependency->MeetsVersion(versionMin, version)) || (!haveInstalledAddon && !optional)) { @@ -1180,8 +1178,7 @@ void CAddonInstallJob::ReportInstallError(const std::string& addonID, const std: if (addon != nullptr) { AddonPtr addon2; - bool success = CServiceBroker::GetAddonMgr().GetAddon(addonID, addon2, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_YES); + bool success = CServiceBroker::GetAddonMgr().GetAddon(addonID, addon2, OnlyEnabled::CHOICE_YES); if (msg.empty()) { msg = g_localizeStrings.Get(addon2 != nullptr && success ? 113 : 114); diff --git a/xbmc/addons/AddonInstaller.h b/xbmc/addons/AddonInstaller.h index a9e25e8cd5..727e9e957a 100644 --- a/xbmc/addons/AddonInstaller.h +++ b/xbmc/addons/AddonInstaller.h @@ -22,7 +22,7 @@ class CFileItemList; namespace ADDON { -class AddonVersion; +class CAddonVersion; class CAddonDatabase; @@ -147,7 +147,7 @@ public: /*! Install an addon with a specific version and repository */ bool Install(const std::string& addonId, - const ADDON::AddonVersion& version, + const ADDON::CAddonVersion& version, const std::string& repoId); /*! Uninstall an addon, remove addon data if requested */ diff --git a/xbmc/addons/AddonManager.cpp b/xbmc/addons/AddonManager.cpp index 7f6858981c..bb0b510378 100644 --- a/xbmc/addons/AddonManager.cpp +++ b/xbmc/addons/AddonManager.cpp @@ -12,14 +12,17 @@ #include "FileItem.h" #include "LangInfo.h" #include "ServiceBroker.h" -#include "addons/Addon.h" #include "addons/AddonBuilder.h" +#include "addons/AddonDatabase.h" #include "addons/AddonEvents.h" #include "addons/AddonInstaller.h" #include "addons/AddonRepos.h" #include "addons/AddonSystemSettings.h" +#include "addons/AddonUpdateRules.h" +#include "addons/IAddon.h" #include "addons/addoninfo/AddonInfo.h" #include "addons/addoninfo/AddonInfoBuilder.h" +#include "addons/addoninfo/AddonType.h" #include "events/AddonManagementEvent.h" #include "events/EventLog.h" #include "events/NotificationEvent.h" @@ -47,7 +50,7 @@ namespace ADDON * */ -std::map<TYPE, IAddonMgrCallback*> CAddonMgr::m_managers; +std::map<AddonType, IAddonMgrCallback*> CAddonMgr::m_managers; static bool LoadManifest(std::set<std::string>& system, std::set<std::string>& optional) { @@ -80,12 +83,18 @@ static bool LoadManifest(std::set<std::string>& system, std::set<std::string>& o return true; } +CAddonMgr::CAddonMgr() + : m_database(std::make_unique<CAddonDatabase>()), + m_updateRules(std::make_unique<CAddonUpdateRules>()) +{ +} + CAddonMgr::~CAddonMgr() { DeInit(); } -IAddonMgrCallback* CAddonMgr::GetCallbackForType(TYPE type) +IAddonMgrCallback* CAddonMgr::GetCallbackForType(AddonType type) { if (m_managers.find(type) == m_managers.end()) return nullptr; @@ -93,7 +102,7 @@ IAddonMgrCallback* CAddonMgr::GetCallbackForType(TYPE type) return m_managers[type]; } -bool CAddonMgr::RegisterAddonMgrCallback(const TYPE type, IAddonMgrCallback* cb) +bool CAddonMgr::RegisterAddonMgrCallback(AddonType type, IAddonMgrCallback* cb) { if (cb == nullptr) return false; @@ -104,7 +113,7 @@ bool CAddonMgr::RegisterAddonMgrCallback(const TYPE type, IAddonMgrCallback* cb) return true; } -void CAddonMgr::UnregisterAddonMgrCallback(TYPE type) +void CAddonMgr::UnregisterAddonMgrCallback(AddonType type) { m_managers.erase(type); } @@ -119,7 +128,7 @@ bool CAddonMgr::Init() return false; } - if (!m_database.Open()) + if (!m_database->Open()) CLog::Log(LOGFATAL, "ADDONS: Failed to open database"); FindAddons(); @@ -128,7 +137,7 @@ bool CAddonMgr::Init() for (const auto& id : m_systemAddons) { AddonPtr addon; - if (!GetAddon(id, addon, ADDON_UNKNOWN, OnlyEnabled::CHOICE_YES)) + if (!GetAddon(id, addon, AddonType::UNKNOWN, OnlyEnabled::CHOICE_YES)) { CLog::Log(LOGFATAL, "addon '{}' not installed or not enabled.", id); return false; @@ -140,14 +149,14 @@ bool CAddonMgr::Init() void CAddonMgr::DeInit() { - m_database.Close(); + m_database->Close(); /* If temporary directory was used from add-on, delete it */ if (XFILE::CDirectory::Exists(m_tempAddonBasePath)) XFILE::CDirectory::RemoveRecursive(CSpecialProtocol::TranslatePath(m_tempAddonBasePath)); } -bool CAddonMgr::HasAddons(const TYPE &type) +bool CAddonMgr::HasAddons(AddonType type) { std::unique_lock<CCriticalSection> lock(m_critSection); @@ -159,7 +168,7 @@ bool CAddonMgr::HasAddons(const TYPE &type) return false; } -bool CAddonMgr::HasInstalledAddons(const TYPE &type) +bool CAddonMgr::HasInstalledAddons(AddonType type) { std::unique_lock<CCriticalSection> lock(m_critSection); @@ -261,13 +270,13 @@ std::vector<std::shared_ptr<IAddon>> CAddonMgr::GetAvailableUpdatesOrOutdatedAdd return result; } -std::map<std::string, CAddonWithUpdate> CAddonMgr::GetAddonsWithAvailableUpdate() const +std::map<std::string, AddonWithUpdate> CAddonMgr::GetAddonsWithAvailableUpdate() const { std::unique_lock<CCriticalSection> lock(m_critSection); auto start = std::chrono::steady_clock::now(); std::vector<std::shared_ptr<IAddon>> installed; - std::map<std::string, CAddonWithUpdate> result; + std::map<std::string, AddonWithUpdate> result; CAddonRepos addonRepos; if (addonRepos.IsValid()) @@ -310,7 +319,7 @@ bool CAddonMgr::HasAvailableUpdates() std::vector<std::shared_ptr<IAddon>> CAddonMgr::GetOrphanedDependencies() const { std::vector<std::shared_ptr<IAddon>> allAddons; - GetAddonsInternal(ADDON_UNKNOWN, allAddons, OnlyEnabled::CHOICE_YES, + GetAddonsInternal(AddonType::UNKNOWN, allAddons, OnlyEnabled::CHOICE_YES, CheckIncompatible::CHOICE_YES); std::vector<std::shared_ptr<IAddon>> orphanedDependencies; @@ -343,38 +352,38 @@ bool CAddonMgr::IsOrphaned(const std::shared_ptr<IAddon>& addon, bool CAddonMgr::GetAddonsForUpdate(VECADDONS& addons) const { - return GetAddonsInternal(ADDON_UNKNOWN, addons, OnlyEnabled::CHOICE_YES, + return GetAddonsInternal(AddonType::UNKNOWN, addons, OnlyEnabled::CHOICE_YES, CheckIncompatible::CHOICE_YES); } bool CAddonMgr::GetAddons(VECADDONS& addons) const { - return GetAddonsInternal(ADDON_UNKNOWN, addons, OnlyEnabled::CHOICE_YES, + return GetAddonsInternal(AddonType::UNKNOWN, addons, OnlyEnabled::CHOICE_YES, CheckIncompatible::CHOICE_NO); } -bool CAddonMgr::GetAddons(VECADDONS& addons, const TYPE& type) +bool CAddonMgr::GetAddons(VECADDONS& addons, AddonType type) { return GetAddonsInternal(type, addons, OnlyEnabled::CHOICE_YES, CheckIncompatible::CHOICE_NO); } bool CAddonMgr::GetInstalledAddons(VECADDONS& addons) { - return GetAddonsInternal(ADDON_UNKNOWN, addons, OnlyEnabled::CHOICE_NO, + return GetAddonsInternal(AddonType::UNKNOWN, addons, OnlyEnabled::CHOICE_NO, CheckIncompatible::CHOICE_NO); } -bool CAddonMgr::GetInstalledAddons(VECADDONS& addons, const TYPE& type) +bool CAddonMgr::GetInstalledAddons(VECADDONS& addons, AddonType type) { return GetAddonsInternal(type, addons, OnlyEnabled::CHOICE_NO, CheckIncompatible::CHOICE_NO); } bool CAddonMgr::GetDisabledAddons(VECADDONS& addons) { - return CAddonMgr::GetDisabledAddons(addons, ADDON_UNKNOWN); + return CAddonMgr::GetDisabledAddons(addons, AddonType::UNKNOWN); } -bool CAddonMgr::GetDisabledAddons(VECADDONS& addons, const TYPE& type) +bool CAddonMgr::GetDisabledAddons(VECADDONS& addons, AddonType type) { VECADDONS all; if (GetInstalledAddons(all, type)) @@ -388,10 +397,10 @@ bool CAddonMgr::GetDisabledAddons(VECADDONS& addons, const TYPE& type) bool CAddonMgr::GetInstallableAddons(VECADDONS& addons) { - return GetInstallableAddons(addons, ADDON_UNKNOWN); + return GetInstallableAddons(addons, AddonType::UNKNOWN); } -bool CAddonMgr::GetInstallableAddons(VECADDONS& addons, const TYPE &type) +bool CAddonMgr::GetInstallableAddons(VECADDONS& addons, AddonType type) { std::unique_lock<CCriticalSection> lock(m_critSection); CAddonRepos addonRepos; @@ -410,7 +419,7 @@ bool CAddonMgr::GetInstallableAddons(VECADDONS& addons, const TYPE &type) bool bErase = false; // check if the addon matches the provided addon type - if (type != ADDON::ADDON_UNKNOWN && addon->Type() != type && !addon->HasType(type)) + if (type != AddonType::UNKNOWN && addon->Type() != type && !addon->HasType(type)) bErase = true; if (!this->CanAddonBeInstalled(addon)) @@ -434,7 +443,7 @@ bool CAddonMgr::FindInstallableById(const std::string& addonId, AddonPtr& result // check for an update if addon is installed already - if (GetAddon(addonId, addonToUpdate, ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO)) + if (GetAddon(addonId, addonToUpdate, AddonType::UNKNOWN, OnlyEnabled::CHOICE_NO)) { if (addonRepos.DoAddonUpdateCheck(addonToUpdate, result)) return true; @@ -451,7 +460,7 @@ bool CAddonMgr::FindInstallableById(const std::string& addonId, AddonPtr& result return addonRepos.GetLatestAddonVersionFromAllRepos(addonId, result); } -bool CAddonMgr::GetAddonsInternal(const TYPE& type, +bool CAddonMgr::GetAddonsInternal(AddonType type, VECADDONS& addons, OnlyEnabled onlyEnabled, CheckIncompatible checkIncompatible) const @@ -460,7 +469,7 @@ bool CAddonMgr::GetAddonsInternal(const TYPE& type, for (const auto& addonInfo : m_installedAddons) { - if (type != ADDON_UNKNOWN && !addonInfo.second->HasType(type)) + if (type != AddonType::UNKNOWN && !addonInfo.second->HasType(type)) continue; if (onlyEnabled == OnlyEnabled::CHOICE_YES && @@ -472,7 +481,7 @@ bool CAddonMgr::GetAddonsInternal(const TYPE& type, //FIXME: hack for skipping special dependency addons (xbmc.python etc.). //Will break if any extension point is added to them - if (addonInfo.second->MainType() == ADDON_UNKNOWN) + if (addonInfo.second->MainType() == AddonType::UNKNOWN) continue; AddonPtr addon = CAddonBuilder::Generate(addonInfo.second, type); @@ -496,9 +505,9 @@ bool CAddonMgr::GetIncompatibleEnabledAddonInfos(std::vector<AddonInfoPtr>& inco bool CAddonMgr::GetIncompatibleAddonInfos(std::vector<AddonInfoPtr>& incompatible, bool includeDisabled) const { - GetAddonInfos(incompatible, true, ADDON_UNKNOWN); + GetAddonInfos(incompatible, true, AddonType::UNKNOWN); if (includeDisabled) - GetDisabledAddonInfos(incompatible, ADDON_UNKNOWN, AddonDisabledReason::INCOMPATIBLE); + GetDisabledAddonInfos(incompatible, AddonType::UNKNOWN, AddonDisabledReason::INCOMPATIBLE); incompatible.erase(std::remove_if(incompatible.begin(), incompatible.end(), [this](const AddonInfoPtr& a) { return IsCompatible(a); }), incompatible.end()); @@ -621,7 +630,7 @@ void CAddonMgr::InstallAddonUpdates(VECADDONS& updates, bool CAddonMgr::GetAddon(const std::string& str, AddonPtr& addon, - const TYPE& type, + AddonType type, OnlyEnabled onlyEnabled) const { std::unique_lock<CCriticalSection> lock(m_critSection); @@ -646,7 +655,12 @@ bool CAddonMgr::GetAddon(const std::string& str, return false; } -bool CAddonMgr::HasType(const std::string &id, const TYPE &type) +bool CAddonMgr::GetAddon(const std::string& str, AddonPtr& addon, OnlyEnabled onlyEnabled) const +{ + return GetAddon(str, addon, AddonType::UNKNOWN, onlyEnabled); +} + +bool CAddonMgr::HasType(const std::string& id, AddonType type) { AddonPtr addon; return GetAddon(id, addon, type, OnlyEnabled::CHOICE_NO); @@ -654,7 +668,7 @@ bool CAddonMgr::HasType(const std::string &id, const TYPE &type) bool CAddonMgr::FindAddon(const std::string& addonId, const std::string& origin, - const AddonVersion& addonVersion) + const CAddonVersion& addonVersion) { std::map<std::string, std::shared_ptr<CAddonInfo>> installedAddons; @@ -670,19 +684,19 @@ bool CAddonMgr::FindAddon(const std::string& addonId, std::unique_lock<CCriticalSection> lock(m_critSection); - m_database.GetInstallData(it->second); + m_database->GetInstallData(it->second); CLog::Log(LOGINFO, "CAddonMgr::{}: {} v{} installed", __FUNCTION__, addonId, addonVersion.asString()); m_installedAddons[addonId] = it->second; // insert/replace entry - m_database.AddInstalledAddon(it->second, origin); + m_database->AddInstalledAddon(it->second, origin); // Reload caches std::map<std::string, AddonDisabledReason> tmpDisabled; - m_database.GetDisabled(tmpDisabled); + m_database->GetDisabled(tmpDisabled); m_disabled = std::move(tmpDisabled); - m_updateRules.RefreshRulesMap(m_database); + m_updateRules->RefreshRulesMap(*m_database); return true; } @@ -703,10 +717,10 @@ bool CAddonMgr::FindAddons() std::unique_lock<CCriticalSection> lock(m_critSection); // Sync with db - m_database.SyncInstalled(installed, m_systemAddons, m_optionalSystemAddons); + m_database->SyncInstalled(installed, m_systemAddons, m_optionalSystemAddons); for (const auto& addon : installedAddons) { - m_database.GetInstallData(addon.second); + m_database->GetInstallData(addon.second); CLog::Log(LOGINFO, "CAddonMgr::{}: {} v{} installed", __FUNCTION__, addon.second->ID(), addon.second->Version().asString()); } @@ -715,10 +729,10 @@ bool CAddonMgr::FindAddons() // Reload caches std::map<std::string, AddonDisabledReason> tmpDisabled; - m_database.GetDisabled(tmpDisabled); + m_database->GetDisabled(tmpDisabled); m_disabled = std::move(tmpDisabled); - m_updateRules.RefreshRulesMap(m_database); + m_updateRules->RefreshRulesMap(*m_database); return true; } @@ -732,7 +746,7 @@ bool CAddonMgr::UnloadAddon(const std::string& addonId) AddonPtr localAddon; // can't unload an binary addon that is in use - if (GetAddon(addonId, localAddon, ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO) && + if (GetAddon(addonId, localAddon, AddonType::UNKNOWN, OnlyEnabled::CHOICE_NO) && localAddon->IsBinary() && localAddon->IsInUse()) { CLog::Log(LOGERROR, "CAddonMgr::{}: could not unload binary add-on {}, as is in use", __func__, @@ -752,12 +766,12 @@ bool CAddonMgr::UnloadAddon(const std::string& addonId) bool CAddonMgr::LoadAddon(const std::string& addonId, const std::string& origin, - const AddonVersion& addonVersion) + const CAddonVersion& addonVersion) { std::unique_lock<CCriticalSection> lock(m_critSection); AddonPtr addon; - if (GetAddon(addonId, addon, ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO)) + if (GetAddon(addonId, addon, AddonType::UNKNOWN, OnlyEnabled::CHOICE_NO)) { return true; } @@ -768,7 +782,7 @@ bool CAddonMgr::LoadAddon(const std::string& addonId, return false; } - if (!GetAddon(addonId, addon, ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO)) + if (!GetAddon(addonId, addon, AddonType::UNKNOWN, OnlyEnabled::CHOICE_NO)) { CLog::Log(LOGERROR, "CAddonMgr: could not load add-on {}. No add-on with that ID is installed.", addonId); @@ -805,8 +819,8 @@ void CAddonMgr::UpdateLastUsed(const std::string& id) CServiceBroker::GetJobManager()->Submit([this, id, time]() { { std::unique_lock<CCriticalSection> lock(m_critSection); - m_database.SetLastUsed(id, time); - auto addonInfo = GetAddonInfo(id); + m_database->SetLastUsed(id, time); + auto addonInfo = GetAddonInfo(id, AddonType::UNKNOWN); if (addonInfo) addonInfo->SetLastUsed(time); } @@ -820,7 +834,7 @@ static void ResolveDependencies(const std::string& addonId, std::vector<std::str return; AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(addonId, addon, ADDON_UNKNOWN, + if (!CServiceBroker::GetAddonMgr().GetAddon(addonId, addon, AddonType::UNKNOWN, OnlyEnabled::CHOICE_NO)) missing.push_back(addonId); else @@ -839,7 +853,7 @@ bool CAddonMgr::DisableAddon(const std::string& id, AddonDisabledReason disabled return false; if (m_disabled.find(id) != m_disabled.end()) return true; //already disabled - if (!m_database.DisableAddon(id, disabledReason)) + if (!m_database->DisableAddon(id, disabledReason)) return false; if (!m_disabled.emplace(id, disabledReason).second) return false; @@ -847,7 +861,7 @@ bool CAddonMgr::DisableAddon(const std::string& id, AddonDisabledReason disabled //success CLog::Log(LOGDEBUG, "CAddonMgr: {} disabled", id); AddonPtr addon; - if (GetAddon(id, addon, ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO) && addon != nullptr) + if (GetAddon(id, addon, AddonType::UNKNOWN, OnlyEnabled::CHOICE_NO) && addon != nullptr) { auto eventLog = CServiceBroker::GetEventLog(); if (eventLog) @@ -863,7 +877,7 @@ bool CAddonMgr::UpdateDisabledReason(const std::string& id, AddonDisabledReason std::unique_lock<CCriticalSection> lock(m_critSection); if (!IsAddonDisabled(id)) return false; - if (!m_database.DisableAddon(id, newDisabledReason)) + if (!m_database->DisableAddon(id, newDisabledReason)) return false; m_disabled[id] = newDisabledReason; @@ -882,7 +896,7 @@ bool CAddonMgr::EnableSingle(const std::string& id) return true; //already enabled AddonPtr addon; - if (!GetAddon(id, addon, ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO) || addon == nullptr) + if (!GetAddon(id, addon, AddonType::UNKNOWN, OnlyEnabled::CHOICE_NO) || addon == nullptr) return false; auto eventLog = CServiceBroker::GetEventLog(); @@ -897,12 +911,12 @@ bool CAddonMgr::EnableSingle(const std::string& id) return false; } - if (!m_database.EnableAddon(id)) + if (!m_database->EnableAddon(id)) return false; m_disabled.erase(id); // If enabling a repo add-on without an origin, set its origin to its own id - if (addon->HasType(ADDON_REPOSITORY) && addon->Origin().empty()) + if (addon->HasType(AddonType::REPOSITORY) && addon->Origin().empty()) SetAddonOrigin(id, id, false); if (eventLog) @@ -957,7 +971,7 @@ bool CAddonMgr::CanAddonBeDisabled(const std::string& ID) AddonPtr localAddon; // can't disable an addon that isn't installed - if (!GetAddon(ID, localAddon, ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO)) + if (!GetAddon(ID, localAddon, AddonType::UNKNOWN, OnlyEnabled::CHOICE_NO)) return false; // can't disable an addon that is in use @@ -975,14 +989,14 @@ bool CAddonMgr::CanAddonBeEnabled(const std::string& id) bool CAddonMgr::IsAddonInstalled(const std::string& ID) { AddonPtr tmp; - return GetAddon(ID, tmp, ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO); + return GetAddon(ID, tmp, AddonType::UNKNOWN, OnlyEnabled::CHOICE_NO); } bool CAddonMgr::IsAddonInstalled(const std::string& ID, const std::string& origin) const { AddonPtr tmp; - if (GetAddon(ID, tmp, ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO) && tmp) + if (GetAddon(ID, tmp, AddonType::UNKNOWN, OnlyEnabled::CHOICE_NO) && tmp) { if (tmp->Origin() == ORIGIN_SYSTEM) { @@ -998,11 +1012,11 @@ bool CAddonMgr::IsAddonInstalled(const std::string& ID, const std::string& origi bool CAddonMgr::IsAddonInstalled(const std::string& ID, const std::string& origin, - const AddonVersion& version) + const CAddonVersion& version) { AddonPtr tmp; - if (GetAddon(ID, tmp, ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO) && tmp) + if (GetAddon(ID, tmp, AddonType::UNKNOWN, OnlyEnabled::CHOICE_NO) && tmp) { if (tmp->Origin() == ORIGIN_SYSTEM) { @@ -1057,29 +1071,29 @@ bool CAddonMgr::LoadAddonDescription(const std::string &directory, AddonPtr &add { auto addonInfo = CAddonInfoBuilder::Generate(directory); if (addonInfo) - addon = CAddonBuilder::Generate(addonInfo, ADDON_UNKNOWN); + addon = CAddonBuilder::Generate(addonInfo, AddonType::UNKNOWN); return addon != nullptr; } bool CAddonMgr::AddUpdateRuleToList(const std::string& id, AddonUpdateRule updateRule) { - return m_updateRules.AddUpdateRuleToList(m_database, id, updateRule); + return m_updateRules->AddUpdateRuleToList(*m_database, id, updateRule); } bool CAddonMgr::RemoveAllUpdateRulesFromList(const std::string& id) { - return m_updateRules.RemoveAllUpdateRulesFromList(m_database, id); + return m_updateRules->RemoveAllUpdateRulesFromList(*m_database, id); } bool CAddonMgr::RemoveUpdateRuleFromList(const std::string& id, AddonUpdateRule updateRule) { - return m_updateRules.RemoveUpdateRuleFromList(m_database, id, updateRule); + return m_updateRules->RemoveUpdateRuleFromList(*m_database, id, updateRule); } bool CAddonMgr::IsAutoUpdateable(const std::string& id) const { - return m_updateRules.IsAutoUpdateable(id); + return m_updateRules->IsAutoUpdateable(id); } void CAddonMgr::PublishEventAutoUpdateStateChanged(const std::string& id) @@ -1109,7 +1123,8 @@ bool CAddonMgr::IsCompatible(const IAddon& addon) const StringUtils::StartsWith(dependency.id, "kodi.")) { AddonPtr addon; - bool haveAddon = GetAddon(dependency.id, addon, ADDON_UNKNOWN, OnlyEnabled::CHOICE_YES); + bool haveAddon = + GetAddon(dependency.id, addon, AddonType::UNKNOWN, OnlyEnabled::CHOICE_YES); if (!haveAddon || !addon->MeetsVersion(dependency.versionMin, dependency.version)) return false; } @@ -1129,7 +1144,7 @@ bool CAddonMgr::IsCompatible(const AddonInfoPtr& addonInfo) const if (StringUtils::StartsWith(dependency.id, "xbmc.") || StringUtils::StartsWith(dependency.id, "kodi.")) { - AddonInfoPtr addonInfo = GetAddonInfo(dependency.id); + AddonInfoPtr addonInfo = GetAddonInfo(dependency.id, AddonType::UNKNOWN); if (!addonInfo || !addonInfo->MeetsVersion(dependency.versionMin, dependency.version)) return false; } @@ -1144,7 +1159,7 @@ std::vector<DependencyInfo> CAddonMgr::GetDepsRecursive(const std::string& id, std::vector<DependencyInfo> added; AddonPtr root_addon; if (!FindInstallableById(id, root_addon) && - !GetAddon(id, root_addon, ADDON_UNKNOWN, static_cast<OnlyEnabled>(onlyEnabledRootAddon))) + !GetAddon(id, root_addon, AddonType::UNKNOWN, static_cast<OnlyEnabled>(onlyEnabledRootAddon))) { return added; } @@ -1187,17 +1202,17 @@ std::vector<DependencyInfo> CAddonMgr::GetDepsRecursive(const std::string& id, return added; } -bool CAddonMgr::GetAddonInfos(AddonInfos& addonInfos, bool onlyEnabled, TYPE type) const +bool CAddonMgr::GetAddonInfos(AddonInfos& addonInfos, bool onlyEnabled, AddonType type) const { std::unique_lock<CCriticalSection> lock(m_critSection); - bool forUnknown = type == ADDON_UNKNOWN; + bool forUnknown = type == AddonType::UNKNOWN; for (auto& info : m_installedAddons) { if (onlyEnabled && m_disabled.find(info.first) != m_disabled.end()) continue; - if (info.second->MainType() != ADDON_UNKNOWN && (forUnknown || info.second->HasType(type))) + if (info.second->MainType() != AddonType::UNKNOWN && (forUnknown || info.second->HasType(type))) addonInfos.push_back(info.second); } @@ -1205,7 +1220,7 @@ bool CAddonMgr::GetAddonInfos(AddonInfos& addonInfos, bool onlyEnabled, TYPE typ } std::vector<AddonInfoPtr> CAddonMgr::GetAddonInfos(bool onlyEnabled, - const std::vector<TYPE>& types) const + const std::vector<AddonType>& types) const { std::vector<AddonInfoPtr> infos; if (types.empty()) @@ -1218,11 +1233,11 @@ std::vector<AddonInfoPtr> CAddonMgr::GetAddonInfos(bool onlyEnabled, if (onlyEnabled && m_disabled.find(info.first) != m_disabled.end()) continue; - if (info.second->MainType() == ADDON_UNKNOWN) + if (info.second->MainType() == AddonType::UNKNOWN) continue; const auto it = std::find_if(types.begin(), types.end(), - [info](TYPE t) { return info.second->HasType(t); }); + [info](AddonType t) { return info.second->HasType(t); }); if (it != types.end()) infos.emplace_back(info.second); } @@ -1230,25 +1245,26 @@ std::vector<AddonInfoPtr> CAddonMgr::GetAddonInfos(bool onlyEnabled, return infos; } -bool CAddonMgr::GetDisabledAddonInfos(std::vector<AddonInfoPtr>& addonInfos, TYPE type) const +bool CAddonMgr::GetDisabledAddonInfos(std::vector<AddonInfoPtr>& addonInfos, AddonType type) const { return GetDisabledAddonInfos(addonInfos, type, AddonDisabledReason::NONE); } bool CAddonMgr::GetDisabledAddonInfos(std::vector<AddonInfoPtr>& addonInfos, - TYPE type, + AddonType type, AddonDisabledReason disabledReason) const { std::unique_lock<CCriticalSection> lock(m_critSection); - bool forUnknown = type == ADDON_UNKNOWN; + bool forUnknown = type == AddonType::UNKNOWN; for (const auto& info : m_installedAddons) { const auto disabledAddon = m_disabled.find(info.first); if (disabledAddon == m_disabled.end()) continue; - if (info.second->MainType() != ADDON_UNKNOWN && (forUnknown || info.second->HasType(type)) && + if (info.second->MainType() != AddonType::UNKNOWN && + (forUnknown || info.second->HasType(type)) && (disabledReason == AddonDisabledReason::NONE || disabledReason == disabledAddon->second)) addonInfos.emplace_back(info.second); } @@ -1256,14 +1272,13 @@ bool CAddonMgr::GetDisabledAddonInfos(std::vector<AddonInfoPtr>& addonInfos, return !addonInfos.empty(); } -const AddonInfoPtr CAddonMgr::GetAddonInfo(const std::string& id, - TYPE type /*= ADDON_UNKNOWN*/) const +const AddonInfoPtr CAddonMgr::GetAddonInfo(const std::string& id, AddonType type) const { std::unique_lock<CCriticalSection> lock(m_critSection); auto addon = m_installedAddons.find(id); if (addon != m_installedAddons.end()) - if ((type == ADDON_UNKNOWN || addon->second->HasType(type))) + if ((type == AddonType::UNKNOWN || addon->second->HasType(type))) return addon->second; return nullptr; @@ -1329,18 +1344,18 @@ bool CAddonMgr::SetAddonOrigin(const std::string& addonId, const std::string& re { std::unique_lock<CCriticalSection> lock(m_critSection); - m_database.SetOrigin(addonId, repoAddonId); + m_database->SetOrigin(addonId, repoAddonId); if (isUpdate) - m_database.SetLastUpdated(addonId, CDateTime::GetCurrentDateTime()); + m_database->SetLastUpdated(addonId, CDateTime::GetCurrentDateTime()); // If available in manager update - const AddonInfoPtr info = GetAddonInfo(addonId); + const AddonInfoPtr info = GetAddonInfo(addonId, AddonType::UNKNOWN); if (info) - m_database.GetInstallData(info); + m_database->GetInstallData(info); return true; } -bool CAddonMgr::AddonsFromRepoXML(const CRepository::DirInfo& repo, +bool CAddonMgr::AddonsFromRepoXML(const RepositoryDirInfo& repo, const std::string& xml, std::vector<AddonInfoPtr>& addons) { diff --git a/xbmc/addons/AddonManager.h b/xbmc/addons/AddonManager.h index 3a8595d9d0..cdce156e0a 100644 --- a/xbmc/addons/AddonManager.h +++ b/xbmc/addons/AddonManager.h @@ -8,12 +8,6 @@ #pragma once -#include "AddonDatabase.h" -#include "AddonUpdateRules.h" -#include "addons/Addon.h" -#include "addons/IAddonManagerCallback.h" -#include "addons/Repository.h" -#include "addons/addoninfo/AddonType.h" #include "threads/CriticalSection.h" #include "utils/EventStream.h" @@ -26,114 +20,135 @@ namespace ADDON { - typedef std::map<TYPE, VECADDONS> MAPADDONS; - typedef std::map<TYPE, VECADDONS>::iterator IMAPADDONS; - typedef std::map<std::string, AddonInfoPtr> ADDON_INFO_LIST; +enum class AddonDisabledReason; +enum class AddonOriginType; +enum class AddonType; +enum class AddonUpdateRule; +enum class AllowCheckForUpdates : bool; - const std::string ADDON_PYTHON_EXT = "*.py"; +class CAddonDatabase; +class CAddonUpdateRules; +class CAddonVersion; +class IAddonMgrCallback; - enum class AddonDisabledReason; +class CAddonInfo; +using AddonInfoPtr = std::shared_ptr<CAddonInfo>; +using ADDON_INFO_LIST = std::map<std::string, AddonInfoPtr>; - enum class AllowCheckForUpdates : bool; +class IAddon; +using AddonPtr = std::shared_ptr<IAddon>; +using VECADDONS = std::vector<AddonPtr>; - enum class AddonCheckType : bool - { - OUTDATED_ADDONS, - AVAILABLE_UPDATES, - }; - - enum class OnlyEnabled : bool - { - CHOICE_YES = true, - CHOICE_NO = false, - }; +struct AddonEvent; +struct AddonWithUpdate; +struct DependencyInfo; +struct RepositoryDirInfo; - enum class OnlyEnabledRootAddon : bool - { - CHOICE_YES = true, - CHOICE_NO = false, - }; +using AddonInstanceId = uint32_t; - enum class CheckIncompatible : bool - { - CHOICE_YES = true, - CHOICE_NO = false, - }; +enum class AddonCheckType : bool +{ + OUTDATED_ADDONS, + AVAILABLE_UPDATES, +}; - enum class AddonOriginType; +enum class OnlyEnabled : bool +{ + CHOICE_YES = true, + CHOICE_NO = false, +}; - struct AddonEvent; - struct CAddonWithUpdate; +enum class OnlyEnabledRootAddon : bool +{ + CHOICE_YES = true, + CHOICE_NO = false, +}; - using AddonInfos = std::vector<AddonInfoPtr>; +enum class CheckIncompatible : bool +{ + CHOICE_YES = true, + CHOICE_NO = false, +}; - /** +/** * Class - CAddonMgr * Holds references to all addons, enabled or * otherwise. Services the generic callbacks available * to all addon variants. */ - class CAddonMgr +class CAddonMgr +{ +public: + bool ReInit() { - public: - bool ReInit() { DeInit(); return Init(); } - bool Init(); - void DeInit(); + DeInit(); + return Init(); + } + bool Init(); + void DeInit(); - CAddonMgr() = default; - CAddonMgr(const CAddonMgr&) = delete; - virtual ~CAddonMgr(); + CAddonMgr(); + CAddonMgr(const CAddonMgr&) = delete; + virtual ~CAddonMgr(); - CEventStream<AddonEvent>& Events() { return m_events; } - CEventStream<AddonEvent>& UnloadEvents() { return m_unloadEvents; } + CEventStream<AddonEvent>& Events() { return m_events; } + CEventStream<AddonEvent>& UnloadEvents() { return m_unloadEvents; } - IAddonMgrCallback* GetCallbackForType(TYPE type); - bool RegisterAddonMgrCallback(TYPE type, IAddonMgrCallback* cb); - void UnregisterAddonMgrCallback(TYPE type); + IAddonMgrCallback* GetCallbackForType(AddonType type); + bool RegisterAddonMgrCallback(AddonType type, IAddonMgrCallback* cb); + void UnregisterAddonMgrCallback(AddonType type); - /*! \brief Retrieve a specific addon (of a specific type) + /*! \brief Retrieve a specific addon (of a specific type) \param id the id of the addon to retrieve. \param addon[out] the retrieved addon pointer - only use if the function returns true. \param type type of addon to retrieve - defaults to any type. \param onlyEnabled whether we only want enabled addons - set to false to allow both enabled and disabled addons - defaults to true. \return true if an addon matching the id of the given type is available and is enabled (if onlyEnabled is true). */ - bool GetAddon(const std::string& id, - AddonPtr& addon, - const TYPE& type, - OnlyEnabled onlyEnabled) const; + bool GetAddon(const std::string& id, + AddonPtr& addon, + AddonType type, + OnlyEnabled onlyEnabled) const; + + /*! \brief Retrieve a specific addon (of no specific type) + \param id the id of the addon to retrieve. + \param addon[out] the retrieved addon pointer - only use if the function returns true. + \param onlyEnabled whether we only want enabled addons - set to false to allow both enabled and disabled addons - defaults to true. + \return true if an addon matching the id of any type is available and is enabled (if onlyEnabled is true). + */ + bool GetAddon(const std::string& id, AddonPtr& addon, OnlyEnabled onlyEnabled) const; - bool HasType(const std::string &id, const TYPE &type); + bool HasType(const std::string& id, AddonType type); - bool HasAddons(const TYPE &type); + bool HasAddons(AddonType type); - bool HasInstalledAddons(const TYPE &type); + bool HasInstalledAddons(AddonType type); - /*! Returns all installed, enabled and incompatible (and disabled) add-ons. */ - bool GetAddonsForUpdate(VECADDONS& addons) const; + /*! Returns all installed, enabled and incompatible (and disabled) add-ons. */ + bool GetAddonsForUpdate(VECADDONS& addons) const; - /*! Returns all installed, enabled add-ons. */ - bool GetAddons(VECADDONS& addons) const; + /*! Returns all installed, enabled add-ons. */ + bool GetAddons(VECADDONS& addons) const; - /*! Returns enabled add-ons with given type. */ - bool GetAddons(VECADDONS& addons, const TYPE& type); + /*! Returns enabled add-ons with given type. */ + bool GetAddons(VECADDONS& addons, AddonType type); - /*! Returns all installed, including disabled. */ - bool GetInstalledAddons(VECADDONS& addons); + /*! Returns all installed, including disabled. */ + bool GetInstalledAddons(VECADDONS& addons); - /*! Returns installed add-ons, including disabled, with given type. */ - bool GetInstalledAddons(VECADDONS& addons, const TYPE& type); + /*! Returns installed add-ons, including disabled, with given type. */ + bool GetInstalledAddons(VECADDONS& addons, AddonType type); - bool GetDisabledAddons(VECADDONS& addons); + bool GetDisabledAddons(VECADDONS& addons); - bool GetDisabledAddons(VECADDONS& addons, const TYPE& type); + bool GetDisabledAddons(VECADDONS& addons, AddonType type); - /*! Get all installable addons */ - bool GetInstallableAddons(VECADDONS& addons); + /*! Get all installable addons */ + bool GetInstallableAddons(VECADDONS& addons); - bool GetInstallableAddons(VECADDONS& addons, const TYPE &type); + bool GetInstallableAddons(VECADDONS& addons, AddonType type); - /*! \brief Get the installable addon depending on install rules + /*! \brief Get the installable addon depending on install rules * or fall back to highest version. * \note This function gets called in different contexts. If it's * called for checking possible updates for already installed addons @@ -145,116 +160,116 @@ namespace ADDON * \param addon[out] the retrieved addon pointer - only use if the function returns true. * \return true if an addon matching the id is available. */ - bool FindInstallableById(const std::string& addonId, AddonPtr& addon); + bool FindInstallableById(const std::string& addonId, AddonPtr& addon); - void AddToUpdateableAddons(AddonPtr &pAddon); - void RemoveFromUpdateableAddons(AddonPtr &pAddon); - bool ReloadSettings(const std::string& addonId, AddonInstanceId instanceId); + void AddToUpdateableAddons(AddonPtr& pAddon); + void RemoveFromUpdateableAddons(AddonPtr& pAddon); + bool ReloadSettings(const std::string& addonId, AddonInstanceId instanceId); - /*! Get addons with available updates */ - std::vector<std::shared_ptr<IAddon>> GetAvailableUpdates() const; + /*! Get addons with available updates */ + std::vector<std::shared_ptr<IAddon>> GetAvailableUpdates() const; - /*! Get addons that are outdated */ - std::vector<std::shared_ptr<IAddon>> GetOutdatedAddons() const; + /*! Get addons that are outdated */ + std::vector<std::shared_ptr<IAddon>> GetOutdatedAddons() const; - /*! Returns true if there is any addon with available updates, otherwise false */ - bool HasAvailableUpdates(); + /*! Returns true if there is any addon with available updates, otherwise false */ + bool HasAvailableUpdates(); - /*! + /*! * \brief Checks if the passed in addon is an orphaned dependency * \param addon the add-on/dependency to check * \param allAddons vector of all installed add-ons * \return true or false */ - bool IsOrphaned(const std::shared_ptr<IAddon>& addon, - const std::vector<std::shared_ptr<IAddon>>& allAddons) const; + bool IsOrphaned(const std::shared_ptr<IAddon>& addon, + const std::vector<std::shared_ptr<IAddon>>& allAddons) const; - /*! \brief Checks for new / updated add-ons + /*! \brief Checks for new / updated add-ons \return True if everything went ok, false otherwise */ - bool FindAddons(); + bool FindAddons(); - /*! \brief Checks whether given addon with given origin/version is installed + /*! \brief Checks whether given addon with given origin/version is installed * \param addonId addon to check * \param origin origin to check * \param addonVersion version to check * \return True if installed, false otherwise */ - bool FindAddon(const std::string& addonId, - const std::string& origin, - const AddonVersion& addonVersion); + bool FindAddon(const std::string& addonId, + const std::string& origin, + const CAddonVersion& addonVersion); - /*! + /*! * @brief Fills the the provided vector with the list of incompatible * enabled addons and returns if there's any. * * @param[out] incompatible List of incompatible addons * @return true if there are incompatible addons */ - bool GetIncompatibleEnabledAddonInfos(std::vector<AddonInfoPtr>& incompatible) const; + bool GetIncompatibleEnabledAddonInfos(std::vector<AddonInfoPtr>& incompatible) const; - /*! + /*! * Migrate all the addons (updates all addons that have an update pending and disables those * that got incompatible) * * @return list of all addons (infos) that were modified. */ - std::vector<AddonInfoPtr> MigrateAddons(); + std::vector<AddonInfoPtr> MigrateAddons(); - /*! + /*! * @brief Try to disable addons in the given list. * * @param[in] incompatible List of incompatible addon infos * @return list of all addon Infos that were disabled */ - std::vector<AddonInfoPtr> DisableIncompatibleAddons( - const std::vector<AddonInfoPtr>& incompatible); + std::vector<AddonInfoPtr> DisableIncompatibleAddons( + const std::vector<AddonInfoPtr>& incompatible); - /*! + /*! * Install available addon updates, if any. * @param wait If kodi should wait for all updates to download and install before returning */ - void CheckAndInstallAddonUpdates(bool wait) const; + void CheckAndInstallAddonUpdates(bool wait) const; - /*! + /*! * @note: should only be called by AddonInstaller * * Unload addon from the system. Returns true if it was unloaded, otherwise false. */ - bool UnloadAddon(const std::string& addonId); + bool UnloadAddon(const std::string& addonId); - /*! + /*! * @note: should only be called by AddonInstaller * * Returns true if the addon was successfully loaded and enabled; otherwise false. */ - bool LoadAddon(const std::string& addonId, - const std::string& origin, - const AddonVersion& addonVersion); + bool LoadAddon(const std::string& addonId, + const std::string& origin, + const CAddonVersion& addonVersion); - /*! @note: should only be called by AddonInstaller + /*! @note: should only be called by AddonInstaller * * Hook for clearing internal state after uninstall. */ - void OnPostUnInstall(const std::string& id); + void OnPostUnInstall(const std::string& id); - /*! \brief Disable an addon. Returns true on success, false on failure. */ - bool DisableAddon(const std::string& ID, AddonDisabledReason disabledReason); + /*! \brief Disable an addon. Returns true on success, false on failure. */ + bool DisableAddon(const std::string& ID, AddonDisabledReason disabledReason); - /*! \brief Updates reason for a disabled addon. Returns true on success, false on failure. */ - bool UpdateDisabledReason(const std::string& id, AddonDisabledReason newDisabledReason); + /*! \brief Updates reason for a disabled addon. Returns true on success, false on failure. */ + bool UpdateDisabledReason(const std::string& id, AddonDisabledReason newDisabledReason); - /*! \brief Enable an addon. Returns true on success, false on failure. */ - bool EnableAddon(const std::string& ID); + /*! \brief Enable an addon. Returns true on success, false on failure. */ + bool EnableAddon(const std::string& ID); - /* \brief Check whether an addon has been disabled via DisableAddon. + /* \brief Check whether an addon has been disabled via DisableAddon. In case the disabled cache does not know about the current state the database routine will be used. \param ID id of the addon \sa DisableAddon */ - bool IsAddonDisabled(const std::string& ID) const; + bool IsAddonDisabled(const std::string& ID) const; - /*! + /*! * @brief Check whether an addon has been disabled via DisableAddon except for a particular * reason In case the disabled cache does not know about the current state the database routine * will be used. @@ -263,31 +278,31 @@ namespace ADDON * @return true if the addon was disabled except for the specified reason * @sa DisableAddon */ - bool IsAddonDisabledExcept(const std::string& ID, AddonDisabledReason disabledReason) const; + bool IsAddonDisabledExcept(const std::string& ID, AddonDisabledReason disabledReason) const; - /* \brief Checks whether an addon can be disabled via DisableAddon. + /* \brief Checks whether an addon can be disabled via DisableAddon. \param ID id of the addon \sa DisableAddon */ - bool CanAddonBeDisabled(const std::string& ID); + bool CanAddonBeDisabled(const std::string& ID); - bool CanAddonBeEnabled(const std::string& id); + bool CanAddonBeEnabled(const std::string& id); - /* \brief Checks whether an addon is installed. + /* \brief Checks whether an addon is installed. \param ID id of the addon */ - bool IsAddonInstalled(const std::string& ID); + bool IsAddonInstalled(const std::string& ID); - /* \brief Checks whether an addon is installed from a + /* \brief Checks whether an addon is installed from a * particular origin repo * \note if checked for an origin defined as official (i.e. repository.xbmc.org) * this function will return true even if the addon is a shipped system add-on * \param ID id of the addon * \param origin origin repository id */ - bool IsAddonInstalled(const std::string& ID, const std::string& origin) const; + bool IsAddonInstalled(const std::string& ID, const std::string& origin) const; - /* \brief Checks whether an addon is installed from a + /* \brief Checks whether an addon is installed from a * particular origin repo and version * \note if checked for an origin defined as official (i.e. repository.xbmc.org) * this function will return true even if the addon is a shipped system add-on @@ -295,50 +310,50 @@ namespace ADDON * \param origin origin repository id * \param version the version of the addon */ - bool IsAddonInstalled(const std::string& ID, - const std::string& origin, - const AddonVersion& version); + bool IsAddonInstalled(const std::string& ID, + const std::string& origin, + const CAddonVersion& version); - /* \brief Checks whether an addon can be installed. Broken addons can't be installed. + /* \brief Checks whether an addon can be installed. Broken addons can't be installed. \param addon addon to be checked */ - bool CanAddonBeInstalled(const AddonPtr& addon); + bool CanAddonBeInstalled(const AddonPtr& addon); - bool CanUninstall(const AddonPtr& addon); + bool CanUninstall(const AddonPtr& addon); - /*! + /*! * @brief Checks whether an addon is a bundled addon * * @param[in] id id of the addon * @return true if addon is bundled addon, false otherwise. */ - bool IsBundledAddon(const std::string& id); + bool IsBundledAddon(const std::string& id); - /*! + /*! * @brief Checks whether an addon is a system addon * * @param[in] id id of the addon * @return true if addon is system addon, false otherwise. */ - bool IsSystemAddon(const std::string& id); + bool IsSystemAddon(const std::string& id); - /*! + /*! * @brief Checks whether an addon is a required system addon * * @param[in] id id of the addon * @return true if addon is a required system addon, false otherwise. */ - bool IsRequiredSystemAddon(const std::string& id); + bool IsRequiredSystemAddon(const std::string& id); - /*! + /*! * @brief Checks whether an addon is an optional system addon * * @param[in] id id of the addon * @return true if addon is an optional system addon, false otherwise. */ - bool IsOptionalSystemAddon(const std::string& id); + bool IsOptionalSystemAddon(const std::string& id); - /*! + /*! * @brief Addon update rules. * * member functions for handling and querying add-on update rules @@ -347,40 +362,40 @@ namespace ADDON * system directory. * */ - /*@{{{*/ + /*@{{{*/ - /* \brief Add a single update rule to the list for an addon + /* \brief Add a single update rule to the list for an addon * \sa CAddonUpdateRules::AddUpdateRuleToList() */ - bool AddUpdateRuleToList(const std::string& id, AddonUpdateRule updateRule); + bool AddUpdateRuleToList(const std::string& id, AddonUpdateRule updateRule); - /* \brief Remove all rules from update rules list for an addon + /* \brief Remove all rules from update rules list for an addon * \sa CAddonUpdateRules::RemoveAllUpdateRulesFromList() */ - bool RemoveAllUpdateRulesFromList(const std::string& id); + bool RemoveAllUpdateRulesFromList(const std::string& id); - /* \brief Remove a specific rule from update rules list for an addon + /* \brief Remove a specific rule from update rules list for an addon * \sa CAddonUpdateRules::RemoveUpdateRuleFromList() */ - bool RemoveUpdateRuleFromList(const std::string& id, AddonUpdateRule updateRule); + bool RemoveUpdateRuleFromList(const std::string& id, AddonUpdateRule updateRule); - /* \brief Check if an addon version is auto-updateable + /* \brief Check if an addon version is auto-updateable * \param id addon id to be checked * \return true is addon is auto-updateable, false otherwise * \sa CAddonUpdateRules::IsAutoUpdateable() */ - bool IsAutoUpdateable(const std::string& id) const; + bool IsAutoUpdateable(const std::string& id) const; - /*@}}}*/ + /*@}}}*/ - /* \brief Launches event AddonEvent::AutoUpdateStateChanged + /* \brief Launches event AddonEvent::AutoUpdateStateChanged * \param id addon id to pass through * \sa CGUIDialogAddonInfo::OnToggleAutoUpdates() */ - void PublishEventAutoUpdateStateChanged(const std::string& id); - void UpdateLastUsed(const std::string& id); + void PublishEventAutoUpdateStateChanged(const std::string& id); + void UpdateLastUsed(const std::string& id); - /*! + /*! * \brief Launches event @ref AddonEvent::InstanceAdded * * This is called when a new instance is added in add-on settings. @@ -388,9 +403,9 @@ namespace ADDON * \param[in] addonId Add-on id to pass through * \param[in] instanceId Identifier of the add-on instance */ - void PublishInstanceAdded(const std::string& addonId, AddonInstanceId instanceId); + void PublishInstanceAdded(const std::string& addonId, AddonInstanceId instanceId); - /*! + /*! * \brief Launches event @ref AddonEvent::InstanceRemoved * * This is called when an instance is removed in add-on settings. @@ -398,40 +413,40 @@ namespace ADDON * \param[in] addonId Add-on id to pass through * \param[in] instanceId Identifier of the add-on instance */ - void PublishInstanceRemoved(const std::string& addonId, AddonInstanceId instanceId); + void PublishInstanceRemoved(const std::string& addonId, AddonInstanceId instanceId); - /*! \brief Load the addon in the given path + /*! \brief Load the addon in the given path This loads the addon using c-pluff which parses the addon descriptor file. \param path folder that contains the addon. \param addon [out] returned addon. \return true if addon is set, false otherwise. */ - bool LoadAddonDescription(const std::string &path, AddonPtr &addon); + bool LoadAddonDescription(const std::string& path, AddonPtr& addon); - bool ServicesHasStarted() const; + bool ServicesHasStarted() const; - /*! + /*! * @deprecated This addon function should no more used and becomes replaced * in future with the other below by his callers. */ - bool IsCompatible(const IAddon& addon) const; + bool IsCompatible(const IAddon& addon) const; - /*! + /*! * @brief Check given addon information is compatible with Kodi. * * @param[in] addonInfo Addon information to check * @return true if compatible, false if not */ - bool IsCompatible(const AddonInfoPtr& addonInfo) const; + bool IsCompatible(const AddonInfoPtr& addonInfo) const; - /*! \brief Recursively get dependencies for an add-on + /*! \brief Recursively get dependencies for an add-on * \param id the id of the root addon * \param onlyEnabledRootAddon whether look for enabled root add-ons only */ - std::vector<DependencyInfo> GetDepsRecursive(const std::string& id, - OnlyEnabledRootAddon onlyEnabledRootAddon); + std::vector<DependencyInfo> GetDepsRecursive(const std::string& id, + OnlyEnabledRootAddon onlyEnabledRootAddon); - /*! + /*! * @brief Get a list of add-on's with info's for the on system available * ones. * @@ -444,9 +459,9 @@ namespace ADDON * match them. Default is for all types. * @return true if the list contains entries */ - bool GetAddonInfos(AddonInfos& addonInfos, bool onlyEnabled, TYPE type) const; + bool GetAddonInfos(std::vector<AddonInfoPtr>& addonInfos, bool onlyEnabled, AddonType type) const; - /*! + /*! * @brief Get a list of add-on's with info's for the on system available * ones. * @@ -457,9 +472,10 @@ namespace ADDON * * @note @ref ADDON_UNKNOWN should not used for here! */ - std::vector<AddonInfoPtr> GetAddonInfos(bool onlyEnabled, const std::vector<TYPE>& types) const; + std::vector<AddonInfoPtr> GetAddonInfos(bool onlyEnabled, + const std::vector<AddonType>& types) const; - /*! + /*! * @brief Get a list of disabled add-on's with info's * * @param[out] addonInfos list where finded addon information becomes stored @@ -470,9 +486,9 @@ namespace ADDON * returned who match them. Default is for all types. * @return true if the list contains entries */ - bool GetDisabledAddonInfos(std::vector<AddonInfoPtr>& addonInfos, TYPE type) const; + bool GetDisabledAddonInfos(std::vector<AddonInfoPtr>& addonInfos, AddonType type) const; - /*! + /*! * @brief Get a list of disabled add-on's with info's for the on system * available ones with a specific disabled reason. * @@ -488,32 +504,32 @@ namespace ADDON * returned. * @return true if the list contains entries */ - bool GetDisabledAddonInfos(std::vector<AddonInfoPtr>& addonInfos, - TYPE type, - AddonDisabledReason disabledReason) const; + bool GetDisabledAddonInfos(std::vector<AddonInfoPtr>& addonInfos, + AddonType type, + AddonDisabledReason disabledReason) const; - const AddonInfoPtr GetAddonInfo(const std::string& id, TYPE type = ADDON_UNKNOWN) const; + const AddonInfoPtr GetAddonInfo(const std::string& id, AddonType type) const; - /*! + /*! * @brief Get the path where temporary add-on files are stored * * @return the base path used for temporary addon paths * * @warning the folder and its contents are deleted when Kodi is closed */ - const std::string& GetTempAddonBasePath() { return m_tempAddonBasePath; } + const std::string& GetTempAddonBasePath() { return m_tempAddonBasePath; } - AddonOriginType GetAddonOriginType(const AddonPtr& addon) const; + AddonOriginType GetAddonOriginType(const AddonPtr& addon) const; - /*! + /*! * \brief Check whether an addon has been disabled with a special reason. * \param ID id of the addon * \param disabledReason reason we want to check for (NONE, USER, INCOMPATIBLE, PERMANENT_FAILURE) * \return true or false */ - bool IsAddonDisabledWithReason(const std::string& ID, AddonDisabledReason disabledReason) const; + bool IsAddonDisabledWithReason(const std::string& ID, AddonDisabledReason disabledReason) const; - /*! + /*! * @brief Addon update and install management. * * Parts inside here are used for changes about addon system. @@ -521,9 +537,9 @@ namespace ADDON * @warning This should be never used from other places outside of addon * system directory. */ - /*@{{{*/ + /*@{{{*/ - /*! + /*! * @brief Update addon origin data. * * This becomes called from @ref CAddonInstallJob to set the source repo and @@ -541,9 +557,9 @@ namespace ADDON * Currently listed call sources: * - @ref CAddonInstallJob::DoWork */ - bool SetAddonOrigin(const std::string& addonId, const std::string& repoAddonId, bool isUpdate); + bool SetAddonOrigin(const std::string& addonId, const std::string& repoAddonId, bool isUpdate); - /*! + /*! * @brief Parse a repository XML file for addons and load their descriptors. * * A repository XML is essentially a concatenated list of addon descriptors. @@ -556,65 +572,65 @@ namespace ADDON * Currently listed call sources: * - @ref CRepository::FetchIndex */ - bool AddonsFromRepoXML(const CRepository::DirInfo& repo, - const std::string& xml, - std::vector<AddonInfoPtr>& addons); + bool AddonsFromRepoXML(const RepositoryDirInfo& repo, + const std::string& xml, + std::vector<AddonInfoPtr>& addons); - /*@}}}*/ + /*@}}}*/ - /*! + /*! * \brief Retrieves list of outdated addons as well as their related * available updates and stores them into map. * \return map of outdated addons with their update */ - std::map<std::string, CAddonWithUpdate> GetAddonsWithAvailableUpdate() const; + std::map<std::string, AddonWithUpdate> GetAddonsWithAvailableUpdate() const; - /*! + /*! * \brief Retrieves list of compatible addon versions of all origins * \param[in] addonId addon to look up * \return vector containing compatible addon versions */ - std::vector<std::shared_ptr<IAddon>> GetCompatibleVersions(const std::string& addonId) const; + std::vector<std::shared_ptr<IAddon>> GetCompatibleVersions(const std::string& addonId) const; - /*! + /*! * \brief Return number of available updates formatted as string * this can be used as a lightweight method of retrieving the number of updates * rather than using the expensive GetAvailableUpdates call * \return number of available updates */ - const std::string& GetLastAvailableUpdatesCountAsString() const; + const std::string& GetLastAvailableUpdatesCountAsString() const; - /*! + /*! * \brief returns a vector with all found orphaned dependencies. * \return the vector */ - std::vector<std::shared_ptr<IAddon>> GetOrphanedDependencies() const; + std::vector<std::shared_ptr<IAddon>> GetOrphanedDependencies() const; - private: - CAddonMgr& operator=(CAddonMgr const&) = delete; +private: + CAddonMgr& operator=(CAddonMgr const&) = delete; - VECADDONS m_updateableAddons; + VECADDONS m_updateableAddons; - /*! + /*! * \brief returns a vector with either available updates or outdated addons. * usually called by its wrappers GetAvailableUpdates() or * GetOutdatedAddons() * \param[in] true to return outdated addons, false to return available updates * \return vector filled with either available updates or outdated addons */ - std::vector<std::shared_ptr<IAddon>> GetAvailableUpdatesOrOutdatedAddons( - AddonCheckType addonCheckType) const; + std::vector<std::shared_ptr<IAddon>> GetAvailableUpdatesOrOutdatedAddons( + AddonCheckType addonCheckType) const; - bool GetAddonsInternal(const TYPE& type, - VECADDONS& addons, - OnlyEnabled onlyEnabled, - CheckIncompatible checkIncompatible) const; + bool GetAddonsInternal(AddonType type, + VECADDONS& addons, + OnlyEnabled onlyEnabled, + CheckIncompatible checkIncompatible) const; - bool EnableSingle(const std::string& id); + bool EnableSingle(const std::string& id); - void FindAddons(ADDON_INFO_LIST& addonmap, const std::string& path); + void FindAddons(ADDON_INFO_LIST& addonmap, const std::string& path); - /*! + /*! * @brief Fills the the provided vector with the list of incompatible * addons and returns if there's any. * @@ -622,59 +638,59 @@ namespace ADDON * @param[in] whether or not to include incompatible addons that are disabled * @return true if there are incompatible addons */ - bool GetIncompatibleAddonInfos(std::vector<AddonInfoPtr>& incompatible, - bool includeDisabled) const; + bool GetIncompatibleAddonInfos(std::vector<AddonInfoPtr>& incompatible, + bool includeDisabled) const; - /*! + /*! * Get the list of of available updates * \param[in,out] updates the vector of addons to be filled with addons that need to be updated (not blacklisted) * \return if there are any addons needing updates */ - bool GetAddonUpdateCandidates(VECADDONS& updates) const; + bool GetAddonUpdateCandidates(VECADDONS& updates) const; - /*!\brief Sort a list of addons for installation, i.e., defines the order of installation depending + /*!\brief Sort a list of addons for installation, i.e., defines the order of installation depending * of each addon dependencies. * \param[in,out] updates the vector of addons to sort */ - void SortByDependencies(VECADDONS& updates) const; + void SortByDependencies(VECADDONS& updates) const; - /*! + /*! * Install the list of addon updates via AddonInstaller * \param[in,out] updates the vector of addons to install (will be sorted) * \param wait if the process should wait for all addons to install * \param allowCheckForUpdates indicates if content update checks are allowed * after installation of a repository addon from the list */ - void InstallAddonUpdates(VECADDONS& updates, - bool wait, - AllowCheckForUpdates allowCheckForUpdates) const; - - // This guards the addon installation process to make sure - // addon updates are not installed concurrently - // while the migration is running. Addon updates can be triggered - // as a result of a repository update event. - // (migration will install any available update anyway) - mutable std::mutex m_installAddonsMutex; - - std::map<std::string, AddonDisabledReason> m_disabled; - static std::map<TYPE, IAddonMgrCallback*> m_managers; - mutable CCriticalSection m_critSection; - CAddonDatabase m_database; - CAddonUpdateRules m_updateRules; - CEventSource<AddonEvent> m_events; - CBlockingEventSource<AddonEvent> m_unloadEvents; - std::set<std::string> m_systemAddons; - std::set<std::string> m_optionalSystemAddons; - ADDON_INFO_LIST m_installedAddons; - - // Temporary path given to add-ons, whose content is deleted when Kodi is stopped - const std::string m_tempAddonBasePath = "special://temp/addons"; - - /*! + void InstallAddonUpdates(VECADDONS& updates, + bool wait, + AllowCheckForUpdates allowCheckForUpdates) const; + + // This guards the addon installation process to make sure + // addon updates are not installed concurrently + // while the migration is running. Addon updates can be triggered + // as a result of a repository update event. + // (migration will install any available update anyway) + mutable std::mutex m_installAddonsMutex; + + std::map<std::string, AddonDisabledReason> m_disabled; + static std::map<AddonType, IAddonMgrCallback*> m_managers; + mutable CCriticalSection m_critSection; + std::unique_ptr<CAddonDatabase> m_database; + std::unique_ptr<CAddonUpdateRules> m_updateRules; + CEventSource<AddonEvent> m_events; + CBlockingEventSource<AddonEvent> m_unloadEvents; + std::set<std::string> m_systemAddons; + std::set<std::string> m_optionalSystemAddons; + ADDON_INFO_LIST m_installedAddons; + + // Temporary path given to add-ons, whose content is deleted when Kodi is stopped + const std::string m_tempAddonBasePath = "special://temp/addons"; + + /*! * latest count of available updates */ - mutable std::string m_lastAvailableUpdatesCountAsString; - mutable std::mutex m_lastAvailableUpdatesCountMutex; - }; + mutable std::string m_lastAvailableUpdatesCountAsString; + mutable std::mutex m_lastAvailableUpdatesCountMutex; +}; }; /* namespace ADDON */ diff --git a/xbmc/addons/AddonRepos.cpp b/xbmc/addons/AddonRepos.cpp index 9f50e1e9e1..6348b106c8 100644 --- a/xbmc/addons/AddonRepos.cpp +++ b/xbmc/addons/AddonRepos.cpp @@ -8,15 +8,16 @@ #include "AddonRepos.h" -#include "Addon.h" -#include "AddonManager.h" -#include "AddonRepoInfo.h" -#include "AddonSystemSettings.h" #include "CompileInfo.h" -#include "Repository.h" -#include "RepositoryUpdater.h" #include "ServiceBroker.h" +#include "addons/Addon.h" +#include "addons/AddonManager.h" +#include "addons/AddonRepoInfo.h" +#include "addons/AddonSystemSettings.h" +#include "addons/Repository.h" +#include "addons/RepositoryUpdater.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "messaging/helpers/DialogOKHelper.h" #include "utils/StringUtils.h" #include "utils/log.h" @@ -200,7 +201,7 @@ void CAddonRepos::BuildUpdateOrOutdatedList(const std::vector<std::shared_ptr<IA void CAddonRepos::BuildAddonsWithUpdateList( const std::vector<std::shared_ptr<IAddon>>& installed, - std::map<std::string, CAddonWithUpdate>& addonsWithUpdate) const + std::map<std::string, AddonWithUpdate>& addonsWithUpdate) const { std::shared_ptr<IAddon> update; @@ -444,7 +445,7 @@ bool CAddonRepos::FindDependency(const std::string& dependsId, // we got the dependency, so now get a repository-pointer to return std::shared_ptr<IAddon> tmp; - if (!m_addonMgr.GetAddon(dependencyToInstall->Origin(), tmp, ADDON_REPOSITORY, + if (!m_addonMgr.GetAddon(dependencyToInstall->Origin(), tmp, AddonType::REPOSITORY, OnlyEnabled::CHOICE_YES)) return false; @@ -453,7 +454,7 @@ bool CAddonRepos::FindDependency(const std::string& dependsId, CLog::Log(LOGDEBUG, "ADDONS: found dependency [{}] for install/update from repo [{}]", dependencyToInstall->ID(), repoForDep->ID()); - if (dependencyToInstall->HasType(ADDON_REPOSITORY)) + if (dependencyToInstall->HasType(AddonType::REPOSITORY)) { CLog::Log(LOGDEBUG, "ADDONS: dependency with id [{}] has type ADDON_REPOSITORY and will not install!", diff --git a/xbmc/addons/AddonRepos.h b/xbmc/addons/AddonRepos.h index 70aa04c3a3..bb9be3473c 100644 --- a/xbmc/addons/AddonRepos.h +++ b/xbmc/addons/AddonRepos.h @@ -8,7 +8,7 @@ #pragma once -#include "AddonDatabase.h" +#include "addons/AddonDatabase.h" #include <map> #include <memory> @@ -18,7 +18,7 @@ namespace ADDON { -class AddonVersion; +class CAddonVersion; class CAddonMgr; class CRepository; class IAddon; @@ -33,7 +33,7 @@ enum class CheckAddonPath /** * Struct - CAddonWithUpdate */ -struct CAddonWithUpdate +struct AddonWithUpdate { std::shared_ptr<IAddon> m_installed; std::shared_ptr<IAddon> m_update; @@ -72,7 +72,7 @@ public: * \param[out] addonsWithUpdate target map */ void BuildAddonsWithUpdateList(const std::vector<std::shared_ptr<IAddon>>& installed, - std::map<std::string, CAddonWithUpdate>& addonsWithUpdate) const; + std::map<std::string, AddonWithUpdate>& addonsWithUpdate) const; /*! * \brief Checks if the origin-repository of a given addon is defined as official repo diff --git a/xbmc/addons/AddonStatusHandler.cpp b/xbmc/addons/AddonStatusHandler.cpp index 17f8a07c2e..3c6f478894 100644 --- a/xbmc/addons/AddonStatusHandler.cpp +++ b/xbmc/addons/AddonStatusHandler.cpp @@ -9,6 +9,7 @@ #include "ServiceBroker.h" #include "addons/AddonManager.h" +#include "addons/IAddonManagerCallback.h" #include "addons/addoninfo/AddonInfo.h" #include "addons/gui/GUIDialogAddonSettings.h" #include "dialogs/GUIDialogKaiToast.h" @@ -49,8 +50,7 @@ CAddonStatusHandler::CAddonStatusHandler(const std::string& addonID, { //! @todo The status handled CAddonStatusHandler by is related to the class, not the instance //! having CAddonMgr construct an instance makes no sense - if (!CServiceBroker::GetAddonMgr().GetAddon(addonID, m_addon, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_YES)) + if (!CServiceBroker::GetAddonMgr().GetAddon(addonID, m_addon, OnlyEnabled::CHOICE_YES)) return; CLog::Log(LOGINFO, diff --git a/xbmc/addons/AddonStatusHandler.h b/xbmc/addons/AddonStatusHandler.h index 5931b52d58..3254ea080e 100644 --- a/xbmc/addons/AddonStatusHandler.h +++ b/xbmc/addons/AddonStatusHandler.h @@ -8,7 +8,7 @@ #pragma once -#include "IAddon.h" +#include "addons/IAddon.h" #include "addons/kodi-dev-kit/include/kodi/c-api/addon_base.h" #include "threads/CriticalSection.h" #include "threads/Thread.h" diff --git a/xbmc/addons/AddonSystemSettings.cpp b/xbmc/addons/AddonSystemSettings.cpp index fe59299d6d..30f3aaf66b 100644 --- a/xbmc/addons/AddonSystemSettings.cpp +++ b/xbmc/addons/AddonSystemSettings.cpp @@ -11,7 +11,9 @@ #include "ServiceBroker.h" #include "addons/AddonInstaller.h" #include "addons/AddonManager.h" +#include "addons/IAddon.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "guilib/GUIComponent.h" #include "guilib/GUIWindowManager.h" #include "guilib/LocalizeStrings.h" @@ -20,27 +22,27 @@ #include "settings/Settings.h" #include "settings/SettingsComponent.h" #include "settings/lib/Setting.h" +#include "utils/StringUtils.h" #include "utils/log.h" - namespace ADDON { CAddonSystemSettings::CAddonSystemSettings() : m_activeSettings{ - {ADDON_AUDIOENCODER, CSettings::SETTING_AUDIOCDS_ENCODER}, - {ADDON_RESOURCE_LANGUAGE, CSettings::SETTING_LOCALE_LANGUAGE}, - {ADDON_RESOURCE_UISOUNDS, CSettings::SETTING_LOOKANDFEEL_SOUNDSKIN}, - {ADDON_SCRAPER_ALBUMS, CSettings::SETTING_MUSICLIBRARY_ALBUMSSCRAPER}, - {ADDON_SCRAPER_ARTISTS, CSettings::SETTING_MUSICLIBRARY_ARTISTSSCRAPER}, - {ADDON_SCRAPER_MOVIES, CSettings::SETTING_SCRAPERS_MOVIESDEFAULT}, - {ADDON_SCRAPER_MUSICVIDEOS, CSettings::SETTING_SCRAPERS_MUSICVIDEOSDEFAULT}, - {ADDON_SCRAPER_TVSHOWS, CSettings::SETTING_SCRAPERS_TVSHOWSDEFAULT}, - {ADDON_SCREENSAVER, CSettings::SETTING_SCREENSAVER_MODE}, - {ADDON_SCRIPT_WEATHER, CSettings::SETTING_WEATHER_ADDON}, - {ADDON_SKIN, CSettings::SETTING_LOOKANDFEEL_SKIN}, - {ADDON_WEB_INTERFACE, CSettings::SETTING_SERVICES_WEBSKIN}, - {ADDON_VIZ, CSettings::SETTING_MUSICPLAYER_VISUALISATION}, + {AddonType::AUDIOENCODER, CSettings::SETTING_AUDIOCDS_ENCODER}, + {AddonType::RESOURCE_LANGUAGE, CSettings::SETTING_LOCALE_LANGUAGE}, + {AddonType::RESOURCE_UISOUNDS, CSettings::SETTING_LOOKANDFEEL_SOUNDSKIN}, + {AddonType::SCRAPER_ALBUMS, CSettings::SETTING_MUSICLIBRARY_ALBUMSSCRAPER}, + {AddonType::SCRAPER_ARTISTS, CSettings::SETTING_MUSICLIBRARY_ARTISTSSCRAPER}, + {AddonType::SCRAPER_MOVIES, CSettings::SETTING_SCRAPERS_MOVIESDEFAULT}, + {AddonType::SCRAPER_MUSICVIDEOS, CSettings::SETTING_SCRAPERS_MUSICVIDEOSDEFAULT}, + {AddonType::SCRAPER_TVSHOWS, CSettings::SETTING_SCRAPERS_TVSHOWSDEFAULT}, + {AddonType::SCREENSAVER, CSettings::SETTING_SCREENSAVER_MODE}, + {AddonType::SCRIPT_WEATHER, CSettings::SETTING_WEATHER_ADDON}, + {AddonType::SKIN, CSettings::SETTING_LOOKANDFEEL_SKIN}, + {AddonType::WEB_INTERFACE, CSettings::SETTING_SERVICES_WEBSKIN}, + {AddonType::VISUALIZATION, CSettings::SETTING_MUSICPLAYER_VISUALISATION}, } {} @@ -94,7 +96,7 @@ void CAddonSystemSettings::OnSettingChanged(const std::shared_ptr<const CSetting } } -bool CAddonSystemSettings::GetActive(const TYPE& type, AddonPtr& addon) +bool CAddonSystemSettings::GetActive(AddonType type, AddonPtr& addon) { auto it = m_activeSettings.find(type); if (it != m_activeSettings.end()) @@ -106,7 +108,7 @@ bool CAddonSystemSettings::GetActive(const TYPE& type, AddonPtr& addon) return false; } -bool CAddonSystemSettings::SetActive(const TYPE& type, const std::string& addonID) +bool CAddonSystemSettings::SetActive(AddonType type, const std::string& addonID) { auto it = m_activeSettings.find(type); if (it != m_activeSettings.end()) diff --git a/xbmc/addons/AddonSystemSettings.h b/xbmc/addons/AddonSystemSettings.h index b890be8128..bf5ca3858d 100644 --- a/xbmc/addons/AddonSystemSettings.h +++ b/xbmc/addons/AddonSystemSettings.h @@ -8,7 +8,6 @@ #pragma once -#include "addons/addoninfo/AddonType.h" #include "settings/lib/ISettingCallback.h" #include <map> @@ -28,6 +27,8 @@ enum class AddonRepoUpdateMode ANY_REPOSITORY = 1 }; +enum class AddonType; + class CAddonInfo; using AddonInfoPtr = std::shared_ptr<CAddonInfo>; @@ -41,8 +42,8 @@ public: void OnSettingAction(const std::shared_ptr<const CSetting>& setting) override; void OnSettingChanged(const std::shared_ptr<const CSetting>& setting) override; - bool GetActive(const TYPE& type, AddonPtr& addon); - bool SetActive(const TYPE& type, const std::string& addonID); + bool GetActive(AddonType type, AddonPtr& addon); + bool SetActive(AddonType type, const std::string& addonID); bool IsActive(const IAddon& addon); /*! @@ -72,6 +73,6 @@ private: CAddonSystemSettings& operator=(const CAddonSystemSettings&) = delete; ~CAddonSystemSettings() override = default; - const std::map<ADDON::TYPE, std::string> m_activeSettings; + const std::map<AddonType, std::string> m_activeSettings; }; }; diff --git a/xbmc/addons/AddonVersion.cpp b/xbmc/addons/AddonVersion.cpp index 3a2ac7abba..10b314e51c 100644 --- a/xbmc/addons/AddonVersion.cpp +++ b/xbmc/addons/AddonVersion.cpp @@ -7,7 +7,6 @@ */ #include "AddonVersion.h" - #include "utils/StringUtils.h" #include "utils/log.h" @@ -16,163 +15,168 @@ #include <stdlib.h> #include <string.h> -namespace { +namespace +{ // Add-on versions are used e.g. in file names and should // not have too much freedom in their accepted characters // Things that should be allowed: e.g. 0.1.0~beta3+git010cab3 // Note that all of these characters are url-safe -const std::string VALID_ADDON_VERSION_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.+_@~"; -} +const std::string VALID_ADDON_VERSION_CHARACTERS = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.+_@~"; +} // namespace namespace ADDON { - AddonVersion::AddonVersion(const std::string& version) - : mEpoch(0), mUpstream(version.empty() ? - "0.0.0" : - [&version] { - auto versionLowerCase = std::string(version); - StringUtils::ToLower(versionLowerCase); - return versionLowerCase; - }()) +CAddonVersion::CAddonVersion(const std::string& version) + : mEpoch(0), mUpstream(version.empty() ? "0.0.0" : [&version] { + auto versionLowerCase = std::string(version); + StringUtils::ToLower(versionLowerCase); + return versionLowerCase; + }()) +{ + size_t pos = mUpstream.find(':'); + if (pos != std::string::npos) { - size_t pos = mUpstream.find(':'); - if (pos != std::string::npos) - { - mEpoch = strtol(mUpstream.c_str(), nullptr, 10); - mUpstream.erase(0, pos+1); - } - - pos = mUpstream.find('-'); - if (pos != std::string::npos) - { - mRevision = mUpstream.substr(pos+1); - if (mRevision.find_first_not_of(VALID_ADDON_VERSION_CHARACTERS) != std::string::npos) - { - CLog::Log(LOGERROR, "AddonVersion: {} is not a valid revision number", mRevision); - mRevision = ""; - } - mUpstream.erase(pos); - } + mEpoch = strtol(mUpstream.c_str(), nullptr, 10); + mUpstream.erase(0, pos + 1); + } - if (mUpstream.find_first_not_of(VALID_ADDON_VERSION_CHARACTERS) != std::string::npos) + pos = mUpstream.find('-'); + if (pos != std::string::npos) + { + mRevision = mUpstream.substr(pos + 1); + if (mRevision.find_first_not_of(VALID_ADDON_VERSION_CHARACTERS) != std::string::npos) { - CLog::Log(LOGERROR, "AddonVersion: {} is not a valid version", mUpstream); - mUpstream = "0.0.0"; + CLog::Log(LOGERROR, "AddonVersion: {} is not a valid revision number", mRevision); + mRevision = ""; } + mUpstream.erase(pos); } - AddonVersion::AddonVersion(const char* version) - : AddonVersion(std::string(version ? version : "")) + if (mUpstream.find_first_not_of(VALID_ADDON_VERSION_CHARACTERS) != std::string::npos) { + CLog::Log(LOGERROR, "AddonVersion: {} is not a valid version", mUpstream); + mUpstream = "0.0.0"; } +} + +CAddonVersion::CAddonVersion(const char* version) + : CAddonVersion(std::string(version ? version : "")) +{ +} - /**Compare two components of a Debian-style version. Return -1, 0, or 1 +/**Compare two components of a Debian-style version. Return -1, 0, or 1 * if a is less than, equal to, or greater than b, respectively. */ - int AddonVersion::CompareComponent(const char *a, const char *b) +int CAddonVersion::CompareComponent(const char* a, const char* b) +{ + while (*a && *b) { - while (*a && *b) + while (*a && *b && !isdigit(*a) && !isdigit(*b)) { - while (*a && *b && !isdigit(*a) && !isdigit(*b)) - { - if (*a != *b) - { - if (*a == '~') return -1; - if (*b == '~') return 1; - return *a < *b ? -1 : 1; - } - a++; - b++; - } - if (*a && *b && (!isdigit(*a) || !isdigit(*b))) + if (*a != *b) { - if (*a == '~') return -1; - if (*b == '~') return 1; - return isdigit(*a) ? -1 : 1; + if (*a == '~') + return -1; + if (*b == '~') + return 1; + return *a < *b ? -1 : 1; } + a++; + b++; + } + if (*a && *b && (!isdigit(*a) || !isdigit(*b))) + { + if (*a == '~') + return -1; + if (*b == '~') + return 1; + return isdigit(*a) ? -1 : 1; + } - char *next_a, *next_b; - long int num_a = strtol(a, &next_a, 10); - long int num_b = strtol(b, &next_b, 10); - if (num_a != num_b) - return num_a < num_b ? -1 : 1; + char *next_a, *next_b; + long int num_a = strtol(a, &next_a, 10); + long int num_b = strtol(b, &next_b, 10); + if (num_a != num_b) + return num_a < num_b ? -1 : 1; - a = next_a; - b = next_b; - } - if (!*a && !*b) - return 0; - if (*a) - return *a == '~' ? -1 : 1; - else - return *b == '~' ? 1 : -1; + a = next_a; + b = next_b; } + if (!*a && !*b) + return 0; + if (*a) + return *a == '~' ? -1 : 1; + else + return *b == '~' ? 1 : -1; +} - bool AddonVersion::operator<(const AddonVersion& other) const - { - if (mEpoch != other.mEpoch) - return mEpoch < other.mEpoch; +bool CAddonVersion::operator<(const CAddonVersion& other) const +{ + if (mEpoch != other.mEpoch) + return mEpoch < other.mEpoch; - int result = CompareComponent(mUpstream.c_str(), other.mUpstream.c_str()); - if (result) - return (result < 0); + int result = CompareComponent(mUpstream.c_str(), other.mUpstream.c_str()); + if (result) + return (result < 0); - return (CompareComponent(mRevision.c_str(), other.mRevision.c_str()) < 0); - } + return (CompareComponent(mRevision.c_str(), other.mRevision.c_str()) < 0); +} - bool AddonVersion::operator>(const AddonVersion & other) const - { - return !(*this <= other); - } +bool CAddonVersion::operator>(const CAddonVersion& other) const +{ + return !(*this <= other); +} - bool AddonVersion::operator==(const AddonVersion& other) const - { - return mEpoch == other.mEpoch - && CompareComponent(mUpstream.c_str(), other.mUpstream.c_str()) == 0 - && CompareComponent(mRevision.c_str(), other.mRevision.c_str()) == 0; - } +bool CAddonVersion::operator==(const CAddonVersion& other) const +{ + return mEpoch == other.mEpoch && + CompareComponent(mUpstream.c_str(), other.mUpstream.c_str()) == 0 && + CompareComponent(mRevision.c_str(), other.mRevision.c_str()) == 0; +} - bool AddonVersion::operator!=(const AddonVersion & other) const - { - return !(*this == other); - } +bool CAddonVersion::operator!=(const CAddonVersion& other) const +{ + return !(*this == other); +} - bool AddonVersion::operator<=(const AddonVersion& other) const - { - return *this < other || *this == other; - } +bool CAddonVersion::operator<=(const CAddonVersion& other) const +{ + return *this < other || *this == other; +} - bool AddonVersion::operator>=(const AddonVersion & other) const - { - return !(*this < other); - } +bool CAddonVersion::operator>=(const CAddonVersion& other) const +{ + return !(*this < other); +} - bool AddonVersion::empty() const - { - return mEpoch == 0 && mUpstream == "0.0.0" && mRevision.empty(); - } +bool CAddonVersion::empty() const +{ + return mEpoch == 0 && mUpstream == "0.0.0" && mRevision.empty(); +} - std::string AddonVersion::asString() const - { - std::string out; - if (mEpoch) - out = StringUtils::Format("{}:", mEpoch); - out += mUpstream; - if (!mRevision.empty()) - out += "-" + mRevision; - return out; - } +std::string CAddonVersion::asString() const +{ + std::string out; + if (mEpoch) + out = StringUtils::Format("{}:", mEpoch); + out += mUpstream; + if (!mRevision.empty()) + out += "-" + mRevision; + return out; +} - bool AddonVersion::SplitFileName(std::string& ID, std::string& version, - const std::string& filename) - { - size_t dpos = filename.rfind('-'); - if (dpos == std::string::npos) - return false; - ID = filename.substr(0, dpos); - version = filename.substr(dpos + 1); - version = version.substr(0, version.size() - 4); - - return true; - } +bool CAddonVersion::SplitFileName(std::string& ID, + std::string& version, + const std::string& filename) +{ + size_t dpos = filename.rfind('-'); + if (dpos == std::string::npos) + return false; + ID = filename.substr(0, dpos); + version = filename.substr(dpos + 1); + version = version.substr(0, version.size() - 4); + + return true; } +} // namespace ADDON diff --git a/xbmc/addons/AddonVersion.h b/xbmc/addons/AddonVersion.h index 1d32bcbcdf..78537a551a 100644 --- a/xbmc/addons/AddonVersion.h +++ b/xbmc/addons/AddonVersion.h @@ -12,9 +12,9 @@ namespace ADDON { - /* \brief Addon versioning using the debian versioning scheme +/* \brief Addon versioning using the debian versioning scheme - AddonVersion uses debian versioning, which means in the each section of the period + CAddonVersion uses debian versioning, which means in the each section of the period separated version string, numbers are compared numerically rather than lexicographically, thus any preceding zeros are ignored. @@ -24,40 +24,39 @@ namespace ADDON See here for more info: http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version */ - class AddonVersion - { - public: - explicit AddonVersion(const char* version = nullptr); - explicit AddonVersion(const std::string& version); - - AddonVersion(const AddonVersion& other) = default; - AddonVersion(AddonVersion&& other) = default; - AddonVersion& operator=(const AddonVersion& other) = default; - AddonVersion& operator=(AddonVersion&& other) = default; - - virtual ~AddonVersion() = default; - - int Epoch() const { return mEpoch; } - const std::string &Upstream() const { return mUpstream; } - const std::string &Revision() const { return mRevision; } - - bool operator< (const AddonVersion& other) const; - bool operator> (const AddonVersion& other) const; - bool operator<=(const AddonVersion& other) const; - bool operator>=(const AddonVersion& other) const; - bool operator==(const AddonVersion& other) const; - bool operator!=(const AddonVersion& other) const; - std::string asString() const; - bool empty() const; - - static bool SplitFileName(std::string& ID, std::string& version, - const std::string& filename); - - protected: - int mEpoch; - std::string mUpstream; - std::string mRevision; - - static int CompareComponent(const char *a, const char *b); - }; -} +class CAddonVersion +{ +public: + explicit CAddonVersion(const char* version = nullptr); + explicit CAddonVersion(const std::string& version); + + CAddonVersion(const CAddonVersion& other) = default; + CAddonVersion(CAddonVersion&& other) = default; + CAddonVersion& operator=(const CAddonVersion& other) = default; + CAddonVersion& operator=(CAddonVersion&& other) = default; + + virtual ~CAddonVersion() = default; + + int Epoch() const { return mEpoch; } + const std::string& Upstream() const { return mUpstream; } + const std::string& Revision() const { return mRevision; } + + bool operator<(const CAddonVersion& other) const; + bool operator>(const CAddonVersion& other) const; + bool operator<=(const CAddonVersion& other) const; + bool operator>=(const CAddonVersion& other) const; + bool operator==(const CAddonVersion& other) const; + bool operator!=(const CAddonVersion& other) const; + std::string asString() const; + bool empty() const; + + static bool SplitFileName(std::string& ID, std::string& version, const std::string& filename); + +protected: + int mEpoch; + std::string mUpstream; + std::string mRevision; + + static int CompareComponent(const char* a, const char* b); +}; +} // namespace ADDON diff --git a/xbmc/addons/AudioDecoder.cpp b/xbmc/addons/AudioDecoder.cpp index 675b1863fb..f2531a19eb 100644 --- a/xbmc/addons/AudioDecoder.cpp +++ b/xbmc/addons/AudioDecoder.cpp @@ -9,6 +9,7 @@ #include "FileItem.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "addons/interfaces/AudioEngine.h" #include "cores/AudioEngine/Utils/AEUtil.h" #include "filesystem/File.h" @@ -24,9 +25,9 @@ using namespace KODI::ADDONS; CAudioDecoder::CAudioDecoder(const AddonInfoPtr& addonInfo) : IAddonInstanceHandler(ADDON_INSTANCE_AUDIODECODER, addonInfo) { - m_CodecName = addonInfo->Type(ADDON_AUDIODECODER)->GetValue("@name").asString(); + m_CodecName = addonInfo->Type(AddonType::AUDIODECODER)->GetValue("@name").asString(); m_strExt = m_CodecName + KODI_ADDON_AUDIODECODER_TRACK_EXT; - m_hasTags = addonInfo->Type(ADDON_AUDIODECODER)->GetValue("@tags").asBoolean(); + m_hasTags = addonInfo->Type(AddonType::AUDIODECODER)->GetValue("@tags").asBoolean(); // Create all interface parts independent to make API changes easier if // something is added diff --git a/xbmc/addons/BinaryAddonCache.cpp b/xbmc/addons/BinaryAddonCache.cpp index 7823b8df94..3005d44516 100644 --- a/xbmc/addons/BinaryAddonCache.cpp +++ b/xbmc/addons/BinaryAddonCache.cpp @@ -8,16 +8,17 @@ #include "BinaryAddonCache.h" -#include "AddonEvents.h" -#include "AddonManager.h" #include "ServiceBroker.h" +#include "addons/AddonEvents.h" +#include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include <mutex> namespace ADDON { -const std::vector<TYPE> ADDONS_TO_CACHE = {ADDON_GAMEDLL}; +const std::vector<AddonType> ADDONS_TO_CACHE = {AddonType::GAMEDLL}; CBinaryAddonCache::~CBinaryAddonCache() { @@ -35,7 +36,7 @@ void CBinaryAddonCache::Deinit() CServiceBroker::GetAddonMgr().Events().Unsubscribe(this); } -void CBinaryAddonCache::GetAddons(VECADDONS& addons, const TYPE& type) +void CBinaryAddonCache::GetAddons(VECADDONS& addons, AddonType type) { VECADDONS myAddons; GetInstalledAddons(myAddons, type); @@ -47,7 +48,7 @@ void CBinaryAddonCache::GetAddons(VECADDONS& addons, const TYPE& type) } } -void CBinaryAddonCache::GetDisabledAddons(VECADDONS& addons, const TYPE& type) +void CBinaryAddonCache::GetDisabledAddons(VECADDONS& addons, AddonType type) { VECADDONS myAddons; GetInstalledAddons(myAddons, type); @@ -59,7 +60,7 @@ void CBinaryAddonCache::GetDisabledAddons(VECADDONS& addons, const TYPE& type) } } -void CBinaryAddonCache::GetInstalledAddons(VECADDONS& addons, const TYPE& type) +void CBinaryAddonCache::GetInstalledAddons(VECADDONS& addons, AddonType type) { std::unique_lock<CCriticalSection> lock(m_critSection); auto it = m_addons.find(type); @@ -67,7 +68,7 @@ void CBinaryAddonCache::GetInstalledAddons(VECADDONS& addons, const TYPE& type) addons = it->second; } -AddonPtr CBinaryAddonCache::GetAddonInstance(const std::string& strId, TYPE type) +AddonPtr CBinaryAddonCache::GetAddonInstance(const std::string& strId, AddonType type) { AddonPtr addon; @@ -113,7 +114,7 @@ void CBinaryAddonCache::OnEvent(const AddonEvent& event) void CBinaryAddonCache::Update() { - using AddonMap = std::multimap<TYPE, VECADDONS>; + using AddonMap = std::multimap<AddonType, VECADDONS>; AddonMap addonmap; for (auto &addonType : ADDONS_TO_CACHE) diff --git a/xbmc/addons/BinaryAddonCache.h b/xbmc/addons/BinaryAddonCache.h index 9c9591cc94..5536c9ff00 100644 --- a/xbmc/addons/BinaryAddonCache.h +++ b/xbmc/addons/BinaryAddonCache.h @@ -8,7 +8,6 @@ #pragma once -#include "addons/addoninfo/AddonType.h" #include "threads/CriticalSection.h" #include <map> @@ -18,6 +17,8 @@ namespace ADDON { +enum class AddonType; + class IAddon; using AddonPtr = std::shared_ptr<IAddon>; using VECADDONS = std::vector<AddonPtr>; @@ -30,17 +31,17 @@ public: virtual ~CBinaryAddonCache(); void Init(); void Deinit(); - void GetAddons(VECADDONS& addons, const TYPE& type); - void GetDisabledAddons(VECADDONS& addons, const TYPE& type); - void GetInstalledAddons(VECADDONS& addons, const TYPE& type); - AddonPtr GetAddonInstance(const std::string& strId, TYPE type); + void GetAddons(VECADDONS& addons, AddonType type); + void GetDisabledAddons(VECADDONS& addons, AddonType type); + void GetInstalledAddons(VECADDONS& addons, AddonType type); + AddonPtr GetAddonInstance(const std::string& strId, AddonType type); protected: void Update(); void OnEvent(const AddonEvent& event); CCriticalSection m_critSection; - std::multimap<TYPE, VECADDONS> m_addons; + std::multimap<AddonType, VECADDONS> m_addons; }; } // namespace ADDON diff --git a/xbmc/addons/ContextMenuAddon.cpp b/xbmc/addons/ContextMenuAddon.cpp index bb1aa90883..1717580da7 100644 --- a/xbmc/addons/ContextMenuAddon.cpp +++ b/xbmc/addons/ContextMenuAddon.cpp @@ -10,6 +10,7 @@ #include "ContextMenuItem.h" #include "ContextMenuManager.h" +#include "addons/addoninfo/AddonType.h" #include "guilib/LocalizeStrings.h" #include "utils/StringUtils.h" #include "utils/URIUtils.h" @@ -20,9 +21,9 @@ namespace ADDON { CContextMenuAddon::CContextMenuAddon(const AddonInfoPtr& addonInfo) - : CAddon(addonInfo, ADDON_CONTEXT_ITEM) + : CAddon(addonInfo, AddonType::CONTEXTMENU_ITEM) { - const CAddonExtensions* menu = Type(ADDON_CONTEXT_ITEM)->GetElement("menu"); + const CAddonExtensions* menu = Type(AddonType::CONTEXTMENU_ITEM)->GetElement("menu"); if (menu) { int tmp = 0; @@ -31,7 +32,7 @@ CContextMenuAddon::CContextMenuAddon(const AddonInfoPtr& addonInfo) else { //backwards compatibility. add first item definition - const CAddonExtensions* elem = Type(ADDON_CONTEXT_ITEM)->GetElement("item"); + const CAddonExtensions* elem = Type(AddonType::CONTEXTMENU_ITEM)->GetElement("item"); if (elem) { std::string visCondition = elem->GetValue("visible").asString(); @@ -45,8 +46,10 @@ CContextMenuAddon::CContextMenuAddon(const AddonInfoPtr& addonInfo) if (StringUtils::IsNaturalNumber(label)) label = g_localizeStrings.GetAddonString(ID(), atoi(label.c_str())); - CContextMenuItem menuItem = CContextMenuItem::CreateItem(label, parent, - URIUtils::AddFileToFolder(Path(), Type(ADDON_CONTEXT_ITEM)->LibName()), visCondition, ID()); + CContextMenuItem menuItem = CContextMenuItem::CreateItem( + label, parent, + URIUtils::AddFileToFolder(Path(), Type(AddonType::CONTEXTMENU_ITEM)->LibName()), + visCondition, ID()); m_items.push_back(menuItem); } diff --git a/xbmc/addons/ContextMenuAddon.h b/xbmc/addons/ContextMenuAddon.h index a3f3e34c2f..74221fdcb1 100644 --- a/xbmc/addons/ContextMenuAddon.h +++ b/xbmc/addons/ContextMenuAddon.h @@ -8,7 +8,7 @@ #pragma once -#include "Addon.h" +#include "addons/Addon.h" #include <memory> #include <vector> @@ -17,6 +17,7 @@ class CContextMenuItem; namespace ADDON { +class CAddonExtensions; class CAddonInfo; using AddonInfoPtr = std::shared_ptr<CAddonInfo>; diff --git a/xbmc/addons/ContextMenus.cpp b/xbmc/addons/ContextMenus.cpp index ac1986b23b..23f50365d4 100644 --- a/xbmc/addons/ContextMenus.cpp +++ b/xbmc/addons/ContextMenus.cpp @@ -8,11 +8,12 @@ #include "ContextMenus.h" -#include "AddonManager.h" #include "FileItem.h" -#include "Repository.h" -#include "RepositoryUpdater.h" #include "ServiceBroker.h" +#include "addons/AddonManager.h" +#include "addons/Repository.h" +#include "addons/RepositoryUpdater.h" +#include "addons/addoninfo/AddonType.h" #include "addons/gui/GUIDialogAddonInfo.h" #include "addons/gui/GUIDialogAddonSettings.h" #include "addons/gui/GUIHelpers.h" @@ -36,7 +37,7 @@ bool CAddonSettings::IsVisible(const CFileItem& item) const { AddonPtr addon; return item.HasAddonInfo() && - CServiceBroker::GetAddonMgr().GetAddon(item.GetAddonInfo()->ID(), addon, ADDON_UNKNOWN, + CServiceBroker::GetAddonMgr().GetAddon(item.GetAddonInfo()->ID(), addon, OnlyEnabled::CHOICE_NO) && addon->CanHaveAddonOrInstanceSettings(); } @@ -44,22 +45,22 @@ bool CAddonSettings::IsVisible(const CFileItem& item) const bool CAddonSettings::Execute(const std::shared_ptr<CFileItem>& item) const { AddonPtr addon; - return CServiceBroker::GetAddonMgr().GetAddon(item->GetAddonInfo()->ID(), addon, ADDON_UNKNOWN, + return CServiceBroker::GetAddonMgr().GetAddon(item->GetAddonInfo()->ID(), addon, OnlyEnabled::CHOICE_NO) && CGUIDialogAddonSettings::ShowForAddon(addon); } bool CCheckForUpdates::IsVisible(const CFileItem& item) const { - return item.HasAddonInfo() && item.GetAddonInfo()->Type() == ADDON::ADDON_REPOSITORY; + return item.HasAddonInfo() && item.GetAddonInfo()->Type() == AddonType::REPOSITORY; } bool CCheckForUpdates::Execute(const std::shared_ptr<CFileItem>& item) const { AddonPtr addon; if (item->HasAddonInfo() && - CServiceBroker::GetAddonMgr().GetAddon(item->GetAddonInfo()->ID(), addon, ADDON_REPOSITORY, - OnlyEnabled::CHOICE_YES)) + CServiceBroker::GetAddonMgr().GetAddon(item->GetAddonInfo()->ID(), addon, + AddonType::REPOSITORY, OnlyEnabled::CHOICE_YES)) { CServiceBroker::GetRepositoryUpdater().CheckForUpdates(std::static_pointer_cast<CRepository>(addon), true); return true; diff --git a/xbmc/addons/ExtsMimeSupportList.cpp b/xbmc/addons/ExtsMimeSupportList.cpp index 781df98a50..88c6d49377 100644 --- a/xbmc/addons/ExtsMimeSupportList.cpp +++ b/xbmc/addons/ExtsMimeSupportList.cpp @@ -11,6 +11,7 @@ #include "addons/AddonEvents.h" #include "addons/AddonManager.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "addons/kodi-dev-kit/include/kodi/addon-instance/AudioDecoder.h" #include "guilib/LocalizeStrings.h" #include "utils/URIUtils.h" @@ -26,7 +27,7 @@ CExtsMimeSupportList::CExtsMimeSupportList(CAddonMgr& addonMgr) : m_addonMgr(add m_addonMgr.Events().Subscribe(this, &CExtsMimeSupportList::OnEvent); // Load all available audio decoder addons during Kodi start - const std::vector<TYPE> types = {ADDON_AUDIODECODER, ADDON_IMAGEDECODER}; + const std::vector<AddonType> types = {AddonType::AUDIODECODER, AddonType::IMAGEDECODER}; const auto addonInfos = m_addonMgr.GetAddonInfos(true, types); for (const auto& addonInfo : addonInfos) m_supportedList.emplace_back(ScanAddonProperties(addonInfo->MainType(), addonInfo)); @@ -43,8 +44,8 @@ void CExtsMimeSupportList::OnEvent(const AddonEvent& event) typeid(event) == typeid(AddonEvents::Disabled) || typeid(event) == typeid(AddonEvents::ReInstalled)) { - if (m_addonMgr.HasType(event.addonId, ADDON_AUDIODECODER) || - m_addonMgr.HasType(event.addonId, ADDON_IMAGEDECODER)) + if (m_addonMgr.HasType(event.addonId, AddonType::AUDIODECODER) || + m_addonMgr.HasType(event.addonId, AddonType::IMAGEDECODER)) Update(event.addonId); } else if (typeid(event) == typeid(AddonEvents::UnInstalled)) @@ -70,10 +71,10 @@ void CExtsMimeSupportList::Update(const std::string& id) } // Create and init the new addon instance - std::shared_ptr<CAddonInfo> addonInfo = m_addonMgr.GetAddonInfo(id); + std::shared_ptr<CAddonInfo> addonInfo = m_addonMgr.GetAddonInfo(id, AddonType::UNKNOWN); if (addonInfo && !m_addonMgr.IsAddonDisabled(id)) { - if (addonInfo->HasType(ADDON_AUDIODECODER) || addonInfo->HasType(ADDON_IMAGEDECODER)) + if (addonInfo->HasType(AddonType::AUDIODECODER) || addonInfo->HasType(AddonType::IMAGEDECODER)) { SupportValues values = ScanAddonProperties(addonInfo->MainType(), addonInfo); { @@ -85,13 +86,13 @@ void CExtsMimeSupportList::Update(const std::string& id) } CExtsMimeSupportList::SupportValues CExtsMimeSupportList::ScanAddonProperties( - ADDON::TYPE type, const std::shared_ptr<CAddonInfo>& addonInfo) + AddonType type, const std::shared_ptr<CAddonInfo>& addonInfo) { SupportValues values; values.m_addonType = type; values.m_addonInfo = addonInfo; - if (type == ADDON_AUDIODECODER) + if (type == AddonType::AUDIODECODER) { values.m_codecName = addonInfo->Type(type)->GetValue("@name").asString(); values.m_hasTags = addonInfo->Type(type)->GetValue("@tags").asBoolean(); @@ -195,10 +196,10 @@ bool CExtsMimeSupportList::IsExtensionSupported(const std::string& ext) return false; } -std::vector<std::pair<ADDON::TYPE, std::shared_ptr<ADDON::CAddonInfo>>> CExtsMimeSupportList:: +std::vector<std::pair<AddonType, std::shared_ptr<ADDON::CAddonInfo>>> CExtsMimeSupportList:: GetExtensionSupportedAddonInfos(const std::string& ext, FilterSelect select) { - std::vector<std::pair<ADDON::TYPE, std::shared_ptr<CAddonInfo>>> addonInfos; + std::vector<std::pair<AddonType, std::shared_ptr<CAddonInfo>>> addonInfos; std::unique_lock<CCriticalSection> lock(m_critSection); @@ -233,10 +234,10 @@ bool CExtsMimeSupportList::IsMimetypeSupported(const std::string& mimetype) return false; } -std::vector<std::pair<ADDON::TYPE, std::shared_ptr<CAddonInfo>>> CExtsMimeSupportList:: +std::vector<std::pair<AddonType, std::shared_ptr<CAddonInfo>>> CExtsMimeSupportList:: GetMimetypeSupportedAddonInfos(const std::string& mimetype, FilterSelect select) { - std::vector<std::pair<ADDON::TYPE, std::shared_ptr<CAddonInfo>>> addonInfos; + std::vector<std::pair<AddonType, std::shared_ptr<CAddonInfo>>> addonInfos; std::unique_lock<CCriticalSection> lock(m_critSection); diff --git a/xbmc/addons/ExtsMimeSupportList.h b/xbmc/addons/ExtsMimeSupportList.h index 84264f21ba..f7e8d475eb 100644 --- a/xbmc/addons/ExtsMimeSupportList.h +++ b/xbmc/addons/ExtsMimeSupportList.h @@ -9,7 +9,6 @@ #pragma once #include "addons/IAddonSupportList.h" -#include "addons/addoninfo/AddonType.h" #include "threads/CriticalSection.h" #include <map> @@ -20,6 +19,7 @@ namespace ADDON { +enum class AddonType; class CAddonMgr; class CAddonInfo; @@ -83,7 +83,7 @@ public: struct SupportValues { // Type of stored addon to check on scan - ADDON::TYPE m_addonType{ADDON::ADDON_UNKNOWN}; + ADDON::AddonType m_addonType{}; // Related addon info class std::shared_ptr<ADDON::CAddonInfo> m_addonInfo; @@ -138,7 +138,7 @@ public: * @param[in] select To filter the listed information by type * @return List of @ref ADDON::CAddonInfo where support related extension */ - std::vector<std::pair<ADDON::TYPE, std::shared_ptr<ADDON::CAddonInfo>>> + std::vector<std::pair<ADDON::AddonType, std::shared_ptr<ADDON::CAddonInfo>>> GetExtensionSupportedAddonInfos(const std::string& ext, FilterSelect select); /*! @@ -156,7 +156,7 @@ public: * @param[in] select To filter the listed information by type * @return List of @ref ADDON::CAddonInfo where support related mimetype */ - std::vector<std::pair<ADDON::TYPE, std::shared_ptr<ADDON::CAddonInfo>>> + std::vector<std::pair<ADDON::AddonType, std::shared_ptr<ADDON::CAddonInfo>>> GetMimetypeSupportedAddonInfos(const std::string& mimetype, FilterSelect select); /*! @@ -174,7 +174,7 @@ protected: void Update(const std::string& id); void OnEvent(const ADDON::AddonEvent& event); - static SupportValues ScanAddonProperties(ADDON::TYPE type, + static SupportValues ScanAddonProperties(ADDON::AddonType type, const std::shared_ptr<ADDON::CAddonInfo>& addonInfo); CCriticalSection m_critSection; diff --git a/xbmc/addons/FontResource.cpp b/xbmc/addons/FontResource.cpp index 8f5023eccb..0ed843bb28 100644 --- a/xbmc/addons/FontResource.cpp +++ b/xbmc/addons/FontResource.cpp @@ -7,9 +7,10 @@ */ #include "FontResource.h" -#include "AddonManager.h" #include "ServiceBroker.h" +#include "addons/AddonManager.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "filesystem/SpecialProtocol.h" #include "messaging/ApplicationMessenger.h" #include "settings/Settings.h" @@ -19,6 +20,11 @@ namespace ADDON { +CFontResource::CFontResource(const AddonInfoPtr& addonInfo) + : CResource(addonInfo, AddonType::RESOURCE_FONT) +{ +} + void CFontResource::OnPostInstall(bool update, bool modal) { std::string skin = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_LOOKANDFEEL_SKIN); diff --git a/xbmc/addons/FontResource.h b/xbmc/addons/FontResource.h index 10cabeaeaa..350090d48a 100644 --- a/xbmc/addons/FontResource.h +++ b/xbmc/addons/FontResource.h @@ -17,7 +17,7 @@ namespace ADDON class CFontResource : public CResource { public: - explicit CFontResource(const AddonInfoPtr& addonInfo) : CResource(addonInfo, ADDON_RESOURCE_FONT) {} + explicit CFontResource(const AddonInfoPtr& addonInfo); //! \brief Check whether file is allowed or not (no filters here). bool IsAllowed(const std::string& file) const override { return true; } diff --git a/xbmc/addons/GameResource.cpp b/xbmc/addons/GameResource.cpp index cce623a3d0..257da967c9 100644 --- a/xbmc/addons/GameResource.cpp +++ b/xbmc/addons/GameResource.cpp @@ -8,11 +8,13 @@ #include "GameResource.h" +#include "addons/addoninfo/AddonType.h" + #include <utility> using namespace ADDON; -CGameResource::CGameResource(const AddonInfoPtr& addonInfo) : - CResource(addonInfo, ADDON_RESOURCE_GAMES) +CGameResource::CGameResource(const AddonInfoPtr& addonInfo) + : CResource(addonInfo, AddonType::RESOURCE_GAMES) { } diff --git a/xbmc/addons/IAddon.h b/xbmc/addons/IAddon.h index 3678b251ad..6953b207c3 100644 --- a/xbmc/addons/IAddon.h +++ b/xbmc/addons/IAddon.h @@ -8,8 +8,6 @@ #pragma once -#include "addons/addoninfo/AddonType.h" - #include <map> #include <memory> #include <string> @@ -20,8 +18,15 @@ class TiXmlElement; namespace ADDON { +enum class AddonInstanceSupport; +enum class AddonLifecycleState; +enum class AddonType; + +class CAddonMgr; +class CAddonSettings; +class CAddonVersion; -class AddonVersion; +struct DependencyInfo; using AddonInstanceId = uint32_t; @@ -55,22 +60,11 @@ constexpr AddonInstanceId ADDON_INSTANCE_ID_UNUSED = ADDON_SINGLETON_INSTANCE_ID */ constexpr AddonInstanceId ADDON_SETTINGS_ID = ADDON_SINGLETON_INSTANCE_ID; +constexpr char const* ORIGIN_SYSTEM = "b6a50484-93a0-4afb-a01c-8d17e059feda"; + class IAddon; typedef std::shared_ptr<IAddon> AddonPtr; -class CInstanceVisualization; -typedef std::shared_ptr<CInstanceVisualization> VizPtr; -class CSkinInfo; -typedef std::shared_ptr<CSkinInfo> SkinPtr; -class CPluginSource; -typedef std::shared_ptr<CPluginSource> PluginPtr; - -enum class AddonInstanceSupport; -enum class AddonLifecycleState; - -class CAddonMgr; -class CAddonSettings; - -struct DependencyInfo; +typedef std::vector<AddonPtr> VECADDONS; using InfoMap = std::map<std::string, std::string>; using ArtMap = std::map<std::string, std::string>; @@ -79,16 +73,16 @@ class IAddon : public std::enable_shared_from_this<IAddon> { public: virtual ~IAddon() = default; - virtual TYPE MainType() const = 0; - virtual TYPE Type() const = 0; - virtual bool HasType(TYPE type) const = 0; - virtual bool HasMainType(TYPE type) const = 0; + virtual AddonType MainType() const = 0; + virtual AddonType Type() const = 0; + virtual bool HasType(AddonType type) const = 0; + virtual bool HasMainType(AddonType type) const = 0; virtual std::string ID() const = 0; virtual std::string Name() const = 0; virtual bool IsInUse() const = 0; virtual bool IsBinary() const = 0; - virtual AddonVersion Version() const = 0; - virtual AddonVersion MinVersion() const = 0; + virtual CAddonVersion Version() const = 0; + virtual CAddonVersion MinVersion() const = 0; virtual std::string Summary() const = 0; virtual std::string Description() const = 0; virtual std::string Path() const = 0; @@ -150,8 +144,9 @@ public: AddonInstanceId id = ADDON_SETTINGS_ID) = 0; virtual std::shared_ptr<CAddonSettings> GetSettings(AddonInstanceId id = ADDON_SETTINGS_ID) = 0; virtual const std::vector<DependencyInfo>& GetDependencies() const = 0; - virtual AddonVersion GetDependencyVersion(const std::string& dependencyID) const = 0; - virtual bool MeetsVersion(const AddonVersion& versionMin, const AddonVersion& version) const = 0; + virtual CAddonVersion GetDependencyVersion(const std::string& dependencyID) const = 0; + virtual bool MeetsVersion(const CAddonVersion& versionMin, + const CAddonVersion& version) const = 0; virtual bool ReloadSettings(AddonInstanceId id = ADDON_SETTINGS_ID) = 0; virtual void ResetSettings(AddonInstanceId id = ADDON_SETTINGS_ID) = 0; virtual AddonPtr GetRunningInstance() const = 0; diff --git a/xbmc/addons/ImageResource.cpp b/xbmc/addons/ImageResource.cpp index 0aea8ded27..06eada3b1a 100644 --- a/xbmc/addons/ImageResource.cpp +++ b/xbmc/addons/ImageResource.cpp @@ -8,6 +8,7 @@ #include "ImageResource.h" #include "URL.h" +#include "addons/addoninfo/AddonType.h" #include "filesystem/XbtManager.h" #include "utils/FileUtils.h" #include "utils/StringUtils.h" @@ -17,9 +18,9 @@ namespace ADDON { CImageResource::CImageResource(const AddonInfoPtr& addonInfo) - : CResource(addonInfo, ADDON_RESOURCE_IMAGES) + : CResource(addonInfo, AddonType::RESOURCE_IMAGES) { - m_type = Type(ADDON_RESOURCE_IMAGES)->GetValue("@type").asString(); + m_type = Type(AddonType::RESOURCE_IMAGES)->GetValue("@type").asString(); } void CImageResource::OnPreUnInstall() diff --git a/xbmc/addons/LanguageResource.cpp b/xbmc/addons/LanguageResource.cpp index 87f18b99b5..c9ec0c8afc 100644 --- a/xbmc/addons/LanguageResource.cpp +++ b/xbmc/addons/LanguageResource.cpp @@ -9,8 +9,9 @@ #include "LangInfo.h" #include "ServiceBroker.h" -#include "Skin.h" #include "addons/AddonManager.h" +#include "addons/Skin.h" +#include "addons/addoninfo/AddonType.h" #include "guilib/GUIWindowManager.h" #include "messaging/helpers/DialogHelper.h" #include "settings/Settings.h" @@ -28,13 +29,15 @@ namespace ADDON { CLanguageResource::CLanguageResource(const AddonInfoPtr& addonInfo) - : CResource(addonInfo, ADDON_RESOURCE_LANGUAGE) + : CResource(addonInfo, AddonType::RESOURCE_LANGUAGE) { // parse <extension> attributes - m_locale = CLocale::FromString(Type(ADDON_RESOURCE_LANGUAGE)->GetValue("@locale").asString()); + m_locale = + CLocale::FromString(Type(AddonType::RESOURCE_LANGUAGE)->GetValue("@locale").asString()); // parse <charsets> - const CAddonExtensions* charsetsElement = Type(ADDON_RESOURCE_LANGUAGE)->GetElement("charsets"); + const CAddonExtensions* charsetsElement = + Type(AddonType::RESOURCE_LANGUAGE)->GetElement("charsets"); if (charsetsElement != nullptr) { m_charsetGui = charsetsElement->GetValue("gui").asString(); @@ -43,7 +46,7 @@ CLanguageResource::CLanguageResource(const AddonInfoPtr& addonInfo) } // parse <dvd> - const CAddonExtensions* dvdElement = Type(ADDON_RESOURCE_LANGUAGE)->GetElement("dvd"); + const CAddonExtensions* dvdElement = Type(AddonType::RESOURCE_LANGUAGE)->GetElement("dvd"); if (dvdElement != nullptr) { m_dvdLanguageMenu = dvdElement->GetValue("menu").asString(); @@ -59,7 +62,8 @@ CLanguageResource::CLanguageResource(const AddonInfoPtr& addonInfo) m_dvdLanguageSubtitle = m_locale.GetLanguageCode(); // parse <sorttokens> - const CAddonExtensions* sorttokensElement = Type(ADDON_RESOURCE_LANGUAGE)->GetElement("sorttokens"); + const CAddonExtensions* sorttokensElement = + Type(AddonType::RESOURCE_LANGUAGE)->GetElement("sorttokens"); if (sorttokensElement != nullptr) { /* First loop goes around rows e.g. @@ -136,7 +140,7 @@ bool CLanguageResource::FindLegacyLanguage(const std::string &locale, std::strin std::string addonId = GetAddonId(locale); AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(addonId, addon, ADDON_RESOURCE_LANGUAGE, + if (!CServiceBroker::GetAddonMgr().GetAddon(addonId, addon, AddonType::RESOURCE_LANGUAGE, OnlyEnabled::CHOICE_YES)) return false; diff --git a/xbmc/addons/PluginSource.cpp b/xbmc/addons/PluginSource.cpp index cc591b5235..c61d7b1fae 100644 --- a/xbmc/addons/PluginSource.cpp +++ b/xbmc/addons/PluginSource.cpp @@ -10,6 +10,7 @@ #include "URL.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "utils/StringUtils.h" #include <utility> @@ -17,7 +18,8 @@ namespace ADDON { -CPluginSource::CPluginSource(const AddonInfoPtr& addonInfo, TYPE addonType) : CAddon(addonInfo, addonType) +CPluginSource::CPluginSource(const AddonInfoPtr& addonInfo, AddonType addonType) + : CAddon(addonInfo, addonType) { std::string provides = addonInfo->Type(addonType)->GetValue("provides").asString(); @@ -51,7 +53,7 @@ void CPluginSource::SetProvides(const std::string &content) m_providedContent.insert(content); } } - if (Type() == ADDON_SCRIPT && m_providedContent.empty()) + if (Type() == AddonType::SCRIPT && m_providedContent.empty()) m_providedContent.insert(EXECUTABLE); } @@ -71,14 +73,13 @@ CPluginSource::Content CPluginSource::Translate(const std::string &content) return CPluginSource::UNKNOWN; } -bool CPluginSource::HasType(TYPE type) const +bool CPluginSource::HasType(AddonType type) const { - return ((type == ADDON_VIDEO && Provides(VIDEO)) - || (type == ADDON_AUDIO && Provides(AUDIO)) - || (type == ADDON_IMAGE && Provides(IMAGE)) - || (type == ADDON_GAME && Provides(GAME)) - || (type == ADDON_EXECUTABLE && Provides(EXECUTABLE)) - || (type == CAddon::Type())); + return ((type == AddonType::VIDEO && Provides(VIDEO)) || + (type == AddonType::AUDIO && Provides(AUDIO)) || + (type == AddonType::IMAGE && Provides(IMAGE)) || + (type == AddonType::GAME && Provides(GAME)) || + (type == AddonType::EXECUTABLE && Provides(EXECUTABLE)) || (type == CAddon::Type())); } } /*namespace ADDON*/ diff --git a/xbmc/addons/PluginSource.h b/xbmc/addons/PluginSource.h index 27a3cee451..722df8bb67 100644 --- a/xbmc/addons/PluginSource.h +++ b/xbmc/addons/PluginSource.h @@ -8,7 +8,9 @@ #pragma once -#include "Addon.h" +#include "addons/Addon.h" + +#include <set> namespace ADDON { @@ -21,9 +23,9 @@ public: enum Content { UNKNOWN, AUDIO, IMAGE, EXECUTABLE, VIDEO, GAME }; - explicit CPluginSource(const AddonInfoPtr& addonInfo, TYPE addonType); + explicit CPluginSource(const AddonInfoPtr& addonInfo, AddonType addonType); - bool HasType(TYPE type) const override; + bool HasType(AddonType type) const override; bool Provides(const Content& content) const { return content == UNKNOWN ? false : m_providedContent.count(content) > 0; diff --git a/xbmc/addons/Repository.cpp b/xbmc/addons/Repository.cpp index a93c51c452..6708e71c2a 100644 --- a/xbmc/addons/Repository.cpp +++ b/xbmc/addons/Repository.cpp @@ -10,13 +10,13 @@ #include "FileItem.h" #include "ServiceBroker.h" -#include "TextureDatabase.h" #include "URL.h" #include "addons/AddonDatabase.h" #include "addons/AddonInstaller.h" #include "addons/AddonManager.h" #include "addons/RepositoryUpdater.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "filesystem/CurlFile.h" #include "filesystem/File.h" #include "filesystem/ZipFile.h" @@ -45,8 +45,7 @@ CRepository::ResolveResult CRepository::ResolvePathAndHash(const AddonPtr& addon { std::string const& path = addon->Path(); - auto dirIt = std::find_if(m_dirs.begin(), m_dirs.end(), [&path](DirInfo const& dir) - { + auto dirIt = std::find_if(m_dirs.begin(), m_dirs.end(), [&path](RepositoryDirInfo const& dir) { return URIUtils::PathHasParent(path, dir.datadir, true); }); if (dirIt == m_dirs.end()) @@ -100,18 +99,18 @@ CRepository::ResolveResult CRepository::ResolvePathAndHash(const AddonPtr& addon return {location, hash}; } -CRepository::CRepository(const AddonInfoPtr& addonInfo) - : CAddon(addonInfo, ADDON_REPOSITORY) +CRepository::CRepository(const AddonInfoPtr& addonInfo) : CAddon(addonInfo, AddonType::REPOSITORY) { - DirList dirs; - AddonVersion version; - AddonInfoPtr addonver = CServiceBroker::GetAddonMgr().GetAddonInfo("xbmc.addon"); + RepositoryDirList dirs; + CAddonVersion version; + AddonInfoPtr addonver = + CServiceBroker::GetAddonMgr().GetAddonInfo("xbmc.addon", AddonType::UNKNOWN); if (addonver) version = addonver->Version(); - for (const auto& element : Type(ADDON_REPOSITORY)->GetElements("dir")) + for (const auto& element : Type(AddonType::REPOSITORY)->GetElements("dir")) { - DirInfo dir = ParseDirConfiguration(element.second); + RepositoryDirInfo dir = ParseDirConfiguration(element.second); if ((dir.minversion.empty() || version >= dir.minversion) && (dir.maxversion.empty() || version <= dir.maxversion)) m_dirs.push_back(std::move(dir)); @@ -120,7 +119,7 @@ CRepository::CRepository(const AddonInfoPtr& addonInfo) // old (dharma compatible) way of defining the addon repository structure, is no longer supported // we error out so the user knows how to migrate. The <dir> way is supported since gotham. //! @todo remove if block completely in v21 - if (!Type(ADDON_REPOSITORY)->GetValue("info").empty()) + if (!Type(AddonType::REPOSITORY)->GetValue("info").empty()) { CLog::Log(LOGERROR, "Repository add-on {} uses old schema definition for the repository extension point! " @@ -199,7 +198,7 @@ bool CRepository::FetchChecksum(const std::string& url, return true; } -bool CRepository::FetchIndex(const DirInfo& repo, +bool CRepository::FetchIndex(const RepositoryDirInfo& repo, std::string const& digest, std::vector<AddonInfoPtr>& addons) noexcept { @@ -244,7 +243,7 @@ CRepository::FetchStatus CRepository::FetchIfChanged(const std::string& oldCheck int& recheckAfter) const { checksum = ""; - std::vector<std::tuple<DirInfo const&, std::string>> dirChecksums; + std::vector<std::tuple<RepositoryDirInfo const&, std::string>> dirChecksums; std::vector<int> recheckAfterTimes; for (const auto& dir : m_dirs) @@ -287,9 +286,9 @@ CRepository::FetchStatus CRepository::FetchIfChanged(const std::string& oldCheck return STATUS_OK; } -CRepository::DirInfo CRepository::ParseDirConfiguration(const CAddonExtensions& configuration) +RepositoryDirInfo CRepository::ParseDirConfiguration(const CAddonExtensions& configuration) { - DirInfo dir; + RepositoryDirInfo dir; dir.checksum = configuration.GetValue("checksum").asString(); std::string checksumStr = configuration.GetValue("checksum@verify").asString(); if (!checksumStr.empty()) @@ -320,77 +319,8 @@ CRepository::DirInfo CRepository::ParseDirConfiguration(const CAddonExtensions& } } - dir.minversion = AddonVersion{configuration.GetValue("@minversion").asString()}; - dir.maxversion = AddonVersion{configuration.GetValue("@maxversion").asString()}; + dir.minversion = CAddonVersion{configuration.GetValue("@minversion").asString()}; + dir.maxversion = CAddonVersion{configuration.GetValue("@maxversion").asString()}; return dir; } - -CRepositoryUpdateJob::CRepositoryUpdateJob(const RepositoryPtr& repo) : m_repo(repo) {} - -bool CRepositoryUpdateJob::DoWork() -{ - CLog::Log(LOGDEBUG, "CRepositoryUpdateJob[{}] checking for updates.", m_repo->ID()); - CAddonDatabase database; - database.Open(); - - std::string oldChecksum; - if (database.GetRepoChecksum(m_repo->ID(), oldChecksum) == -1) - oldChecksum = ""; - - const CAddonDatabase::RepoUpdateData updateData{database.GetRepoUpdateData(m_repo->ID())}; - if (updateData.lastCheckedVersion != m_repo->Version()) - oldChecksum = ""; - - std::string newChecksum; - std::vector<AddonInfoPtr> addons; - int recheckAfter; - auto status = m_repo->FetchIfChanged(oldChecksum, newChecksum, addons, recheckAfter); - - database.SetRepoUpdateData( - m_repo->ID(), CAddonDatabase::RepoUpdateData( - CDateTime::GetCurrentDateTime(), m_repo->Version(), - CDateTime::GetCurrentDateTime() + CDateTimeSpan(0, 0, 0, recheckAfter))); - - MarkFinished(); - - if (status == CRepository::STATUS_ERROR) - return false; - - if (status == CRepository::STATUS_NOT_MODIFIED) - { - CLog::Log(LOGDEBUG, "CRepositoryUpdateJob[{}] checksum not changed.", m_repo->ID()); - return true; - } - - //Invalidate art. - { - CTextureDatabase textureDB; - textureDB.Open(); - textureDB.BeginMultipleExecute(); - - for (const auto& addon : addons) - { - AddonPtr oldAddon; - if (CServiceBroker::GetAddonMgr().FindInstallableById(addon->ID(), oldAddon) && oldAddon && - addon->Version() > oldAddon->Version()) - { - if (!oldAddon->Icon().empty() || !oldAddon->Art().empty() || !oldAddon->Screenshots().empty()) - CLog::Log(LOGDEBUG, "CRepository: invalidating cached art for '{}'", addon->ID()); - - if (!oldAddon->Icon().empty()) - textureDB.InvalidateCachedTexture(oldAddon->Icon()); - - for (const auto& path : oldAddon->Screenshots()) - textureDB.InvalidateCachedTexture(path); - - for (const auto& art : oldAddon->Art()) - textureDB.InvalidateCachedTexture(art.second); - } - } - textureDB.CommitMultipleExecute(); - } - - database.UpdateRepositoryContent(m_repo->ID(), m_repo->Version(), newChecksum, addons); - return true; -} diff --git a/xbmc/addons/Repository.h b/xbmc/addons/Repository.h index 8644a4a653..4c2ac32f46 100644 --- a/xbmc/addons/Repository.h +++ b/xbmc/addons/Repository.h @@ -8,10 +8,9 @@ #pragma once -#include "Addon.h" +#include "addons/Addon.h" #include "addons/AddonVersion.h" #include "utils/Digest.h" -#include "utils/ProgressJob.h" #include <memory> #include <string> @@ -19,70 +18,59 @@ namespace ADDON { - class CRepository : public CAddon - { - public: - struct DirInfo - { - AddonVersion minversion{""}; - AddonVersion maxversion{""}; - std::string info; - std::string checksum; - KODI::UTILITY::CDigest::Type checksumType{KODI::UTILITY::CDigest::Type::INVALID}; - std::string datadir; - std::string artdir; - KODI::UTILITY::CDigest::Type hashType{KODI::UTILITY::CDigest::Type::INVALID}; - }; - - typedef std::vector<DirInfo> DirList; - - explicit CRepository(const AddonInfoPtr& addonInfo); +class CAddonExtensions; - enum FetchStatus - { - STATUS_OK, - STATUS_NOT_MODIFIED, - STATUS_ERROR - }; - - FetchStatus FetchIfChanged(const std::string& oldChecksum, - std::string& checksum, - std::vector<AddonInfoPtr>& addons, - int& recheckAfter) const; - - struct ResolveResult - { - std::string location; - KODI::UTILITY::TypedDigest digest; - }; - ResolveResult ResolvePathAndHash(AddonPtr const& addon) const; +struct RepositoryDirInfo +{ + CAddonVersion minversion{""}; + CAddonVersion maxversion{""}; + std::string info; + std::string checksum; + KODI::UTILITY::CDigest::Type checksumType{KODI::UTILITY::CDigest::Type::INVALID}; + std::string datadir; + std::string artdir; + KODI::UTILITY::CDigest::Type hashType{KODI::UTILITY::CDigest::Type::INVALID}; +}; + +typedef std::vector<RepositoryDirInfo> RepositoryDirList; + +class CRepository : public CAddon +{ +public: + explicit CRepository(const AddonInfoPtr& addonInfo); - private: - static bool FetchChecksum(const std::string& url, - std::string& checksum, - int& recheckAfter) noexcept; - static bool FetchIndex(const DirInfo& repo, - std::string const& digest, - std::vector<AddonInfoPtr>& addons) noexcept; + enum FetchStatus + { + STATUS_OK, + STATUS_NOT_MODIFIED, + STATUS_ERROR + }; - static DirInfo ParseDirConfiguration(const CAddonExtensions& configuration); + FetchStatus FetchIfChanged(const std::string& oldChecksum, + std::string& checksum, + std::vector<AddonInfoPtr>& addons, + int& recheckAfter) const; - DirList m_dirs; + struct ResolveResult + { + std::string location; + KODI::UTILITY::TypedDigest digest; }; + ResolveResult ResolvePathAndHash(AddonPtr const& addon) const; - typedef std::shared_ptr<CRepository> RepositoryPtr; +private: + static bool FetchChecksum(const std::string& url, + std::string& checksum, + int& recheckAfter) noexcept; + static bool FetchIndex(const RepositoryDirInfo& repo, + std::string const& digest, + std::vector<AddonInfoPtr>& addons) noexcept; + static RepositoryDirInfo ParseDirConfiguration(const CAddonExtensions& configuration); - class CRepositoryUpdateJob : public CProgressJob - { - public: - explicit CRepositoryUpdateJob(const RepositoryPtr& repo); - ~CRepositoryUpdateJob() override = default; - bool DoWork() override; - const RepositoryPtr& GetAddon() const { return m_repo; } + RepositoryDirList m_dirs; +}; - private: - const RepositoryPtr m_repo; - }; +typedef std::shared_ptr<CRepository> RepositoryPtr; } diff --git a/xbmc/addons/RepositoryUpdater.cpp b/xbmc/addons/RepositoryUpdater.cpp index 1efbb2e3b7..3ea8b9c83d 100644 --- a/xbmc/addons/RepositoryUpdater.cpp +++ b/xbmc/addons/RepositoryUpdater.cpp @@ -9,10 +9,15 @@ #include "RepositoryUpdater.h" #include "ServiceBroker.h" +#include "TextureDatabase.h" +#include "addons/AddonDatabase.h" #include "addons/AddonEvents.h" #include "addons/AddonInstaller.h" #include "addons/AddonManager.h" #include "addons/AddonSystemSettings.h" +#include "addons/Repository.h" +#include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "dialogs/GUIDialogExtendedProgressBar.h" #include "dialogs/GUIDialogKaiToast.h" #include "events/AddonManagementEvent.h" @@ -24,6 +29,7 @@ #include "settings/SettingsComponent.h" #include "settings/lib/Setting.h" #include "utils/JobManager.h" +#include "utils/ProgressJob.h" #include "utils/log.h" #include <algorithm> @@ -36,6 +42,86 @@ using namespace std::chrono_literals; namespace ADDON { +class CRepositoryUpdateJob : public CProgressJob +{ +public: + explicit CRepositoryUpdateJob(const RepositoryPtr& repo) : m_repo(repo) {} + ~CRepositoryUpdateJob() override = default; + bool DoWork() override; + const RepositoryPtr& GetAddon() const { return m_repo; } + +private: + const RepositoryPtr m_repo; +}; + +bool CRepositoryUpdateJob::DoWork() +{ + CLog::Log(LOGDEBUG, "CRepositoryUpdateJob[{}] checking for updates.", m_repo->ID()); + CAddonDatabase database; + database.Open(); + + std::string oldChecksum; + if (database.GetRepoChecksum(m_repo->ID(), oldChecksum) == -1) + oldChecksum = ""; + + const CAddonDatabase::RepoUpdateData updateData{database.GetRepoUpdateData(m_repo->ID())}; + if (updateData.lastCheckedVersion != m_repo->Version()) + oldChecksum = ""; + + std::string newChecksum; + std::vector<AddonInfoPtr> addons; + int recheckAfter; + auto status = m_repo->FetchIfChanged(oldChecksum, newChecksum, addons, recheckAfter); + + database.SetRepoUpdateData( + m_repo->ID(), CAddonDatabase::RepoUpdateData( + CDateTime::GetCurrentDateTime(), m_repo->Version(), + CDateTime::GetCurrentDateTime() + CDateTimeSpan(0, 0, 0, recheckAfter))); + + MarkFinished(); + + if (status == CRepository::STATUS_ERROR) + return false; + + if (status == CRepository::STATUS_NOT_MODIFIED) + { + CLog::Log(LOGDEBUG, "CRepositoryUpdateJob[{}] checksum not changed.", m_repo->ID()); + return true; + } + + //Invalidate art. + { + CTextureDatabase textureDB; + textureDB.Open(); + textureDB.BeginMultipleExecute(); + + for (const auto& addon : addons) + { + AddonPtr oldAddon; + if (CServiceBroker::GetAddonMgr().FindInstallableById(addon->ID(), oldAddon) && oldAddon && + addon->Version() > oldAddon->Version()) + { + if (!oldAddon->Icon().empty() || !oldAddon->Art().empty() || + !oldAddon->Screenshots().empty()) + CLog::Log(LOGDEBUG, "CRepository: invalidating cached art for '{}'", addon->ID()); + + if (!oldAddon->Icon().empty()) + textureDB.InvalidateCachedTexture(oldAddon->Icon()); + + for (const auto& path : oldAddon->Screenshots()) + textureDB.InvalidateCachedTexture(path); + + for (const auto& art : oldAddon->Art()) + textureDB.InvalidateCachedTexture(art.second); + } + } + textureDB.CommitMultipleExecute(); + } + + database.UpdateRepositoryContent(m_repo->ID(), m_repo->Version(), newChecksum, addons); + return true; +} + CRepositoryUpdater::CRepositoryUpdater(CAddonMgr& addonMgr) : m_timer(this), m_doneEvent(true), @@ -65,7 +151,7 @@ void CRepositoryUpdater::OnEvent(const ADDON::AddonEvent& event) { if (typeid(event) == typeid(ADDON::AddonEvents::Enabled)) { - if (m_addonMgr.HasType(event.addonId, ADDON_REPOSITORY)) + if (m_addonMgr.HasType(event.addonId, AddonType::REPOSITORY)) ScheduleUpdate(); } } @@ -117,7 +203,7 @@ void CRepositoryUpdater::OnJobComplete(unsigned int jobID, bool success, CJob* j bool CRepositoryUpdater::CheckForUpdates(bool showProgress) { VECADDONS addons; - if (m_addonMgr.GetAddons(addons, ADDON_REPOSITORY) && !addons.empty()) + if (m_addonMgr.GetAddons(addons, AddonType::REPOSITORY) && !addons.empty()) { std::unique_lock<CCriticalSection> lock(m_criticalSection); for (const auto& addon : addons) @@ -188,7 +274,7 @@ void CRepositoryUpdater::OnSettingChanged(const std::shared_ptr<const CSetting>& CDateTime CRepositoryUpdater::LastUpdated() const { VECADDONS repos; - if (!m_addonMgr.GetAddons(repos, ADDON_REPOSITORY) || repos.empty()) + if (!m_addonMgr.GetAddons(repos, AddonType::REPOSITORY) || repos.empty()) return CDateTime(); CAddonDatabase db; @@ -208,7 +294,7 @@ CDateTime CRepositoryUpdater::LastUpdated() const CDateTime CRepositoryUpdater::ClosestNextCheck() const { VECADDONS repos; - if (!m_addonMgr.GetAddons(repos, ADDON_REPOSITORY) || repos.empty()) + if (!m_addonMgr.GetAddons(repos, AddonType::REPOSITORY) || repos.empty()) return CDateTime(); CAddonDatabase db; @@ -233,7 +319,7 @@ void CRepositoryUpdater::ScheduleUpdate() if (CAddonSystemSettings::GetInstance().GetAddonAutoUpdateMode() == AUTO_UPDATES_NEVER) return; - if (!m_addonMgr.HasAddons(ADDON_REPOSITORY)) + if (!m_addonMgr.HasAddons(AddonType::REPOSITORY)) return; int delta{1}; diff --git a/xbmc/addons/Resource.h b/xbmc/addons/Resource.h index e74c11774e..d426c85f1d 100644 --- a/xbmc/addons/Resource.h +++ b/xbmc/addons/Resource.h @@ -29,7 +29,10 @@ public: } protected: - explicit CResource(const AddonInfoPtr& addonInfo, TYPE addonType) : CAddon(addonInfo, addonType) {} + explicit CResource(const AddonInfoPtr& addonInfo, AddonType addonType) + : CAddon(addonInfo, addonType) + { + } std::string GetResourcePath() const { diff --git a/xbmc/addons/Scraper.cpp b/xbmc/addons/Scraper.cpp index 8834cec26e..14c555f33b 100644 --- a/xbmc/addons/Scraper.cpp +++ b/xbmc/addons/Scraper.cpp @@ -8,12 +8,13 @@ #include "Scraper.h" -#include "AddonManager.h" #include "FileItem.h" #include "ServiceBroker.h" #include "URL.h" #include "Util.h" +#include "addons/AddonManager.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "addons/settings/AddonSettings.h" #include "filesystem/CurlFile.h" #include "filesystem/Directory.h" @@ -89,22 +90,22 @@ CONTENT_TYPE TranslateContent(const std::string &string) return CONTENT_NONE; } -TYPE ScraperTypeFromContent(const CONTENT_TYPE &content) +AddonType ScraperTypeFromContent(const CONTENT_TYPE& content) { switch (content) { case CONTENT_ALBUMS: - return ADDON_SCRAPER_ALBUMS; + return AddonType::SCRAPER_ALBUMS; case CONTENT_ARTISTS: - return ADDON_SCRAPER_ARTISTS; + return AddonType::SCRAPER_ARTISTS; case CONTENT_MOVIES: - return ADDON_SCRAPER_MOVIES; + return AddonType::SCRAPER_MOVIES; case CONTENT_MUSICVIDEOS: - return ADDON_SCRAPER_MUSICVIDEOS; + return AddonType::SCRAPER_MUSICVIDEOS; case CONTENT_TVSHOWS: - return ADDON_SCRAPER_TVSHOWS; + return AddonType::SCRAPER_TVSHOWS; default: - return ADDON_UNKNOWN; + return AddonType::UNKNOWN; } } @@ -120,11 +121,11 @@ static void CheckScraperError(const TiXmlElement *pxeRoot) throw CScraperError(sTitle, sMessage); } -CScraper::CScraper(const AddonInfoPtr& addonInfo, TYPE addonType) - : CAddon(addonInfo, addonType) - , m_fLoaded(false) - , m_requiressettings(false) - , m_pathContent(CONTENT_NONE) +CScraper::CScraper(const AddonInfoPtr& addonInfo, AddonType addonType) + : CAddon(addonInfo, addonType), + m_fLoaded(false), + m_requiressettings(false), + m_pathContent(CONTENT_NONE) { m_requiressettings = addonInfo->Type(addonType)->GetValue("@requiressettings").asBoolean(); @@ -135,23 +136,23 @@ CScraper::CScraper(const AddonInfoPtr& addonInfo, TYPE addonType) switch (addonType) { - case ADDON_SCRAPER_ALBUMS: - m_pathContent = CONTENT_ALBUMS; - break; - case ADDON_SCRAPER_ARTISTS: - m_pathContent = CONTENT_ARTISTS; - break; - case ADDON_SCRAPER_MOVIES: - m_pathContent = CONTENT_MOVIES; - break; - case ADDON_SCRAPER_MUSICVIDEOS: - m_pathContent = CONTENT_MUSICVIDEOS; - break; - case ADDON_SCRAPER_TVSHOWS: - m_pathContent = CONTENT_TVSHOWS; - break; - default: - break; + case AddonType::SCRAPER_ALBUMS: + m_pathContent = CONTENT_ALBUMS; + break; + case AddonType::SCRAPER_ARTISTS: + m_pathContent = CONTENT_ARTISTS; + break; + case AddonType::SCRAPER_MOVIES: + m_pathContent = CONTENT_MOVIES; + break; + case AddonType::SCRAPER_MUSICVIDEOS: + m_pathContent = CONTENT_MUSICVIDEOS; + break; + case AddonType::SCRAPER_TVSHOWS: + m_pathContent = CONTENT_TVSHOWS; + break; + default: + break; } m_isPython = URIUtils::GetExtension(addonInfo->Type(addonType)->LibPath()) == ".py"; @@ -369,11 +370,10 @@ bool CScraper::Load() bool bOptional = itr->optional; - if (CServiceBroker::GetAddonMgr().GetAddon((*itr).id, dep, ADDON::ADDON_UNKNOWN, - ADDON::OnlyEnabled::CHOICE_YES)) + if (CServiceBroker::GetAddonMgr().GetAddon((*itr).id, dep, ADDON::OnlyEnabled::CHOICE_YES)) { CXBMCTinyXML doc; - if (dep->Type() == ADDON_SCRAPER_LIBRARY && doc.LoadFile(dep->LibPath())) + if (dep->Type() == AddonType::SCRAPER_LIBRARY && doc.LoadFile(dep->LibPath())) m_parser.AddDocument(&doc); } else diff --git a/xbmc/addons/Scraper.h b/xbmc/addons/Scraper.h index a925a931d5..d9f72868bf 100644 --- a/xbmc/addons/Scraper.h +++ b/xbmc/addons/Scraper.h @@ -52,7 +52,7 @@ typedef std::shared_ptr<CScraper> ScraperPtr; std::string TranslateContent(const CONTENT_TYPE &content, bool pretty=false); CONTENT_TYPE TranslateContent(const std::string &string); -TYPE ScraperTypeFromContent(const CONTENT_TYPE &content); +AddonType ScraperTypeFromContent(const CONTENT_TYPE& content); // thrown as exception to signal abort or show error dialog class CScraperError @@ -75,7 +75,7 @@ private: class CScraper : public CAddon { public: - explicit CScraper(const AddonInfoPtr& addonInfo, TYPE addonType); + explicit CScraper(const AddonInfoPtr& addonInfo, AddonType addonType); /*! \brief Set the scraper settings for a particular path from an XML string Loads the default and user settings (if not already loaded) and, if the given XML string is non-empty, diff --git a/xbmc/addons/Service.cpp b/xbmc/addons/Service.cpp index c8a825288a..e9b6b402ed 100644 --- a/xbmc/addons/Service.cpp +++ b/xbmc/addons/Service.cpp @@ -7,7 +7,8 @@ */ #include "Service.h" -#include "AddonManager.h" +#include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "interfaces/generic/ScriptInvocationManager.h" #include "utils/StringUtils.h" #include "utils/log.h" @@ -18,6 +19,10 @@ namespace ADDON { +CService::CService(const AddonInfoPtr& addonInfo) : CAddon(addonInfo, AddonType::SERVICE) +{ +} + CServiceAddonManager::CServiceAddonManager(CAddonMgr& addonMgr) : m_addonMgr(addonMgr) { @@ -52,7 +57,7 @@ void CServiceAddonManager::Start() m_addonMgr.Events().Subscribe(this, &CServiceAddonManager::OnEvent); m_addonMgr.UnloadEvents().Subscribe(this, &CServiceAddonManager::OnEvent); VECADDONS addons; - if (m_addonMgr.GetAddons(addons, ADDON_SERVICE)) + if (m_addonMgr.GetAddons(addons, AddonType::SERVICE)) { for (const auto& addon : addons) { @@ -64,7 +69,7 @@ void CServiceAddonManager::Start() void CServiceAddonManager::Start(const std::string& addonId) { AddonPtr addon; - if (m_addonMgr.GetAddon(addonId, addon, ADDON_SERVICE, OnlyEnabled::CHOICE_YES)) + if (m_addonMgr.GetAddon(addonId, addon, AddonType::SERVICE, OnlyEnabled::CHOICE_YES)) { Start(addon); } diff --git a/xbmc/addons/Service.h b/xbmc/addons/Service.h index c997ef01b3..38f1d1edd2 100644 --- a/xbmc/addons/Service.h +++ b/xbmc/addons/Service.h @@ -8,8 +8,8 @@ #pragma once -#include "Addon.h" -#include "AddonEvents.h" +#include "addons/Addon.h" +#include "addons/AddonEvents.h" #include "threads/CriticalSection.h" namespace ADDON @@ -17,7 +17,7 @@ namespace ADDON class CService: public CAddon { public: - explicit CService(const AddonInfoPtr& addonInfo) : CAddon(addonInfo, ADDON_SERVICE) {} + explicit CService(const AddonInfoPtr& addonInfo); }; class CServiceAddonManager diff --git a/xbmc/addons/Skin.cpp b/xbmc/addons/Skin.cpp index 5e7e045ca2..4450a90860 100644 --- a/xbmc/addons/Skin.cpp +++ b/xbmc/addons/Skin.cpp @@ -11,8 +11,8 @@ #include "FileItem.h" #include "ServiceBroker.h" #include "Util.h" +#include "addons/addoninfo/AddonType.h" #include "dialogs/GUIDialogKaiToast.h" -// fallback for new skin resolution code #include "filesystem/Directory.h" #include "filesystem/SpecialProtocol.h" #include "guilib/GUIComponent.h" @@ -150,20 +150,19 @@ bool CSkinSettingBool::SerializeSetting(TiXmlElement* element) const return true; } -CSkinInfo::CSkinInfo( - const AddonInfoPtr& addonInfo, - const RESOLUTION_INFO& resolution /* = RESOLUTION_INFO() */) - : CAddon(addonInfo, ADDON_SKIN), - m_defaultRes(resolution), - m_effectsSlowDown(1.f), - m_debugging(false) - { - m_settingsUpdateHandler.reset(new CSkinSettingUpdateHandler(*this)); - } +CSkinInfo::CSkinInfo(const AddonInfoPtr& addonInfo, + const RESOLUTION_INFO& resolution /* = RESOLUTION_INFO() */) + : CAddon(addonInfo, AddonType::SKIN), + m_defaultRes(resolution), + m_effectsSlowDown(1.f), + m_debugging(false) +{ + m_settingsUpdateHandler.reset(new CSkinSettingUpdateHandler(*this)); +} -CSkinInfo::CSkinInfo(const AddonInfoPtr& addonInfo) : CAddon(addonInfo, ADDON_SKIN) +CSkinInfo::CSkinInfo(const AddonInfoPtr& addonInfo) : CAddon(addonInfo, AddonType::SKIN) { - for (const auto& values : Type(ADDON_SKIN)->GetValues()) + for (const auto& values : Type(AddonType::SKIN)->GetValues()) { if (values.first != "res") continue; @@ -177,7 +176,7 @@ CSkinInfo::CSkinInfo(const AddonInfoPtr& addonInfo) : CAddon(addonInfo, ADDON_SK std::vector<std::string> fracs = StringUtils::Split(strAspect, ':'); if (fracs.size() == 2) - aspect = (float)(atof(fracs[0].c_str())/atof(fracs[1].c_str())); + aspect = (float)(atof(fracs[0].c_str()) / atof(fracs[1].c_str())); if (width > 0 && height > 0) { RESOLUTION_INFO res(width, height, aspect, folder); @@ -188,11 +187,11 @@ CSkinInfo::CSkinInfo(const AddonInfoPtr& addonInfo) : CAddon(addonInfo, ADDON_SK } } - m_effectsSlowDown = Type(ADDON_SKIN)->GetValue("@effectslowdown").asFloat(); + m_effectsSlowDown = Type(AddonType::SKIN)->GetValue("@effectslowdown").asFloat(); if (m_effectsSlowDown == 0.0f) m_effectsSlowDown = 1.f; - m_debugging = Type(ADDON_SKIN)->GetValue("@debugging").asBoolean(); + m_debugging = Type(AddonType::SKIN)->GetValue("@debugging").asBoolean(); m_settingsUpdateHandler.reset(new CSkinSettingUpdateHandler(*this)); LoadStartupWindows(addonInfo); diff --git a/xbmc/addons/Skin.h b/xbmc/addons/Skin.h index 188bf181a5..41261678cf 100644 --- a/xbmc/addons/Skin.h +++ b/xbmc/addons/Skin.h @@ -14,6 +14,7 @@ #include "windowing/GraphicContext.h" // needed for the RESOLUTION members #include <map> +#include <memory> #include <set> #include <utility> #include <vector> diff --git a/xbmc/addons/UISoundsResource.cpp b/xbmc/addons/UISoundsResource.cpp index 503e68a688..6ca53ddfd8 100644 --- a/xbmc/addons/UISoundsResource.cpp +++ b/xbmc/addons/UISoundsResource.cpp @@ -8,6 +8,7 @@ #include "UISoundsResource.h" #include "ServiceBroker.h" +#include "addons/addoninfo/AddonType.h" #include "guilib/GUIAudioManager.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" @@ -18,6 +19,11 @@ namespace ADDON { +CUISoundsResource::CUISoundsResource(const AddonInfoPtr& addonInfo) + : CResource(addonInfo, AddonType::RESOURCE_UISOUNDS) +{ +} + bool CUISoundsResource::IsAllowed(const std::string& file) const { return StringUtils::EqualsNoCase(file, "sounds.xml") diff --git a/xbmc/addons/UISoundsResource.h b/xbmc/addons/UISoundsResource.h index 8dc5dd262e..0a07f11e5c 100644 --- a/xbmc/addons/UISoundsResource.h +++ b/xbmc/addons/UISoundsResource.h @@ -16,7 +16,8 @@ namespace ADDON class CUISoundsResource : public CResource { public: - explicit CUISoundsResource(const AddonInfoPtr& addonInfo) : CResource(addonInfo, ADDON_RESOURCE_UISOUNDS) {} + explicit CUISoundsResource(const AddonInfoPtr& addonInfo); + bool IsAllowed(const std::string &file) const override; bool IsInUse() const override; void OnPostInstall(bool update, bool modal) override; diff --git a/xbmc/addons/VFSEntry.cpp b/xbmc/addons/VFSEntry.cpp index 074b734bac..ab645518de 100644 --- a/xbmc/addons/VFSEntry.cpp +++ b/xbmc/addons/VFSEntry.cpp @@ -12,6 +12,7 @@ #include "addons/AddonEvents.h" #include "addons/AddonManager.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "addons/interfaces/Filesystem.h" #include "network/ZeroconfBrowser.h" #include "utils/StringUtils.h" @@ -58,7 +59,7 @@ void CVFSAddonCache::Init() // Load all available VFS addons during Kodi start std::vector<AddonInfoPtr> addonInfos; - CServiceBroker::GetAddonMgr().GetAddonInfos(addonInfos, true, ADDON_VFS); + CServiceBroker::GetAddonMgr().GetAddonInfos(addonInfos, true, AddonType::VFS); std::unique_lock<CCriticalSection> lock(m_critSection); for (const auto& addonInfo : addonInfos) @@ -117,7 +118,7 @@ void CVFSAddonCache::OnEvent(const AddonEvent& event) typeid(event) == typeid(AddonEvents::Disabled) || typeid(event) == typeid(AddonEvents::ReInstalled)) { - if (CServiceBroker::GetAddonMgr().HasType(event.addonId, ADDON_VFS)) + if (CServiceBroker::GetAddonMgr().HasType(event.addonId, AddonType::VFS)) Update(event.addonId); } else if (typeid(event) == typeid(AddonEvents::UnInstalled)) @@ -157,7 +158,7 @@ void CVFSAddonCache::Update(const std::string& id) } // Create and init the new VFS addon instance - AddonInfoPtr addonInfo = CServiceBroker::GetAddonMgr().GetAddonInfo(id, ADDON_VFS); + AddonInfoPtr addonInfo = CServiceBroker::GetAddonMgr().GetAddonInfo(id, AddonType::VFS); if (addonInfo && !CServiceBroker::GetAddonMgr().IsAddonDisabled(id)) { VFSEntryPtr vfs = std::make_shared<CVFSEntry>(addonInfo); @@ -205,29 +206,29 @@ class CVFSURLWrapper }; CVFSEntry::ProtocolInfo::ProtocolInfo(const AddonInfoPtr& addonInfo) - : supportPath(addonInfo->Type(ADDON_VFS)->GetValue("@supportPath").asBoolean()), - supportUsername(addonInfo->Type(ADDON_VFS)->GetValue("@supportUsername").asBoolean()), - supportPassword(addonInfo->Type(ADDON_VFS)->GetValue("@supportPassword").asBoolean()), - supportPort(addonInfo->Type(ADDON_VFS)->GetValue("@supportPort").asBoolean()), - supportBrowsing(addonInfo->Type(ADDON_VFS)->GetValue("@supportBrowsing").asBoolean()), - supportWrite(addonInfo->Type(ADDON_VFS)->GetValue("@supportWrite").asBoolean()), - defaultPort(addonInfo->Type(ADDON_VFS)->GetValue("@defaultPort").asInteger()), - type(addonInfo->Type(ADDON_VFS)->GetValue("@protocols").asString()), - label(addonInfo->Type(ADDON_VFS)->GetValue("@label").asInteger()) + : supportPath(addonInfo->Type(AddonType::VFS)->GetValue("@supportPath").asBoolean()), + supportUsername(addonInfo->Type(AddonType::VFS)->GetValue("@supportUsername").asBoolean()), + supportPassword(addonInfo->Type(AddonType::VFS)->GetValue("@supportPassword").asBoolean()), + supportPort(addonInfo->Type(AddonType::VFS)->GetValue("@supportPort").asBoolean()), + supportBrowsing(addonInfo->Type(AddonType::VFS)->GetValue("@supportBrowsing").asBoolean()), + supportWrite(addonInfo->Type(AddonType::VFS)->GetValue("@supportWrite").asBoolean()), + defaultPort(addonInfo->Type(AddonType::VFS)->GetValue("@defaultPort").asInteger()), + type(addonInfo->Type(AddonType::VFS)->GetValue("@protocols").asString()), + label(addonInfo->Type(AddonType::VFS)->GetValue("@label").asInteger()) { } CVFSEntry::CVFSEntry(const AddonInfoPtr& addonInfo) : IAddonInstanceHandler(ADDON_INSTANCE_VFS, addonInfo), - m_protocols(addonInfo->Type(ADDON_VFS)->GetValue("@protocols").asString()), - m_extensions(addonInfo->Type(ADDON_VFS)->GetValue("@extensions").asString()), - m_zeroconf(addonInfo->Type(ADDON_VFS)->GetValue("@zeroconf").asString()), - m_files(addonInfo->Type(ADDON_VFS)->GetValue("@files").asBoolean()), - m_directories(addonInfo->Type(ADDON_VFS)->GetValue("@directories").asBoolean()), - m_filedirectories(addonInfo->Type(ADDON_VFS)->GetValue("@filedirectories").asBoolean()), + m_protocols(addonInfo->Type(AddonType::VFS)->GetValue("@protocols").asString()), + m_extensions(addonInfo->Type(AddonType::VFS)->GetValue("@extensions").asString()), + m_zeroconf(addonInfo->Type(AddonType::VFS)->GetValue("@zeroconf").asString()), + m_files(addonInfo->Type(AddonType::VFS)->GetValue("@files").asBoolean()), + m_directories(addonInfo->Type(AddonType::VFS)->GetValue("@directories").asBoolean()), + m_filedirectories(addonInfo->Type(AddonType::VFS)->GetValue("@filedirectories").asBoolean()), m_protocolInfo(addonInfo) { - if (!addonInfo->Type(ADDON_VFS)->GetValue("@supportDialog").asBoolean()) + if (!addonInfo->Type(AddonType::VFS)->GetValue("@supportDialog").asBoolean()) m_protocolInfo.type.clear(); // Create "C" interface structures, used as own parts to prevent API problems on update diff --git a/xbmc/addons/Webinterface.cpp b/xbmc/addons/Webinterface.cpp index 0e00e37e12..75af3b2c9d 100644 --- a/xbmc/addons/Webinterface.cpp +++ b/xbmc/addons/Webinterface.cpp @@ -8,6 +8,7 @@ #include "Webinterface.h" +#include "addons/addoninfo/AddonType.h" #include "utils/StringUtils.h" #include "utils/URIUtils.h" #include "utils/log.h" @@ -15,12 +16,12 @@ using namespace ADDON; CWebinterface::CWebinterface(const AddonInfoPtr& addonInfo) - : CAddon(addonInfo, ADDON_WEB_INTERFACE), + : CAddon(addonInfo, AddonType::WEB_INTERFACE), m_type(WebinterfaceTypeStatic), m_entryPoint(WEBINTERFACE_DEFAULT_ENTRY_POINT) { // determine the type of the webinterface - std::string webinterfaceType = Type(ADDON_WEB_INTERFACE)->GetValue("@type").asString(); + std::string webinterfaceType = Type(AddonType::WEB_INTERFACE)->GetValue("@type").asString(); if (StringUtils::EqualsNoCase(webinterfaceType, "wsgi")) m_type = WebinterfaceTypeWsgi; else if (!webinterfaceType.empty() && !StringUtils::EqualsNoCase(webinterfaceType, "static") && !StringUtils::EqualsNoCase(webinterfaceType, "html")) @@ -29,7 +30,7 @@ CWebinterface::CWebinterface(const AddonInfoPtr& addonInfo) ID(), webinterfaceType); // determine the entry point of the webinterface - std::string entry = Type(ADDON_WEB_INTERFACE)->GetValue("@entry").asString(); + std::string entry = Type(AddonType::WEB_INTERFACE)->GetValue("@entry").asString(); if (!entry.empty()) m_entryPoint = entry; } diff --git a/xbmc/addons/Webinterface.h b/xbmc/addons/Webinterface.h index 7186f4cc29..7a0ea7c87e 100644 --- a/xbmc/addons/Webinterface.h +++ b/xbmc/addons/Webinterface.h @@ -8,7 +8,7 @@ #pragma once -#include "Addon.h" +#include "addons/Addon.h" #define WEBINTERFACE_DEFAULT_ENTRY_POINT "index.html" diff --git a/xbmc/addons/addoninfo/AddonInfo.cpp b/xbmc/addons/addoninfo/AddonInfo.cpp index 7d5d559a99..61bc087443 100644 --- a/xbmc/addons/addoninfo/AddonInfo.cpp +++ b/xbmc/addons/addoninfo/AddonInfo.cpp @@ -13,8 +13,10 @@ #include "ServiceBroker.h" #include "addons/AddonManager.h" #include "addons/IAddon.h" +#include "addons/addoninfo/AddonType.h" #include "filesystem/Directory.h" #include "guilib/LocalizeStrings.h" +#include "utils/StringUtils.h" #include "utils/URIUtils.h" #include <algorithm> @@ -28,7 +30,7 @@ typedef struct { std::string_view name; std::string_view old_name; - TYPE type; + AddonType type; int pretty; AddonInstanceSupport instance_support; std::string_view icon; @@ -37,46 +39,46 @@ typedef struct // clang-format off static constexpr const std::array<TypeMapping, 40> types = {{ - {"unknown", "", ADDON_UNKNOWN, 0, AddonInstanceSupport::SUPPORT_NONE, "" }, - {"xbmc.metadata.scraper.albums", "", ADDON_SCRAPER_ALBUMS, 24016, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonAlbumInfo.png" }, - {"xbmc.metadata.scraper.artists", "", ADDON_SCRAPER_ARTISTS, 24017, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonArtistInfo.png" }, - {"xbmc.metadata.scraper.movies", "", ADDON_SCRAPER_MOVIES, 24007, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonMovieInfo.png" }, - {"xbmc.metadata.scraper.musicvideos", "", ADDON_SCRAPER_MUSICVIDEOS, 24015, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonMusicVideoInfo.png" }, - {"xbmc.metadata.scraper.tvshows", "", ADDON_SCRAPER_TVSHOWS, 24014, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonTvInfo.png" }, - {"xbmc.metadata.scraper.library", "", ADDON_SCRAPER_LIBRARY, 24083, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonInfoLibrary.png" }, - {"xbmc.ui.screensaver", "", ADDON_SCREENSAVER, 24008, AddonInstanceSupport::SUPPORT_OPTIONAL, "DefaultAddonScreensaver.png" }, - {"xbmc.player.musicviz", "", ADDON_VIZ, 24010, AddonInstanceSupport::SUPPORT_OPTIONAL, "DefaultAddonVisualization.png" }, - {"xbmc.python.pluginsource", "", ADDON_PLUGIN, 24005, AddonInstanceSupport::SUPPORT_NONE, "" }, - {"xbmc.python.script", "", ADDON_SCRIPT, 24009, AddonInstanceSupport::SUPPORT_NONE, "" }, - {"xbmc.python.weather", "", ADDON_SCRIPT_WEATHER, 24027, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonWeather.png" }, - {"xbmc.python.lyrics", "", ADDON_SCRIPT_LYRICS, 24013, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonLyrics.png" }, - {"xbmc.python.library", "", ADDON_SCRIPT_LIBRARY, 24081, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonHelper.png" }, - {"xbmc.python.module", "", ADDON_SCRIPT_MODULE, 24082, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonLibrary.png" }, - {"xbmc.subtitle.module", "", ADDON_SUBTITLE_MODULE, 24012, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonSubtitles.png" }, - {"kodi.context.item", "", ADDON_CONTEXT_ITEM, 24025, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonContextItem.png" }, - {"kodi.game.controller", "", ADDON_GAME_CONTROLLER, 35050, AddonInstanceSupport::SUPPORT_OPTIONAL, "DefaultAddonGame.png" }, - {"xbmc.gui.skin", "", ADDON_SKIN, 166, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonSkin.png" }, - {"xbmc.webinterface", "", ADDON_WEB_INTERFACE, 199, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonWebSkin.png" }, - {"xbmc.addon.repository", "", ADDON_REPOSITORY, 24011, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonRepository.png" }, - {"kodi.pvrclient", "xbmc.pvrclient", ADDON_PVRDLL, 24019, AddonInstanceSupport::SUPPORT_SETTINGS, "DefaultAddonPVRClient.png" }, - {"kodi.gameclient", "", ADDON_GAMEDLL, 35049, AddonInstanceSupport::SUPPORT_OPTIONAL, "DefaultAddonGame.png" }, - {"kodi.peripheral", "", ADDON_PERIPHERALDLL, 35010, AddonInstanceSupport::SUPPORT_MANDATORY, "DefaultAddonPeripheral.png" }, - {"xbmc.addon.video", "", ADDON_VIDEO, 1037, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonVideo.png" }, - {"xbmc.addon.audio", "", ADDON_AUDIO, 1038, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonMusic.png" }, - {"xbmc.addon.image", "", ADDON_IMAGE, 1039, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonPicture.png" }, - {"xbmc.addon.executable", "", ADDON_EXECUTABLE, 1043, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonProgram.png" }, - {"kodi.addon.game", "", ADDON_GAME, 35049, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonGame.png" }, - {"kodi.audioencoder", "", ADDON_AUDIOENCODER, 200, AddonInstanceSupport::SUPPORT_MANDATORY, "DefaultAddonAudioEncoder.png" }, - {"kodi.audiodecoder", "", ADDON_AUDIODECODER, 201, AddonInstanceSupport::SUPPORT_MANDATORY, "DefaultAddonAudioDecoder.png" }, - {"xbmc.service", "", ADDON_SERVICE, 24018, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonService.png" }, - {"kodi.resource.images", "", ADDON_RESOURCE_IMAGES, 24035, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonImages.png" }, - {"kodi.resource.language", "", ADDON_RESOURCE_LANGUAGE, 24026, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonLanguage.png" }, - {"kodi.resource.uisounds", "", ADDON_RESOURCE_UISOUNDS, 24006, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonUISounds.png" }, - {"kodi.resource.games", "", ADDON_RESOURCE_GAMES, 35209, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonGame.png" }, - {"kodi.resource.font", "", ADDON_RESOURCE_FONT, 13303, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonFont.png" }, - {"kodi.inputstream", "", ADDON_INPUTSTREAM, 24048, AddonInstanceSupport::SUPPORT_MANDATORY, "DefaultAddonInputstream.png" }, - {"kodi.vfs", "", ADDON_VFS, 39013, AddonInstanceSupport::SUPPORT_MANDATORY, "DefaultAddonVfs.png" }, - {"kodi.imagedecoder", "", ADDON_IMAGEDECODER, 39015, AddonInstanceSupport::SUPPORT_MANDATORY, "DefaultAddonImageDecoder.png" }, + {"unknown", "", AddonType::UNKNOWN, 0, AddonInstanceSupport::SUPPORT_NONE, "" }, + {"xbmc.metadata.scraper.albums", "", AddonType::SCRAPER_ALBUMS, 24016, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonAlbumInfo.png" }, + {"xbmc.metadata.scraper.artists", "", AddonType::SCRAPER_ARTISTS, 24017, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonArtistInfo.png" }, + {"xbmc.metadata.scraper.movies", "", AddonType::SCRAPER_MOVIES, 24007, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonMovieInfo.png" }, + {"xbmc.metadata.scraper.musicvideos", "", AddonType::SCRAPER_MUSICVIDEOS, 24015, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonMusicVideoInfo.png" }, + {"xbmc.metadata.scraper.tvshows", "", AddonType::SCRAPER_TVSHOWS, 24014, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonTvInfo.png" }, + {"xbmc.metadata.scraper.library", "", AddonType::SCRAPER_LIBRARY, 24083, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonInfoLibrary.png" }, + {"xbmc.ui.screensaver", "", AddonType::SCREENSAVER, 24008, AddonInstanceSupport::SUPPORT_OPTIONAL, "DefaultAddonScreensaver.png" }, + {"xbmc.player.musicviz", "", AddonType::VISUALIZATION, 24010, AddonInstanceSupport::SUPPORT_OPTIONAL, "DefaultAddonVisualization.png" }, + {"xbmc.python.pluginsource", "", AddonType::PLUGIN, 24005, AddonInstanceSupport::SUPPORT_NONE, "" }, + {"xbmc.python.script", "", AddonType::SCRIPT, 24009, AddonInstanceSupport::SUPPORT_NONE, "" }, + {"xbmc.python.weather", "", AddonType::SCRIPT_WEATHER, 24027, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonWeather.png" }, + {"xbmc.python.lyrics", "", AddonType::SCRIPT_LYRICS, 24013, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonLyrics.png" }, + {"xbmc.python.library", "", AddonType::SCRIPT_LIBRARY, 24081, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonHelper.png" }, + {"xbmc.python.module", "", AddonType::SCRIPT_MODULE, 24082, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonLibrary.png" }, + {"xbmc.subtitle.module", "", AddonType::SUBTITLE_MODULE, 24012, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonSubtitles.png" }, + {"kodi.context.item", "", AddonType::CONTEXTMENU_ITEM, 24025, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonContextItem.png" }, + {"kodi.game.controller", "", AddonType::GAME_CONTROLLER, 35050, AddonInstanceSupport::SUPPORT_OPTIONAL, "DefaultAddonGame.png" }, + {"xbmc.gui.skin", "", AddonType::SKIN, 166, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonSkin.png" }, + {"xbmc.webinterface", "", AddonType::WEB_INTERFACE, 199, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonWebSkin.png" }, + {"xbmc.addon.repository", "", AddonType::REPOSITORY, 24011, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonRepository.png" }, + {"kodi.pvrclient", "xbmc.pvrclient", AddonType::PVRDLL, 24019, AddonInstanceSupport::SUPPORT_SETTINGS, "DefaultAddonPVRClient.png" }, + {"kodi.gameclient", "", AddonType::GAMEDLL, 35049, AddonInstanceSupport::SUPPORT_OPTIONAL, "DefaultAddonGame.png" }, + {"kodi.peripheral", "", AddonType::PERIPHERALDLL, 35010, AddonInstanceSupport::SUPPORT_MANDATORY, "DefaultAddonPeripheral.png" }, + {"xbmc.addon.video", "", AddonType::VIDEO, 1037, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonVideo.png" }, + {"xbmc.addon.audio", "", AddonType::AUDIO, 1038, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonMusic.png" }, + {"xbmc.addon.image", "", AddonType::IMAGE, 1039, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonPicture.png" }, + {"xbmc.addon.executable", "", AddonType::EXECUTABLE, 1043, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonProgram.png" }, + {"kodi.addon.game", "", AddonType::GAME, 35049, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonGame.png" }, + {"kodi.audioencoder", "", AddonType::AUDIOENCODER, 200, AddonInstanceSupport::SUPPORT_MANDATORY, "DefaultAddonAudioEncoder.png" }, + {"kodi.audiodecoder", "", AddonType::AUDIODECODER, 201, AddonInstanceSupport::SUPPORT_MANDATORY, "DefaultAddonAudioDecoder.png" }, + {"xbmc.service", "", AddonType::SERVICE, 24018, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonService.png" }, + {"kodi.resource.images", "", AddonType::RESOURCE_IMAGES, 24035, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonImages.png" }, + {"kodi.resource.language", "", AddonType::RESOURCE_LANGUAGE, 24026, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonLanguage.png" }, + {"kodi.resource.uisounds", "", AddonType::RESOURCE_UISOUNDS, 24006, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonUISounds.png" }, + {"kodi.resource.games", "", AddonType::RESOURCE_GAMES, 35209, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonGame.png" }, + {"kodi.resource.font", "", AddonType::RESOURCE_FONT, 13303, AddonInstanceSupport::SUPPORT_NONE, "DefaultAddonFont.png" }, + {"kodi.inputstream", "", AddonType::INPUTSTREAM, 24048, AddonInstanceSupport::SUPPORT_MANDATORY, "DefaultAddonInputstream.png" }, + {"kodi.vfs", "", AddonType::VFS, 39013, AddonInstanceSupport::SUPPORT_MANDATORY, "DefaultAddonVfs.png" }, + {"kodi.imagedecoder", "", AddonType::IMAGEDECODER, 39015, AddonInstanceSupport::SUPPORT_MANDATORY, "DefaultAddonImageDecoder.png" }, }}; // clang-format on @@ -85,8 +87,7 @@ const std::string& CAddonInfo::OriginName() const if (!m_originName) { ADDON::AddonPtr origin; - if (CServiceBroker::GetAddonMgr().GetAddon(m_origin, origin, ADDON::ADDON_UNKNOWN, - ADDON::OnlyEnabled::CHOICE_NO)) + if (CServiceBroker::GetAddonMgr().GetAddon(m_origin, origin, ADDON::OnlyEnabled::CHOICE_NO)) m_originName = std::make_unique<std::string>(origin->Name()); else m_originName = std::make_unique<std::string>(); // remember we tried to fetch the name @@ -99,7 +100,7 @@ const std::string& CAddonInfo::OriginName() const * */ -std::string CAddonInfo::TranslateType(ADDON::TYPE type, bool pretty /*= false*/) +std::string CAddonInfo::TranslateType(AddonType type, bool pretty /*= false*/) { for (const TypeMapping& map : types) { @@ -114,7 +115,7 @@ std::string CAddonInfo::TranslateType(ADDON::TYPE type, bool pretty /*= false*/) return ""; } -TYPE CAddonInfo::TranslateType(const std::string& string) +AddonType CAddonInfo::TranslateType(const std::string& string) { for (const TypeMapping& map : types) { @@ -122,10 +123,10 @@ TYPE CAddonInfo::TranslateType(const std::string& string) return map.type; } - return ADDON_UNKNOWN; + return AddonType::UNKNOWN; } -std::string CAddonInfo::TranslateIconType(ADDON::TYPE type) +std::string CAddonInfo::TranslateIconType(AddonType type) { for (const TypeMapping& map : types) { @@ -135,23 +136,23 @@ std::string CAddonInfo::TranslateIconType(ADDON::TYPE type) return ""; } -TYPE CAddonInfo::TranslateSubContent(const std::string& content) +AddonType CAddonInfo::TranslateSubContent(const std::string& content) { if (content == "audio") - return ADDON_AUDIO; + return AddonType::AUDIO; else if (content == "image") - return ADDON_IMAGE; + return AddonType::IMAGE; else if (content == "executable") - return ADDON_EXECUTABLE; + return AddonType::EXECUTABLE; else if (content == "video") - return ADDON_VIDEO; + return AddonType::VIDEO; else if (content == "game") - return ADDON_GAME; + return AddonType::GAME; else - return ADDON_UNKNOWN; + return AddonType::UNKNOWN; } -AddonInstanceSupport CAddonInfo::InstanceSupportType(TYPE type) +AddonInstanceSupport CAddonInfo::InstanceSupportType(AddonType type) { const auto it = std::find_if(types.begin(), types.end(), [type](const TypeMapping& entry) { return entry.type == type; }); @@ -161,20 +162,18 @@ AddonInstanceSupport CAddonInfo::InstanceSupportType(TYPE type) return AddonInstanceSupport::SUPPORT_NONE; } -CAddonInfo::CAddonInfo(std::string id, TYPE type) - : m_id(std::move(id)), - m_mainType(type) +CAddonInfo::CAddonInfo(std::string id, AddonType type) : m_id(std::move(id)), m_mainType(type) { } -const CAddonType* CAddonInfo::Type(TYPE type) const +const CAddonType* CAddonInfo::Type(AddonType type) const { static CAddonType dummy; if (!m_types.empty()) { - if (type == ADDON_UNKNOWN) + if (type == AddonType::UNKNOWN) return &m_types[0]; for (auto& addonType : m_types) @@ -187,19 +186,21 @@ const CAddonType* CAddonInfo::Type(TYPE type) const return &dummy; } -bool CAddonInfo::HasType(TYPE type, bool mainOnly /*= false*/) const +bool CAddonInfo::HasType(AddonType type, bool mainOnly /*= false*/) const { - return (m_mainType == type || ProvidesSubContent(type, mainOnly ? m_mainType : ADDON_UNKNOWN)); + return (m_mainType == type || + ProvidesSubContent(type, mainOnly ? m_mainType : AddonType::UNKNOWN)); } -bool CAddonInfo::ProvidesSubContent(const TYPE& content, const TYPE& mainType /*= ADDON_UNKNOWN*/) const +bool CAddonInfo::ProvidesSubContent(AddonType content, AddonType mainType) const { - if (content == ADDON_UNKNOWN) + if (content == AddonType::UNKNOWN) return false; for (const auto& addonType : m_types) { - if ((mainType == ADDON_UNKNOWN || addonType.Type() == mainType) && addonType.ProvidesSubContent(content)) + if ((mainType == AddonType::UNKNOWN || addonType.Type() == mainType) && + addonType.ProvidesSubContent(content)) return true; } @@ -214,12 +215,12 @@ bool CAddonInfo::ProvidesSeveralSubContents() const return contents > 0 ? true : false; } -bool CAddonInfo::MeetsVersion(const AddonVersion& versionMin, const AddonVersion& version) const +bool CAddonInfo::MeetsVersion(const CAddonVersion& versionMin, const CAddonVersion& version) const { return !(versionMin > m_version || version < m_minversion); } -const AddonVersion& CAddonInfo::DependencyMinVersion(const std::string& dependencyID) const +const CAddonVersion& CAddonInfo::DependencyMinVersion(const std::string& dependencyID) const { auto it = std::find_if(m_dependencies.begin(), m_dependencies.end(), [&](const DependencyInfo& other) { return other.id == dependencyID; }); @@ -227,18 +228,18 @@ const AddonVersion& CAddonInfo::DependencyMinVersion(const std::string& dependen if (it != m_dependencies.end()) return it->versionMin; - static AddonVersion emptyVersion; + static CAddonVersion emptyVersion; return emptyVersion; } -const AddonVersion& CAddonInfo::DependencyVersion(const std::string& dependencyID) const +const CAddonVersion& CAddonInfo::DependencyVersion(const std::string& dependencyID) const { auto it = std::find_if(m_dependencies.begin(), m_dependencies.end(), [&](const DependencyInfo& other) { return other.id == dependencyID; }); if (it != m_dependencies.end()) return it->version; - static AddonVersion emptyVersion; + static CAddonVersion emptyVersion; return emptyVersion; } diff --git a/xbmc/addons/addoninfo/AddonInfo.h b/xbmc/addons/addoninfo/AddonInfo.h index e806121554..5998e2d23c 100644 --- a/xbmc/addons/addoninfo/AddonInfo.h +++ b/xbmc/addons/addoninfo/AddonInfo.h @@ -10,7 +10,6 @@ #include "XBDateTime.h" #include "addons/AddonVersion.h" -#include "addons/addoninfo/AddonType.h" #include <map> #include <memory> @@ -22,8 +21,11 @@ namespace ADDON { +enum class AddonType; + class CAddonBuilder; class CAddonInfo; +class CAddonType; typedef std::shared_ptr<CAddonInfo> AddonInfoPtr; typedef std::vector<AddonInfoPtr> AddonInfos; @@ -106,11 +108,11 @@ enum class AddonLifecycleState struct DependencyInfo { std::string id; - AddonVersion versionMin, version; + CAddonVersion versionMin, version; bool optional; DependencyInfo(std::string id, - const AddonVersion& versionMin, - const AddonVersion& version, + const CAddonVersion& versionMin, + const CAddonVersion& version, bool optional) : id(std::move(id)), versionMin(versionMin.empty() ? version : versionMin), @@ -140,9 +142,9 @@ class CAddonInfo { public: CAddonInfo() = default; - CAddonInfo(std::string id, TYPE type); + CAddonInfo(std::string id, AddonType type); - void SetMainType(TYPE type) { m_mainType = type; } + void SetMainType(AddonType type) { m_mainType = type; } void SetBinary(bool isBinary) { m_isBinary = isBinary; } void SetLibName(const std::string& libname) { m_libname = libname; } void SetPath(const std::string& path) { m_path = path; } @@ -158,7 +160,7 @@ public: * * @return The used main type of addon */ - TYPE MainType() const { return m_mainType; } + AddonType MainType() const { return m_mainType; } /** * @brief To check addon contains a type @@ -167,7 +169,7 @@ public: * @param[in] mainOnly to check only in first defined main addon inside addon.xml * @return true in case the wanted type is supported, false if not */ - bool HasType(TYPE type, bool mainOnly = false) const; + bool HasType(AddonType type, bool mainOnly = false) const; /** * @brief To get all available types inside the addon @@ -196,16 +198,16 @@ public: * ~~~~~~~~~~~~~ * */ - const CAddonType* Type(TYPE type) const; + const CAddonType* Type(AddonType type) const; - bool ProvidesSubContent(const TYPE& content, const TYPE& mainType = ADDON_UNKNOWN) const; + bool ProvidesSubContent(AddonType content, AddonType mainType) const; bool ProvidesSeveralSubContents() const; - const AddonVersion& Version() const { return m_version; } - const AddonVersion& MinVersion() const { return m_minversion; } + const CAddonVersion& Version() const { return m_version; } + const CAddonVersion& MinVersion() const { return m_minversion; } bool IsBinary() const { return m_isBinary; } - const AddonVersion& DependencyMinVersion(const std::string& dependencyID) const; - const AddonVersion& DependencyVersion(const std::string& dependencyID) const; + const CAddonVersion& DependencyMinVersion(const std::string& dependencyID) const; + const CAddonVersion& DependencyVersion(const std::string& dependencyID) const; const std::string& Name() const { return m_name; } const std::string& License() const { return m_license; } const std::string& Summary() const { return GetTranslatedText(m_summary); } @@ -234,7 +236,7 @@ public: const InfoMap& ExtraInfo() const { return m_extrainfo; } - bool MeetsVersion(const AddonVersion& versionMin, const AddonVersion& version) const; + bool MeetsVersion(const CAddonVersion& versionMin, const CAddonVersion& version) const; uint64_t PackageSize() const { return m_packageSize; } CDateTime InstallDate() const { return m_installDate; } CDateTime LastUpdated() const { return m_lastUpdated; } @@ -251,22 +253,23 @@ public: * @brief Utilities to translate add-on parts to his requested part. */ //@{ - static std::string TranslateType(TYPE type, bool pretty = false); - static std::string TranslateIconType(TYPE type); - static TYPE TranslateType(const std::string& string); - static TYPE TranslateSubContent(const std::string& content); - static AddonInstanceSupport InstanceSupportType(TYPE type); + static std::string TranslateType(AddonType type, bool pretty = false); + static std::string TranslateIconType(AddonType type); + static AddonType TranslateType(const std::string& string); + static AddonType TranslateSubContent(const std::string& content); + static AddonInstanceSupport InstanceSupportType(AddonType type); //@} private: friend class CAddonInfoBuilder; + friend class CAddonInfoBuilderFromDB; std::string m_id; - TYPE m_mainType = ADDON_UNKNOWN; + AddonType m_mainType{}; std::vector<CAddonType> m_types; - AddonVersion m_version; - AddonVersion m_minversion; + CAddonVersion m_version; + CAddonVersion m_minversion; bool m_isBinary = false; std::string m_name; std::string m_license; diff --git a/xbmc/addons/addoninfo/AddonInfoBuilder.cpp b/xbmc/addons/addoninfo/AddonInfoBuilder.cpp index b3e8aa8365..268efa6ced 100644 --- a/xbmc/addons/addoninfo/AddonInfoBuilder.cpp +++ b/xbmc/addons/addoninfo/AddonInfoBuilder.cpp @@ -10,6 +10,7 @@ #include "CompileInfo.h" #include "LangInfo.h" +#include "addons/Repository.h" #include "addons/addoninfo/AddonInfo.h" #include "addons/addoninfo/AddonType.h" #include "filesystem/File.h" @@ -35,150 +36,149 @@ const std::string VALID_ADDON_IDENTIFIER_CHARACTERS = "abcdefghijklmnopqrstuvwxy namespace ADDON { -CAddonInfoBuilder::CFromDB::CFromDB() : m_addonInfo(std::make_shared<CAddonInfo>()) +CAddonInfoBuilderFromDB::CAddonInfoBuilderFromDB() : m_addonInfo(std::make_shared<CAddonInfo>()) { } -void CAddonInfoBuilder::CFromDB::SetId(std::string id) +void CAddonInfoBuilderFromDB::SetId(std::string id) { m_addonInfo->m_id = std::move(id); } -void CAddonInfoBuilder::CFromDB::SetName(std::string name) +void CAddonInfoBuilderFromDB::SetName(std::string name) { m_addonInfo->m_name = std::move(name); } -void CAddonInfoBuilder::CFromDB::SetLicense(std::string license) +void CAddonInfoBuilderFromDB::SetLicense(std::string license) { m_addonInfo->m_license = std::move(license); } -void CAddonInfoBuilder::CFromDB::SetSummary(std::string summary) +void CAddonInfoBuilderFromDB::SetSummary(std::string summary) { m_addonInfo->m_summary.insert(std::pair<std::string, std::string>("unk", std::move(summary))); } -void CAddonInfoBuilder::CFromDB::SetDescription(std::string description) +void CAddonInfoBuilderFromDB::SetDescription(std::string description) { m_addonInfo->m_description.insert( std::pair<std::string, std::string>("unk", std::move(description))); } -void CAddonInfoBuilder::CFromDB::SetDisclaimer(std::string disclaimer) +void CAddonInfoBuilderFromDB::SetDisclaimer(std::string disclaimer) { m_addonInfo->m_disclaimer.insert( std::pair<std::string, std::string>("unk", std::move(disclaimer))); } -void CAddonInfoBuilder::CFromDB::SetAuthor(std::string author) +void CAddonInfoBuilderFromDB::SetAuthor(std::string author) { m_addonInfo->m_author = std::move(author); } -void CAddonInfoBuilder::CFromDB::SetSource(std::string source) +void CAddonInfoBuilderFromDB::SetSource(std::string source) { m_addonInfo->m_source = std::move(source); } -void CAddonInfoBuilder::CFromDB::SetWebsite(std::string website) +void CAddonInfoBuilderFromDB::SetWebsite(std::string website) { m_addonInfo->m_website = std::move(website); } -void CAddonInfoBuilder::CFromDB::SetForum(std::string forum) +void CAddonInfoBuilderFromDB::SetForum(std::string forum) { m_addonInfo->m_forum = std::move(forum); } -void CAddonInfoBuilder::CFromDB::SetEMail(std::string email) +void CAddonInfoBuilderFromDB::SetEMail(std::string email) { m_addonInfo->m_email = std::move(email); } -void CAddonInfoBuilder::CFromDB::SetIcon(std::string icon) +void CAddonInfoBuilderFromDB::SetIcon(std::string icon) { m_addonInfo->m_icon = std::move(icon); } -void CAddonInfoBuilder::CFromDB::SetArt(const std::string& type, std::string value) +void CAddonInfoBuilderFromDB::SetArt(const std::string& type, std::string value) { m_addonInfo->m_art[type] = std::move(value); } -void CAddonInfoBuilder::CFromDB::SetArt(std::map<std::string, std::string> art) +void CAddonInfoBuilderFromDB::SetArt(std::map<std::string, std::string> art) { m_addonInfo->m_art = std::move(art); } -void CAddonInfoBuilder::CFromDB::SetScreenshots(std::vector<std::string> screenshots) +void CAddonInfoBuilderFromDB::SetScreenshots(std::vector<std::string> screenshots) { m_addonInfo->m_screenshots = std::move(screenshots); } -void CAddonInfoBuilder::CFromDB::SetChangelog(std::string changelog) +void CAddonInfoBuilderFromDB::SetChangelog(std::string changelog) { m_addonInfo->m_changelog.insert(std::pair<std::string, std::string>("unk", std::move(changelog))); } -void CAddonInfoBuilder::CFromDB::SetLifecycleState(AddonLifecycleState state, - std::string description) +void CAddonInfoBuilderFromDB::SetLifecycleState(AddonLifecycleState state, std::string description) { m_addonInfo->m_lifecycleState = state; m_addonInfo->m_lifecycleStateDescription.emplace("unk", std::move(description)); } -void CAddonInfoBuilder::CFromDB::SetPath(std::string path) +void CAddonInfoBuilderFromDB::SetPath(std::string path) { m_addonInfo->m_path = std::move(path); } -void CAddonInfoBuilder::CFromDB::SetLibName(std::string libname) +void CAddonInfoBuilderFromDB::SetLibName(std::string libname) { m_addonInfo->m_libname = std::move(libname); } -void CAddonInfoBuilder::CFromDB::SetVersion(AddonVersion version) +void CAddonInfoBuilderFromDB::SetVersion(CAddonVersion version) { m_addonInfo->m_version = std::move(version); } -void CAddonInfoBuilder::CFromDB::SetDependencies(std::vector<DependencyInfo> dependencies) +void CAddonInfoBuilderFromDB::SetDependencies(std::vector<DependencyInfo> dependencies) { m_addonInfo->m_dependencies = std::move(dependencies); } -void CAddonInfoBuilder::CFromDB::SetExtrainfo(InfoMap extrainfo) +void CAddonInfoBuilderFromDB::SetExtrainfo(InfoMap extrainfo) { m_addonInfo->m_extrainfo = std::move(extrainfo); } -void CAddonInfoBuilder::CFromDB::SetInstallDate(const CDateTime& installDate) +void CAddonInfoBuilderFromDB::SetInstallDate(const CDateTime& installDate) { m_addonInfo->m_installDate = installDate; } -void CAddonInfoBuilder::CFromDB::SetLastUpdated(const CDateTime& lastUpdated) +void CAddonInfoBuilderFromDB::SetLastUpdated(const CDateTime& lastUpdated) { m_addonInfo->m_lastUpdated = lastUpdated; } -void CAddonInfoBuilder::CFromDB::SetLastUsed(const CDateTime& lastUsed) +void CAddonInfoBuilderFromDB::SetLastUsed(const CDateTime& lastUsed) { m_addonInfo->m_lastUsed = lastUsed; } -void CAddonInfoBuilder::CFromDB::SetOrigin(std::string origin) +void CAddonInfoBuilderFromDB::SetOrigin(std::string origin) { m_addonInfo->m_origin = std::move(origin); } -void CAddonInfoBuilder::CFromDB::SetPackageSize(uint64_t size) +void CAddonInfoBuilderFromDB::SetPackageSize(uint64_t size) { m_addonInfo->m_packageSize = size; } -void CAddonInfoBuilder::CFromDB::SetExtensions(CAddonType addonType) +void CAddonInfoBuilderFromDB::SetExtensions(CAddonType addonType) { if (!addonType.GetValue("provides").empty()) addonType.SetProvides(addonType.GetValue("provides").asString()); @@ -187,7 +187,7 @@ void CAddonInfoBuilder::CFromDB::SetExtensions(CAddonType addonType) m_addonInfo->m_mainType = addonType.m_type; } -AddonInfoPtr CAddonInfoBuilder::Generate(const std::string& id, TYPE type) +AddonInfoPtr CAddonInfoBuilder::Generate(const std::string& id, AddonType type) { // Check addon identifier for forbidden characters // The identifier is used e.g. in URLs so we shouldn't allow just @@ -229,7 +229,9 @@ AddonInfoPtr CAddonInfoBuilder::Generate(const std::string& addonPath, bool plat return nullptr; } -AddonInfoPtr CAddonInfoBuilder::Generate(const TiXmlElement* baseElement, const CRepository::DirInfo& repo, bool platformCheck /*= true*/) +AddonInfoPtr CAddonInfoBuilder::Generate(const TiXmlElement* baseElement, + const RepositoryDirInfo& repo, + bool platformCheck /*= true*/) { AddonInfoPtr addon = std::make_shared<CAddonInfo>(); if (!ParseXML(addon, baseElement, repo.datadir, repo)) @@ -253,7 +255,17 @@ void CAddonInfoBuilder::SetInstallData(const AddonInfoPtr& addon, const CDateTim addon->m_origin = origin; } -bool CAddonInfoBuilder::ParseXML(const AddonInfoPtr& addon, const TiXmlElement* element, const std::string& addonPath, const CRepository::DirInfo& repo) +bool CAddonInfoBuilder::ParseXML(const AddonInfoPtr& addon, + const TiXmlElement* element, + const std::string& addonPath) +{ + return ParseXML(addon, element, addonPath, {}); +} + +bool CAddonInfoBuilder::ParseXML(const AddonInfoPtr& addon, + const TiXmlElement* element, + const std::string& addonPath, + const RepositoryDirInfo& repo) { /* * Following values currently not set from creator: @@ -287,7 +299,7 @@ bool CAddonInfoBuilder::ParseXML(const AddonInfoPtr& addon, const TiXmlElement* addon->m_author = StringUtils::CreateFromCString(element->Attribute("provider-name")); const std::string version = StringUtils::CreateFromCString(element->Attribute("version")); - addon->m_version = AddonVersion(version); + addon->m_version = CAddonVersion(version); if (addon->m_id.empty() || addon->m_version.empty()) { @@ -316,7 +328,7 @@ bool CAddonInfoBuilder::ParseXML(const AddonInfoPtr& addon, const TiXmlElement* if (backwards) { const std::string minVersion = StringUtils::CreateFromCString(backwards->Attribute("abi")); - addon->m_minversion = AddonVersion(minVersion); + addon->m_minversion = CAddonVersion(minVersion); } /* @@ -339,8 +351,8 @@ bool CAddonInfoBuilder::ParseXML(const AddonInfoPtr& addon, const TiXmlElement* bool optional = false; child->QueryBoolAttribute("optional", &optional); - addon->m_dependencies.emplace_back(child->Attribute("addon"), AddonVersion(minVersion), - AddonVersion(version), optional); + addon->m_dependencies.emplace_back(child->Attribute("addon"), CAddonVersion(minVersion), + CAddonVersion(version), optional); } } } @@ -545,8 +557,8 @@ bool CAddonInfoBuilder::ParseXML(const AddonInfoPtr& addon, const TiXmlElement* } else { - TYPE type = CAddonInfo::TranslateType(point); - if (type == ADDON_UNKNOWN || type >= ADDON_MAX) + AddonType type = CAddonInfo::TranslateType(point); + if (type == AddonType::UNKNOWN || type >= AddonType::MAX_TYPES) { CLog::Log(LOGERROR, "CAddonInfoBuilder::{}: file '{}' doesn't contain a valid add-on type name ({})", __FUNCTION__, addon->m_path, point); return false; @@ -564,7 +576,7 @@ bool CAddonInfoBuilder::ParseXML(const AddonInfoPtr& addon, const TiXmlElement* */ if (addon->m_types.empty()) { - CAddonType addonType(ADDON_UNKNOWN); + CAddonType addonType(AddonType::UNKNOWN); addon->m_types.emplace_back(std::move(addonType)); } @@ -574,16 +586,12 @@ bool CAddonInfoBuilder::ParseXML(const AddonInfoPtr& addon, const TiXmlElement* addon->AddExtraInfo("provides", addon->m_types[0].GetValue("provides").asString()); // Ensure binary types have a valid library for the platform - if (addon->m_mainType == ADDON_VIZ || - addon->m_mainType == ADDON_SCREENSAVER || - addon->m_mainType == ADDON_PVRDLL || - addon->m_mainType == ADDON_AUDIOENCODER || - addon->m_mainType == ADDON_AUDIODECODER || - addon->m_mainType == ADDON_VFS || - addon->m_mainType == ADDON_IMAGEDECODER || - addon->m_mainType == ADDON_INPUTSTREAM || - addon->m_mainType == ADDON_PERIPHERALDLL || - addon->m_mainType == ADDON_GAMEDLL) + if (addon->m_mainType == AddonType::VISUALIZATION || + addon->m_mainType == AddonType::SCREENSAVER || addon->m_mainType == AddonType::PVRDLL || + addon->m_mainType == AddonType::AUDIOENCODER || + addon->m_mainType == AddonType::AUDIODECODER || addon->m_mainType == AddonType::VFS || + addon->m_mainType == AddonType::IMAGEDECODER || addon->m_mainType == AddonType::INPUTSTREAM || + addon->m_mainType == AddonType::PERIPHERALDLL || addon->m_mainType == AddonType::GAMEDLL) { if (addon->m_libname.empty()) { diff --git a/xbmc/addons/addoninfo/AddonInfoBuilder.h b/xbmc/addons/addoninfo/AddonInfoBuilder.h index 55eb23be53..adbbc84a87 100644 --- a/xbmc/addons/addoninfo/AddonInfoBuilder.h +++ b/xbmc/addons/addoninfo/AddonInfoBuilder.h @@ -8,64 +8,39 @@ #pragma once -#include "addons/Repository.h" +#include "addons/IAddon.h" #include <map> +#include <memory> #include <string> #include <unordered_map> #include <vector> +class CDateTime; class TiXmlElement; namespace ADDON { +enum class AddonLifecycleState; +enum class AddonType; + +class CAddonExtensions; +class CAddonType; + +struct DependencyInfo; +struct RepositoryDirInfo; + +class CAddonInfo; +using AddonInfoPtr = std::shared_ptr<CAddonInfo>; class CAddonInfoBuilder { public: - static AddonInfoPtr Generate(const std::string& id, TYPE type); + static AddonInfoPtr Generate(const std::string& id, AddonType type); static AddonInfoPtr Generate(const std::string& addonPath, bool platformCheck = true); - static AddonInfoPtr Generate(const TiXmlElement* baseElement, const CRepository::DirInfo& repo, bool platformCheck = true); - - class CFromDB - { - public: - CFromDB(); - - void SetId(std::string id); - void SetName(std::string name); - void SetLicense(std::string license); - void SetSummary(std::string summary); - void SetDescription(std::string description); - void SetDisclaimer(std::string disclaimer); - void SetAuthor(std::string author); - void SetSource(std::string source); - void SetWebsite(std::string website); - void SetForum(std::string forum); - void SetEMail(std::string email); - void SetIcon(std::string icon); - void SetArt(const std::string& type, std::string value); - void SetArt(std::map<std::string, std::string> art); - void SetScreenshots(std::vector<std::string> screenshots); - void SetChangelog(std::string changelog); - void SetLifecycleState(AddonLifecycleState state, std::string description); - void SetPath(std::string path); - void SetLibName(std::string libname); - void SetVersion(AddonVersion version); - void SetDependencies(std::vector<DependencyInfo> dependencies); - void SetExtrainfo(InfoMap extrainfo); - void SetInstallDate(const CDateTime& installDate); - void SetLastUpdated(const CDateTime& lastUpdated); - void SetLastUsed(const CDateTime& lastUsed); - void SetOrigin(std::string origin); - void SetPackageSize(uint64_t size); - void SetExtensions(CAddonType addonType); - - const AddonInfoPtr& get() { return m_addonInfo; } - - private: - AddonInfoPtr m_addonInfo; - }; + static AddonInfoPtr Generate(const TiXmlElement* baseElement, + const RepositoryDirInfo& repo, + bool platformCheck = true); /*! * @brief Parts used from CAddonDatabase @@ -76,7 +51,13 @@ public: //@} private: - static bool ParseXML(const AddonInfoPtr& addon, const TiXmlElement* element, const std::string& addonPath, const CRepository::DirInfo& repo = {}); + static bool ParseXML(const AddonInfoPtr& addon, + const TiXmlElement* element, + const std::string& addonPath); + static bool ParseXML(const AddonInfoPtr& addon, + const TiXmlElement* element, + const std::string& addonPath, + const RepositoryDirInfo& repo); static bool ParseXMLTypes(CAddonType& addonType, const AddonInfoPtr& info, const TiXmlElement* child); @@ -86,4 +67,43 @@ private: static bool PlatformSupportsAddon(const AddonInfoPtr& addon); }; +class CAddonInfoBuilderFromDB +{ +public: + CAddonInfoBuilderFromDB(); + + void SetId(std::string id); + void SetName(std::string name); + void SetLicense(std::string license); + void SetSummary(std::string summary); + void SetDescription(std::string description); + void SetDisclaimer(std::string disclaimer); + void SetAuthor(std::string author); + void SetSource(std::string source); + void SetWebsite(std::string website); + void SetForum(std::string forum); + void SetEMail(std::string email); + void SetIcon(std::string icon); + void SetArt(const std::string& type, std::string value); + void SetArt(std::map<std::string, std::string> art); + void SetScreenshots(std::vector<std::string> screenshots); + void SetChangelog(std::string changelog); + void SetLifecycleState(AddonLifecycleState state, std::string description); + void SetPath(std::string path); + void SetLibName(std::string libname); + void SetVersion(CAddonVersion version); + void SetDependencies(std::vector<DependencyInfo> dependencies); + void SetExtrainfo(InfoMap extrainfo); + void SetInstallDate(const CDateTime& installDate); + void SetLastUpdated(const CDateTime& lastUpdated); + void SetLastUsed(const CDateTime& lastUsed); + void SetOrigin(std::string origin); + void SetPackageSize(uint64_t size); + void SetExtensions(CAddonType addonType); + + const AddonInfoPtr& get() { return m_addonInfo; } + +private: + AddonInfoPtr m_addonInfo; +}; } diff --git a/xbmc/addons/addoninfo/AddonType.cpp b/xbmc/addons/addoninfo/AddonType.cpp index 111addcf8d..875e66f625 100644 --- a/xbmc/addons/addoninfo/AddonType.cpp +++ b/xbmc/addons/addoninfo/AddonType.cpp @@ -14,10 +14,10 @@ namespace ADDON { -static const std::set<TYPE> dependencyTypes = { - ADDON_SCRAPER_LIBRARY, - ADDON_SCRIPT_LIBRARY, - ADDON_SCRIPT_MODULE, +static const std::set<AddonType> dependencyTypes = { + AddonType::SCRAPER_LIBRARY, + AddonType::SCRIPT_LIBRARY, + AddonType::SCRIPT_MODULE, }; } /* namespace ADDON */ @@ -46,14 +46,14 @@ void CAddonType::SetProvides(const std::string& content) for (const auto& provide : StringUtils::Split(content, ' ')) { - TYPE content = CAddonInfo::TranslateSubContent(provide); - if (content != ADDON_UNKNOWN) + AddonType content = CAddonInfo::TranslateSubContent(provide); + if (content != AddonType::UNKNOWN) m_providedSubContent.insert(content); } } } -bool CAddonType::IsDependencyType(TYPE type) +bool CAddonType::IsDependencyType(AddonType type) { return dependencyTypes.find(type) != dependencyTypes.end(); } diff --git a/xbmc/addons/addoninfo/AddonType.h b/xbmc/addons/addoninfo/AddonType.h index 36b43a8cf6..9a0ee260cf 100644 --- a/xbmc/addons/addoninfo/AddonType.h +++ b/xbmc/addons/addoninfo/AddonType.h @@ -18,58 +18,58 @@ class TiXmlElement; namespace ADDON { -typedef enum +enum class AddonType { - ADDON_UNKNOWN, - ADDON_VIZ, - ADDON_SKIN, - ADDON_PVRDLL, - ADDON_INPUTSTREAM, - ADDON_GAMEDLL, - ADDON_PERIPHERALDLL, - ADDON_SCRIPT, - ADDON_SCRIPT_WEATHER, - ADDON_SUBTITLE_MODULE, - ADDON_SCRIPT_LYRICS, - ADDON_SCRAPER_ALBUMS, - ADDON_SCRAPER_ARTISTS, - ADDON_SCRAPER_MOVIES, - ADDON_SCRAPER_MUSICVIDEOS, - ADDON_SCRAPER_TVSHOWS, - ADDON_SCREENSAVER, - ADDON_PLUGIN, - ADDON_REPOSITORY, - ADDON_WEB_INTERFACE, - ADDON_SERVICE, - ADDON_AUDIOENCODER, - ADDON_CONTEXT_ITEM, - ADDON_AUDIODECODER, - ADDON_RESOURCE_IMAGES, - ADDON_RESOURCE_LANGUAGE, - ADDON_RESOURCE_UISOUNDS, - ADDON_RESOURCE_GAMES, - ADDON_RESOURCE_FONT, - ADDON_VFS, - ADDON_IMAGEDECODER, - ADDON_SCRAPER_LIBRARY, - ADDON_SCRIPT_LIBRARY, - ADDON_SCRIPT_MODULE, - ADDON_GAME_CONTROLLER, - ADDON_VIDEOCODEC, + UNKNOWN = 0, + VISUALIZATION, + SKIN, + PVRDLL, + INPUTSTREAM, + GAMEDLL, + PERIPHERALDLL, + SCRIPT, + SCRIPT_WEATHER, + SUBTITLE_MODULE, + SCRIPT_LYRICS, + SCRAPER_ALBUMS, + SCRAPER_ARTISTS, + SCRAPER_MOVIES, + SCRAPER_MUSICVIDEOS, + SCRAPER_TVSHOWS, + SCREENSAVER, + PLUGIN, + REPOSITORY, + WEB_INTERFACE, + SERVICE, + AUDIOENCODER, + CONTEXTMENU_ITEM, + AUDIODECODER, + RESOURCE_IMAGES, + RESOURCE_LANGUAGE, + RESOURCE_UISOUNDS, + RESOURCE_GAMES, + RESOURCE_FONT, + VFS, + IMAGEDECODER, + SCRAPER_LIBRARY, + SCRIPT_LIBRARY, + SCRIPT_MODULE, + GAME_CONTROLLER, + VIDEOCODEC, /** * @brief virtual addon types */ //@{ - ADDON_VIDEO, - ADDON_AUDIO, - ADDON_IMAGE, - ADDON_EXECUTABLE, - ADDON_GAME, + VIDEO, + AUDIO, + IMAGE, + EXECUTABLE, + GAME, //@} - ADDON_MAX -} TYPE; + MAX_TYPES +}; class CAddonInfoBuilder; class CAddonDatabaseSerializer; @@ -77,15 +77,17 @@ class CAddonDatabaseSerializer; class CAddonType : public CAddonExtensions { public: - CAddonType(TYPE type = ADDON_UNKNOWN) : m_type(type) {} + CAddonType(AddonType type = AddonType::UNKNOWN) : m_type(type) {} - TYPE Type() const { return m_type; } + AddonType Type() const { return m_type; } std::string LibPath() const; const std::string& LibName() const { return m_libname; } - bool ProvidesSubContent(const TYPE& content) const + bool ProvidesSubContent(const AddonType& content) const { - return content == ADDON_UNKNOWN ? false : m_type == content || m_providedSubContent.count(content) > 0; + return content == AddonType::UNKNOWN + ? false + : m_type == content || m_providedSubContent.count(content) > 0; } bool ProvidesSeveralSubContents() const @@ -105,18 +107,19 @@ public: * @param[in] type the provided type * @return true if type is one of the dependency types */ - static bool IsDependencyType(TYPE type); + static bool IsDependencyType(AddonType type); private: friend class CAddonInfoBuilder; + friend class CAddonInfoBuilderFromDB; friend class CAddonDatabaseSerializer; void SetProvides(const std::string& content); - TYPE m_type; + AddonType m_type; std::string m_path; std::string m_libname; - std::set<TYPE> m_providedSubContent; + std::set<AddonType> m_providedSubContent; }; } /* namespace ADDON */ diff --git a/xbmc/addons/binary-addons/AddonDll.cpp b/xbmc/addons/binary-addons/AddonDll.cpp index b1d535dec3..4ff52549db 100644 --- a/xbmc/addons/binary-addons/AddonDll.cpp +++ b/xbmc/addons/binary-addons/AddonDll.cpp @@ -39,7 +39,7 @@ CAddonDll::CAddonDll(const AddonInfoPtr& addonInfo, BinaryAddonBasePtr addonBase { } -CAddonDll::CAddonDll(const AddonInfoPtr& addonInfo, TYPE addonType) +CAddonDll::CAddonDll(const AddonInfoPtr& addonInfo, AddonType addonType) : CAddon(addonInfo, addonType), m_binaryAddonBase(CServiceBroker::GetBinaryAddonManager().GetRunningAddonBase(addonInfo->ID())) { @@ -335,14 +335,14 @@ bool CAddonDll::DllLoaded(void) const return m_pDll != nullptr; } -AddonVersion CAddonDll::GetTypeVersionDll(int type) const +CAddonVersion CAddonDll::GetTypeVersionDll(int type) const { - return AddonVersion(m_pDll ? m_pDll->GetAddonTypeVersion(type) : nullptr); + return CAddonVersion(m_pDll ? m_pDll->GetAddonTypeVersion(type) : nullptr); } -AddonVersion CAddonDll::GetTypeMinVersionDll(int type) const +CAddonVersion CAddonDll::GetTypeMinVersionDll(int type) const { - return AddonVersion(m_pDll ? m_pDll->GetAddonTypeMinVersion(type) : nullptr); + return CAddonVersion(m_pDll ? m_pDll->GetAddonTypeMinVersion(type) : nullptr); } void CAddonDll::SaveSettings(AddonInstanceId id /* = ADDON_SETTINGS_ID */) @@ -510,11 +510,11 @@ ADDON_STATUS CAddonDll::TransferSettings(AddonInstanceId instanceId) bool CAddonDll::CheckAPIVersion(int type) { /* check the API version */ - AddonVersion kodiMinVersion(kodi::addon::GetTypeMinVersion(type)); - AddonVersion addonVersion(m_pDll->GetAddonTypeVersion(type)); - AddonVersion addonMinVersion = m_pDll->GetAddonTypeMinVersion_available() - ? AddonVersion(m_pDll->GetAddonTypeMinVersion(type)) - : addonVersion; + CAddonVersion kodiMinVersion(kodi::addon::GetTypeMinVersion(type)); + CAddonVersion addonVersion(m_pDll->GetAddonTypeVersion(type)); + CAddonVersion addonMinVersion = m_pDll->GetAddonTypeMinVersion_available() + ? CAddonVersion(m_pDll->GetAddonTypeMinVersion(type)) + : addonVersion; /* Check the global usage from addon * if not used from addon, empty version is returned @@ -526,7 +526,7 @@ bool CAddonDll::CheckAPIVersion(int type) * present. */ if (kodiMinVersion > addonVersion || - addonMinVersion > AddonVersion(kodi::addon::GetTypeVersion(type))) + addonMinVersion > CAddonVersion(kodi::addon::GetTypeVersion(type))) { CLog::Log(LOGERROR, "Add-on '{}' is using an incompatible API version for type '{}'. Kodi API min version = '{}/{}', add-on API version '{}/{}'", Name(), diff --git a/xbmc/addons/binary-addons/AddonDll.h b/xbmc/addons/binary-addons/AddonDll.h index e4c1b973bf..5f17a042f6 100644 --- a/xbmc/addons/binary-addons/AddonDll.h +++ b/xbmc/addons/binary-addons/AddonDll.h @@ -52,7 +52,7 @@ class CAddonDll : public CAddon { public: CAddonDll(const AddonInfoPtr& addonInfo, BinaryAddonBasePtr addonBase); - CAddonDll(const AddonInfoPtr& addonInfo, TYPE addonType); + CAddonDll(const AddonInfoPtr& addonInfo, AddonType addonType); ~CAddonDll() override; // Implementation of IAddon via CAddon @@ -72,7 +72,7 @@ public: * @note This should only be called if the associated dll is loaded. * Otherwise use @ref CAddonInfo::DependencyVersion(...) */ - AddonVersion GetTypeVersionDll(int type) const; + CAddonVersion GetTypeVersionDll(int type) const; /*! * @brief Get api min version of moduleType type @@ -83,7 +83,7 @@ public: * @note This should only be called if the associated dll is loaded. * Otherwise use @ref CAddonInfo::DependencyMinVersion(...) */ - AddonVersion GetTypeMinVersionDll(int type) const; + CAddonVersion GetTypeMinVersionDll(int type) const; /*! * @brief Function to create a addon instance class diff --git a/xbmc/addons/binary-addons/AddonInstanceHandler.cpp b/xbmc/addons/binary-addons/AddonInstanceHandler.cpp index 6deb993c86..34c303b965 100644 --- a/xbmc/addons/binary-addons/AddonInstanceHandler.cpp +++ b/xbmc/addons/binary-addons/AddonInstanceHandler.cpp @@ -104,9 +104,9 @@ std::string IAddonInstanceHandler::Profile() const return m_addon ? m_addon->Profile() : ""; } -AddonVersion IAddonInstanceHandler::Version() const +CAddonVersion IAddonInstanceHandler::Version() const { - return m_addon ? m_addon->Version() : AddonVersion(); + return m_addon ? m_addon->Version() : CAddonVersion(); } ADDON_STATUS IAddonInstanceHandler::CreateInstance() diff --git a/xbmc/addons/binary-addons/AddonInstanceHandler.h b/xbmc/addons/binary-addons/AddonInstanceHandler.h index fbc0cdd553..27ba95b2be 100644 --- a/xbmc/addons/binary-addons/AddonInstanceHandler.h +++ b/xbmc/addons/binary-addons/AddonInstanceHandler.h @@ -75,7 +75,7 @@ public: std::string Icon() const; std::string Path() const; std::string Profile() const; - AddonVersion Version() const; + CAddonVersion Version() const; ADDON_STATUS CreateInstance(); void DestroyInstance(); diff --git a/xbmc/addons/binary-addons/BinaryAddonManager.cpp b/xbmc/addons/binary-addons/BinaryAddonManager.cpp index 2e6dbc04a6..699fc09a1a 100644 --- a/xbmc/addons/binary-addons/BinaryAddonManager.cpp +++ b/xbmc/addons/binary-addons/BinaryAddonManager.cpp @@ -8,9 +8,9 @@ #include "BinaryAddonManager.h" -#include "BinaryAddonBase.h" #include "addons/addoninfo/AddonInfo.h" #include "addons/binary-addons/AddonDll.h" +#include "addons/binary-addons/BinaryAddonBase.h" #include "utils/log.h" #include <mutex> diff --git a/xbmc/addons/gui/GUIDialogAddonInfo.cpp b/xbmc/addons/gui/GUIDialogAddonInfo.cpp index d613345f68..7ada638a34 100644 --- a/xbmc/addons/gui/GUIDialogAddonInfo.cpp +++ b/xbmc/addons/gui/GUIDialogAddonInfo.cpp @@ -21,6 +21,7 @@ #include "addons/ExtsMimeSupportList.h" #include "addons/IAddon.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "addons/gui/GUIDialogAddonSettings.h" #include "addons/gui/GUIHelpers.h" #include "dialogs/GUIDialogSelect.h" @@ -282,8 +283,7 @@ void CGUIDialogAddonInfo::UpdateControls(PerformButtonFocus performButtonFocus) static const std::string LOCAL_CACHE = "\\0_local_cache"; // \0 to give it the lowest priority when sorting - -int CGUIDialogAddonInfo::AskForVersion(std::vector<std::pair<AddonVersion, std::string>>& versions) +int CGUIDialogAddonInfo::AskForVersion(std::vector<std::pair<CAddonVersion, std::string>>& versions) { auto dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>( WINDOW_DIALOG_SELECT); @@ -305,7 +305,7 @@ int CGUIDialogAddonInfo::AskForVersion(std::vector<std::pair<AddonVersion, std:: item.SetArt("icon", "DefaultAddonRepository.png"); dialog->Add(item); } - else if (CServiceBroker::GetAddonMgr().GetAddon(versionInfo.second, repo, ADDON_REPOSITORY, + else if (CServiceBroker::GetAddonMgr().GetAddon(versionInfo.second, repo, AddonType::REPOSITORY, OnlyEnabled::CHOICE_YES)) { item.SetLabel2(repo->Name()); @@ -323,8 +323,8 @@ void CGUIDialogAddonInfo::OnUpdate() const auto& itemAddonInfo = m_item->GetAddonInfo(); const std::string& addonId = itemAddonInfo->ID(); const std::string& origin = m_item->GetProperty("Addon.ValidUpdateOrigin").asString(); - const AddonVersion& version = - static_cast<AddonVersion>(m_item->GetProperty("Addon.ValidUpdateVersion").asString()); + const CAddonVersion& version = + static_cast<CAddonVersion>(m_item->GetProperty("Addon.ValidUpdateVersion").asString()); Close(); if (!m_depsInstalledWithAvailable.empty() && @@ -346,7 +346,7 @@ void CGUIDialogAddonInfo::OnSelectVersion() std::vector<std::shared_ptr<IAddon>> compatibleVersions = CServiceBroker::GetAddonMgr().GetCompatibleVersions(processAddonId); - std::vector<std::pair<AddonVersion, std::string>> versions; + std::vector<std::pair<CAddonVersion, std::string>> versions; versions.reserve(compatibleVersions.size()); for (const auto& compatibleVersion : compatibleVersions) @@ -363,7 +363,7 @@ void CGUIDialogAddonInfo::OnSelectVersion() { std::string packageId; std::string versionString; - if (AddonVersion::SplitFileName(packageId, versionString, items[i]->GetLabel())) + if (CAddonVersion::SplitFileName(packageId, versionString, items[i]->GetLabel())) { if (packageId == processAddonId) { @@ -376,7 +376,7 @@ void CGUIDialogAddonInfo::OnSelectVersion() // don't offer locally cached packages that result in an invalid version. // usually this happens when the package filename gets malformed on the fs // e.g. downloading "http://localhost/a+b.zip" ends up in "a b.zip" - const AddonVersion version(versionString); + const CAddonVersion version(versionString); if (StringUtils::EqualsNoCase(sha256, hash) && !version.empty()) versions.emplace_back(version, LOCAL_CACHE); } @@ -477,7 +477,7 @@ void CGUIDialogAddonInfo::OnInstall() } const std::string& addonId = itemAddonInfo->ID(); - const AddonVersion& version = itemAddonInfo->Version(); + const CAddonVersion& version = itemAddonInfo->Version(); Close(); if (!m_depsInstalledWithAvailable.empty() && @@ -508,14 +508,14 @@ void CGUIDialogAddonInfo::OnSelect() bool CGUIDialogAddonInfo::CanOpen() const { - return m_localAddon && m_localAddon->Type() == ADDON_PLUGIN; + return m_localAddon && m_localAddon->Type() == AddonType::PLUGIN; } bool CGUIDialogAddonInfo::CanRun() const { if (m_localAddon) { - if (m_localAddon->Type() == ADDON_SCRIPT) + if (m_localAddon->Type() == AddonType::SCRIPT) return true; if (GAME::CGameUtils::IsStandaloneGame(m_localAddon)) @@ -527,18 +527,19 @@ bool CGUIDialogAddonInfo::CanRun() const bool CGUIDialogAddonInfo::CanUse() const { - return m_localAddon && - (m_localAddon->Type() == ADDON_SKIN || m_localAddon->Type() == ADDON_SCREENSAVER || - m_localAddon->Type() == ADDON_VIZ || m_localAddon->Type() == ADDON_SCRIPT_WEATHER || - m_localAddon->Type() == ADDON_RESOURCE_LANGUAGE || - m_localAddon->Type() == ADDON_RESOURCE_UISOUNDS || - m_localAddon->Type() == ADDON_AUDIOENCODER); + return m_localAddon && (m_localAddon->Type() == AddonType::SKIN || + m_localAddon->Type() == AddonType::SCREENSAVER || + m_localAddon->Type() == AddonType::VISUALIZATION || + m_localAddon->Type() == AddonType::SCRIPT_WEATHER || + m_localAddon->Type() == AddonType::RESOURCE_LANGUAGE || + m_localAddon->Type() == AddonType::RESOURCE_UISOUNDS || + m_localAddon->Type() == AddonType::AUDIOENCODER); } bool CGUIDialogAddonInfo::CanShowSupportList() const { - return m_localAddon && - (m_localAddon->Type() == ADDON_AUDIODECODER || m_localAddon->Type() == ADDON_IMAGEDECODER); + return m_localAddon && (m_localAddon->Type() == AddonType::AUDIODECODER || + m_localAddon->Type() == AddonType::IMAGEDECODER); } bool CGUIDialogAddonInfo::PromptIfDependency(int heading, int line2) @@ -679,7 +680,7 @@ bool CGUIDialogAddonInfo::ShowDependencyList(Reactivate reactivate, EntryPoint e } if (entryPoint == EntryPoint::SHOW_DEPENDENCIES || - infoAddon->MainType() != ADDON_SCRIPT_MODULE || + infoAddon->MainType() != AddonType::SCRIPT_MODULE || !CAddonRepos::IsFromOfficialRepo(infoAddon, CheckAddonPath::CHOICE_NO)) { item->SetLabel2(StringUtils::Format( @@ -814,7 +815,7 @@ bool CGUIDialogAddonInfo::SetItem(const CFileItemPtr& item) m_item = std::make_shared<CFileItem>(*item); m_localAddon.reset(); if (CServiceBroker::GetAddonMgr().GetAddon(item->GetAddonInfo()->ID(), m_localAddon, - ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO)) + OnlyEnabled::CHOICE_NO)) { CLog::Log(LOGDEBUG, "{} - Addon with id {} not found locally.", __FUNCTION__, item->GetAddonInfo()->ID()); @@ -838,8 +839,7 @@ void CGUIDialogAddonInfo::BuildDependencyList() std::shared_ptr<IAddon> addonAvailable; // Find add-on in local installation - if (!CServiceBroker::GetAddonMgr().GetAddon(dep.id, addonInstalled, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_YES)) + if (!CServiceBroker::GetAddonMgr().GetAddon(dep.id, addonInstalled, OnlyEnabled::CHOICE_YES)) { addonInstalled = nullptr; } @@ -858,7 +858,7 @@ void CGUIDialogAddonInfo::BuildDependencyList() // - dependencies are unavailable (for informational purposes) OR // - the dependency is not a script/module OR // - the script/module is not available at an official repo - if (!addonAvailable || addonAvailable->MainType() != ADDON_SCRIPT_MODULE || + if (!addonAvailable || addonAvailable->MainType() != AddonType::SCRIPT_MODULE || !CAddonRepos::IsFromOfficialRepo(addonAvailable, CheckAddonPath::CHOICE_NO)) { m_showDepDialogOnInstall = true; @@ -902,7 +902,7 @@ void CGUIDialogAddonInfo::BuildDependencyList() if (depA && depB && depA->MainType() != depB->MainType()) { - return depA->MainType() != ADDON_SCRIPT_MODULE; + return depA->MainType() != AddonType::SCRIPT_MODULE; } // 4. finally order by addon-id diff --git a/xbmc/addons/gui/GUIDialogAddonInfo.h b/xbmc/addons/gui/GUIDialogAddonInfo.h index be332b0de1..b28a858087 100644 --- a/xbmc/addons/gui/GUIDialogAddonInfo.h +++ b/xbmc/addons/gui/GUIDialogAddonInfo.h @@ -95,7 +95,7 @@ private: void OnSettings(); void OnSelect(); void OnToggleAutoUpdates(); - int AskForVersion(std::vector<std::pair<ADDON::AddonVersion, std::string>>& versions); + int AskForVersion(std::vector<std::pair<ADDON::CAddonVersion, std::string>>& versions); /*! * @brief Returns true if current addon can be opened (i.e is a plugin) diff --git a/xbmc/addons/gui/GUIWindowAddonBrowser.cpp b/xbmc/addons/gui/GUIWindowAddonBrowser.cpp index 5098a029dd..ac34a3b071 100644 --- a/xbmc/addons/gui/GUIWindowAddonBrowser.cpp +++ b/xbmc/addons/gui/GUIWindowAddonBrowser.cpp @@ -18,7 +18,9 @@ #include "addons/AddonInstaller.h" #include "addons/AddonManager.h" #include "addons/AddonSystemSettings.h" +#include "addons/IAddon.h" #include "addons/RepositoryUpdater.h" +#include "addons/addoninfo/AddonType.h" #include "dialogs/GUIDialogBusy.h" #include "dialogs/GUIDialogFileBrowser.h" #include "dialogs/GUIDialogSelect.h" @@ -331,8 +333,7 @@ bool CGUIWindowAddonBrowser::GetDirectory(const std::string& strDirectory, CFile //check if it's installed AddonPtr addon; if (!CServiceBroker::GetAddonMgr().GetAddon(items[i]->GetProperty("Addon.ID").asString(), - addon, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_YES)) + addon, OnlyEnabled::CHOICE_YES)) items.Remove(i); } } @@ -378,7 +379,7 @@ bool CGUIWindowAddonBrowser::Update(const std::string& strDirectory, return true; } -int CGUIWindowAddonBrowser::SelectAddonID(TYPE type, +int CGUIWindowAddonBrowser::SelectAddonID(AddonType type, std::string& addonID, bool showNone /* = false */, bool showDetails /* = true */, @@ -386,13 +387,13 @@ int CGUIWindowAddonBrowser::SelectAddonID(TYPE type, bool showInstallable /*= false */, bool showMore /* = true */) { - std::vector<ADDON::TYPE> types; + std::vector<AddonType> types; types.push_back(type); return SelectAddonID(types, addonID, showNone, showDetails, showInstalled, showInstallable, showMore); } -int CGUIWindowAddonBrowser::SelectAddonID(ADDON::TYPE type, +int CGUIWindowAddonBrowser::SelectAddonID(AddonType type, std::vector<std::string>& addonIDs, bool showNone /* = false */, bool showDetails /* = true */, @@ -401,13 +402,13 @@ int CGUIWindowAddonBrowser::SelectAddonID(ADDON::TYPE type, bool showInstallable /* = false */, bool showMore /* = true */) { - std::vector<ADDON::TYPE> types; + std::vector<AddonType> types; types.push_back(type); return SelectAddonID(types, addonIDs, showNone, showDetails, multipleSelection, showInstalled, showInstallable, showMore); } -int CGUIWindowAddonBrowser::SelectAddonID(const std::vector<ADDON::TYPE>& types, +int CGUIWindowAddonBrowser::SelectAddonID(const std::vector<AddonType>& types, std::string& addonID, bool showNone /* = false */, bool showDetails /* = true */, @@ -427,7 +428,7 @@ int CGUIWindowAddonBrowser::SelectAddonID(const std::vector<ADDON::TYPE>& types, return retval; } -int CGUIWindowAddonBrowser::SelectAddonID(const std::vector<ADDON::TYPE>& types, +int CGUIWindowAddonBrowser::SelectAddonID(const std::vector<AddonType>& types, std::vector<std::string>& addonIDs, bool showNone /* = false */, bool showDetails /* = true */, @@ -451,9 +452,9 @@ int CGUIWindowAddonBrowser::SelectAddonID(const std::vector<ADDON::TYPE>& types, return -1; // get rid of any invalid addon types - std::vector<ADDON::TYPE> validTypes(types.size()); + std::vector<AddonType> validTypes(types.size()); std::copy_if(types.begin(), types.end(), validTypes.begin(), - [](ADDON::TYPE type) { return type != ADDON_UNKNOWN; }); + [](AddonType type) { return type != AddonType::UNKNOWN; }); if (validTypes.empty()) return -1; @@ -462,19 +463,19 @@ int CGUIWindowAddonBrowser::SelectAddonID(const std::vector<ADDON::TYPE>& types, VECADDONS addons; if (showInstalled) { - for (std::vector<ADDON::TYPE>::const_iterator type = validTypes.begin(); - type != validTypes.end(); ++type) + for (std::vector<AddonType>::const_iterator type = validTypes.begin(); type != validTypes.end(); + ++type) { VECADDONS typeAddons; - if (*type == ADDON_AUDIO) + if (*type == AddonType::AUDIO) CAddonsDirectory::GetScriptsAndPlugins("audio", typeAddons); - else if (*type == ADDON_EXECUTABLE) + else if (*type == AddonType::EXECUTABLE) CAddonsDirectory::GetScriptsAndPlugins("executable", typeAddons); - else if (*type == ADDON_IMAGE) + else if (*type == AddonType::IMAGE) CAddonsDirectory::GetScriptsAndPlugins("image", typeAddons); - else if (*type == ADDON_VIDEO) + else if (*type == AddonType::VIDEO) CAddonsDirectory::GetScriptsAndPlugins("video", typeAddons); - else if (*type == ADDON_GAME) + else if (*type == AddonType::GAME) CAddonsDirectory::GetScriptsAndPlugins("game", typeAddons); else CServiceBroker::GetAddonMgr().GetAddons(typeAddons, *type); @@ -488,13 +489,13 @@ int CGUIWindowAddonBrowser::SelectAddonID(const std::vector<ADDON::TYPE>& types, VECADDONS installableAddons; if (CServiceBroker::GetAddonMgr().GetInstallableAddons(installableAddons)) { - for (ADDON::IVECADDONS addon = installableAddons.begin(); addon != installableAddons.end();) + for (auto addon = installableAddons.begin(); addon != installableAddons.end();) { AddonPtr pAddon = *addon; // check if the addon matches one of the provided addon types bool matchesType = false; - for (std::vector<ADDON::TYPE>::const_iterator type = validTypes.begin(); + for (std::vector<AddonType>::const_iterator type = validTypes.begin(); type != validTypes.end(); ++type) { if (pAddon->HasType(*type)) @@ -526,14 +527,14 @@ int CGUIWindowAddonBrowser::SelectAddonID(const std::vector<ADDON::TYPE>& types, // turn the addons into items std::map<std::string, AddonPtr> addonMap; CFileItemList items; - for (ADDON::IVECADDONS addon = addons.begin(); addon != addons.end(); ++addon) + for (const auto& addon : addons) { - CFileItemPtr item(CAddonsDirectory::FileItemFromAddon(*addon, (*addon)->ID())); - item->SetLabel2((*addon)->Summary()); + const CFileItemPtr item(CAddonsDirectory::FileItemFromAddon(addon, addon->ID())); + item->SetLabel2(addon->Summary()); if (!items.Contains(item->GetPath())) { items.Add(item); - addonMap.insert(std::make_pair(item->GetPath(), *addon)); + addonMap.insert(std::make_pair(item->GetPath(), addon)); } } @@ -541,7 +542,7 @@ int CGUIWindowAddonBrowser::SelectAddonID(const std::vector<ADDON::TYPE>& types, return -1; std::string heading; - for (std::vector<ADDON::TYPE>::const_iterator type = validTypes.begin(); type != validTypes.end(); + for (std::vector<AddonType>::const_iterator type = validTypes.begin(); type != validTypes.end(); ++type) { if (!heading.empty()) diff --git a/xbmc/addons/gui/GUIWindowAddonBrowser.h b/xbmc/addons/gui/GUIWindowAddonBrowser.h index c37c05365b..7f605eefe3 100644 --- a/xbmc/addons/gui/GUIWindowAddonBrowser.h +++ b/xbmc/addons/gui/GUIWindowAddonBrowser.h @@ -10,7 +10,6 @@ #include "ThumbLoader.h" #include "addons/RepositoryUpdater.h" -#include "addons/addoninfo/AddonType.h" #include "windows/GUIMediaWindow.h" #include <string> @@ -20,6 +19,7 @@ class CFileItemList; namespace ADDON { +enum class AddonType; struct AddonEvent; } @@ -45,14 +45,14 @@ public: * "Get More" was chosen, 0 if the selection process was cancelled or -1 * if an error occurred or */ - static int SelectAddonID(ADDON::TYPE type, + static int SelectAddonID(ADDON::AddonType type, std::string& addonID, bool showNone = false, bool showDetails = true, bool showInstalled = true, bool showInstallable = false, bool showMore = true); - static int SelectAddonID(const std::vector<ADDON::TYPE>& types, + static int SelectAddonID(const std::vector<ADDON::AddonType>& types, std::string& addonID, bool showNone = false, bool showDetails = true, @@ -76,7 +76,7 @@ public: * "Get More" was chosen, 0 if the selection process was cancelled or -1 * if an error occurred or */ - static int SelectAddonID(ADDON::TYPE type, + static int SelectAddonID(ADDON::AddonType type, std::vector<std::string>& addonIDs, bool showNone = false, bool showDetails = true, @@ -84,7 +84,7 @@ public: bool showInstalled = true, bool showInstallable = false, bool showMore = true); - static int SelectAddonID(const std::vector<ADDON::TYPE>& types, + static int SelectAddonID(const std::vector<ADDON::AddonType>& types, std::vector<std::string>& addonIDs, bool showNone = false, bool showDetails = true, diff --git a/xbmc/addons/interfaces/AddonBase.cpp b/xbmc/addons/interfaces/AddonBase.cpp index edaea8407b..496ca92b68 100644 --- a/xbmc/addons/interfaces/AddonBase.cpp +++ b/xbmc/addons/interfaces/AddonBase.cpp @@ -11,6 +11,7 @@ #include "GUIUserMessages.h" #include "addons/AddonManager.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "addons/binary-addons/AddonDll.h" #include "addons/gui/GUIDialogAddonSettings.h" #include "addons/settings/AddonSettings.h" @@ -21,6 +22,7 @@ #include "guilib/GUIWindowManager.h" #include "guilib/LocalizeStrings.h" #include "settings/lib/Setting.h" +#include "utils/StringUtils.h" #include "utils/URIUtils.h" #include "utils/log.h" @@ -317,8 +319,7 @@ bool Interface_Base::open_settings_dialog(const KODI_ADDON_BACKEND_HDL hdl) // show settings dialog AddonPtr addonInfo; - if (!CServiceBroker::GetAddonMgr().GetAddon(addon->ID(), addonInfo, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_YES)) + if (!CServiceBroker::GetAddonMgr().GetAddon(addon->ID(), addonInfo, OnlyEnabled::CHOICE_YES)) { CLog::Log(LOGERROR, "Interface_Base::{} - Could not get addon information for '{}'", __func__, addon->ID()); diff --git a/xbmc/addons/interfaces/General.cpp b/xbmc/addons/interfaces/General.cpp index 44b33214ee..eef6ccd2bc 100644 --- a/xbmc/addons/interfaces/General.cpp +++ b/xbmc/addons/interfaces/General.cpp @@ -12,6 +12,7 @@ #include "LangInfo.h" #include "ServiceBroker.h" #include "addons/AddonManager.h" +#include "addons/AddonVersion.h" #include "addons/binary-addons/AddonDll.h" #include "addons/kodi-dev-kit/include/kodi/General.h" #include "application/ApplicationComponents.h" @@ -325,7 +326,7 @@ bool Interface_General::is_addon_avilable(void* kodiBase, } AddonPtr addonInfo; - if (!CServiceBroker::GetAddonMgr().GetAddon(id, addonInfo, ADDON_UNKNOWN, OnlyEnabled::CHOICE_NO)) + if (!CServiceBroker::GetAddonMgr().GetAddon(id, addonInfo, OnlyEnabled::CHOICE_NO)) return false; *version = strdup(addonInfo->Version().asString().c_str()); diff --git a/xbmc/addons/interfaces/gui/Window.cpp b/xbmc/addons/interfaces/gui/Window.cpp index 4282bcedc3..307c339f2b 100644 --- a/xbmc/addons/interfaces/gui/Window.cpp +++ b/xbmc/addons/interfaces/gui/Window.cpp @@ -15,6 +15,7 @@ #include "Window.h" #include "addons/Skin.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "addons/binary-addons/AddonDll.h" #include "application/Application.h" #include "controls/Rendering.h" @@ -137,7 +138,8 @@ KODI_GUI_WINDOW_HANDLE Interface_GUIWindow::create(KODI_HANDLE kodiBase, if (!CFileUtils::Exists(strSkinPath)) { std::string str("none"); - ADDON::AddonInfoPtr addonInfo = std::make_shared<ADDON::CAddonInfo>(str, ADDON::ADDON_SKIN); + ADDON::AddonInfoPtr addonInfo = + std::make_shared<ADDON::CAddonInfo>(str, ADDON::AddonType::SKIN); // Check for the matching folder for the skin in the fallback skins folder std::string fallbackPath = URIUtils::AddFileToFolder(addon->Path(), "resources", "skins"); diff --git a/xbmc/addons/settings/AddonSettings.cpp b/xbmc/addons/settings/AddonSettings.cpp index ea1ae319a6..83bbdd9152 100644 --- a/xbmc/addons/settings/AddonSettings.cpp +++ b/xbmc/addons/settings/AddonSettings.cpp @@ -13,6 +13,7 @@ #include "LangInfo.h" #include "ServiceBroker.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "addons/binary-addons/AddonInstanceHandler.h" #include "addons/gui/GUIDialogAddonSettings.h" #include "addons/settings/SettingUrlEncodedString.h" @@ -1145,11 +1146,11 @@ SettingPtr CAddonSettings::InitializeFromOldSettingAddon(const std::string& sett // get addon types std::string addonTypeStr = XMLUtils::GetAttribute(settingElement, "addontype"); const auto addonTypesStr = StringUtils::Split(addonTypeStr, ","); - std::set<ADDON::TYPE> addonTypes; + std::set<AddonType> addonTypes; for (auto addonType : addonTypesStr) { auto type = ADDON::CAddonInfo::TranslateType(StringUtils::Trim(addonType)); - if (type != ADDON::ADDON_UNKNOWN) + if (type != ADDON::AddonType::UNKNOWN) addonTypes.insert(type); } diff --git a/xbmc/addons/test/TestAddonBuilder.cpp b/xbmc/addons/test/TestAddonBuilder.cpp index e730ee5ab0..08f6c6de65 100644 --- a/xbmc/addons/test/TestAddonBuilder.cpp +++ b/xbmc/addons/test/TestAddonBuilder.cpp @@ -10,6 +10,7 @@ #include "addons/LanguageResource.h" #include "addons/addoninfo/AddonInfo.h" #include "addons/addoninfo/AddonInfoBuilder.h" +#include "addons/addoninfo/AddonType.h" #include <gtest/gtest.h> @@ -24,29 +25,30 @@ protected: TEST_F(TestAddonBuilder, ShouldFailWhenEmpty) { - EXPECT_EQ(nullptr, CAddonBuilder::Generate(nullptr, ADDON_UNKNOWN)); + EXPECT_EQ(nullptr, CAddonBuilder::Generate(nullptr, AddonType::UNKNOWN)); } TEST_F(TestAddonBuilder, ShouldBuildDependencyAddons) { std::vector<DependencyInfo> deps; - deps.emplace_back("a", AddonVersion("1.0.0"), AddonVersion("1.0.10"), false); + deps.emplace_back("a", CAddonVersion("1.0.0"), CAddonVersion("1.0.10"), false); - CAddonInfoBuilder::CFromDB builder; + CAddonInfoBuilderFromDB builder; builder.SetId("aa"); builder.SetDependencies(deps); - CAddonType addonType(ADDON_UNKNOWN); + CAddonType addonType(AddonType::UNKNOWN); builder.SetExtensions(addonType); - AddonPtr addon = CAddonBuilder::Generate(builder.get(), ADDON_UNKNOWN); + AddonPtr addon = CAddonBuilder::Generate(builder.get(), AddonType::UNKNOWN); EXPECT_EQ(deps, addon->GetDependencies()); } TEST_F(TestAddonBuilder, ShouldReturnDerivedType) { - CAddonInfoBuilder::CFromDB builder; + CAddonInfoBuilderFromDB builder; builder.SetId("aa"); - CAddonType addonType(ADDON_RESOURCE_LANGUAGE); + CAddonType addonType(AddonType::RESOURCE_LANGUAGE); builder.SetExtensions(addonType); - auto addon = std::dynamic_pointer_cast<CLanguageResource>(CAddonBuilder::Generate(builder.get(), ADDON_UNKNOWN)); + auto addon = std::dynamic_pointer_cast<CLanguageResource>( + CAddonBuilder::Generate(builder.get(), AddonType::UNKNOWN)); EXPECT_NE(nullptr, addon); } diff --git a/xbmc/addons/test/TestAddonDatabase.cpp b/xbmc/addons/test/TestAddonDatabase.cpp index 289a6af959..d5557dc273 100644 --- a/xbmc/addons/test/TestAddonDatabase.cpp +++ b/xbmc/addons/test/TestAddonDatabase.cpp @@ -39,19 +39,19 @@ protected: std::vector<AddonInfoPtr> addons; CreateAddon(addons, "foo.bar", "1.0.0"); database.SetRepoUpdateData("repository.a", {}); - database.UpdateRepositoryContent("repository.a", AddonVersion("1.0.0"), "test", addons); + database.UpdateRepositoryContent("repository.a", CAddonVersion("1.0.0"), "test", addons); addons.clear(); CreateAddon(addons, "foo.baz", "1.1.0"); database.SetRepoUpdateData("repository.b", {}); - database.UpdateRepositoryContent("repository.b", AddonVersion("1.0.0"), "test", addons); + database.UpdateRepositoryContent("repository.b", CAddonVersion("1.0.0"), "test", addons); } void CreateAddon(std::vector<AddonInfoPtr>& addons, std::string id, const std::string& version) { - CAddonInfoBuilder::CFromDB builder; + CAddonInfoBuilderFromDB builder; builder.SetId(std::move(id)); - builder.SetVersion(AddonVersion(version)); + builder.SetVersion(CAddonVersion(version)); addons.push_back(builder.get()); } diff --git a/xbmc/addons/test/TestAddonInfoBuilder.cpp b/xbmc/addons/test/TestAddonInfoBuilder.cpp index 1e2c8933b7..294d930db3 100644 --- a/xbmc/addons/test/TestAddonInfoBuilder.cpp +++ b/xbmc/addons/test/TestAddonInfoBuilder.cpp @@ -6,8 +6,10 @@ * See LICENSES/README.md for more information. */ +#include "addons/Repository.h" #include "addons/addoninfo/AddonInfo.h" #include "addons/addoninfo/AddonInfoBuilder.h" +#include "addons/addoninfo/AddonType.h" #include "utils/XBMCTinyXML.h" #include <set> @@ -55,18 +57,18 @@ protected: TEST_F(TestAddonInfoBuilder, ShouldFailWhenIdIsNotSet) { - AddonInfoPtr addon = CAddonInfoBuilder::Generate("", ADDON_UNKNOWN); + AddonInfoPtr addon = CAddonInfoBuilder::Generate("", AddonType::UNKNOWN); EXPECT_EQ(nullptr, addon); } TEST_F(TestAddonInfoBuilder, TestGenerate_Id_Type) { - AddonInfoPtr addon = CAddonInfoBuilder::Generate("foo.baz", ADDON_VIZ); + AddonInfoPtr addon = CAddonInfoBuilder::Generate("foo.baz", AddonType::VISUALIZATION); EXPECT_NE(nullptr, addon); EXPECT_EQ(addon->ID(), "foo.baz"); - EXPECT_EQ(addon->MainType(), ADDON_VIZ); - EXPECT_TRUE(addon->HasType(ADDON_VIZ)); - EXPECT_FALSE(addon->HasType(ADDON_SCREENSAVER)); + EXPECT_EQ(addon->MainType(), AddonType::VISUALIZATION); + EXPECT_TRUE(addon->HasType(AddonType::VISUALIZATION)); + EXPECT_FALSE(addon->HasType(AddonType::SCREENSAVER)); } TEST_F(TestAddonInfoBuilder, TestGenerate_Repo) @@ -75,19 +77,19 @@ TEST_F(TestAddonInfoBuilder, TestGenerate_Repo) EXPECT_TRUE(doc.Parse(addonXML)); ASSERT_NE(nullptr, doc.RootElement()); - CRepository::DirInfo repo; + RepositoryDirInfo repo; AddonInfoPtr addon = CAddonInfoBuilder::Generate(doc.RootElement(), repo); ASSERT_NE(nullptr, addon); EXPECT_EQ(addon->ID(), "metadata.blablabla.org"); - EXPECT_EQ(addon->MainType(), ADDON_SCRAPER_MOVIES); - EXPECT_TRUE(addon->HasType(ADDON_SCRAPER_MOVIES)); - EXPECT_EQ(addon->Type(ADDON_SCRAPER_MOVIES)->LibName(), "blablabla.xml"); - EXPECT_EQ(addon->Type(ADDON_SCRAPER_MOVIES)->GetValue("@language").asString(), "en"); + EXPECT_EQ(addon->MainType(), AddonType::SCRAPER_MOVIES); + EXPECT_TRUE(addon->HasType(AddonType::SCRAPER_MOVIES)); + EXPECT_EQ(addon->Type(AddonType::SCRAPER_MOVIES)->LibName(), "blablabla.xml"); + EXPECT_EQ(addon->Type(AddonType::SCRAPER_MOVIES)->GetValue("@language").asString(), "en"); - EXPECT_TRUE(addon->HasType(ADDON_SCRIPT_MODULE)); - EXPECT_EQ(addon->Type(ADDON_SCRIPT_MODULE)->LibName(), "lib.so"); - EXPECT_FALSE(addon->HasType(ADDON_SCRAPER_ARTISTS)); + EXPECT_TRUE(addon->HasType(AddonType::SCRIPT_MODULE)); + EXPECT_EQ(addon->Type(AddonType::SCRIPT_MODULE)->LibName(), "lib.so"); + EXPECT_FALSE(addon->HasType(AddonType::SCRAPER_ARTISTS)); EXPECT_EQ(addon->Name(), "The Bla Bla Bla Addon"); EXPECT_EQ(addon->Author(), "Team Kodi"); @@ -128,10 +130,10 @@ TEST_F(TestAddonInfoBuilder, TestGenerate_Repo) TEST_F(TestAddonInfoBuilder, TestGenerate_DBEntry) { - CAddonInfoBuilder::CFromDB builder; + CAddonInfoBuilderFromDB builder; builder.SetId("video.blablabla.org"); - builder.SetVersion(AddonVersion("1.2.3")); - CAddonType addonType(ADDON_PLUGIN); + builder.SetVersion(CAddonVersion("1.2.3")); + CAddonType addonType(AddonType::PLUGIN); addonType.Insert("provides", "video audio"); builder.SetExtensions(addonType); builder.SetName("The Bla Bla Bla Addon"); @@ -152,11 +154,11 @@ TEST_F(TestAddonInfoBuilder, TestGenerate_DBEntry) ASSERT_NE(nullptr, addon); EXPECT_EQ(addon->ID(), "video.blablabla.org"); - EXPECT_EQ(addon->MainType(), ADDON_PLUGIN); - EXPECT_TRUE(addon->HasType(ADDON_PLUGIN)); - EXPECT_TRUE(addon->HasType(ADDON_VIDEO)); - EXPECT_TRUE(addon->HasType(ADDON_AUDIO)); - EXPECT_FALSE(addon->HasType(ADDON_GAME)); + EXPECT_EQ(addon->MainType(), AddonType::PLUGIN); + EXPECT_TRUE(addon->HasType(AddonType::PLUGIN)); + EXPECT_TRUE(addon->HasType(AddonType::VIDEO)); + EXPECT_TRUE(addon->HasType(AddonType::AUDIO)); + EXPECT_FALSE(addon->HasType(AddonType::GAME)); EXPECT_EQ(addon->Name(), "The Bla Bla Bla Addon"); EXPECT_EQ(addon->Author(), "Team Kodi"); diff --git a/xbmc/addons/test/TestAddonVersion.cpp b/xbmc/addons/test/TestAddonVersion.cpp index 7c82be768d..0397792f73 100644 --- a/xbmc/addons/test/TestAddonVersion.cpp +++ b/xbmc/addons/test/TestAddonVersion.cpp @@ -36,23 +36,23 @@ public: { } - AddonVersion v1_0; - AddonVersion v1_00; - AddonVersion v1_0_0; - AddonVersion v1_1; - AddonVersion v1_01; - AddonVersion v1_0_1; - AddonVersion e1_v1_0_0; - AddonVersion e1_v1_0_1; - AddonVersion e2_v1_0_0; - AddonVersion e1_v1_0_0_r1; - AddonVersion e1_v1_0_1_r1; - AddonVersion e1_v1_0_0_r2; - AddonVersion v1_0_0_beta; - AddonVersion v1_0_0_alpha; - AddonVersion v1_0_0_alpha2; - AddonVersion v1_0_0_alpha3; - AddonVersion v1_0_0_alpha10; + CAddonVersion v1_0; + CAddonVersion v1_00; + CAddonVersion v1_0_0; + CAddonVersion v1_1; + CAddonVersion v1_01; + CAddonVersion v1_0_1; + CAddonVersion e1_v1_0_0; + CAddonVersion e1_v1_0_1; + CAddonVersion e2_v1_0_0; + CAddonVersion e1_v1_0_0_r1; + CAddonVersion e1_v1_0_1_r1; + CAddonVersion e1_v1_0_0_r2; + CAddonVersion v1_0_0_beta; + CAddonVersion v1_0_0_alpha; + CAddonVersion v1_0_0_alpha2; + CAddonVersion v1_0_0_alpha3; + CAddonVersion v1_0_0_alpha10; }; TEST_F(TestAddonVersion, Constructor) @@ -149,23 +149,23 @@ TEST_F(TestAddonVersion, asString) TEST_F(TestAddonVersion, Equals) { - EXPECT_EQ(v1_0, AddonVersion("1.0")); - EXPECT_EQ(v1_00, AddonVersion("1.00")); - EXPECT_EQ(v1_0_0, AddonVersion("1.0.0")); - EXPECT_EQ(v1_1, AddonVersion("1.1")); - EXPECT_EQ(v1_01, AddonVersion("1.01")); - EXPECT_EQ(v1_0_1, AddonVersion("1.0.1")); - EXPECT_EQ(e1_v1_0_0, AddonVersion("1:1.0.0")); - EXPECT_EQ(e1_v1_0_1, AddonVersion("1:1.0.1")); - EXPECT_EQ(e2_v1_0_0, AddonVersion("2:1.0.0")); - EXPECT_EQ(e1_v1_0_0_r1, AddonVersion("1:1.0.0-1")); - EXPECT_EQ(e1_v1_0_1_r1, AddonVersion("1:1.0.1-1")); - EXPECT_EQ(e1_v1_0_0_r2, AddonVersion("1:1.0.0-2")); - EXPECT_EQ(v1_0_0_beta, AddonVersion("1.0.0~beta")); - EXPECT_EQ(v1_0_0_alpha, AddonVersion("1.0.0~alpha")); - EXPECT_EQ(v1_0_0_alpha2, AddonVersion("1.0.0~alpha2")); - EXPECT_EQ(v1_0_0_alpha3, AddonVersion("1.0.0~alpha3")); - EXPECT_EQ(v1_0_0_alpha10, AddonVersion("1.0.0~alpha10")); + EXPECT_EQ(v1_0, CAddonVersion("1.0")); + EXPECT_EQ(v1_00, CAddonVersion("1.00")); + EXPECT_EQ(v1_0_0, CAddonVersion("1.0.0")); + EXPECT_EQ(v1_1, CAddonVersion("1.1")); + EXPECT_EQ(v1_01, CAddonVersion("1.01")); + EXPECT_EQ(v1_0_1, CAddonVersion("1.0.1")); + EXPECT_EQ(e1_v1_0_0, CAddonVersion("1:1.0.0")); + EXPECT_EQ(e1_v1_0_1, CAddonVersion("1:1.0.1")); + EXPECT_EQ(e2_v1_0_0, CAddonVersion("2:1.0.0")); + EXPECT_EQ(e1_v1_0_0_r1, CAddonVersion("1:1.0.0-1")); + EXPECT_EQ(e1_v1_0_1_r1, CAddonVersion("1:1.0.1-1")); + EXPECT_EQ(e1_v1_0_0_r2, CAddonVersion("1:1.0.0-2")); + EXPECT_EQ(v1_0_0_beta, CAddonVersion("1.0.0~beta")); + EXPECT_EQ(v1_0_0_alpha, CAddonVersion("1.0.0~alpha")); + EXPECT_EQ(v1_0_0_alpha2, CAddonVersion("1.0.0~alpha2")); + EXPECT_EQ(v1_0_0_alpha3, CAddonVersion("1.0.0~alpha3")); + EXPECT_EQ(v1_0_0_alpha10, CAddonVersion("1.0.0~alpha10")); } TEST_F(TestAddonVersion, LessThan) @@ -243,15 +243,15 @@ TEST_F(TestAddonVersion, LessThan) // script.module.foo-1.0.0+matrix.1 for upstream module foo (1.0.0) for matrix. // In summary, 1.0.0 or 1.0.0+leia.1 must be < than 1.0.0+matrix.1 // tests below assure this won't get broken inadvertently - EXPECT_LT(AddonVersion("1.0.0"), AddonVersion("1.0.0+matrix.1")); - EXPECT_LT(AddonVersion("1.0.0+leia.1"), AddonVersion("1.0.0+matrix.1")); - EXPECT_LT(AddonVersion("1.0.0+matrix.1"), AddonVersion("1.0.0+matrix.2")); - EXPECT_LT(AddonVersion("1.0.0+matrix.1"), AddonVersion("1.0.1+matrix.1")); - EXPECT_LT(AddonVersion("1.0.0+matrix.1"), AddonVersion("1.1.0+matrix.1")); - EXPECT_LT(AddonVersion("1.0.0+matrix.1"), AddonVersion("2.0.0+matrix.1")); - EXPECT_LT(AddonVersion("1.0.0+matrix.1"), AddonVersion("1.0.0.1")); - EXPECT_LT(AddonVersion("1.0.0+Leia.1"), AddonVersion("1.0.0+matrix.1")); - EXPECT_LT(AddonVersion("1.0.0+leia.1"), AddonVersion("1.0.0+Matrix.1")); + EXPECT_LT(CAddonVersion("1.0.0"), CAddonVersion("1.0.0+matrix.1")); + EXPECT_LT(CAddonVersion("1.0.0+leia.1"), CAddonVersion("1.0.0+matrix.1")); + EXPECT_LT(CAddonVersion("1.0.0+matrix.1"), CAddonVersion("1.0.0+matrix.2")); + EXPECT_LT(CAddonVersion("1.0.0+matrix.1"), CAddonVersion("1.0.1+matrix.1")); + EXPECT_LT(CAddonVersion("1.0.0+matrix.1"), CAddonVersion("1.1.0+matrix.1")); + EXPECT_LT(CAddonVersion("1.0.0+matrix.1"), CAddonVersion("2.0.0+matrix.1")); + EXPECT_LT(CAddonVersion("1.0.0+matrix.1"), CAddonVersion("1.0.0.1")); + EXPECT_LT(CAddonVersion("1.0.0+Leia.1"), CAddonVersion("1.0.0+matrix.1")); + EXPECT_LT(CAddonVersion("1.0.0+leia.1"), CAddonVersion("1.0.0+Matrix.1")); } TEST_F(TestAddonVersion, Equivalent) @@ -267,5 +267,5 @@ TEST_F(TestAddonVersion, Equivalent) EXPECT_TRUE(v1_01 == v1_1); // pep-0440/local-version-identifiers - EXPECT_TRUE(AddonVersion("1.0.0+leia.1") == AddonVersion("1.0.0+Leia.1")); + EXPECT_TRUE(CAddonVersion("1.0.0+leia.1") == CAddonVersion("1.0.0+Leia.1")); } diff --git a/xbmc/application/Application.cpp b/xbmc/application/Application.cpp index 4295cd1819..8fde4cf44c 100644 --- a/xbmc/application/Application.cpp +++ b/xbmc/application/Application.cpp @@ -23,6 +23,7 @@ #include "addons/Skin.h" #include "addons/VFSEntry.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "application/AppInboundProtocol.h" #include "application/AppParams.h" #include "application/ApplicationActionListeners.h" @@ -2266,7 +2267,7 @@ bool CApplication::PlayMedia(CFileItem& item, const std::string& player, PLAYLIS if (path.GetProtocol() == "game") { AddonPtr addon; - if (CServiceBroker::GetAddonMgr().GetAddon(path.GetHostName(), addon, ADDON_GAMEDLL, + if (CServiceBroker::GetAddonMgr().GetAddon(path.GetHostName(), addon, AddonType::GAMEDLL, OnlyEnabled::CHOICE_YES)) { CFileItem addonItem(addon); @@ -3012,7 +3013,7 @@ void CApplication::ConfigureAndEnableAddons() { if (addonMgr.IsAddonDisabledWithReason(addon->ID(), ADDON::AddonDisabledReason::INCOMPATIBLE)) { - auto addonInfo = addonMgr.GetAddonInfo(addon->ID()); + auto addonInfo = addonMgr.GetAddonInfo(addon->ID(), AddonType::UNKNOWN); if (addonInfo && addonMgr.IsCompatible(addonInfo)) { CLog::Log(LOGDEBUG, "CApplication::{}: enabling the compatible version of [{}].", diff --git a/xbmc/application/ApplicationPowerHandling.cpp b/xbmc/application/ApplicationPowerHandling.cpp index 2c8f8eda9a..ea182d554e 100644 --- a/xbmc/application/ApplicationPowerHandling.cpp +++ b/xbmc/application/ApplicationPowerHandling.cpp @@ -10,7 +10,9 @@ #include "GUIUserMessages.h" #include "ServiceBroker.h" +#include "addons/Addon.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "addons/gui/GUIDialogAddonSettings.h" #include "application/ApplicationComponents.h" #include "application/ApplicationPlayer.h" @@ -420,7 +422,7 @@ void CApplicationPowerHandling::ActivateScreenSaver(bool forceType /*= false */) return; } else if (CServiceBroker::GetAddonMgr().GetAddon(m_screensaverIdInUse, m_pythonScreenSaver, - ADDON::ADDON_SCREENSAVER, + ADDON::AddonType::SCREENSAVER, ADDON::OnlyEnabled::CHOICE_YES)) { std::string libPath = m_pythonScreenSaver->LibPath(); @@ -586,7 +588,7 @@ bool CApplicationPowerHandling::OnSettingAction(const CSetting& setting) if (CServiceBroker::GetAddonMgr().GetAddon( CServiceBroker::GetSettingsComponent()->GetSettings()->GetString( CSettings::SETTING_SCREENSAVER_MODE), - addon, ADDON::ADDON_SCREENSAVER, ADDON::OnlyEnabled::CHOICE_YES)) + addon, ADDON::AddonType::SCREENSAVER, ADDON::OnlyEnabled::CHOICE_YES)) CGUIDialogAddonSettings::ShowForAddon(addon); } else diff --git a/xbmc/application/ApplicationSettingsHandling.cpp b/xbmc/application/ApplicationSettingsHandling.cpp index a6d78c468b..52f64750b3 100644 --- a/xbmc/application/ApplicationSettingsHandling.cpp +++ b/xbmc/application/ApplicationSettingsHandling.cpp @@ -10,6 +10,7 @@ #include "ServiceBroker.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "addons/gui/GUIDialogAddonSettings.h" #include "application/ApplicationComponents.h" #include "application/ApplicationPlayer.h" @@ -158,7 +159,7 @@ void CApplicationSettingsHandling::OnSettingAction(const std::shared_ptr<const C if (CServiceBroker::GetAddonMgr().GetAddon( CServiceBroker::GetSettingsComponent()->GetSettings()->GetString( CSettings::SETTING_AUDIOCDS_ENCODER), - addon, ADDON::ADDON_AUDIOENCODER, ADDON::OnlyEnabled::CHOICE_YES)) + addon, ADDON::AddonType::AUDIOENCODER, ADDON::OnlyEnabled::CHOICE_YES)) CGUIDialogAddonSettings::ShowForAddon(addon); } else if (settingId == CSettings::SETTING_VIDEOSCREEN_GUICALIBRATION) diff --git a/xbmc/application/ApplicationSkinHandling.cpp b/xbmc/application/ApplicationSkinHandling.cpp index 9b095a786a..edca76b962 100644 --- a/xbmc/application/ApplicationSkinHandling.cpp +++ b/xbmc/application/ApplicationSkinHandling.cpp @@ -16,7 +16,9 @@ #include "ServiceBroker.h" #include "TextureCache.h" #include "addons/AddonManager.h" +#include "addons/AddonVersion.h" #include "addons/Skin.h" +#include "addons/addoninfo/AddonType.h" #include "application/ApplicationComponents.h" #include "application/ApplicationPlayer.h" #include "dialogs/GUIDialogButtonMenu.h" @@ -37,6 +39,7 @@ #include "settings/SettingsComponent.h" #include "settings/SkinSettings.h" #include "settings/lib/Setting.h" +#include "utils/StringUtils.h" #include "utils/URIUtils.h" #include "utils/XBMCTinyXML.h" #include "utils/log.h" @@ -53,10 +56,10 @@ CApplicationSkinHandling::CApplicationSkinHandling(IMsgTargetCallback* msgCb, bool CApplicationSkinHandling::LoadSkin(const std::string& skinID) { - ADDON::SkinPtr skin; + std::shared_ptr<ADDON::CSkinInfo> skin; { ADDON::AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(skinID, addon, ADDON::ADDON_SKIN, + if (!CServiceBroker::GetAddonMgr().GetAddon(skinID, addon, ADDON::AddonType::SKIN, ADDON::OnlyEnabled::CHOICE_YES)) return false; skin = std::static_pointer_cast<ADDON::CSkinInfo>(addon); diff --git a/xbmc/cdrip/CDDARipJob.cpp b/xbmc/cdrip/CDDARipJob.cpp index 2d37a9787f..d8cbab93ab 100644 --- a/xbmc/cdrip/CDDARipJob.cpp +++ b/xbmc/cdrip/CDDARipJob.cpp @@ -15,6 +15,7 @@ #include "ServiceBroker.h" #include "Util.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "dialogs/GUIDialogExtendedProgressBar.h" #include "filesystem/File.h" #include "filesystem/SpecialProtocol.h" @@ -190,7 +191,7 @@ std::unique_ptr<CEncoder> CCDDARipJob::SetupEncoder(CFile& reader) else { const AddonInfoPtr addonInfo = - CServiceBroker::GetAddonMgr().GetAddonInfo(audioEncoder, ADDON_AUDIOENCODER); + CServiceBroker::GetAddonMgr().GetAddonInfo(audioEncoder, AddonType::AUDIOENCODER); if (addonInfo) { encoder = std::make_unique<CEncoderAddon>(addonInfo); diff --git a/xbmc/cdrip/CDDARipper.cpp b/xbmc/cdrip/CDDARipper.cpp index e41e97e978..fdea7b1f0a 100644 --- a/xbmc/cdrip/CDDARipper.cpp +++ b/xbmc/cdrip/CDDARipper.cpp @@ -14,6 +14,7 @@ #include "Util.h" #include "addons/AddonManager.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "filesystem/CDDADirectory.h" #include "guilib/GUIWindowManager.h" #include "guilib/LocalizeStrings.h" @@ -291,9 +292,9 @@ std::string CCDDARipper::GetTrackName(CFileItem* item) const std::string encoder = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString( CSettings::SETTING_AUDIOCDS_ENCODER); const AddonInfoPtr addonInfo = - CServiceBroker::GetAddonMgr().GetAddonInfo(encoder, ADDON_AUDIOENCODER); + CServiceBroker::GetAddonMgr().GetAddonInfo(encoder, AddonType::AUDIOENCODER); if (addonInfo) - track += addonInfo->Type(ADDON_AUDIOENCODER)->GetValue("@extension").asString(); + track += addonInfo->Type(AddonType::AUDIOENCODER)->GetValue("@extension").asString(); return track; } diff --git a/xbmc/cdrip/EncoderFFmpeg.cpp b/xbmc/cdrip/EncoderFFmpeg.cpp index 5f238416f6..2867b7cb67 100644 --- a/xbmc/cdrip/EncoderFFmpeg.cpp +++ b/xbmc/cdrip/EncoderFFmpeg.cpp @@ -9,9 +9,11 @@ #include "EncoderFFmpeg.h" #include "ServiceBroker.h" +#include "addons/Addon.h" #include "addons/AddonManager.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" +#include "utils/StringUtils.h" #include "utils/SystemInfo.h" #include "utils/URIUtils.h" #include "utils/log.h" @@ -42,8 +44,8 @@ bool CEncoderFFmpeg::Init() ADDON::AddonPtr addon; const std::string addonId = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString( CSettings::SETTING_AUDIOCDS_ENCODER); - bool success = CServiceBroker::GetAddonMgr().GetAddon(addonId, addon, ADDON::ADDON_UNKNOWN, - ADDON::OnlyEnabled::CHOICE_YES); + bool success = + CServiceBroker::GetAddonMgr().GetAddon(addonId, addon, ADDON::OnlyEnabled::CHOICE_YES); int bitrate; if (success && addon) { diff --git a/xbmc/cores/RetroPlayer/RetroPlayer.cpp b/xbmc/cores/RetroPlayer/RetroPlayer.cpp index 07ea16143c..f27c4268f8 100644 --- a/xbmc/cores/RetroPlayer/RetroPlayer.cpp +++ b/xbmc/cores/RetroPlayer/RetroPlayer.cpp @@ -14,6 +14,7 @@ #include "ServiceBroker.h" #include "URL.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "cores/DataCacheCore.h" #include "cores/IPlayerCallback.h" #include "cores/RetroPlayer/cheevos/Cheevos.h" @@ -113,7 +114,7 @@ bool CRetroPlayer::OpenFile(const CFileItem& file, const CPlayerOptions& options { CLog::Log(LOGERROR, "RetroPlayer[PLAYER]: Can't play game, no game client was passed!"); } - else if (!CServiceBroker::GetAddonMgr().GetAddon(gameClientId, addon, ADDON::ADDON_GAMEDLL, + else if (!CServiceBroker::GetAddonMgr().GetAddon(gameClientId, addon, ADDON::AddonType::GAMEDLL, ADDON::OnlyEnabled::CHOICE_YES)) { CLog::Log(LOGERROR, "RetroPlayer[PLAYER]: Can't find add-on {} for game file!", gameClientId); @@ -159,8 +160,8 @@ bool CRetroPlayer::OpenFile(const CFileItem& file, const CPlayerOptions& options if (save->GameClientID() != m_gameClient->ID()) { ADDON::AddonPtr addon; - if (CServiceBroker::GetAddonMgr().GetAddon( - save->GameClientID(), addon, ADDON::ADDON_UNKNOWN, ADDON::OnlyEnabled::CHOICE_YES)) + if (CServiceBroker::GetAddonMgr().GetAddon(save->GameClientID(), addon, + ADDON::OnlyEnabled::CHOICE_YES)) { // Warn the user that continuing with a different game client will // overwrite the save diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp b/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp index 846ccaa1ef..97c0896269 100644 --- a/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp @@ -25,6 +25,7 @@ #include "URL.h" #include "Util.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "cores/VideoPlayer/Interface/InputStreamConstants.h" #include "filesystem/CurlFile.h" #include "filesystem/IFileTypes.h" @@ -51,7 +52,8 @@ std::shared_ptr<CDVDInputStream> CDVDFactoryInputStream::CreateInputStream(IVide } std::vector<AddonInfoPtr> addonInfos; - CServiceBroker::GetAddonMgr().GetAddonInfos(addonInfos, true /*enabled only*/, ADDON_INPUTSTREAM); + CServiceBroker::GetAddonMgr().GetAddonInfos(addonInfos, true /*enabled only*/, + AddonType::INPUTSTREAM); for (const auto& addonInfo : addonInfos) { if (CInputStreamAddon::Supports(addonInfo, fileitem)) diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamAddon.cpp b/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamAddon.cpp index c869842ea6..52f77ea9cd 100644 --- a/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamAddon.cpp +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamAddon.cpp @@ -9,6 +9,7 @@ #include "InputStreamAddon.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "addons/binary-addons/AddonDll.h" #include "addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h" #include "cores/VideoPlayer/DVDDemuxers/DVDDemux.h" @@ -53,7 +54,7 @@ CInputStreamAddon::CInputStreamAddon(const AddonInfoPtr& addonInfo, m_player(player) { std::string listitemprops = - addonInfo->Type(ADDON_INPUTSTREAM)->GetValue("@listitemprops").asString(); + addonInfo->Type(AddonType::INPUTSTREAM)->GetValue("@listitemprops").asString(); std::string name(addonInfo->ID()); m_fileItemProps = StringUtils::Tokenize(listitemprops, "|"); @@ -91,7 +92,8 @@ bool CInputStreamAddon::Supports(const AddonInfoPtr& addonInfo, const CFileItem& std::string protocol = CURL(fileitem.GetDynPath()).GetProtocol(); if (!protocol.empty()) { - std::string protocols = addonInfo->Type(ADDON_INPUTSTREAM)->GetValue("@protocols").asString(); + std::string protocols = + addonInfo->Type(AddonType::INPUTSTREAM)->GetValue("@protocols").asString(); if (!protocols.empty()) { std::vector<std::string> protocolsList = StringUtils::Tokenize(protocols, "|"); @@ -107,7 +109,8 @@ bool CInputStreamAddon::Supports(const AddonInfoPtr& addonInfo, const CFileItem& std::string filetype = fileitem.GetURL().GetFileType(); if (!filetype.empty()) { - std::string extensions = addonInfo->Type(ADDON_INPUTSTREAM)->GetValue("@extension").asString(); + std::string extensions = + addonInfo->Type(AddonType::INPUTSTREAM)->GetValue("@extension").asString(); if (!extensions.empty()) { std::vector<std::string> extensionsList = StringUtils::Tokenize(extensions, "|"); @@ -520,7 +523,7 @@ KODI_HANDLE CInputStreamAddon::cb_get_stream_transfer(KODI_HANDLE handle, demuxStream->language = stream->m_language; if (thisClass->GetAddonInfo()->DependencyVersion(ADDON_INSTANCE_VERSION_INPUTSTREAM_XML_ID) >= - AddonVersion("2.0.8")) + CAddonVersion("2.0.8")) { demuxStream->codec_fourcc = stream->m_codecFourCC; } diff --git a/xbmc/cores/paplayer/CodecFactory.cpp b/xbmc/cores/paplayer/CodecFactory.cpp index 3699ba82b9..70684d876c 100644 --- a/xbmc/cores/paplayer/CodecFactory.cpp +++ b/xbmc/cores/paplayer/CodecFactory.cpp @@ -13,6 +13,7 @@ #include "VideoPlayerCodec.h" #include "addons/AudioDecoder.h" #include "addons/ExtsMimeSupportList.h" +#include "addons/addoninfo/AddonType.h" #include "utils/StringUtils.h" using namespace KODI::ADDONS; @@ -27,7 +28,7 @@ ICodec* CodecFactory::CreateCodec(const CURL& urlFile) for (const auto& addonInfo : addonInfos) { // Check asked and given extension is supported by only for here allowed audiodecoder addons. - if (addonInfo.first == ADDON::ADDON_AUDIODECODER) + if (addonInfo.first == ADDON::AddonType::AUDIODECODER) { std::unique_ptr<CAudioDecoder> result = std::make_unique<CAudioDecoder>(addonInfo.second); if (!result->CreateDecoder()) @@ -53,7 +54,7 @@ ICodec* CodecFactory::CreateCodecDemux(const CFileItem& file, unsigned int filec for (const auto& addonInfo : addonInfos) { // Check asked and given mime type is supported by only for here allowed audiodecoder addons. - if (addonInfo.first == ADDON::ADDON_AUDIODECODER) + if (addonInfo.first == ADDON::AddonType::AUDIODECODER) { std::unique_ptr<CAudioDecoder> result = std::make_unique<CAudioDecoder>(addonInfo.second); if (!result->CreateDecoder() && result->SupportsFile(file.GetPath())) diff --git a/xbmc/filesystem/AddonsDirectory.cpp b/xbmc/filesystem/AddonsDirectory.cpp index 7addc62c55..1439ae054b 100644 --- a/xbmc/filesystem/AddonsDirectory.cpp +++ b/xbmc/filesystem/AddonsDirectory.cpp @@ -19,6 +19,7 @@ #include "addons/PluginSource.h" #include "addons/RepositoryUpdater.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "games/GameUtils.h" #include "games/addons/GameClient.h" #include "guilib/LocalizeStrings.h" @@ -55,32 +56,29 @@ const auto CATEGORY_GAME_PROVIDERS = "category.gameproviders"; const auto CATEGORY_GAME_RESOURCES = "category.gameresources"; const auto CATEGORY_GAME_SUPPORT_ADDONS = "category.gamesupport"; -const std::set<TYPE> infoProviderTypes = { - ADDON_SCRAPER_ALBUMS, - ADDON_SCRAPER_ARTISTS, - ADDON_SCRAPER_MOVIES, - ADDON_SCRAPER_MUSICVIDEOS, - ADDON_SCRAPER_TVSHOWS, +const std::set<AddonType> infoProviderTypes = { + AddonType::SCRAPER_ALBUMS, AddonType::SCRAPER_ARTISTS, AddonType::SCRAPER_MOVIES, + AddonType::SCRAPER_MUSICVIDEOS, AddonType::SCRAPER_TVSHOWS, }; -const std::set<TYPE> lookAndFeelTypes = { - ADDON_SKIN, - ADDON_SCREENSAVER, - ADDON_RESOURCE_IMAGES, - ADDON_RESOURCE_LANGUAGE, - ADDON_RESOURCE_UISOUNDS, - ADDON_RESOURCE_FONT, - ADDON_VIZ, +const std::set<AddonType> lookAndFeelTypes = { + AddonType::SKIN, + AddonType::SCREENSAVER, + AddonType::RESOURCE_IMAGES, + AddonType::RESOURCE_LANGUAGE, + AddonType::RESOURCE_UISOUNDS, + AddonType::RESOURCE_FONT, + AddonType::VISUALIZATION, }; -const std::set<TYPE> gameTypes = { - ADDON_GAME_CONTROLLER, - ADDON_GAMEDLL, - ADDON_GAME, - ADDON_RESOURCE_GAMES, +const std::set<AddonType> gameTypes = { + AddonType::GAME_CONTROLLER, + AddonType::GAMEDLL, + AddonType::GAME, + AddonType::RESOURCE_GAMES, }; -static bool IsInfoProviderType(TYPE type) +static bool IsInfoProviderType(AddonType type) { return infoProviderTypes.find(type) != infoProviderTypes.end(); } @@ -90,7 +88,7 @@ static bool IsInfoProviderTypeAddon(const AddonPtr& addon) return IsInfoProviderType(addon->Type()); } -static bool IsLookAndFeelType(TYPE type) +static bool IsLookAndFeelType(AddonType type) { return lookAndFeelTypes.find(type) != lookAndFeelTypes.end(); } @@ -100,7 +98,7 @@ static bool IsLookAndFeelTypeAddon(const AddonPtr& addon) return IsLookAndFeelType(addon->Type()); } -static bool IsGameType(TYPE type) +static bool IsGameType(AddonType type) { return gameTypes.find(type) != gameTypes.end(); } @@ -112,22 +110,23 @@ static bool IsStandaloneGame(const AddonPtr& addon) static bool IsEmulator(const AddonPtr& addon) { - return addon->Type() == ADDON_GAMEDLL && std::static_pointer_cast<GAME::CGameClient>(addon)->SupportsPath(); + return addon->Type() == AddonType::GAMEDLL && + std::static_pointer_cast<GAME::CGameClient>(addon)->SupportsPath(); } static bool IsGameProvider(const AddonPtr& addon) { - return addon->Type() == ADDON_PLUGIN && addon->HasType(ADDON_GAME); + return addon->Type() == AddonType::PLUGIN && addon->HasType(AddonType::GAME); } static bool IsGameResource(const AddonPtr& addon) { - return addon->Type() == ADDON_RESOURCE_GAMES; + return addon->Type() == AddonType::RESOURCE_GAMES; } static bool IsGameSupportAddon(const AddonPtr& addon) { - return addon->Type() == ADDON_GAMEDLL && + return addon->Type() == AddonType::GAMEDLL && !std::static_pointer_cast<GAME::CGameClient>(addon)->SupportsPath() && !std::static_pointer_cast<GAME::CGameClient>(addon)->SupportsStandalone(); } @@ -147,8 +146,10 @@ static bool IsUserInstalled(const AddonPtr& addon) } // Creates categories from addon types, if we have any addons with that type. -static void GenerateTypeListing(const CURL& path, const std::set<TYPE>& types, - const VECADDONS& addons, CFileItemList& items) +static void GenerateTypeListing(const CURL& path, + const std::set<AddonType>& types, + const VECADDONS& addons, + CFileItemList& items) { for (const auto& type : types) { @@ -177,14 +178,14 @@ static void GenerateGameListing(const CURL& path, const VECADDONS& addons, CFile // Game controllers for (const auto& addon : addons) { - if (addon->Type() == ADDON_GAME_CONTROLLER) + if (addon->Type() == AddonType::GAME_CONTROLLER) { - CFileItemPtr item(new CFileItem(CAddonInfo::TranslateType(ADDON_GAME_CONTROLLER, true))); + CFileItemPtr item(new CFileItem(CAddonInfo::TranslateType(AddonType::GAME_CONTROLLER, true))); CURL itemPath = path; - itemPath.SetFileName(CAddonInfo::TranslateType(ADDON_GAME_CONTROLLER, false)); + itemPath.SetFileName(CAddonInfo::TranslateType(AddonType::GAME_CONTROLLER, false)); item->SetPath(itemPath.Get()); item->m_bIsFolder = true; - std::string thumb = CAddonInfo::TranslateIconType(ADDON_GAME_CONTROLLER); + std::string thumb = CAddonInfo::TranslateIconType(AddonType::GAME_CONTROLLER); if (!thumb.empty() && CServiceBroker::GetGUI()->GetTextureManager().HasTexture(thumb)) item->SetArt("thumb", thumb); items.Add(item); @@ -201,7 +202,7 @@ static void GenerateGameListing(const CURL& path, const VECADDONS& addons, CFile itemPath.SetFileName(CATEGORY_EMULATORS); item->SetPath(itemPath.Get()); item->m_bIsFolder = true; - std::string thumb = CAddonInfo::TranslateIconType(ADDON_GAMEDLL); + std::string thumb = CAddonInfo::TranslateIconType(AddonType::GAMEDLL); if (!thumb.empty() && CServiceBroker::GetGUI()->GetTextureManager().HasTexture(thumb)) item->SetArt("thumb", thumb); items.Add(item); @@ -218,7 +219,7 @@ static void GenerateGameListing(const CURL& path, const VECADDONS& addons, CFile itemPath.SetFileName(CATEGORY_STANDALONE_GAMES); item->SetPath(itemPath.Get()); item->m_bIsFolder = true; - std::string thumb = CAddonInfo::TranslateIconType(ADDON_GAMEDLL); + std::string thumb = CAddonInfo::TranslateIconType(AddonType::GAMEDLL); if (!thumb.empty() && CServiceBroker::GetGUI()->GetTextureManager().HasTexture(thumb)) item->SetArt("thumb", thumb); items.Add(item); @@ -235,7 +236,7 @@ static void GenerateGameListing(const CURL& path, const VECADDONS& addons, CFile itemPath.SetFileName(CATEGORY_GAME_PROVIDERS); item->SetPath(itemPath.Get()); item->m_bIsFolder = true; - std::string thumb = CAddonInfo::TranslateIconType(ADDON_GAMEDLL); + std::string thumb = CAddonInfo::TranslateIconType(AddonType::GAMEDLL); if (!thumb.empty() && CServiceBroker::GetGUI()->GetTextureManager().HasTexture(thumb)) item->SetArt("thumb", thumb); items.Add(item); @@ -252,7 +253,7 @@ static void GenerateGameListing(const CURL& path, const VECADDONS& addons, CFile itemPath.SetFileName(CATEGORY_GAME_RESOURCES); item->SetPath(itemPath.Get()); item->m_bIsFolder = true; - std::string thumb = CAddonInfo::TranslateIconType(ADDON_GAMEDLL); + std::string thumb = CAddonInfo::TranslateIconType(AddonType::GAMEDLL); if (!thumb.empty() && CServiceBroker::GetGUI()->GetTextureManager().HasTexture(thumb)) item->SetArt("thumb", thumb); items.Add(item); @@ -269,7 +270,7 @@ static void GenerateGameListing(const CURL& path, const VECADDONS& addons, CFile itemPath.SetFileName(CATEGORY_GAME_SUPPORT_ADDONS); item->SetPath(itemPath.Get()); item->m_bIsFolder = true; - std::string thumb = CAddonInfo::TranslateIconType(ADDON_GAMEDLL); + std::string thumb = CAddonInfo::TranslateIconType(AddonType::GAMEDLL); if (!thumb.empty() && CServiceBroker::GetGUI()->GetTextureManager().HasTexture(thumb)) item->SetArt("thumb", thumb); items.Add(item); @@ -304,19 +305,20 @@ static void GenerateMainCategoryListing(const CURL& path, const VECADDONS& addon } if (std::any_of(addons.begin(), addons.end(), IsGameAddon)) { - CFileItemPtr item(new CFileItem(CAddonInfo::TranslateType(ADDON_GAME, true))); + CFileItemPtr item(new CFileItem(CAddonInfo::TranslateType(AddonType::GAME, true))); item->SetPath(URIUtils::AddFileToFolder(path.Get(), CATEGORY_GAME_ADDONS)); item->m_bIsFolder = true; - const std::string thumb = CAddonInfo::TranslateIconType(ADDON_GAME); + const std::string thumb = CAddonInfo::TranslateIconType(AddonType::GAME); if (CServiceBroker::GetGUI()->GetTextureManager().HasTexture(thumb)) item->SetArt("thumb", thumb); items.Add(item); } - std::set<TYPE> uncategorized; - for (unsigned int i = ADDON_UNKNOWN + 1; i < ADDON_MAX - 1; ++i) + std::set<AddonType> uncategorized; + for (unsigned int i = static_cast<unsigned int>(AddonType::UNKNOWN) + 1; + i < static_cast<unsigned int>(AddonType::MAX_TYPES) - 1; ++i) { - const TYPE type = (TYPE)i; + const AddonType type = static_cast<AddonType>(i); /* * Check and prevent insert for this cases: * - By a provider, look and feel, dependency and game becomes given to @@ -326,9 +328,9 @@ static void GenerateMainCategoryListing(const CURL& path, const VECADDONS& addon * together in a Script or Plugin list */ if (!IsInfoProviderType(type) && !IsLookAndFeelType(type) && - !CAddonType::IsDependencyType(type) && !IsGameType(type) && type != ADDON_SCRIPT && - type != ADDON_PLUGIN) - uncategorized.insert(static_cast<TYPE>(i)); + !CAddonType::IsDependencyType(type) && !IsGameType(type) && type != AddonType::SCRIPT && + type != AddonType::PLUGIN) + uncategorized.insert(type); } GenerateTypeListing(path, uncategorized, addons, items); } @@ -352,8 +354,8 @@ static void GenerateCategoryListing(const CURL& path, VECADDONS& addons, } else if (category == CATEGORY_GAME_ADDONS) { - items.SetProperty("addoncategory", CAddonInfo::TranslateType(ADDON_GAME, true)); - items.SetLabel(CAddonInfo::TranslateType(ADDON_GAME, true)); + items.SetProperty("addoncategory", CAddonInfo::TranslateType(AddonType::GAME, true)); + items.SetLabel(CAddonInfo::TranslateType(AddonType::GAME, true)); GenerateGameListing(path, addons, items); } else if (category == CATEGORY_EMULATORS) @@ -393,7 +395,7 @@ static void GenerateCategoryListing(const CURL& path, VECADDONS& addons, } else { // fallback to addon type - TYPE type = CAddonInfo::TranslateType(category); + AddonType type = CAddonInfo::TranslateType(category); items.SetProperty("addoncategory", CAddonInfo::TranslateType(type, true)); addons.erase(std::remove_if(addons.begin(), addons.end(), [type](const AddonPtr& addon) { return !addon->HasType(type); }), @@ -509,7 +511,7 @@ static void OutdatedAddons(const CURL& path, CFileItemList &items) static void RunningAddons(const CURL& path, CFileItemList &items) { VECADDONS addons; - CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON_SERVICE); + CServiceBroker::GetAddonMgr().GetAddons(addons, AddonType::SERVICE); addons.erase(std::remove_if(addons.begin(), addons.end(), [](const AddonPtr& addon){ return !CScriptInvocationManager::GetInstance().IsRunning(addon->LibPath()); }), addons.end()); @@ -537,7 +539,7 @@ static bool Browse(const CURL& path, CFileItemList &items) else { AddonPtr repoAddon; - if (!CServiceBroker::GetAddonMgr().GetAddon(repoId, repoAddon, ADDON_REPOSITORY, + if (!CServiceBroker::GetAddonMgr().GetAddon(repoId, repoAddon, AddonType::REPOSITORY, OnlyEnabled::CHOICE_YES)) { return false; @@ -584,7 +586,7 @@ static bool Repos(const CURL& path, CFileItemList &items) items.SetLabel(g_localizeStrings.Get(24033)); VECADDONS addons; - CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON_REPOSITORY); + CServiceBroker::GetAddonMgr().GetAddons(addons, AddonType::REPOSITORY); if (addons.empty()) return true; else if (addons.size() == 1) @@ -633,7 +635,7 @@ static void RootDirectory(CFileItemList& items) item->SetArt("icon", "DefaultAddonsRecentlyUpdated.png"); items.Add(item); } - if (CServiceBroker::GetAddonMgr().HasAddons(ADDON_REPOSITORY)) + if (CServiceBroker::GetAddonMgr().HasAddons(AddonType::REPOSITORY)) { CFileItemPtr item(new CFileItem("addons://repos/", true)); item->SetLabel(g_localizeStrings.Get(24033)); @@ -684,16 +686,17 @@ bool CAddonsDirectory::GetDirectory(const CURL& url, CFileItemList &items) else if (endpoint == "disabled") { VECADDONS addons; - ADDON::TYPE type; + AddonType type; if (path.GetFileName() == "kodi.pvrclient") - type = ADDON_PVRDLL; + type = AddonType::PVRDLL; else if (path.GetFileName() == "kodi.vfs") - type = ADDON_VFS; + type = AddonType::VFS; else - type = ADDON_UNKNOWN; + type = AddonType::UNKNOWN; - if (type != ADDON_UNKNOWN && CServiceBroker::GetAddonMgr().GetInstalledAddons(addons, type)) + if (type != AddonType::UNKNOWN && + CServiceBroker::GetAddonMgr().GetInstalledAddons(addons, type)) { CAddonsDirectory::GenerateAddonListing(path, addons, items, CAddonInfo::TranslateType(type, true)); return true; @@ -761,7 +764,7 @@ bool CAddonsDirectory::IsRepoDirectory(const CURL& url) AddonPtr tmp; return url.GetHostName() == "repos" || url.GetHostName() == "all" || url.GetHostName() == "search" || - CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), tmp, ADDON_REPOSITORY, + CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), tmp, AddonType::REPOSITORY, OnlyEnabled::CHOICE_YES); } @@ -770,7 +773,7 @@ void CAddonsDirectory::GenerateAddonListing(const CURL& path, CFileItemList& items, const std::string& label) { - std::map<std::string, CAddonWithUpdate> addonsWithUpdate = + std::map<std::string, AddonWithUpdate> addonsWithUpdate = CServiceBroker::GetAddonMgr().GetAddonsWithAvailableUpdate(); items.ClearItems(); @@ -874,18 +877,18 @@ bool CAddonsDirectory::GetScriptsAndPlugins(const std::string &content, VECADDON return false; VECADDONS tempAddons; - CServiceBroker::GetAddonMgr().GetAddons(tempAddons, ADDON_PLUGIN); + CServiceBroker::GetAddonMgr().GetAddons(tempAddons, AddonType::PLUGIN); for (unsigned i=0; i<tempAddons.size(); i++) { - PluginPtr plugin = std::dynamic_pointer_cast<CPluginSource>(tempAddons[i]); + const auto plugin = std::dynamic_pointer_cast<CPluginSource>(tempAddons[i]); if (plugin && plugin->Provides(type)) addons.push_back(tempAddons[i]); } tempAddons.clear(); - CServiceBroker::GetAddonMgr().GetAddons(tempAddons, ADDON_SCRIPT); + CServiceBroker::GetAddonMgr().GetAddons(tempAddons, AddonType::SCRIPT); for (unsigned i=0; i<tempAddons.size(); i++) { - PluginPtr plugin = std::dynamic_pointer_cast<CPluginSource>(tempAddons[i]); + const auto plugin = std::dynamic_pointer_cast<CPluginSource>(tempAddons[i]); if (plugin && plugin->Provides(type)) addons.push_back(tempAddons[i]); } @@ -893,7 +896,7 @@ bool CAddonsDirectory::GetScriptsAndPlugins(const std::string &content, VECADDON if (type == CPluginSource::GAME) { - CServiceBroker::GetAddonMgr().GetAddons(tempAddons, ADDON_GAMEDLL); + CServiceBroker::GetAddonMgr().GetAddons(tempAddons, AddonType::GAMEDLL); for (auto& addon : tempAddons) { if (IsStandaloneGame(addon)) @@ -912,13 +915,13 @@ bool CAddonsDirectory::GetScriptsAndPlugins(const std::string &content, CFileIte for (AddonPtr& addon : addons) { - const bool bIsFolder = (addon->Type() == ADDON_PLUGIN); + const bool bIsFolder = (addon->Type() == AddonType::PLUGIN); std::string path; - if (addon->HasType(ADDON_PLUGIN)) + if (addon->HasType(AddonType::PLUGIN)) { path = "plugin://" + addon->ID(); - PluginPtr plugin = std::dynamic_pointer_cast<CPluginSource>(addon); + const auto plugin = std::dynamic_pointer_cast<CPluginSource>(addon); if (plugin && plugin->ProvidesSeveral()) { CURL url(path); @@ -927,11 +930,11 @@ bool CAddonsDirectory::GetScriptsAndPlugins(const std::string &content, CFileIte path = url.Get(); } } - else if (addon->HasType(ADDON_SCRIPT)) + else if (addon->HasType(AddonType::SCRIPT)) { path = "script://" + addon->ID(); } - else if (addon->HasType(ADDON_GAMEDLL)) + else if (addon->HasType(AddonType::GAMEDLL)) { // Kodi fails to launch games with empty path from home screen path = "game://" + addon->ID(); diff --git a/xbmc/filesystem/PluginDirectory.cpp b/xbmc/filesystem/PluginDirectory.cpp index 5e5dad1e33..827388679c 100644 --- a/xbmc/filesystem/PluginDirectory.cpp +++ b/xbmc/filesystem/PluginDirectory.cpp @@ -15,6 +15,7 @@ #include "addons/AddonManager.h" #include "addons/IAddon.h" #include "addons/PluginSource.h" +#include "addons/addoninfo/AddonType.h" #include "interfaces/generic/RunningScriptObserver.h" #include "messaging/ApplicationMessenger.h" #include "settings/Settings.h" @@ -69,9 +70,9 @@ bool CPluginDirectory::StartScript(const std::string& strPath, bool resume) ADDON::AddonPtr addon; // try the plugin type first, and if not found, try an unknown type - if (!CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, ADDON_PLUGIN, + if (!CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, AddonType::PLUGIN, OnlyEnabled::CHOICE_YES) && - !CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, ADDON_UNKNOWN, + !CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, AddonType::UNKNOWN, OnlyEnabled::CHOICE_YES) && !CAddonInstaller::GetInstance().InstallModal(url.GetHostName(), addon, InstallModalPrompt::CHOICE_YES)) @@ -426,7 +427,7 @@ bool CPluginDirectory::RunScriptWithParams(const std::string& strPath, bool resu return false; AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, ADDON_PLUGIN, + if (!CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, AddonType::PLUGIN, OnlyEnabled::CHOICE_YES) && !CAddonInstaller::GetInstance().InstallModal(url.GetHostName(), addon, InstallModalPrompt::CHOICE_YES)) @@ -511,7 +512,7 @@ bool CPluginDirectory::IsMediaLibraryScanningAllowed(const std::string& content, if (url.GetHostName().empty()) return false; AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, ADDON_PLUGIN, + if (!CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, AddonType::PLUGIN, OnlyEnabled::CHOICE_YES)) { CLog::Log(LOGERROR, "Unable to find plugin {}", url.GetHostName()); diff --git a/xbmc/filesystem/ResourceFile.cpp b/xbmc/filesystem/ResourceFile.cpp index 4b0b5fd439..81a9982b78 100644 --- a/xbmc/filesystem/ResourceFile.cpp +++ b/xbmc/filesystem/ResourceFile.cpp @@ -46,8 +46,7 @@ bool CResourceFile::TranslatePath(const CURL &url, std::string &translatedPath) return false; AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(addonId, addon, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_YES) || + if (!CServiceBroker::GetAddonMgr().GetAddon(addonId, addon, OnlyEnabled::CHOICE_YES) || addon == NULL) return false; diff --git a/xbmc/games/GameUtils.cpp b/xbmc/games/GameUtils.cpp index ff62fbcdc3..5eba00b049 100644 --- a/xbmc/games/GameUtils.cpp +++ b/xbmc/games/GameUtils.cpp @@ -15,6 +15,7 @@ #include "addons/AddonInstaller.h" #include "addons/AddonManager.h" #include "addons/BinaryAddonCache.h" +#include "addons/addoninfo/AddonType.h" #include "cores/RetroPlayer/savestates/ISavestate.h" #include "cores/RetroPlayer/savestates/SavestateDatabase.h" #include "filesystem/SpecialProtocol.h" @@ -39,7 +40,7 @@ bool CGameUtils::FillInGameClient(CFileItem& item, std::string& savestatePath) if (item.GetGameInfoTag()->GetGameClient().empty()) { // If the fileitem is an add-on, fall back to that - if (item.HasAddonInfo() && item.GetAddonInfo()->Type() == ADDON::ADDON_GAMEDLL) + if (item.HasAddonInfo() && item.GetAddonInfo()->Type() == AddonType::GAMEDLL) { item.GetGameInfoTag()->SetGameClient(item.GetAddonInfo()->ID()); } @@ -126,7 +127,7 @@ void CGameUtils::GetGameClients(const CFileItem& file, // Get local candidates VECADDONS localAddons; CBinaryAddonCache& addonCache = CServiceBroker::GetBinaryAddonCache(); - addonCache.GetAddons(localAddons, ADDON_GAMEDLL); + addonCache.GetAddons(localAddons, AddonType::GAMEDLL); bool bVfs = false; GetGameClients(localAddons, translatedUrl, candidates, bVfs); @@ -134,7 +135,7 @@ void CGameUtils::GetGameClients(const CFileItem& file, // Get remote candidates VECADDONS remoteAddons; - if (CServiceBroker::GetAddonMgr().GetInstallableAddons(remoteAddons, ADDON_GAMEDLL)) + if (CServiceBroker::GetAddonMgr().GetInstallableAddons(remoteAddons, AddonType::GAMEDLL)) { GetGameClients(remoteAddons, translatedUrl, installable, bVfs); bHasVfsGameClient |= bVfs; @@ -208,7 +209,7 @@ bool CGameUtils::HasGameExtension(const std::string& path) // Look for a game client that supports this extension VECADDONS gameClients; CBinaryAddonCache& addonCache = CServiceBroker::GetBinaryAddonCache(); - addonCache.GetInstalledAddons(gameClients, ADDON_GAMEDLL); + addonCache.GetInstalledAddons(gameClients, AddonType::GAMEDLL); for (auto& gameClient : gameClients) { GameClientPtr gc(std::static_pointer_cast<CGameClient>(gameClient)); @@ -218,7 +219,7 @@ bool CGameUtils::HasGameExtension(const std::string& path) // Check remote add-ons gameClients.clear(); - if (CServiceBroker::GetAddonMgr().GetInstallableAddons(gameClients, ADDON_GAMEDLL)) + if (CServiceBroker::GetAddonMgr().GetInstallableAddons(gameClients, AddonType::GAMEDLL)) { for (auto& gameClient : gameClients) { @@ -239,7 +240,7 @@ std::set<std::string> CGameUtils::GetGameExtensions() VECADDONS gameClients; CBinaryAddonCache& addonCache = CServiceBroker::GetBinaryAddonCache(); - addonCache.GetAddons(gameClients, ADDON_GAMEDLL); + addonCache.GetAddons(gameClients, AddonType::GAMEDLL); for (auto& gameClient : gameClients) { GameClientPtr gc(std::static_pointer_cast<CGameClient>(gameClient)); @@ -248,7 +249,7 @@ std::set<std::string> CGameUtils::GetGameExtensions() // Check remote add-ons gameClients.clear(); - if (CServiceBroker::GetAddonMgr().GetInstallableAddons(gameClients, ADDON_GAMEDLL)) + if (CServiceBroker::GetAddonMgr().GetInstallableAddons(gameClients, AddonType::GAMEDLL)) { for (auto& gameClient : gameClients) { @@ -266,13 +267,13 @@ bool CGameUtils::IsStandaloneGame(const ADDON::AddonPtr& addon) switch (addon->Type()) { - case ADDON_GAMEDLL: + case AddonType::GAMEDLL: { return std::static_pointer_cast<GAME::CGameClient>(addon)->SupportsStandalone(); } - case ADDON_SCRIPT: + case AddonType::SCRIPT: { - return addon->HasType(ADDON_GAME); + return addon->HasType(AddonType::GAME); } default: break; diff --git a/xbmc/games/GameUtils.h b/xbmc/games/GameUtils.h index ec3ee9a2a3..b49985c818 100644 --- a/xbmc/games/GameUtils.h +++ b/xbmc/games/GameUtils.h @@ -9,8 +9,6 @@ #pragma once #include "GameTypes.h" -#include "addons/Addon.h" -#include "addons/IAddon.h" #include <set> #include <string> @@ -18,6 +16,13 @@ class CFileItem; class CURL; +namespace ADDON +{ +class IAddon; +using AddonPtr = std::shared_ptr<IAddon>; +using VECADDONS = std::vector<AddonPtr>; +} // namespace ADDON + namespace KODI { namespace GAME diff --git a/xbmc/games/addons/GameClient.cpp b/xbmc/games/addons/GameClient.cpp index 6a1c36c8d8..f41836ff0c 100644 --- a/xbmc/games/addons/GameClient.cpp +++ b/xbmc/games/addons/GameClient.cpp @@ -18,6 +18,7 @@ #include "addons/AddonManager.h" #include "addons/BinaryAddonCache.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "filesystem/Directory.h" #include "filesystem/SpecialProtocol.h" #include "games/GameServices.h" @@ -80,7 +81,7 @@ std::string NormalizeExtension(const std::string& strExtension) // --- CGameClient ------------------------------------------------------------- CGameClient::CGameClient(const ADDON::AddonInfoPtr& addonInfo) - : CAddonDll(addonInfo, ADDON::ADDON_GAMEDLL), + : CAddonDll(addonInfo, ADDON::AddonType::GAMEDLL), m_subsystems(CGameClientSubsystem::CreateSubsystems(*this, *m_ifc.game, m_critSection)), m_bSupportsAllExtensions(false), m_bIsPlaying(false), @@ -90,7 +91,7 @@ CGameClient::CGameClient(const ADDON::AddonInfoPtr& addonInfo) using namespace ADDON; std::vector<std::string> extensions = StringUtils::Split( - Type(ADDON_GAMEDLL)->GetValue(GAME_PROPERTY_EXTENSIONS).asString(), EXTENSION_SEPARATOR); + Type(AddonType::GAMEDLL)->GetValue(GAME_PROPERTY_EXTENSIONS).asString(), EXTENSION_SEPARATOR); std::transform(extensions.begin(), extensions.end(), std::inserter(m_extensions, m_extensions.begin()), NormalizeExtension); @@ -101,9 +102,10 @@ CGameClient::CGameClient(const ADDON::AddonInfoPtr& addonInfo) m_extensions.clear(); } - m_bSupportsVFS = addonInfo->Type(ADDON_GAMEDLL)->GetValue(GAME_PROPERTY_SUPPORTS_VFS).asBoolean(); + m_bSupportsVFS = + addonInfo->Type(AddonType::GAMEDLL)->GetValue(GAME_PROPERTY_SUPPORTS_VFS).asBoolean(); m_bSupportsStandalone = - addonInfo->Type(ADDON_GAMEDLL)->GetValue(GAME_PROPERTY_SUPPORTS_STANDALONE).asBoolean(); + addonInfo->Type(AddonType::GAMEDLL)->GetValue(GAME_PROPERTY_SUPPORTS_STANDALONE).asBoolean(); } CGameClient::~CGameClient(void) @@ -425,8 +427,8 @@ std::string CGameClient::GetMissingResource() if (StringUtils::StartsWith(strDependencyId, "resource.games")) { AddonPtr addon; - const bool bInstalled = CServiceBroker::GetAddonMgr().GetAddon( - strDependencyId, addon, ADDON_UNKNOWN, OnlyEnabled::CHOICE_YES); + const bool bInstalled = + CServiceBroker::GetAddonMgr().GetAddon(strDependencyId, addon, OnlyEnabled::CHOICE_YES); if (!bInstalled) { strAddonId = strDependencyId; diff --git a/xbmc/games/addons/GameClientProperties.cpp b/xbmc/games/addons/GameClientProperties.cpp index 4861e01298..4f7273a913 100644 --- a/xbmc/games/addons/GameClientProperties.cpp +++ b/xbmc/games/addons/GameClientProperties.cpp @@ -15,11 +15,13 @@ #include "addons/GameResource.h" #include "addons/IAddon.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "dialogs/GUIDialogYesNo.h" #include "filesystem/Directory.h" #include "filesystem/SpecialProtocol.h" #include "guilib/LocalizeStrings.h" #include "messaging/helpers/DialogOKHelper.h" +#include "utils/StringUtils.h" #include "utils/Variant.h" #include "utils/log.h" @@ -114,7 +116,7 @@ const char** CGameClientProperties::GetResourceDirectories(void) { const std::string& strAddonId = it->id; AddonPtr addon; - if (CServiceBroker::GetAddonMgr().GetAddon(strAddonId, addon, ADDON_RESOURCE_GAMES, + if (CServiceBroker::GetAddonMgr().GetAddon(strAddonId, addon, AddonType::RESOURCE_GAMES, OnlyEnabled::CHOICE_YES)) { std::shared_ptr<CGameResource> resource = std::static_pointer_cast<CGameResource>(addon); @@ -205,8 +207,7 @@ bool CGameClientProperties::GetProxyAddons(ADDON::VECADDONS& addons) for (const auto& dependency : m_parent.GetDependencies()) { AddonPtr addon; - if (CServiceBroker::GetAddonMgr().GetAddon(dependency.id, addon, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_NO)) + if (CServiceBroker::GetAddonMgr().GetAddon(dependency.id, addon, OnlyEnabled::CHOICE_NO)) { // If add-on is disabled, ask the user to enable it if (CServiceBroker::GetAddonMgr().IsAddonDisabled(dependency.id)) @@ -230,7 +231,7 @@ bool CGameClientProperties::GetProxyAddons(ADDON::VECADDONS& addons) } } - if (addon && addon->Type() == ADDON_GAMEDLL) + if (addon && addon->Type() == AddonType::GAMEDLL) ret.emplace_back(std::move(addon)); } else diff --git a/xbmc/games/addons/GameClientProperties.h b/xbmc/games/addons/GameClientProperties.h index 83a44171c1..5cb1c6ac34 100644 --- a/xbmc/games/addons/GameClientProperties.h +++ b/xbmc/games/addons/GameClientProperties.h @@ -8,7 +8,6 @@ #pragma once -#include "addons/Addon.h" #include "addons/kodi-dev-kit/include/kodi/addon-instance/Game.h" #include "games/GameTypes.h" @@ -17,6 +16,13 @@ struct AddonProps_Game; +namespace ADDON +{ +class IAddon; +using AddonPtr = std::shared_ptr<IAddon>; +using VECADDONS = std::vector<AddonPtr>; +} // namespace ADDON + namespace KODI { namespace GAME diff --git a/xbmc/games/controllers/Controller.cpp b/xbmc/games/controllers/Controller.cpp index 178a131f66..e51af4e3a7 100644 --- a/xbmc/games/controllers/Controller.cpp +++ b/xbmc/games/controllers/Controller.cpp @@ -11,6 +11,7 @@ #include "ControllerDefinitions.h" #include "ControllerLayout.h" #include "URL.h" +#include "addons/addoninfo/AddonType.h" #include "games/controllers/input/PhysicalTopology.h" #include "utils/XBMCTinyXML.h" #include "utils/XMLUtils.h" @@ -55,7 +56,7 @@ struct FeatureTypeEqual const ControllerPtr CController::EmptyPtr; CController::CController(const ADDON::AddonInfoPtr& addonInfo) - : CAddon(addonInfo, ADDON::ADDON_GAME_CONTROLLER), m_layout(new CControllerLayout) + : CAddon(addonInfo, ADDON::AddonType::GAME_CONTROLLER), m_layout(new CControllerLayout) { } diff --git a/xbmc/games/controllers/ControllerManager.cpp b/xbmc/games/controllers/ControllerManager.cpp index d612020be3..c6f077a33e 100644 --- a/xbmc/games/controllers/ControllerManager.cpp +++ b/xbmc/games/controllers/ControllerManager.cpp @@ -12,6 +12,7 @@ #include "ControllerIDs.h" #include "ServiceBroker.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" using namespace KODI; using namespace GAME; @@ -25,7 +26,7 @@ ControllerPtr CControllerManager::GetController(const std::string& controllerId) if (!cachedController && m_failedControllers.find(controllerId) == m_failedControllers.end()) { AddonPtr addon; - if (CServiceBroker::GetAddonMgr().GetAddon(controllerId, addon, ADDON_GAME_CONTROLLER, + if (CServiceBroker::GetAddonMgr().GetAddon(controllerId, addon, AddonType::GAME_CONTROLLER, OnlyEnabled::CHOICE_NO)) cachedController = LoadController(addon); } @@ -55,7 +56,7 @@ ControllerVector CControllerManager::GetControllers() ControllerVector controllers; VECADDONS addons; - if (CServiceBroker::GetAddonMgr().GetInstalledAddons(addons, ADDON_GAME_CONTROLLER)) + if (CServiceBroker::GetAddonMgr().GetInstalledAddons(addons, AddonType::GAME_CONTROLLER)) { for (auto& addon : addons) { diff --git a/xbmc/games/controllers/dialogs/ControllerInstaller.cpp b/xbmc/games/controllers/dialogs/ControllerInstaller.cpp index 26cf854749..9b0fe6fc87 100644 --- a/xbmc/games/controllers/dialogs/ControllerInstaller.cpp +++ b/xbmc/games/controllers/dialogs/ControllerInstaller.cpp @@ -13,6 +13,7 @@ #include "addons/Addon.h" #include "addons/AddonInstaller.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "dialogs/GUIDialogProgress.h" #include "dialogs/GUIDialogSelect.h" #include "guilib/GUIComponent.h" @@ -48,7 +49,7 @@ void CControllerInstaller::Process() ADDON::VECADDONS installableAddons; CServiceBroker::GetAddonMgr().GetInstallableAddons(installableAddons, - ADDON::ADDON_GAME_CONTROLLER); + ADDON::AddonType::GAME_CONTROLLER); if (installableAddons.empty()) { // "Controller profiles" diff --git a/xbmc/games/controllers/windows/GUIControllerWindow.cpp b/xbmc/games/controllers/windows/GUIControllerWindow.cpp index 724dd1bf61..6b2d2ac744 100644 --- a/xbmc/games/controllers/windows/GUIControllerWindow.cpp +++ b/xbmc/games/controllers/windows/GUIControllerWindow.cpp @@ -14,6 +14,7 @@ #include "ServiceBroker.h" #include "addons/AddonManager.h" #include "addons/IAddon.h" +#include "addons/addoninfo/AddonType.h" #include "addons/gui/GUIWindowAddonBrowser.h" #include "cores/RetroPlayer/guibridge/GUIGameRenderManager.h" #include "cores/RetroPlayer/guibridge/GUIGameSettingsHandle.h" @@ -206,7 +207,7 @@ void CGUIControllerWindow::OnEvent(const ADDON::AddonEvent& event) typeid(event) == typeid(AddonEvents::UnInstalled) || typeid(event) == typeid(AddonEvents::ReInstalled)) { - if (CServiceBroker::GetAddonMgr().HasType(event.addonId, ADDON_GAME_CONTROLLER)) + if (CServiceBroker::GetAddonMgr().HasType(event.addonId, AddonType::GAME_CONTROLLER)) { UpdateButtons(); } @@ -223,7 +224,7 @@ void CGUIControllerWindow::OnInitWindow(void) { ADDON::AddonPtr addon; if (CServiceBroker::GetAddonMgr().GetAddon(gameSettingsHandle->GameClientID(), addon, - ADDON::ADDON_GAMEDLL, + ADDON::AddonType::GAMEDLL, ADDON::OnlyEnabled::CHOICE_YES)) gameClient = std::static_pointer_cast<CGameClient>(addon); } @@ -326,9 +327,9 @@ void CGUIControllerWindow::UpdateButtons(void) } else { - const bool bEnable = - CServiceBroker::GetAddonMgr().GetInstallableAddons(addons, ADDON::ADDON_GAME_CONTROLLER) && - !addons.empty(); + const bool bEnable = CServiceBroker::GetAddonMgr().GetInstallableAddons( + addons, ADDON::AddonType::GAME_CONTROLLER) && + !addons.empty(); CONTROL_ENABLE_ON_CONDITION(CONTROL_GET_MORE, bEnable); CONTROL_ENABLE_ON_CONDITION(CONTROL_GET_ALL, bEnable); } @@ -337,8 +338,8 @@ void CGUIControllerWindow::UpdateButtons(void) void CGUIControllerWindow::GetMoreControllers(void) { std::string strAddonId; - if (CGUIWindowAddonBrowser::SelectAddonID(ADDON::ADDON_GAME_CONTROLLER, strAddonId, false, true, - false, true, false) < 0) + if (CGUIWindowAddonBrowser::SelectAddonID(ADDON::AddonType::GAME_CONTROLLER, strAddonId, false, + true, false, true, false) < 0) { // "Controller profiles" // "All available controller profiles are installed." diff --git a/xbmc/games/dialogs/osd/DialogGameAdvancedSettings.cpp b/xbmc/games/dialogs/osd/DialogGameAdvancedSettings.cpp index dd3fc7f307..83b7a3fe8f 100644 --- a/xbmc/games/dialogs/osd/DialogGameAdvancedSettings.cpp +++ b/xbmc/games/dialogs/osd/DialogGameAdvancedSettings.cpp @@ -10,6 +10,7 @@ #include "ServiceBroker.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "addons/gui/GUIDialogAddonSettings.h" #include "cores/RetroPlayer/guibridge/GUIGameRenderManager.h" #include "cores/RetroPlayer/guibridge/GUIGameSettingsHandle.h" @@ -35,7 +36,7 @@ bool CDialogGameAdvancedSettings::OnMessage(CGUIMessage& message) { ADDON::AddonPtr addon; if (CServiceBroker::GetAddonMgr().GetAddon(gameSettingsHandle->GameClientID(), addon, - ADDON::ADDON_GAMEDLL, + ADDON::AddonType::GAMEDLL, ADDON::OnlyEnabled::CHOICE_YES)) { gameSettingsHandle.reset(); diff --git a/xbmc/games/ports/windows/GUIPortWindow.cpp b/xbmc/games/ports/windows/GUIPortWindow.cpp index 47e7aa347b..9dabb53e4b 100644 --- a/xbmc/games/ports/windows/GUIPortWindow.cpp +++ b/xbmc/games/ports/windows/GUIPortWindow.cpp @@ -13,6 +13,7 @@ #include "ServiceBroker.h" #include "addons/AddonManager.h" #include "addons/IAddon.h" +#include "addons/addoninfo/AddonType.h" #include "cores/RetroPlayer/guibridge/GUIGameRenderManager.h" #include "cores/RetroPlayer/guibridge/GUIGameSettingsHandle.h" #include "games/addons/GameClient.h" @@ -119,7 +120,7 @@ void CGUIPortWindow::OnInitWindow() { ADDON::AddonPtr addon; if (CServiceBroker::GetAddonMgr().GetAddon(gameSettingsHandle->GameClientID(), addon, - ADDON::ADDON_GAMEDLL, + ADDON::AddonType::GAMEDLL, ADDON::OnlyEnabled::CHOICE_YES)) gameClient = std::static_pointer_cast<CGameClient>(addon); } diff --git a/xbmc/guilib/GUIAudioManager.cpp b/xbmc/guilib/GUIAudioManager.cpp index b59f76737d..7f461c4d1b 100644 --- a/xbmc/guilib/GUIAudioManager.cpp +++ b/xbmc/guilib/GUIAudioManager.cpp @@ -11,6 +11,7 @@ #include "ServiceBroker.h" #include "addons/AddonManager.h" #include "addons/Skin.h" +#include "addons/addoninfo/AddonType.h" #include "cores/AudioEngine/Interfaces/AE.h" #include "filesystem/Directory.h" #include "input/Key.h" @@ -210,7 +211,7 @@ std::string GetSoundSkinPath() return ""; ADDON::AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(value, addon, ADDON::ADDON_RESOURCE_UISOUNDS, + if (!CServiceBroker::GetAddonMgr().GetAddon(value, addon, ADDON::AddonType::RESOURCE_UISOUNDS, ADDON::OnlyEnabled::CHOICE_YES)) { CLog::Log(LOGINFO, "Unknown sounds addon '{}'. Setting default sounds.", value); diff --git a/xbmc/guilib/GUIFontManager.cpp b/xbmc/guilib/GUIFontManager.cpp index 921fff1262..605b9c8540 100644 --- a/xbmc/guilib/GUIFontManager.cpp +++ b/xbmc/guilib/GUIFontManager.cpp @@ -14,6 +14,7 @@ #include "addons/AddonManager.h" #include "addons/FontResource.h" #include "addons/Skin.h" +#include "addons/addoninfo/AddonType.h" #include "windowing/GraphicContext.h" #include <mutex> @@ -178,7 +179,7 @@ CGUIFont* GUIFontManager::LoadTTF(const std::string& strFontName, !CheckFont(strPath, "special://xbmc/media/Fonts", file)) { VECADDONS addons; - CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON_RESOURCE_FONT); + CServiceBroker::GetAddonMgr().GetAddons(addons, AddonType::RESOURCE_FONT); for (auto& it : addons) { std::shared_ptr<CFontResource> font(std::static_pointer_cast<CFontResource>(it)); diff --git a/xbmc/guilib/GUIVisualisationControl.cpp b/xbmc/guilib/GUIVisualisationControl.cpp index 21d68485d3..0399edde0c 100644 --- a/xbmc/guilib/GUIVisualisationControl.cpp +++ b/xbmc/guilib/GUIVisualisationControl.cpp @@ -15,6 +15,7 @@ #include "ServiceBroker.h" #include "addons/AddonManager.h" #include "addons/Visualization.h" +#include "addons/addoninfo/AddonType.h" #include "application/Application.h" #include "application/ApplicationComponents.h" #include "application/ApplicationPlayer.h" @@ -362,7 +363,7 @@ bool CGUIVisualisationControl::InitVisualization() const std::string addon = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString( CSettings::SETTING_MUSICPLAYER_VISUALISATION); const ADDON::AddonInfoPtr addonBase = - CServiceBroker::GetAddonMgr().GetAddonInfo(addon, ADDON::ADDON_VIZ); + CServiceBroker::GetAddonMgr().GetAddonInfo(addon, ADDON::AddonType::VISUALIZATION); if (!addonBase) return false; diff --git a/xbmc/guilib/guiinfo/AddonsGUIInfo.cpp b/xbmc/guilib/guiinfo/AddonsGUIInfo.cpp index 35c092ae86..6630fa14d8 100644 --- a/xbmc/guilib/guiinfo/AddonsGUIInfo.cpp +++ b/xbmc/guilib/guiinfo/AddonsGUIInfo.cpp @@ -147,7 +147,7 @@ bool CAddonsGUIInfo::GetLabel(std::string& value, const CFileItem *item, int con case ADDON_SETTING_STRING: { ADDON::AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(info.GetData3(), addon, ADDON::ADDON_UNKNOWN, + if (!CServiceBroker::GetAddonMgr().GetAddon(info.GetData3(), addon, ADDON::OnlyEnabled::CHOICE_YES)) { return false; @@ -169,8 +169,8 @@ bool CAddonsGUIInfo::GetLabel(std::string& value, const CFileItem *item, int con ADDON::AddonPtr addon; if (!info.GetData3().empty()) { - bool success = CServiceBroker::GetAddonMgr().GetAddon( - info.GetData3(), addon, ADDON::ADDON_UNKNOWN, ADDON::OnlyEnabled::CHOICE_YES); + bool success = CServiceBroker::GetAddonMgr().GetAddon(info.GetData3(), addon, + ADDON::OnlyEnabled::CHOICE_YES); if (!success || !addon) break; @@ -207,7 +207,7 @@ bool CAddonsGUIInfo::GetInt(int& value, const CGUIListItem *gitem, int contextWi case ADDON_SETTING_INT: { ADDON::AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(info.GetData3(), addon, ADDON::ADDON_UNKNOWN, + if (!CServiceBroker::GetAddonMgr().GetAddon(info.GetData3(), addon, ADDON::OnlyEnabled::CHOICE_YES)) { return false; @@ -228,7 +228,7 @@ bool CAddonsGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int context case ADDON_SETTING_BOOL: { ADDON::AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(info.GetData3(), addon, ADDON::ADDON_UNKNOWN, + if (!CServiceBroker::GetAddonMgr().GetAddon(info.GetData3(), addon, ADDON::OnlyEnabled::CHOICE_YES)) { return false; @@ -248,7 +248,7 @@ bool CAddonsGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int context { value = false; ADDON::AddonPtr addon; - if (CServiceBroker::GetAddonMgr().GetAddon(info.GetData3(), addon, ADDON::ADDON_UNKNOWN, + if (CServiceBroker::GetAddonMgr().GetAddon(info.GetData3(), addon, ADDON::OnlyEnabled::CHOICE_YES)) value = !CServiceBroker::GetAddonMgr().IsAddonDisabled(info.GetData3()); return true; diff --git a/xbmc/guilib/guiinfo/SystemGUIInfo.cpp b/xbmc/guilib/guiinfo/SystemGUIInfo.cpp index 781092fb12..bc01047b3b 100644 --- a/xbmc/guilib/guiinfo/SystemGUIInfo.cpp +++ b/xbmc/guilib/guiinfo/SystemGUIInfo.cpp @@ -13,6 +13,7 @@ #include "LangInfo.h" #include "ServiceBroker.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "application/AppParams.h" #include "application/ApplicationComponents.h" #include "application/ApplicationPowerHandling.h" @@ -613,7 +614,7 @@ bool CSystemGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int context value = true; return true; case SYSTEM_HAS_PVR_ADDON: - value = CServiceBroker::GetAddonMgr().HasAddons(ADDON::ADDON_PVRDLL); + value = CServiceBroker::GetAddonMgr().HasAddons(ADDON::AddonType::PVRDLL); return true; case SYSTEM_HAS_CMS: #if defined(HAS_GL) || defined(HAS_DX) diff --git a/xbmc/guilib/guiinfo/VisualisationGUIInfo.cpp b/xbmc/guilib/guiinfo/VisualisationGUIInfo.cpp index 2fe972255d..27a892f106 100644 --- a/xbmc/guilib/guiinfo/VisualisationGUIInfo.cpp +++ b/xbmc/guilib/guiinfo/VisualisationGUIInfo.cpp @@ -10,6 +10,7 @@ #include "GUIUserMessages.h" #include "ServiceBroker.h" +#include "addons/Addon.h" #include "addons/AddonManager.h" #include "guilib/GUIComponent.h" #include "guilib/GUIVisualisationControl.h" @@ -54,8 +55,7 @@ bool CVisualisationGUIInfo::GetLabel(std::string& value, const CFileItem *item, { ADDON::AddonPtr addon; value = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_MUSICPLAYER_VISUALISATION); - if (CServiceBroker::GetAddonMgr().GetAddon(value, addon, ADDON::ADDON_UNKNOWN, - ADDON::OnlyEnabled::CHOICE_YES) && + if (CServiceBroker::GetAddonMgr().GetAddon(value, addon, ADDON::OnlyEnabled::CHOICE_YES) && addon) { value = addon->Name(); diff --git a/xbmc/guilib/imagefactory.cpp b/xbmc/guilib/imagefactory.cpp index fbd8f1f95e..81567825f8 100644 --- a/xbmc/guilib/imagefactory.cpp +++ b/xbmc/guilib/imagefactory.cpp @@ -11,6 +11,7 @@ #include "ServiceBroker.h" #include "addons/ExtsMimeSupportList.h" #include "addons/ImageDecoder.h" +#include "addons/addoninfo/AddonType.h" #include "guilib/FFmpegImage.h" #include "utils/Mime.h" @@ -41,7 +42,7 @@ IImage* ImageFactory::CreateLoaderFromMimeType(const std::string& strMimeType) for (const auto& addonInfo : addonInfos) { // Check asked and given mime type is supported by only for here allowed imagedecoder addons. - if (addonInfo.first != ADDON::ADDON_IMAGEDECODER) + if (addonInfo.first != ADDON::AddonType::IMAGEDECODER) continue; std::unique_lock<CCriticalSection> lock(m_createSec); diff --git a/xbmc/interfaces/builtins/AddonBuiltins.cpp b/xbmc/interfaces/builtins/AddonBuiltins.cpp index 66b34d69e9..056128d2b3 100644 --- a/xbmc/interfaces/builtins/AddonBuiltins.cpp +++ b/xbmc/interfaces/builtins/AddonBuiltins.cpp @@ -18,6 +18,7 @@ #include "addons/PluginSource.h" #include "addons/RepositoryUpdater.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "addons/gui/GUIDialogAddonSettings.h" #include "addons/gui/GUIWindowAddonBrowser.h" #include "application/Application.h" @@ -71,8 +72,7 @@ static int EnableAddon(const std::vector<std::string>& params) return -1; AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(addonid, addon, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_NO)) + if (!CServiceBroker::GetAddonMgr().GetAddon(addonid, addon, OnlyEnabled::CHOICE_NO)) return -1; auto response = HELPERS::ShowYesNoDialogLines(CVariant{24076}, CVariant{24135}, CVariant{addon->Name()}, CVariant{24136}); @@ -119,10 +119,10 @@ static int RunAddon(const std::vector<std::string>& params) const std::string& addonid = params[0]; AddonPtr addon; - if (CServiceBroker::GetAddonMgr().GetAddon(addonid, addon, ADDON_PLUGIN, + if (CServiceBroker::GetAddonMgr().GetAddon(addonid, addon, AddonType::PLUGIN, OnlyEnabled::CHOICE_YES)) { - PluginPtr plugin = std::dynamic_pointer_cast<CPluginSource>(addon); + const auto plugin = std::dynamic_pointer_cast<CPluginSource>(addon); std::string urlParameters; std::vector<std::string> parameters; if (params.size() == 2 && @@ -162,13 +162,13 @@ static int RunAddon(const std::vector<std::string>& params) cmd = StringUtils::Format("RunPlugin({})", StringUtils::Join(params, ",")); CBuiltins::GetInstance().Execute(cmd); } - else if (CServiceBroker::GetAddonMgr().GetAddon(addonid, addon, ADDON_SCRIPT, + else if (CServiceBroker::GetAddonMgr().GetAddon(addonid, addon, AddonType::SCRIPT, OnlyEnabled::CHOICE_YES) || - CServiceBroker::GetAddonMgr().GetAddon(addonid, addon, ADDON_SCRIPT_WEATHER, + CServiceBroker::GetAddonMgr().GetAddon(addonid, addon, AddonType::SCRIPT_WEATHER, OnlyEnabled::CHOICE_YES) || - CServiceBroker::GetAddonMgr().GetAddon(addonid, addon, ADDON_SCRIPT_LYRICS, + CServiceBroker::GetAddonMgr().GetAddon(addonid, addon, AddonType::SCRIPT_LYRICS, OnlyEnabled::CHOICE_YES) || - CServiceBroker::GetAddonMgr().GetAddon(addonid, addon, ADDON_SCRIPT_LIBRARY, + CServiceBroker::GetAddonMgr().GetAddon(addonid, addon, AddonType::SCRIPT_LIBRARY, OnlyEnabled::CHOICE_YES)) { // Pass the script name (addonid) and all the parameters @@ -176,7 +176,7 @@ static int RunAddon(const std::vector<std::string>& params) CBuiltins::GetInstance().Execute( StringUtils::Format("RunScript({})", StringUtils::Join(params, ","))); } - else if (CServiceBroker::GetAddonMgr().GetAddon(addonid, addon, ADDON_GAMEDLL, + else if (CServiceBroker::GetAddonMgr().GetAddon(addonid, addon, AddonType::GAMEDLL, OnlyEnabled::CHOICE_YES)) { CFileItem item; @@ -239,17 +239,16 @@ static int RunScript(const std::vector<std::string>& params) AddonPtr addon; std::string scriptpath; // Test to see if the param is an addon ID - if (CServiceBroker::GetAddonMgr().GetAddon(params[0], addon, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_YES)) + if (CServiceBroker::GetAddonMgr().GetAddon(params[0], addon, OnlyEnabled::CHOICE_YES)) { //Get the correct extension point to run - if (CServiceBroker::GetAddonMgr().GetAddon(params[0], addon, ADDON_SCRIPT, + if (CServiceBroker::GetAddonMgr().GetAddon(params[0], addon, AddonType::SCRIPT, OnlyEnabled::CHOICE_YES) || - CServiceBroker::GetAddonMgr().GetAddon(params[0], addon, ADDON_SCRIPT_WEATHER, + CServiceBroker::GetAddonMgr().GetAddon(params[0], addon, AddonType::SCRIPT_WEATHER, OnlyEnabled::CHOICE_YES) || - CServiceBroker::GetAddonMgr().GetAddon(params[0], addon, ADDON_SCRIPT_LYRICS, + CServiceBroker::GetAddonMgr().GetAddon(params[0], addon, AddonType::SCRIPT_LYRICS, OnlyEnabled::CHOICE_YES) || - CServiceBroker::GetAddonMgr().GetAddon(params[0], addon, ADDON_SCRIPT_LIBRARY, + CServiceBroker::GetAddonMgr().GetAddon(params[0], addon, AddonType::SCRIPT_LIBRARY, OnlyEnabled::CHOICE_YES)) { scriptpath = addon->LibPath(); @@ -257,8 +256,7 @@ static int RunScript(const std::vector<std::string>& params) else { // Run a random extension point (old behaviour). - if (CServiceBroker::GetAddonMgr().GetAddon(params[0], addon, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_YES)) + if (CServiceBroker::GetAddonMgr().GetAddon(params[0], addon, OnlyEnabled::CHOICE_YES)) { scriptpath = addon->LibPath(); CLog::Log(LOGWARNING, @@ -293,11 +291,11 @@ static int RunScript(const std::vector<std::string>& params) static int OpenDefaultSettings(const std::vector<std::string>& params) { AddonPtr addon; - ADDON::TYPE type = CAddonInfo::TranslateType(params[0]); + AddonType type = CAddonInfo::TranslateType(params[0]); if (CAddonSystemSettings::GetInstance().GetActive(type, addon)) { bool changed = CGUIDialogAddonSettings::ShowForAddon(addon); - if (type == ADDON_VIZ && changed) + if (type == AddonType::VISUALIZATION && changed) CServiceBroker::GetGUI()->GetWindowManager().SendMessage(GUI_MSG_VISUALISATION_RELOAD, 0, 0); } @@ -311,16 +309,15 @@ static int OpenDefaultSettings(const std::vector<std::string>& params) static int SetDefaultAddon(const std::vector<std::string>& params) { std::string addonID; - TYPE type = CAddonInfo::TranslateType(params[0]); + AddonType type = CAddonInfo::TranslateType(params[0]); bool allowNone = false; - if (type == ADDON_VIZ) + if (type == AddonType::VISUALIZATION) allowNone = true; - if (type != ADDON_UNKNOWN && - CGUIWindowAddonBrowser::SelectAddonID(type,addonID,allowNone)) + if (type != AddonType::UNKNOWN && CGUIWindowAddonBrowser::SelectAddonID(type, addonID, allowNone)) { CAddonSystemSettings::GetInstance().SetActive(type, addonID); - if (type == ADDON_VIZ) + if (type == AddonType::VISUALIZATION) CServiceBroker::GetGUI()->GetWindowManager().SendMessage(GUI_MSG_VISUALISATION_RELOAD, 0, 0); } @@ -334,8 +331,7 @@ static int SetDefaultAddon(const std::vector<std::string>& params) static int AddonSettings(const std::vector<std::string>& params) { AddonPtr addon; - if (CServiceBroker::GetAddonMgr().GetAddon(params[0], addon, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_YES)) + if (CServiceBroker::GetAddonMgr().GetAddon(params[0], addon, OnlyEnabled::CHOICE_YES)) CGUIDialogAddonSettings::ShowForAddon(addon); return 0; @@ -363,8 +359,7 @@ static int StopScript(const std::vector<std::string>& params) std::string scriptpath(params[0]); // Test to see if the param is an addon ID AddonPtr script; - if (CServiceBroker::GetAddonMgr().GetAddon(params[0], script, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_YES)) + if (CServiceBroker::GetAddonMgr().GetAddon(params[0], script, OnlyEnabled::CHOICE_YES)) scriptpath = script->LibPath(); CScriptInvocationManager::GetInstance().Stop(scriptpath); diff --git a/xbmc/interfaces/builtins/SkinBuiltins.cpp b/xbmc/interfaces/builtins/SkinBuiltins.cpp index ef708d5b5d..5b2b4c2fd9 100644 --- a/xbmc/interfaces/builtins/SkinBuiltins.cpp +++ b/xbmc/interfaces/builtins/SkinBuiltins.cpp @@ -13,6 +13,7 @@ #include "URL.h" #include "Util.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "addons/gui/GUIWindowAddonBrowser.h" #include "application/ApplicationComponents.h" #include "application/ApplicationSkinHandling.h" @@ -80,11 +81,11 @@ static int ToggleSetting(const std::vector<std::string>& params) static int SetAddon(const std::vector<std::string>& params) { int string = CSkinSettings::GetInstance().TranslateString(params[0]); - std::vector<ADDON::TYPE> types; + std::vector<ADDON::AddonType> types; for (unsigned int i = 1 ; i < params.size() ; i++) { - ADDON::TYPE type = CAddonInfo::TranslateType(params[i]); - if (type != ADDON_UNKNOWN) + ADDON::AddonType type = CAddonInfo::TranslateType(params[i]); + if (type != AddonType::UNKNOWN) types.push_back(type); } std::string result; @@ -230,8 +231,8 @@ static int SetFile(const std::vector<std::string>& params) // as contenttype string see IAddon.h & ADDON::TranslateXX std::string strMask = (params.size() > 1) ? params[1] : ""; StringUtils::ToLower(strMask); - ADDON::TYPE type; - if ((type = CAddonInfo::TranslateType(strMask)) != ADDON_UNKNOWN) + ADDON::AddonType type; + if ((type = CAddonInfo::TranslateType(strMask)) != AddonType::UNKNOWN) { CURL url; url.SetProtocol("addons"); @@ -242,7 +243,7 @@ static int SetFile(const std::vector<std::string>& params) StringUtils::ToLower(content); url.SetPassword(content); std::string strMask; - if (type == ADDON_SCRIPT) + if (type == AddonType::SCRIPT) strMask = ".py"; std::string replace; if (CGUIDialogFileBrowser::ShowAndGetFile(url.Get(), strMask, CAddonInfo::TranslateType(type, true), replace, true, true, true)) diff --git a/xbmc/interfaces/json-rpc/AddonsOperations.cpp b/xbmc/interfaces/json-rpc/AddonsOperations.cpp index 47e469a603..db6c90a191 100644 --- a/xbmc/interfaces/json-rpc/AddonsOperations.cpp +++ b/xbmc/interfaces/json-rpc/AddonsOperations.cpp @@ -15,6 +15,7 @@ #include "addons/AddonManager.h" #include "addons/PluginSource.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "messaging/ApplicationMessenger.h" #include "utils/FileUtils.h" #include "utils/StringUtils.h" @@ -25,41 +26,41 @@ using namespace ADDON; JSONRPC_STATUS CAddonsOperations::GetAddons(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { - std::vector<TYPE> addonTypes; - TYPE addonType = CAddonInfo::TranslateType(parameterObject["type"].asString()); + std::vector<AddonType> addonTypes; + AddonType addonType = CAddonInfo::TranslateType(parameterObject["type"].asString()); CPluginSource::Content content = CPluginSource::Translate(parameterObject["content"].asString()); CVariant enabled = parameterObject["enabled"]; CVariant installed = parameterObject["installed"]; // ignore the "content" parameter if the type is specified but not a plugin or script - if (addonType != ADDON_UNKNOWN && addonType != ADDON_PLUGIN && addonType != ADDON_SCRIPT) + if (addonType != AddonType::UNKNOWN && addonType != AddonType::PLUGIN && + addonType != AddonType::SCRIPT) content = CPluginSource::UNKNOWN; - if (addonType >= ADDON_VIDEO && addonType <= ADDON_EXECUTABLE) + if (addonType >= AddonType::VIDEO && addonType <= AddonType::EXECUTABLE) { - addonTypes.push_back(ADDON_PLUGIN); - addonTypes.push_back(ADDON_SCRIPT); + addonTypes.push_back(AddonType::PLUGIN); + addonTypes.push_back(AddonType::SCRIPT); switch (addonType) { - case ADDON_VIDEO: - content = CPluginSource::VIDEO; - break; - case ADDON_AUDIO: - content = CPluginSource::AUDIO; - break; - case ADDON_IMAGE: - content = CPluginSource::IMAGE; - break; - case ADDON_GAME: - content = CPluginSource::GAME; - break; - case ADDON_EXECUTABLE: - content = CPluginSource::EXECUTABLE; - break; - - default: - break; + case AddonType::VIDEO: + content = CPluginSource::VIDEO; + break; + case AddonType::AUDIO: + content = CPluginSource::AUDIO; + break; + case AddonType::IMAGE: + content = CPluginSource::IMAGE; + break; + case AddonType::GAME: + content = CPluginSource::GAME; + break; + case AddonType::EXECUTABLE: + content = CPluginSource::EXECUTABLE; + break; + default: + break; } } else @@ -69,7 +70,7 @@ JSONRPC_STATUS CAddonsOperations::GetAddons(const std::string &method, ITranspor for (const auto& typeIt : addonTypes) { VECADDONS typeAddons; - if (typeIt == ADDON_UNKNOWN) + if (typeIt == AddonType::UNKNOWN) { if (!enabled.isBoolean()) //All { @@ -104,12 +105,14 @@ JSONRPC_STATUS CAddonsOperations::GetAddons(const std::string &method, ITranspor // remove library addons for (int index = 0; index < (int)addons.size(); index++) { - PluginPtr plugin; + std::shared_ptr<CPluginSource> plugin; if (content != CPluginSource::UNKNOWN) plugin = std::dynamic_pointer_cast<CPluginSource>(addons.at(index)); - if ((addons.at(index)->Type() <= ADDON_UNKNOWN || addons.at(index)->Type() >= ADDON_MAX) || - ((content != CPluginSource::UNKNOWN && plugin == NULL) || (plugin != NULL && !plugin->Provides(content)))) + if ((addons.at(index)->Type() <= AddonType::UNKNOWN || + addons.at(index)->Type() >= AddonType::MAX_TYPES) || + ((content != CPluginSource::UNKNOWN && plugin == NULL) || + (plugin != NULL && !plugin->Provides(content)))) { addons.erase(addons.begin() + index); index--; @@ -130,9 +133,9 @@ JSONRPC_STATUS CAddonsOperations::GetAddonDetails(const std::string &method, ITr { std::string id = parameterObject["addonid"].asString(); AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(id, addon, ADDON::ADDON_UNKNOWN, - OnlyEnabled::CHOICE_NO) || - addon.get() == NULL || addon->Type() <= ADDON_UNKNOWN || addon->Type() >= ADDON_MAX) + if (!CServiceBroker::GetAddonMgr().GetAddon(id, addon, OnlyEnabled::CHOICE_NO) || + addon.get() == NULL || addon->Type() <= AddonType::UNKNOWN || + addon->Type() >= AddonType::MAX_TYPES) return InvalidParams; CAddonDatabase addondb; @@ -145,9 +148,9 @@ JSONRPC_STATUS CAddonsOperations::SetAddonEnabled(const std::string &method, ITr { std::string id = parameterObject["addonid"].asString(); AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(id, addon, ADDON::ADDON_UNKNOWN, - OnlyEnabled::CHOICE_NO) || - addon == nullptr || addon->Type() <= ADDON_UNKNOWN || addon->Type() >= ADDON_MAX) + if (!CServiceBroker::GetAddonMgr().GetAddon(id, addon, OnlyEnabled::CHOICE_NO) || + addon == nullptr || addon->Type() <= AddonType::UNKNOWN || + addon->Type() >= AddonType::MAX_TYPES) return InvalidParams; bool disabled = false; @@ -176,8 +179,9 @@ JSONRPC_STATUS CAddonsOperations::ExecuteAddon(const std::string &method, ITrans { std::string id = parameterObject["addonid"].asString(); AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(id, addon, ADDON_UNKNOWN, OnlyEnabled::CHOICE_YES) || - addon.get() == NULL || addon->Type() < ADDON_VIZ || addon->Type() >= ADDON_MAX) + if (!CServiceBroker::GetAddonMgr().GetAddon(id, addon, OnlyEnabled::CHOICE_YES) || + addon.get() == NULL || addon->Type() < AddonType::VISUALIZATION || + addon->Type() >= AddonType::MAX_TYPES) return InvalidParams; std::string argv; diff --git a/xbmc/interfaces/json-rpc/GUIOperations.cpp b/xbmc/interfaces/json-rpc/GUIOperations.cpp index d397a7ee7a..06b1f7505b 100644 --- a/xbmc/interfaces/json-rpc/GUIOperations.cpp +++ b/xbmc/interfaces/json-rpc/GUIOperations.cpp @@ -11,6 +11,8 @@ #include "GUIInfoManager.h" #include "ServiceBroker.h" #include "addons/AddonManager.h" +#include "addons/IAddon.h" +#include "addons/addoninfo/AddonType.h" #include "application/Application.h" #include "dialogs/GUIDialogKaiToast.h" #include "guilib/GUIComponent.h" @@ -143,7 +145,8 @@ JSONRPC_STATUS CGUIOperations::GetPropertyValue(const std::string &property, CVa { std::string skinId = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_LOOKANDFEEL_SKIN); AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon(skinId, addon, ADDON_SKIN, OnlyEnabled::CHOICE_YES)) + if (!CServiceBroker::GetAddonMgr().GetAddon(skinId, addon, AddonType::SKIN, + OnlyEnabled::CHOICE_YES)) return InternalError; result["id"] = skinId; diff --git a/xbmc/interfaces/json-rpc/JSONRPC.cpp b/xbmc/interfaces/json-rpc/JSONRPC.cpp index e95900533c..4b861887a4 100644 --- a/xbmc/interfaces/json-rpc/JSONRPC.cpp +++ b/xbmc/interfaces/json-rpc/JSONRPC.cpp @@ -16,6 +16,7 @@ #include "addons/Addon.h" #include "addons/IAddon.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "dbwrappers/DatabaseQuery.h" #include "guilib/GUIComponent.h" #include "guilib/GUIMessage.h" @@ -43,8 +44,10 @@ void CJSONRPC::Initialize() // Add some types/enums at runtime std::vector<std::string> enumList; - for (int addonType = ADDON::ADDON_UNKNOWN; addonType < ADDON::ADDON_MAX; addonType++) - enumList.push_back(ADDON::CAddonInfo::TranslateType(static_cast<ADDON::TYPE>(addonType), false)); + for (int addonType = static_cast<int>(ADDON::AddonType::UNKNOWN); + addonType < static_cast<int>(ADDON::AddonType::MAX_TYPES); addonType++) + enumList.push_back( + ADDON::CAddonInfo::TranslateType(static_cast<ADDON::AddonType>(addonType), false)); CJSONServiceDescription::AddEnum("Addon.Types", enumList); enumList.clear(); diff --git a/xbmc/interfaces/legacy/Addon.cpp b/xbmc/interfaces/legacy/Addon.cpp index 37b01a267c..4b4db1e108 100644 --- a/xbmc/interfaces/legacy/Addon.cpp +++ b/xbmc/interfaces/legacy/Addon.cpp @@ -65,8 +65,7 @@ namespace XBMCAddon throw AddonException("No valid addon id could be obtained. None was passed and the script " "wasn't executed in a normal Kodi manner."); - if (!CServiceBroker::GetAddonMgr().GetAddon(id, pAddon, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_YES)) + if (!CServiceBroker::GetAddonMgr().GetAddon(id, pAddon, OnlyEnabled::CHOICE_YES)) throw AddonException("Unknown addon id '%s'.", id.c_str()); CServiceBroker::GetAddonMgr().AddToUpdateableAddons(pAddon); diff --git a/xbmc/interfaces/legacy/WindowXML.cpp b/xbmc/interfaces/legacy/WindowXML.cpp index 11e57b3368..51a4fbf943 100644 --- a/xbmc/interfaces/legacy/WindowXML.cpp +++ b/xbmc/interfaces/legacy/WindowXML.cpp @@ -14,6 +14,7 @@ #include "addons/Addon.h" #include "addons/Skin.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "guilib/GUIComponent.h" #include "guilib/GUIWindowManager.h" #include "guilib/TextureManager.h" @@ -102,7 +103,8 @@ namespace XBMCAddon if (!CFileUtils::Exists(strSkinPath)) { std::string str("none"); - ADDON::AddonInfoPtr addonInfo = std::make_shared<ADDON::CAddonInfo>(str, ADDON::ADDON_SKIN); + ADDON::AddonInfoPtr addonInfo = + std::make_shared<ADDON::CAddonInfo>(str, ADDON::AddonType::SKIN); ADDON::CSkinInfo::TranslateResolution(defaultRes, res); // Check for the matching folder for the skin in the fallback skins folder diff --git a/xbmc/interfaces/python/PythonInvoker.cpp b/xbmc/interfaces/python/PythonInvoker.cpp index f2ce7f6356..55c5181403 100644 --- a/xbmc/interfaces/python/PythonInvoker.cpp +++ b/xbmc/interfaces/python/PythonInvoker.cpp @@ -17,6 +17,7 @@ #include "ServiceBroker.h" #include "addons/AddonManager.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "dialogs/GUIDialogKaiToast.h" #include "filesystem/SpecialProtocol.h" #include "guilib/GUIComponent.h" @@ -219,7 +220,7 @@ bool CPythonInvoker::execute(const std::string& script, std::vector<std::wstring "version.", GetId()); ADDON::VECADDONS addons; - CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON::ADDON_SCRIPT_MODULE); + CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON::AddonType::SCRIPT_MODULE); for (unsigned int i = 0; i < addons.size(); ++i) pythonPath.emplace(CSpecialProtocol::TranslatePath(addons[i]->LibPath())); } @@ -643,7 +644,7 @@ void CPythonInvoker::onPythonModuleInitialization(void* moduleDict) PyObject* pyaddonid = PyUnicode_FromString(m_addon->ID().c_str()); PyDict_SetItemString(moduleDictionary, "__xbmcaddonid__", pyaddonid); - ADDON::AddonVersion version = m_addon->GetDependencyVersion("xbmc.python"); + ADDON::CAddonVersion version = m_addon->GetDependencyVersion("xbmc.python"); PyObject* pyxbmcapiversion = PyUnicode_FromString(version.asString().c_str()); PyDict_SetItemString(moduleDictionary, "__xbmcapiversion__", pyxbmcapiversion); @@ -707,7 +708,7 @@ void CPythonInvoker::getAddonModuleDeps(const ADDON::AddonPtr& addon, std::set<s { //Check if dependency is a module addon ADDON::AddonPtr dependency; - if (CServiceBroker::GetAddonMgr().GetAddon(it.id, dependency, ADDON::ADDON_SCRIPT_MODULE, + if (CServiceBroker::GetAddonMgr().GetAddon(it.id, dependency, ADDON::AddonType::SCRIPT_MODULE, ADDON::OnlyEnabled::CHOICE_YES)) { std::string path = CSpecialProtocol::TranslatePath(dependency->LibPath()); diff --git a/xbmc/music/MusicDatabase.cpp b/xbmc/music/MusicDatabase.cpp index 92346d5ebd..14fefe2591 100644 --- a/xbmc/music/MusicDatabase.cpp +++ b/xbmc/music/MusicDatabase.cpp @@ -11594,7 +11594,7 @@ bool CMusicDatabase::GetScraper(int id, const CONTENT_TYPE& content, ADDON::Scra // Use pre configured or default scraper ADDON::AddonPtr addon; if (!scraperUUID.empty() && - CServiceBroker::GetAddonMgr().GetAddon(scraperUUID, addon, ADDON::ADDON_UNKNOWN, + CServiceBroker::GetAddonMgr().GetAddon(scraperUUID, addon, ADDON::OnlyEnabled::CHOICE_YES) && addon) { diff --git a/xbmc/music/dialogs/GUIDialogInfoProviderSettings.cpp b/xbmc/music/dialogs/GUIDialogInfoProviderSettings.cpp index c5d2eb26d5..a9e223244f 100644 --- a/xbmc/music/dialogs/GUIDialogInfoProviderSettings.cpp +++ b/xbmc/music/dialogs/GUIDialogInfoProviderSettings.cpp @@ -12,6 +12,7 @@ #include "Util.h" #include "addons/AddonManager.h" #include "addons/AddonSystemSettings.h" +#include "addons/addoninfo/AddonType.h" #include "addons/gui/GUIDialogAddonSettings.h" #include "addons/gui/GUIWindowAddonBrowser.h" #include "dialogs/GUIDialogFileBrowser.h" @@ -62,14 +63,16 @@ bool CGUIDialogInfoProviderSettings::Show() ADDON::AddonPtr defaultScraper; // Get default album scraper (when enabled - can default scraper be disabled??) - if (ADDON::CAddonSystemSettings::GetInstance().GetActive(ADDON::ADDON_SCRAPER_ALBUMS, defaultScraper)) + if (ADDON::CAddonSystemSettings::GetInstance().GetActive(ADDON::AddonType::SCRAPER_ALBUMS, + defaultScraper)) { ADDON::ScraperPtr scraper = std::dynamic_pointer_cast<ADDON::CScraper>(defaultScraper); dialog->SetAlbumScraper(scraper); } // Get default artist scraper - if (ADDON::CAddonSystemSettings::GetInstance().GetActive(ADDON::ADDON_SCRAPER_ARTISTS, defaultScraper)) + if (ADDON::CAddonSystemSettings::GetInstance().GetActive(ADDON::AddonType::SCRAPER_ARTISTS, + defaultScraper)) { ADDON::ScraperPtr scraper = std::dynamic_pointer_cast<ADDON::CScraper>(defaultScraper); dialog->SetArtistScraper(scraper); @@ -176,11 +179,12 @@ void CGUIDialogInfoProviderSettings::OnSettingAction(const std::shared_ptr<const currentScraperId = m_albumscraper->ID(); std::string selectedAddonId = currentScraperId; - if (CGUIWindowAddonBrowser::SelectAddonID(ADDON_SCRAPER_ALBUMS, selectedAddonId, false) == 1 - && selectedAddonId != currentScraperId) + if (CGUIWindowAddonBrowser::SelectAddonID(AddonType::SCRAPER_ALBUMS, selectedAddonId, false) == + 1 && + selectedAddonId != currentScraperId) { AddonPtr scraperAddon; - if (CServiceBroker::GetAddonMgr().GetAddon(selectedAddonId, scraperAddon, ADDON_UNKNOWN, + if (CServiceBroker::GetAddonMgr().GetAddon(selectedAddonId, scraperAddon, OnlyEnabled::CHOICE_YES)) { m_albumscraper = std::dynamic_pointer_cast<CScraper>(scraperAddon); @@ -201,11 +205,12 @@ void CGUIDialogInfoProviderSettings::OnSettingAction(const std::shared_ptr<const currentScraperId = m_artistscraper->ID(); std::string selectedAddonId = currentScraperId; - if (CGUIWindowAddonBrowser::SelectAddonID(ADDON_SCRAPER_ARTISTS, selectedAddonId, false) == 1 - && selectedAddonId != currentScraperId) + if (CGUIWindowAddonBrowser::SelectAddonID(AddonType::SCRAPER_ARTISTS, selectedAddonId, false) == + 1 && + selectedAddonId != currentScraperId) { AddonPtr scraperAddon; - if (CServiceBroker::GetAddonMgr().GetAddon(selectedAddonId, scraperAddon, ADDON_UNKNOWN, + if (CServiceBroker::GetAddonMgr().GetAddon(selectedAddonId, scraperAddon, OnlyEnabled::CHOICE_YES)) { m_artistscraper = std::dynamic_pointer_cast<CScraper>(scraperAddon); diff --git a/xbmc/music/dialogs/GUIDialogMusicOSD.cpp b/xbmc/music/dialogs/GUIDialogMusicOSD.cpp index 7e6348103f..6cd110bd27 100644 --- a/xbmc/music/dialogs/GUIDialogMusicOSD.cpp +++ b/xbmc/music/dialogs/GUIDialogMusicOSD.cpp @@ -10,6 +10,7 @@ #include "GUIUserMessages.h" #include "ServiceBroker.h" +#include "addons/addoninfo/AddonType.h" #include "addons/gui/GUIWindowAddonBrowser.h" #include "guilib/GUIComponent.h" #include "guilib/GUIWindowManager.h" @@ -39,7 +40,8 @@ bool CGUIDialogMusicOSD::OnMessage(CGUIMessage &message) if (iControl == CONTROL_VIS_BUTTON) { std::string addonID; - if (CGUIWindowAddonBrowser::SelectAddonID(ADDON::ADDON_VIZ, addonID, true) == 1) + if (CGUIWindowAddonBrowser::SelectAddonID(ADDON::AddonType::VISUALIZATION, addonID, true) == + 1) { const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings(); settings->SetString(CSettings::SETTING_MUSICPLAYER_VISUALISATION, addonID); diff --git a/xbmc/music/infoscanner/MusicInfoScanner.cpp b/xbmc/music/infoscanner/MusicInfoScanner.cpp index bb6477cf50..f828b44914 100644 --- a/xbmc/music/infoscanner/MusicInfoScanner.cpp +++ b/xbmc/music/infoscanner/MusicInfoScanner.cpp @@ -20,6 +20,7 @@ #include "Util.h" #include "addons/AddonSystemSettings.h" #include "addons/Scraper.h" +#include "addons/addoninfo/AddonType.h" #include "dialogs/GUIDialogExtendedProgressBar.h" #include "dialogs/GUIDialogProgress.h" #include "dialogs/GUIDialogSelect.h" @@ -995,10 +996,11 @@ void MUSIC_INFO::CMusicInfoScanner::ScrapeInfoAddedAlbums() ADDON::ScraperPtr albumScraper; ADDON::ScraperPtr artistScraper; - if (ADDON::CAddonSystemSettings::GetInstance().GetActive(ADDON::ADDON_SCRAPER_ALBUMS, addon)) + if (ADDON::CAddonSystemSettings::GetInstance().GetActive(ADDON::AddonType::SCRAPER_ALBUMS, addon)) albumScraper = std::dynamic_pointer_cast<ADDON::CScraper>(addon); - if (ADDON::CAddonSystemSettings::GetInstance().GetActive(ADDON::ADDON_SCRAPER_ARTISTS, addon)) + if (ADDON::CAddonSystemSettings::GetInstance().GetActive(ADDON::AddonType::SCRAPER_ARTISTS, + addon)) artistScraper = std::dynamic_pointer_cast<ADDON::CScraper>(addon); bool albumartistsonly = !CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MUSICLIBRARY_SHOWCOMPILATIONARTISTS); diff --git a/xbmc/music/tags/MusicInfoTagLoaderFactory.cpp b/xbmc/music/tags/MusicInfoTagLoaderFactory.cpp index 4abb84ec24..56b2c17c43 100644 --- a/xbmc/music/tags/MusicInfoTagLoaderFactory.cpp +++ b/xbmc/music/tags/MusicInfoTagLoaderFactory.cpp @@ -17,6 +17,7 @@ #include "TagLoaderTagLib.h" #include "addons/AudioDecoder.h" #include "addons/ExtsMimeSupportList.h" +#include "addons/addoninfo/AddonType.h" #include "utils/StringUtils.h" #include "utils/URIUtils.h" @@ -47,7 +48,7 @@ IMusicInfoTagLoader* CMusicInfoTagLoaderFactory::CreateLoader(const CFileItem& i "." + strExtension, CExtsMimeSupportList::FilterSelect::hasTags); for (const auto& addonInfo : addonInfos) { - if (addonInfo.first == ADDON::ADDON_AUDIODECODER) + if (addonInfo.first == ADDON::AddonType::AUDIODECODER) { std::unique_ptr<CAudioDecoder> result = std::make_unique<CAudioDecoder>(addonInfo.second); if (!result->CreateDecoder() && result->SupportsFile(item.GetPath())) diff --git a/xbmc/network/httprequesthandler/HTTPPythonHandler.cpp b/xbmc/network/httprequesthandler/HTTPPythonHandler.cpp index dd64ccfd36..86337447a1 100644 --- a/xbmc/network/httprequesthandler/HTTPPythonHandler.cpp +++ b/xbmc/network/httprequesthandler/HTTPPythonHandler.cpp @@ -11,6 +11,7 @@ #include "ServiceBroker.h" #include "URL.h" #include "addons/Webinterface.h" +#include "addons/addoninfo/AddonType.h" #include "filesystem/File.h" #include "interfaces/generic/ScriptInvocationManager.h" #include "interfaces/python/XBPython.h" @@ -51,8 +52,9 @@ CHTTPPythonHandler::CHTTPPythonHandler(const HTTPRequest &request) // get the real path of the script and check if it actually exists m_response.status = CHTTPWebinterfaceHandler::ResolveUrl(m_request.pathUrl, m_scriptPath, m_addon); // only allow requests to a non-static webinterface addon - if (m_addon == NULL || m_addon->Type() != ADDON::ADDON_WEB_INTERFACE || - std::dynamic_pointer_cast<ADDON::CWebinterface>(m_addon)->GetType() == ADDON::WebinterfaceTypeStatic) + if (m_addon == NULL || m_addon->Type() != ADDON::AddonType::WEB_INTERFACE || + std::dynamic_pointer_cast<ADDON::CWebinterface>(m_addon)->GetType() == + ADDON::WebinterfaceTypeStatic) { m_response.type = HTTPError; m_response.status = MHD_HTTP_INTERNAL_SERVER_ERROR; @@ -102,8 +104,8 @@ bool CHTTPPythonHandler::CanHandleRequest(const HTTPRequest &request) const ADDON::AddonPtr addon; std::string path; // try to resolve the addon as any python script must be part of a webinterface - if (!CHTTPWebinterfaceHandler::ResolveAddon(request.pathUrl, addon, path) || - addon == NULL || addon->Type() != ADDON::ADDON_WEB_INTERFACE) + if (!CHTTPWebinterfaceHandler::ResolveAddon(request.pathUrl, addon, path) || addon == NULL || + addon->Type() != ADDON::AddonType::WEB_INTERFACE) return false; // static webinterfaces aren't allowed to run python scripts diff --git a/xbmc/network/httprequesthandler/HTTPWebinterfaceAddonsHandler.cpp b/xbmc/network/httprequesthandler/HTTPWebinterfaceAddonsHandler.cpp index 7ceac820f3..fa47144ca8 100644 --- a/xbmc/network/httprequesthandler/HTTPWebinterfaceAddonsHandler.cpp +++ b/xbmc/network/httprequesthandler/HTTPWebinterfaceAddonsHandler.cpp @@ -9,7 +9,9 @@ #include "HTTPWebinterfaceAddonsHandler.h" #include "ServiceBroker.h" +#include "addons/Addon.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "network/WebServer.h" #define ADDON_HEADER "<html><head><title>Add-on List</title></head><body>\n<h1>Available web interfaces:</h1>\n<ul>\n" @@ -23,7 +25,8 @@ MHD_RESULT CHTTPWebinterfaceAddonsHandler::HandleRequest() { m_responseData = ADDON_HEADER; ADDON::VECADDONS addons; - if (!CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON::ADDON_WEB_INTERFACE) || addons.empty()) + if (!CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON::AddonType::WEB_INTERFACE) || + addons.empty()) { m_response.type = HTTPError; m_response.status = MHD_HTTP_INTERNAL_SERVER_ERROR; @@ -31,8 +34,8 @@ MHD_RESULT CHTTPWebinterfaceAddonsHandler::HandleRequest() return MHD_YES; } - for (ADDON::IVECADDONS addon = addons.begin(); addon != addons.end(); ++addon) - m_responseData += "<li><a href=/addons/" + (*addon)->ID() + "/>" + (*addon)->Name() + "</a></li>\n"; + for (const auto& addon : addons) + m_responseData += "<li><a href=/addons/" + addon->ID() + "/>" + addon->Name() + "</a></li>\n"; m_responseData += "</ul>\n</body></html>"; diff --git a/xbmc/network/httprequesthandler/HTTPWebinterfaceHandler.cpp b/xbmc/network/httprequesthandler/HTTPWebinterfaceHandler.cpp index 8180244697..fe6e76038c 100644 --- a/xbmc/network/httprequesthandler/HTTPWebinterfaceHandler.cpp +++ b/xbmc/network/httprequesthandler/HTTPWebinterfaceHandler.cpp @@ -12,6 +12,7 @@ #include "addons/AddonManager.h" #include "addons/AddonSystemSettings.h" #include "addons/Webinterface.h" +#include "addons/addoninfo/AddonType.h" #include "filesystem/Directory.h" #include "utils/FileUtils.h" #include "utils/StringUtils.h" @@ -52,7 +53,7 @@ int CHTTPWebinterfaceHandler::ResolveUrl(const std::string &url, std::string &pa if (URIUtils::GetFileName(path).empty()) { // determine the actual file path using the default entry point - if (addon != NULL && addon->Type() == ADDON::ADDON_WEB_INTERFACE) + if (addon != NULL && addon->Type() == ADDON::AddonType::WEB_INTERFACE) path = std::dynamic_pointer_cast<ADDON::CWebinterface>(addon)->GetEntryPoint(path); } else @@ -89,13 +90,14 @@ bool CHTTPWebinterfaceHandler::ResolveAddon(const std::string &url, ADDON::Addon if (components.size() <= 1) return false; - if (!CServiceBroker::GetAddonMgr().GetAddon(components.at(1), addon, ADDON::ADDON_UNKNOWN, + if (!CServiceBroker::GetAddonMgr().GetAddon(components.at(1), addon, ADDON::OnlyEnabled::CHOICE_YES) || addon == NULL) return false; addonPath = addon->Path(); - if (addon->Type() != ADDON::ADDON_WEB_INTERFACE) // No need to append /htdocs for web interfaces + if (addon->Type() != + ADDON::AddonType::WEB_INTERFACE) // No need to append /htdocs for web interfaces addonPath = URIUtils::AddFileToFolder(addonPath, "/htdocs/"); // remove /addons/<addon-id> from the path @@ -104,14 +106,16 @@ bool CHTTPWebinterfaceHandler::ResolveAddon(const std::string &url, ADDON::Addon // determine the path within the addon path = StringUtils::Join(components, WEBSERVER_DIRECTORY_SEPARATOR); } - else if (!ADDON::CAddonSystemSettings::GetInstance().GetActive(ADDON::ADDON_WEB_INTERFACE, addon) || addon == NULL) + else if (!ADDON::CAddonSystemSettings::GetInstance().GetActive(ADDON::AddonType::WEB_INTERFACE, + addon) || + addon == NULL) return false; // get the path of the addon addonPath = addon->Path(); // add /htdocs/ to the addon's path if it's not a webinterface - if (addon->Type() != ADDON::ADDON_WEB_INTERFACE) + if (addon->Type() != ADDON::AddonType::WEB_INTERFACE) addonPath = URIUtils::AddFileToFolder(addonPath, "/htdocs/"); // append the path within the addon to the path of the addon diff --git a/xbmc/network/httprequesthandler/python/HTTPPythonWsgiInvoker.cpp b/xbmc/network/httprequesthandler/python/HTTPPythonWsgiInvoker.cpp index b48c294eb5..ac047a7530 100644 --- a/xbmc/network/httprequesthandler/python/HTTPPythonWsgiInvoker.cpp +++ b/xbmc/network/httprequesthandler/python/HTTPPythonWsgiInvoker.cpp @@ -11,6 +11,7 @@ #include "ServiceBroker.h" #include "URL.h" #include "addons/Webinterface.h" +#include "addons/addoninfo/AddonType.h" #include "interfaces/legacy/wsgi/WsgiErrorStream.h" #include "interfaces/legacy/wsgi/WsgiInputStream.h" #include "interfaces/legacy/wsgi/WsgiResponse.h" @@ -116,7 +117,7 @@ HTTPPythonRequest* CHTTPPythonWsgiInvoker::GetRequest() void CHTTPPythonWsgiInvoker::executeScript(FILE* fp, const std::string& script, PyObject* moduleDict) { - if (m_request == NULL || m_addon == NULL || m_addon->Type() != ADDON::ADDON_WEB_INTERFACE || + if (m_request == NULL || m_addon == NULL || m_addon->Type() != ADDON::AddonType::WEB_INTERFACE || fp == NULL || script.empty() || moduleDict == NULL) return; diff --git a/xbmc/peripherals/Peripherals.cpp b/xbmc/peripherals/Peripherals.cpp index dbc6ff128a..ce5653887a 100644 --- a/xbmc/peripherals/Peripherals.cpp +++ b/xbmc/peripherals/Peripherals.cpp @@ -12,6 +12,7 @@ #include "EventScanner.h" #include "addons/AddonButtonMap.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "addons/gui/GUIDialogAddonSettings.h" #include "addons/gui/GUIWindowAddonBrowser.h" #include "bus/PeripheralBus.h" @@ -967,13 +968,12 @@ void CPeripherals::OnSettingAction(const std::shared_ptr<const CSetting>& settin else if (settingId == CSettings::SETTING_INPUT_PERIPHERALLIBRARIES) { std::string strAddonId; - if (CGUIWindowAddonBrowser::SelectAddonID(ADDON::ADDON_PERIPHERALDLL, strAddonId, false, true, - true, false, true) == 1 && + if (CGUIWindowAddonBrowser::SelectAddonID(ADDON::AddonType::PERIPHERALDLL, strAddonId, false, + true, true, false, true) == 1 && !strAddonId.empty()) { ADDON::AddonPtr addon; - if (CServiceBroker::GetAddonMgr().GetAddon(strAddonId, addon, ADDON::ADDON_UNKNOWN, - ADDON::OnlyEnabled::CHOICE_YES)) + if (CServiceBroker::GetAddonMgr().GetAddon(strAddonId, addon, ADDON::OnlyEnabled::CHOICE_YES)) CGUIDialogAddonSettings::ShowForAddon(addon); } } diff --git a/xbmc/peripherals/addons/PeripheralAddon.cpp b/xbmc/peripherals/addons/PeripheralAddon.cpp index 91c6f2b193..7a55bb37d4 100644 --- a/xbmc/peripherals/addons/PeripheralAddon.cpp +++ b/xbmc/peripherals/addons/PeripheralAddon.cpp @@ -11,6 +11,7 @@ #include "FileItem.h" #include "PeripheralAddonTranslator.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "filesystem/Directory.h" #include "filesystem/SpecialProtocol.h" #include "games/controllers/Controller.h" @@ -56,9 +57,10 @@ CPeripheralAddon::CPeripheralAddon(const ADDON::AddonInfoPtr& addonInfo, CPeriph m_bSupportsJoystickPowerOff(false) { m_bProvidesJoysticks = - addonInfo->Type(ADDON::ADDON_PERIPHERALDLL)->GetValue("@provides_joysticks").asBoolean(); - m_bProvidesButtonMaps = - addonInfo->Type(ADDON::ADDON_PERIPHERALDLL)->GetValue("@provides_buttonmaps").asBoolean(); + addonInfo->Type(ADDON::AddonType::PERIPHERALDLL)->GetValue("@provides_joysticks").asBoolean(); + m_bProvidesButtonMaps = addonInfo->Type(ADDON::AddonType::PERIPHERALDLL) + ->GetValue("@provides_buttonmaps") + .asBoolean(); // Create "C" interface structures, used as own parts to prevent API problems on update m_ifc.peripheral = new AddonInstance_Peripheral; @@ -818,12 +820,16 @@ void CPeripheralAddon::RefreshButtonMaps(const std::string& strDeviceName /* = " bool CPeripheralAddon::ProvidesJoysticks(const ADDON::AddonInfoPtr& addonInfo) { - return addonInfo->Type(ADDON::ADDON_PERIPHERALDLL)->GetValue("@provides_joysticks").asBoolean(); + return addonInfo->Type(ADDON::AddonType::PERIPHERALDLL) + ->GetValue("@provides_joysticks") + .asBoolean(); } bool CPeripheralAddon::ProvidesButtonMaps(const ADDON::AddonInfoPtr& addonInfo) { - return addonInfo->Type(ADDON::ADDON_PERIPHERALDLL)->GetValue("@provides_buttonmaps").asBoolean(); + return addonInfo->Type(ADDON::AddonType::PERIPHERALDLL) + ->GetValue("@provides_buttonmaps") + .asBoolean(); } void CPeripheralAddon::TriggerDeviceScan() diff --git a/xbmc/peripherals/bus/virtual/PeripheralBusAddon.cpp b/xbmc/peripherals/bus/virtual/PeripheralBusAddon.cpp index cc2f6ea6e6..2162c458f5 100644 --- a/xbmc/peripherals/bus/virtual/PeripheralBusAddon.cpp +++ b/xbmc/peripherals/bus/virtual/PeripheralBusAddon.cpp @@ -12,6 +12,7 @@ #include "addons/AddonEvents.h" #include "addons/AddonManager.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "messaging/helpers/DialogHelper.h" #include "peripherals/Peripherals.h" #include "peripherals/addons/PeripheralAddon.h" @@ -181,7 +182,7 @@ void CPeripheralBusAddon::EnableButtonMapping() if (!GetAddonWithButtonMap(dummy)) { std::vector<AddonInfoPtr> disabledAddons; - CServiceBroker::GetAddonMgr().GetDisabledAddonInfos(disabledAddons, ADDON_PERIPHERALDLL); + CServiceBroker::GetAddonMgr().GetDisabledAddonInfos(disabledAddons, AddonType::PERIPHERALDLL); if (!disabledAddons.empty()) PromptEnableAddons(disabledAddons); } @@ -326,12 +327,12 @@ void CPeripheralBusAddon::OnEvent(const ADDON::AddonEvent& event) if (typeid(event) == typeid(ADDON::AddonEvents::Enabled) || typeid(event) == typeid(ADDON::AddonEvents::ReInstalled)) { - if (CServiceBroker::GetAddonMgr().HasType(event.addonId, ADDON::ADDON_PERIPHERALDLL)) + if (CServiceBroker::GetAddonMgr().HasType(event.addonId, ADDON::AddonType::PERIPHERALDLL)) UpdateAddons(); } else if (typeid(event) == typeid(ADDON::AddonEvents::Disabled)) { - if (CServiceBroker::GetAddonMgr().HasType(event.addonId, ADDON::ADDON_PERIPHERALDLL)) + if (CServiceBroker::GetAddonMgr().HasType(event.addonId, ADDON::AddonType::PERIPHERALDLL)) UnRegisterAddon(event.addonId); } else if (typeid(event) == typeid(ADDON::AddonEvents::UnInstalled)) @@ -388,7 +389,7 @@ void CPeripheralBusAddon::UpdateAddons(void) // Get new add-ons std::vector<AddonInfoPtr> newAddons; - CServiceBroker::GetAddonMgr().GetAddonInfos(newAddons, true, ADDON_PERIPHERALDLL); + CServiceBroker::GetAddonMgr().GetAddonInfos(newAddons, true, AddonType::PERIPHERALDLL); std::transform(newAddons.begin(), newAddons.end(), std::inserter(newIds, newIds.end()), GetAddonID); diff --git a/xbmc/pictures/PictureInfoTag.cpp b/xbmc/pictures/PictureInfoTag.cpp index bda50ec1da..4aab3e0b19 100644 --- a/xbmc/pictures/PictureInfoTag.cpp +++ b/xbmc/pictures/PictureInfoTag.cpp @@ -11,6 +11,7 @@ #include "ServiceBroker.h" #include "addons/ExtsMimeSupportList.h" #include "addons/ImageDecoder.h" +#include "addons/addoninfo/AddonType.h" #include "guilib/guiinfo/GUIInfoLabels.h" #include "utils/Archive.h" #include "utils/CharsetConverter.h" @@ -139,7 +140,7 @@ bool CPictureInfoTag::Load(const std::string &path) strExtension, CExtsMimeSupportList::FilterSelect::all); for (const auto& addonInfo : addonInfos) { - if (addonInfo.first != ADDON::ADDON_IMAGEDECODER) + if (addonInfo.first != ADDON::AddonType::IMAGEDECODER) continue; std::unique_ptr<CImageDecoder> result = std::make_unique<CImageDecoder>(addonInfo.second, ""); diff --git a/xbmc/pvr/addons/PVRClients.cpp b/xbmc/pvr/addons/PVRClients.cpp index 42ff5bf1fe..c5c9f4325d 100644 --- a/xbmc/pvr/addons/PVRClients.cpp +++ b/xbmc/pvr/addons/PVRClients.cpp @@ -12,6 +12,7 @@ #include "addons/AddonEvents.h" #include "addons/AddonManager.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "guilib/LocalizeStrings.h" #include "messaging/ApplicationMessenger.h" #include "pvr/PVREventLogJob.h" @@ -37,14 +38,14 @@ using namespace PVR; CPVRClients::CPVRClients() { - CServiceBroker::GetAddonMgr().RegisterAddonMgrCallback(ADDON_PVRDLL, this); + CServiceBroker::GetAddonMgr().RegisterAddonMgrCallback(AddonType::PVRDLL, this); CServiceBroker::GetAddonMgr().Events().Subscribe(this, &CPVRClients::OnAddonEvent); } CPVRClients::~CPVRClients() { CServiceBroker::GetAddonMgr().Events().Unsubscribe(this); - CServiceBroker::GetAddonMgr().UnregisterAddonMgrCallback(ADDON_PVRDLL); + CServiceBroker::GetAddonMgr().UnregisterAddonMgrCallback(AddonType::PVRDLL); for (const auto& client : m_clientMap) { @@ -263,7 +264,7 @@ void CPVRClients::OnAddonEvent(const AddonEvent& event) // update addons const std::string addonId = event.addonId; const ADDON::AddonInstanceId instanceId = event.instanceId; - if (CServiceBroker::GetAddonMgr().HasType(addonId, ADDON_PVRDLL)) + if (CServiceBroker::GetAddonMgr().HasType(addonId, AddonType::PVRDLL)) { CServiceBroker::GetJobManager()->Submit([this, addonId, instanceId] { UpdateClients(addonId, instanceId); @@ -347,7 +348,7 @@ std::vector<CVariant> CPVRClients::GetClientProviderInfos() const { std::vector<AddonInfoPtr> addonInfos; // Get enabled and disabled PVR client addon infos - CServiceBroker::GetAddonMgr().GetAddonInfos(addonInfos, false, ADDON_PVRDLL); + CServiceBroker::GetAddonMgr().GetAddonInfos(addonInfos, false, AddonType::PVRDLL); std::unique_lock<CCriticalSection> lock(m_critSection); @@ -391,7 +392,7 @@ PVR_ERROR CPVRClients::GetCallableClients(CPVRClientMap& clientsReady, clientsNotReady.clear(); std::vector<AddonInfoPtr> addons; - CServiceBroker::GetAddonMgr().GetAddonInfos(addons, true, ADDON::ADDON_PVRDLL); + CServiceBroker::GetAddonMgr().GetAddonInfos(addons, true, AddonType::PVRDLL); for (const auto& addon : addons) { @@ -447,7 +448,8 @@ std::vector<CVariant> CPVRClients::GetEnabledClientInfos() const for (const auto& client : clientMap) { - const auto& addonInfo = CServiceBroker::GetAddonMgr().GetAddonInfo(client.second->ID()); + const auto& addonInfo = + CServiceBroker::GetAddonMgr().GetAddonInfo(client.second->ID(), AddonType::PVRDLL); if (addonInfo) { @@ -502,7 +504,7 @@ bool CPVRClients::GetAddonsWithStatus( std::vector<std::pair<AddonInfoPtr, bool>>& addonsWithStatus) const { std::vector<AddonInfoPtr> addons; - CServiceBroker::GetAddonMgr().GetAddonInfos(addons, false, ADDON_PVRDLL); + CServiceBroker::GetAddonMgr().GetAddonInfos(addons, false, AddonType::PVRDLL); if (addons.empty()) return false; diff --git a/xbmc/pvr/windows/GUIWindowPVRBase.cpp b/xbmc/pvr/windows/GUIWindowPVRBase.cpp index 6335126c55..e33259a953 100644 --- a/xbmc/pvr/windows/GUIWindowPVRBase.cpp +++ b/xbmc/pvr/windows/GUIWindowPVRBase.cpp @@ -12,6 +12,7 @@ #include "GUIUserMessages.h" #include "ServiceBroker.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "dialogs/GUIDialogExtendedProgressBar.h" #include "dialogs/GUIDialogSelect.h" #include "guilib/GUIComponent.h" @@ -394,7 +395,7 @@ void CGUIWindowPVRBase::SetInvalid() bool CGUIWindowPVRBase::CanBeActivated() const { // check if there is at least one enabled PVR add-on - if (!CServiceBroker::GetAddonMgr().HasAddons(ADDON::ADDON_PVRDLL)) + if (!CServiceBroker::GetAddonMgr().HasAddons(ADDON::AddonType::PVRDLL)) { HELPERS::ShowOKDialogText(CVariant{19296}, CVariant{19272}); // No PVR add-on enabled, You need a tuner, backend software... return false; diff --git a/xbmc/settings/SettingAddon.cpp b/xbmc/settings/SettingAddon.cpp index c21d71f027..fd39fe91d8 100644 --- a/xbmc/settings/SettingAddon.cpp +++ b/xbmc/settings/SettingAddon.cpp @@ -10,6 +10,7 @@ #include "addons/Addon.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "settings/lib/SettingsManager.h" #include "utils/XBMCTinyXML.h" #include "utils/XMLUtils.h" @@ -59,7 +60,7 @@ bool CSettingAddon::Deserialize(const TiXmlNode *node, bool update /* = false */ if (XMLUtils::GetString(constraints, "addontype", strAddonType) && !strAddonType.empty()) { m_addonType = ADDON::CAddonInfo::TranslateType(strAddonType); - if (m_addonType != ADDON::ADDON_UNKNOWN) + if (m_addonType != ADDON::AddonType::UNKNOWN) ok = true; } } diff --git a/xbmc/settings/SettingAddon.h b/xbmc/settings/SettingAddon.h index 10ecca75de..d4aefc8025 100644 --- a/xbmc/settings/SettingAddon.h +++ b/xbmc/settings/SettingAddon.h @@ -11,6 +11,11 @@ #include "addons/IAddon.h" #include "settings/lib/Setting.h" +namespace ADDON +{ +enum class AddonType; +} + class CSettingAddon : public CSettingString { public: @@ -23,11 +28,11 @@ public: bool Deserialize(const TiXmlNode *node, bool update = false) override; - ADDON::TYPE GetAddonType() const { return m_addonType; } - void SetAddonType(ADDON::TYPE addonType) { m_addonType = addonType; } + ADDON::AddonType GetAddonType() const { return m_addonType; } + void SetAddonType(ADDON::AddonType addonType) { m_addonType = addonType; } private: void copyaddontype(const CSettingAddon &setting); - ADDON::TYPE m_addonType = ADDON::ADDON_UNKNOWN; + ADDON::AddonType m_addonType{}; }; diff --git a/xbmc/settings/SettingConditions.cpp b/xbmc/settings/SettingConditions.cpp index 693ee06ae2..41a2d9237c 100644 --- a/xbmc/settings/SettingConditions.cpp +++ b/xbmc/settings/SettingConditions.cpp @@ -11,6 +11,7 @@ #include "LockType.h" #include "addons/AddonManager.h" #include "addons/Skin.h" +#include "addons/addoninfo/AddonType.h" #include "application/AppParams.h" #if defined(TARGET_ANDROID) #include "platform/android/activity/AndroidFeatures.h" @@ -50,7 +51,7 @@ bool AddonHasSettings(const std::string& condition, addon == NULL) return false; - if (addon->Type() == ADDON::ADDON_SKIN) + if (addon->Type() == ADDON::AddonType::SKIN) return ((ADDON::CSkinInfo*)addon.get())->HasSkinFile("SkinSettings.xml"); return addon->CanHaveAddonOrInstanceSettings(); @@ -77,7 +78,7 @@ bool HasPeripheralLibraries(const std::string& condition, const SettingConstPtr& setting, void* data) { - return CServiceBroker::GetAddonMgr().HasInstalledAddons(ADDON::ADDON_PERIPHERALDLL); + return CServiceBroker::GetAddonMgr().HasInstalledAddons(ADDON::AddonType::PERIPHERALDLL); } bool HasRumbleFeature(const std::string& condition, diff --git a/xbmc/settings/SkinSettings.cpp b/xbmc/settings/SkinSettings.cpp index 5d2ebef063..71ff616c6c 100644 --- a/xbmc/settings/SkinSettings.cpp +++ b/xbmc/settings/SkinSettings.cpp @@ -140,7 +140,7 @@ void CSkinSettings::Clear() m_settings.clear(); } -void CSkinSettings::MigrateSettings(const ADDON::SkinPtr& skin) +void CSkinSettings::MigrateSettings(const std::shared_ptr<ADDON::CSkinInfo>& skin) { if (skin == nullptr) return; diff --git a/xbmc/settings/SkinSettings.h b/xbmc/settings/SkinSettings.h index d3d0bbe093..9ade2458d9 100644 --- a/xbmc/settings/SkinSettings.h +++ b/xbmc/settings/SkinSettings.h @@ -12,6 +12,7 @@ #include "settings/ISubSettings.h" #include "threads/CriticalSection.h" +#include <memory> #include <set> #include <string> @@ -26,7 +27,7 @@ public: bool Save(TiXmlNode *settings) const override; void Clear() override; - void MigrateSettings(const ADDON::SkinPtr& skin); + void MigrateSettings(const std::shared_ptr<ADDON::CSkinInfo>& skin); int TranslateString(const std::string &setting); const std::string& GetString(int setting) const; diff --git a/xbmc/settings/dialogs/GUIDialogContentSettings.cpp b/xbmc/settings/dialogs/GUIDialogContentSettings.cpp index c7147d9dde..da4caf1b6c 100644 --- a/xbmc/settings/dialogs/GUIDialogContentSettings.cpp +++ b/xbmc/settings/dialogs/GUIDialogContentSettings.cpp @@ -239,7 +239,7 @@ void CGUIDialogContentSettings::OnSettingAction(const std::shared_ptr<const CSet } else if (settingId == SETTING_SCRAPER_LIST) { - ADDON::TYPE type = ADDON::ScraperTypeFromContent(m_content); + ADDON::AddonType type = ADDON::ScraperTypeFromContent(m_content); std::string currentScraperId; if (m_scraper != nullptr) currentScraperId = m_scraper->ID(); @@ -249,8 +249,8 @@ void CGUIDialogContentSettings::OnSettingAction(const std::shared_ptr<const CSet && selectedAddonId != currentScraperId) { AddonPtr scraperAddon; - if (CServiceBroker::GetAddonMgr().GetAddon( - selectedAddonId, scraperAddon, ADDON::ADDON_UNKNOWN, ADDON::OnlyEnabled::CHOICE_YES)) + if (CServiceBroker::GetAddonMgr().GetAddon(selectedAddonId, scraperAddon, + ADDON::OnlyEnabled::CHOICE_YES)) { m_scraper = std::dynamic_pointer_cast<CScraper>(scraperAddon); SetupView(); diff --git a/xbmc/settings/dialogs/GUIDialogSettingsManualBase.cpp b/xbmc/settings/dialogs/GUIDialogSettingsManualBase.cpp index 3bc269b97d..07f7ae34b1 100644 --- a/xbmc/settings/dialogs/GUIDialogSettingsManualBase.cpp +++ b/xbmc/settings/dialogs/GUIDialogSettingsManualBase.cpp @@ -336,7 +336,7 @@ std::shared_ptr<CSettingAddon> CGUIDialogSettingsManualBase::AddAddon( int label, SettingLevel level, const std::string& value, - ADDON::TYPE addonType, + ADDON::AddonType addonType, bool allowEmpty /* = false */, int heading /* = -1 */, bool hideValue /* = false */, diff --git a/xbmc/settings/dialogs/GUIDialogSettingsManualBase.h b/xbmc/settings/dialogs/GUIDialogSettingsManualBase.h index 27a86d0e74..a877902dba 100644 --- a/xbmc/settings/dialogs/GUIDialogSettingsManualBase.h +++ b/xbmc/settings/dialogs/GUIDialogSettingsManualBase.h @@ -144,7 +144,7 @@ protected: int label, SettingLevel level, const std::string& value, - ADDON::TYPE addonType, + ADDON::AddonType addonType, bool allowEmpty = false, int heading = -1, bool hideValue = false, diff --git a/xbmc/settings/windows/GUIControlSettings.cpp b/xbmc/settings/windows/GUIControlSettings.cpp index 0aa1bf1526..4dc8688cc7 100644 --- a/xbmc/settings/windows/GUIControlSettings.cpp +++ b/xbmc/settings/windows/GUIControlSettings.cpp @@ -1085,7 +1085,7 @@ void CGUIControlButtonSetting::Update(bool fromControl, bool updateDisplayOnly) for (const auto& addonID : addonIDs) { ADDON::AddonPtr addon; - if (CServiceBroker::GetAddonMgr().GetAddon(addonID, addon, ADDON::ADDON_UNKNOWN, + if (CServiceBroker::GetAddonMgr().GetAddon(addonID, addon, ADDON::OnlyEnabled::CHOICE_YES)) addonNames.push_back(addon->Name()); } diff --git a/xbmc/utils/FileExtensionProvider.cpp b/xbmc/utils/FileExtensionProvider.cpp index c07e538116..79ce46cd93 100644 --- a/xbmc/utils/FileExtensionProvider.cpp +++ b/xbmc/utils/FileExtensionProvider.cpp @@ -15,6 +15,7 @@ #include "addons/ExtsMimeSupportList.h" #include "addons/ImageDecoder.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "settings/AdvancedSettings.h" #include "settings/SettingsComponent.h" #include "utils/URIUtils.h" @@ -25,11 +26,8 @@ using namespace ADDON; using namespace KODI::ADDONS; -const std::vector<TYPE> ADDON_TYPES = { - ADDON_VFS, - ADDON_IMAGEDECODER, - ADDON_AUDIODECODER -}; +const std::vector<AddonType> ADDON_TYPES = {AddonType::VFS, AddonType::IMAGEDECODER, + AddonType::AUDIODECODER}; CFileExtensionProvider::CFileExtensionProvider(ADDON::CAddonMgr& addonManager) : m_advancedSettings(CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()), @@ -56,8 +54,8 @@ std::string CFileExtensionProvider::GetDiscStubExtensions() const std::string CFileExtensionProvider::GetMusicExtensions() const { std::string extensions(m_advancedSettings->m_musicExtensions); - extensions += '|' + GetAddonExtensions(ADDON_VFS); - extensions += '|' + GetAddonExtensions(ADDON_AUDIODECODER); + extensions += '|' + GetAddonExtensions(AddonType::VFS); + extensions += '|' + GetAddonExtensions(AddonType::AUDIODECODER); return extensions; } @@ -65,8 +63,8 @@ std::string CFileExtensionProvider::GetMusicExtensions() const std::string CFileExtensionProvider::GetPictureExtensions() const { std::string extensions(m_advancedSettings->m_pictureExtensions); - extensions += '|' + GetAddonExtensions(ADDON_VFS); - extensions += '|' + GetAddonExtensions(ADDON_IMAGEDECODER); + extensions += '|' + GetAddonExtensions(AddonType::VFS); + extensions += '|' + GetAddonExtensions(AddonType::IMAGEDECODER); return extensions; } @@ -74,7 +72,7 @@ std::string CFileExtensionProvider::GetPictureExtensions() const std::string CFileExtensionProvider::GetSubtitleExtensions() const { std::string extensions(m_advancedSettings->m_subtitlesExtensions); - extensions += '|' + GetAddonExtensions(ADDON_VFS); + extensions += '|' + GetAddonExtensions(AddonType::VFS); return extensions; } @@ -84,17 +82,17 @@ std::string CFileExtensionProvider::GetVideoExtensions() const std::string extensions(m_advancedSettings->m_videoExtensions); if (!extensions.empty()) extensions += '|'; - extensions += GetAddonExtensions(ADDON_VFS); + extensions += GetAddonExtensions(AddonType::VFS); return extensions; } std::string CFileExtensionProvider::GetFileFolderExtensions() const { - std::string extensions(GetAddonFileFolderExtensions(ADDON_VFS)); + std::string extensions(GetAddonFileFolderExtensions(AddonType::VFS)); if (!extensions.empty()) extensions += '|'; - extensions += GetAddonFileFolderExtensions(ADDON_AUDIODECODER); + extensions += GetAddonFileFolderExtensions(AddonType::AUDIODECODER); return extensions; } @@ -118,10 +116,10 @@ bool CFileExtensionProvider::CanOperateExtension(const std::string& path) const { switch (addonInfo.first) { - case ADDON_AUDIODECODER: + case AddonType::AUDIODECODER: supportList.emplace_back(new CAudioDecoder(addonInfo.second)); break; - case ADDON_IMAGEDECODER: + case AddonType::IMAGEDECODER: supportList.emplace_back(new CImageDecoder(addonInfo.second, "")); break; default: @@ -162,7 +160,7 @@ bool CFileExtensionProvider::CanOperateExtension(const std::string& path) const return false; } -std::string CFileExtensionProvider::GetAddonExtensions(const TYPE &type) const +std::string CFileExtensionProvider::GetAddonExtensions(AddonType type) const { auto it = m_addonExtensions.find(type); if (it != m_addonExtensions.end()) @@ -171,7 +169,7 @@ std::string CFileExtensionProvider::GetAddonExtensions(const TYPE &type) const return ""; } -std::string CFileExtensionProvider::GetAddonFileFolderExtensions(const TYPE &type) const +std::string CFileExtensionProvider::GetAddonFileFolderExtensions(AddonType type) const { auto it = m_addonFileFolderExtensions.find(type); if (it != m_addonFileFolderExtensions.end()) @@ -188,12 +186,12 @@ void CFileExtensionProvider::SetAddonExtensions() } } -void CFileExtensionProvider::SetAddonExtensions(const TYPE& type) +void CFileExtensionProvider::SetAddonExtensions(AddonType type) { std::vector<std::string> extensions; std::vector<std::string> fileFolderExtensions; - if (type == ADDON_AUDIODECODER || type == ADDON_IMAGEDECODER) + if (type == AddonType::AUDIODECODER || type == AddonType::IMAGEDECODER) { auto addonInfos = CServiceBroker::GetExtsMimeSupportList().GetSupportedAddonInfos( CExtsMimeSupportList::FilterSelect::all); @@ -210,7 +208,7 @@ void CFileExtensionProvider::SetAddonExtensions(const TYPE& type) } } } - else if (type == ADDON_VFS) + else if (type == AddonType::VFS) { std::vector<AddonInfoPtr> addonInfos; m_addonManager.GetAddonInfos(addonInfos, true, type); diff --git a/xbmc/utils/FileExtensionProvider.h b/xbmc/utils/FileExtensionProvider.h index d96df2c218..586f155d3c 100644 --- a/xbmc/utils/FileExtensionProvider.h +++ b/xbmc/utils/FileExtensionProvider.h @@ -8,8 +8,6 @@ #pragma once -#include "addons/addoninfo/AddonType.h" - #include <map> #include <memory> #include <string> @@ -17,8 +15,9 @@ namespace ADDON { - class CAddonMgr; - struct AddonEvent; +enum class AddonType; +class CAddonMgr; +struct AddonEvent; } class CAdvancedSettings; @@ -72,10 +71,10 @@ public: bool CanOperateExtension(const std::string& path) const; private: - std::string GetAddonExtensions(const ADDON::TYPE &type) const; - std::string GetAddonFileFolderExtensions(const ADDON::TYPE &type) const; + std::string GetAddonExtensions(ADDON::AddonType type) const; + std::string GetAddonFileFolderExtensions(ADDON::AddonType type) const; void SetAddonExtensions(); - void SetAddonExtensions(const ADDON::TYPE &type); + void SetAddonExtensions(ADDON::AddonType type); void OnAddonEvent(const ADDON::AddonEvent& event); @@ -84,8 +83,8 @@ private: ADDON::CAddonMgr &m_addonManager; // File extension properties - std::map<ADDON::TYPE, std::string> m_addonExtensions; - std::map<ADDON::TYPE, std::string> m_addonFileFolderExtensions; + std::map<ADDON::AddonType, std::string> m_addonExtensions; + std::map<ADDON::AddonType, std::string> m_addonFileFolderExtensions; // Protocols from add-ons with encoded host names std::vector<std::string> m_encoded; diff --git a/xbmc/utils/RssManager.cpp b/xbmc/utils/RssManager.cpp index da00e9a62f..b8d350cac5 100644 --- a/xbmc/utils/RssManager.cpp +++ b/xbmc/utils/RssManager.cpp @@ -11,6 +11,7 @@ #include "ServiceBroker.h" #include "addons/AddonInstaller.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "interfaces/builtins/Builtins.h" #include "profiles/ProfileManager.h" #include "settings/Settings.h" @@ -62,7 +63,7 @@ void CRssManager::OnSettingAction(const std::shared_ptr<const CSetting>& setting if (settingId == CSettings::SETTING_LOOKANDFEEL_RSSEDIT) { ADDON::AddonPtr addon; - if (!CServiceBroker::GetAddonMgr().GetAddon("script.rss.editor", addon, ADDON::ADDON_UNKNOWN, + if (!CServiceBroker::GetAddonMgr().GetAddon("script.rss.editor", addon, ADDON::OnlyEnabled::CHOICE_YES)) { if (!ADDON::CAddonInstaller::GetInstance().InstallModal( diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp index 4a3c10d329..fb81182ad6 100644 --- a/xbmc/video/VideoDatabase.cpp +++ b/xbmc/video/VideoDatabase.cpp @@ -60,8 +60,8 @@ #include <map> #include <memory> #include <string> -#include <vector> #include <unordered_set> +#include <vector> using namespace dbiplus; using namespace XFILE; @@ -8177,8 +8177,7 @@ ScraperPtr CVideoDatabase::GetScraperForPath(const std::string& strPath, SScanSe AddonPtr addon; if (!scraperID.empty() && - CServiceBroker::GetAddonMgr().GetAddon(scraperID, addon, ADDON::ADDON_UNKNOWN, - ADDON::OnlyEnabled::CHOICE_YES)) + CServiceBroker::GetAddonMgr().GetAddon(scraperID, addon, ADDON::OnlyEnabled::CHOICE_YES)) { scraper = std::dynamic_pointer_cast<CScraper>(addon); if (!scraper) @@ -8224,9 +8223,9 @@ ScraperPtr CVideoDatabase::GetScraperForPath(const std::string& strPath, SScanSe content = TranslateContent(strcontent); AddonPtr addon; - if (content != CONTENT_NONE && CServiceBroker::GetAddonMgr().GetAddon( - m_pDS->fv("path.strScraper").get_asString(), addon, - ADDON::ADDON_UNKNOWN, ADDON::OnlyEnabled::CHOICE_YES)) + if (content != CONTENT_NONE && + CServiceBroker::GetAddonMgr().GetAddon(m_pDS->fv("path.strScraper").get_asString(), + addon, ADDON::OnlyEnabled::CHOICE_YES)) { scraper = std::dynamic_pointer_cast<CScraper>(addon); scraper->SetPathSettings(content, m_pDS->fv("path.strSettings").get_asString()); @@ -10553,8 +10552,7 @@ void CVideoDatabase::ImportFromXML(const std::string &path) AddonPtr addon; std::string id; XMLUtils::GetString(path,"scraperpath",id); - if (CServiceBroker::GetAddonMgr().GetAddon(id, addon, ADDON::ADDON_UNKNOWN, - ADDON::OnlyEnabled::CHOICE_YES)) + if (CServiceBroker::GetAddonMgr().GetAddon(id, addon, ADDON::OnlyEnabled::CHOICE_YES)) { SScanSettings settings; ScraperPtr scraper = std::dynamic_pointer_cast<CScraper>(addon); diff --git a/xbmc/video/dialogs/GUIDialogSubtitles.cpp b/xbmc/video/dialogs/GUIDialogSubtitles.cpp index 065f79c0fa..600c6dad8a 100644 --- a/xbmc/video/dialogs/GUIDialogSubtitles.cpp +++ b/xbmc/video/dialogs/GUIDialogSubtitles.cpp @@ -15,6 +15,7 @@ #include "Util.h" #include "addons/AddonManager.h" #include "addons/addoninfo/AddonInfo.h" +#include "addons/addoninfo/AddonType.h" #include "addons/gui/GUIDialogAddonSettings.h" #include "application/Application.h" #include "application/ApplicationComponents.h" @@ -261,7 +262,7 @@ void CGUIDialogSubtitles::FillServices() ClearServices(); VECADDONS addons; - CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON_SUBTITLE_MODULE); + CServiceBroker::GetAddonMgr().GetAddons(addons, AddonType::SUBTITLE_MODULE); if (addons.empty()) { @@ -446,7 +447,8 @@ void CGUIDialogSubtitles::OnSubtitleServiceContextMenu(int itemIdx) { AddonPtr addon; if (CServiceBroker::GetAddonMgr().GetAddon(service->GetProperty("Addon.ID").asString(), addon, - ADDON_SUBTITLE_MODULE, OnlyEnabled::CHOICE_YES)) + AddonType::SUBTITLE_MODULE, + OnlyEnabled::CHOICE_YES)) { CGUIDialogAddonSettings::ShowForAddon(addon); } diff --git a/xbmc/view/GUIViewState.cpp b/xbmc/view/GUIViewState.cpp index 5378828176..7976adaff6 100644 --- a/xbmc/view/GUIViewState.cpp +++ b/xbmc/view/GUIViewState.cpp @@ -18,6 +18,7 @@ #include "addons/Addon.h" #include "addons/AddonManager.h" #include "addons/PluginSource.h" +#include "addons/addoninfo/AddonType.h" #include "addons/gui/GUIViewStateAddonBrowser.h" #include "dialogs/GUIDialogSelect.h" #include "events/windows/GUIViewStateEventLog.h" @@ -586,10 +587,10 @@ CGUIViewStateFromItems::CGUIViewStateFromItems(const CFileItemList &items) : CGU { CURL url(items.GetPath()); AddonPtr addon; - if (CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, ADDON_PLUGIN, + if (CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, AddonType::PLUGIN, OnlyEnabled::CHOICE_YES)) { - PluginPtr plugin = std::static_pointer_cast<CPluginSource>(addon); + const auto plugin = std::static_pointer_cast<CPluginSource>(addon); if (plugin->Provides(CPluginSource::AUDIO)) m_playlist = PLAYLIST::TYPE_MUSIC; if (plugin->Provides(CPluginSource::VIDEO)) diff --git a/xbmc/weather/WeatherJob.cpp b/xbmc/weather/WeatherJob.cpp index ef485dda26..17a09950e7 100644 --- a/xbmc/weather/WeatherJob.cpp +++ b/xbmc/weather/WeatherJob.cpp @@ -11,7 +11,9 @@ #include "GUIUserMessages.h" #include "LangInfo.h" #include "ServiceBroker.h" +#include "XBDateTime.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "guilib/GUIComponent.h" #include "guilib/GUIWindowManager.h" #include "guilib/LocalizeStrings.h" @@ -55,7 +57,7 @@ bool CWeatherJob::DoWork() if (!CServiceBroker::GetAddonMgr().GetAddon( CServiceBroker::GetSettingsComponent()->GetSettings()->GetString( CSettings::SETTING_WEATHER_ADDON), - addon, ADDON_SCRIPT_WEATHER, OnlyEnabled::CHOICE_YES)) + addon, AddonType::SCRIPT_WEATHER, OnlyEnabled::CHOICE_YES)) return false; // initialize our sys.argv variables diff --git a/xbmc/weather/WeatherManager.cpp b/xbmc/weather/WeatherManager.cpp index 078383ddd8..98f576fe14 100644 --- a/xbmc/weather/WeatherManager.cpp +++ b/xbmc/weather/WeatherManager.cpp @@ -12,6 +12,7 @@ #include "ServiceBroker.h" #include "WeatherJob.h" #include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" #include "addons/gui/GUIDialogAddonSettings.h" #include "guilib/GUIComponent.h" #include "guilib/GUIWindowManager.h" @@ -177,7 +178,7 @@ void CWeatherManager::OnSettingAction(const std::shared_ptr<const CSetting>& set if (CServiceBroker::GetAddonMgr().GetAddon( CServiceBroker::GetSettingsComponent()->GetSettings()->GetString( CSettings::SETTING_WEATHER_ADDON), - addon, ADDON_SCRIPT_WEATHER, OnlyEnabled::CHOICE_YES) && + addon, AddonType::SCRIPT_WEATHER, OnlyEnabled::CHOICE_YES) && addon != NULL) { //! @todo maybe have ShowAndGetInput return a bool if settings changed, then only reset weather if true. CGUIDialogAddonSettings::ShowForAddon(addon); diff --git a/xbmc/windows/GUIMediaWindow.cpp b/xbmc/windows/GUIMediaWindow.cpp index 8741fa9d7d..e1e39245be 100644 --- a/xbmc/windows/GUIMediaWindow.cpp +++ b/xbmc/windows/GUIMediaWindow.cpp @@ -20,6 +20,7 @@ #include "Util.h" #include "addons/AddonManager.h" #include "addons/PluginSource.h" +#include "addons/addoninfo/AddonType.h" #include "application/Application.h" #include "messaging/ApplicationMessenger.h" #if defined(TARGET_ANDROID) @@ -1053,7 +1054,7 @@ bool CGUIMediaWindow::OnClick(int iItem, const std::string &player) // execute the script CURL url(pItem->GetPath()); AddonPtr addon; - if (CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, ADDON_SCRIPT, + if (CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, AddonType::SCRIPT, OnlyEnabled::CHOICE_YES)) { if (!CScriptInvocationManager::GetInstance().Stop(addon->LibPath())) @@ -1157,10 +1158,9 @@ bool CGUIMediaWindow::OnClick(int iItem, const std::string &player) { CURL url(m_vecItems->GetPath()); AddonPtr addon; - if (CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, ADDON_UNKNOWN, - OnlyEnabled::CHOICE_YES)) + if (CServiceBroker::GetAddonMgr().GetAddon(url.GetHostName(), addon, OnlyEnabled::CHOICE_YES)) { - PluginPtr plugin = std::dynamic_pointer_cast<CPluginSource>(addon); + const auto plugin = std::dynamic_pointer_cast<CPluginSource>(addon); if (plugin && plugin->Provides(CPluginSource::AUDIO)) { CFileItemList items; diff --git a/xbmc/windows/GUIWindowScreensaver.cpp b/xbmc/windows/GUIWindowScreensaver.cpp index ff0aac615c..76eaa96a1e 100644 --- a/xbmc/windows/GUIWindowScreensaver.cpp +++ b/xbmc/windows/GUIWindowScreensaver.cpp @@ -13,6 +13,7 @@ #include "ServiceBroker.h" #include "addons/AddonManager.h" #include "addons/ScreenSaver.h" +#include "addons/addoninfo/AddonType.h" #include "application/ApplicationComponents.h" #include "application/ApplicationPowerHandling.h" #include "guilib/GUIComponent.h" @@ -80,7 +81,7 @@ bool CGUIWindowScreensaver::OnMessage(CGUIMessage& message) const std::string addon = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString( CSettings::SETTING_SCREENSAVER_MODE); const ADDON::AddonInfoPtr addonBase = - CServiceBroker::GetAddonMgr().GetAddonInfo(addon, ADDON::ADDON_SCREENSAVER); + CServiceBroker::GetAddonMgr().GetAddonInfo(addon, ADDON::AddonType::SCREENSAVER); if (!addonBase) return false; m_addon = std::make_unique<KODI::ADDONS::CScreenSaver>(addonBase); diff --git a/xbmc/windows/GUIWindowScreensaverDim.cpp b/xbmc/windows/GUIWindowScreensaverDim.cpp index 83e4389221..f617fba405 100644 --- a/xbmc/windows/GUIWindowScreensaverDim.cpp +++ b/xbmc/windows/GUIWindowScreensaverDim.cpp @@ -10,6 +10,8 @@ #include "ServiceBroker.h" #include "addons/AddonManager.h" +#include "addons/IAddon.h" +#include "addons/addoninfo/AddonType.h" #include "application/ApplicationComponents.h" #include "application/ApplicationPowerHandling.h" #include "guilib/GUITexture.h" @@ -40,8 +42,8 @@ void CGUIWindowScreensaverDim::UpdateVisibility() { m_visible = true; ADDON::AddonPtr info; - bool success = CServiceBroker::GetAddonMgr().GetAddon(usedId, info, ADDON::ADDON_SCREENSAVER, - ADDON::OnlyEnabled::CHOICE_YES); + bool success = CServiceBroker::GetAddonMgr().GetAddon( + usedId, info, ADDON::AddonType::SCREENSAVER, ADDON::OnlyEnabled::CHOICE_YES); if (success && info && !info->GetSetting("level").empty()) m_newDimLevel = 100.0f - (float)atof(info->GetSetting("level").c_str()); else |