2 * Copyright (C) 2005-2020 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "addons/AddonDatabase.h"
26 enum class AddonCheckType
: bool;
28 enum class CheckAddonPath
34 using AddonWithUpdate
= std::pair
<std::shared_ptr
<IAddon
>, std::shared_ptr
<IAddon
>>;
38 * Reads information about installed official/third party repos and their contained add-ons from the database.
39 * Used to check for updates for installed add-ons and dependencies while obeying permission rules.
40 * Note that this class is not responsible for refreshing the repo data stored in the database.
45 CAddonRepos(); // load all add-ons from all installed repositories
46 explicit CAddonRepos(const std::string
& addonId
); // load a specific add-on id only
47 explicit CAddonRepos(const std::shared_ptr
<IAddon
>& repoAddon
); // load add-ons of a specific repo
50 * \brief Build the list of addons to be updated depending on defined rules
51 * or the list of outdated addons
52 * \param installed vector of all addons installed on the system that are
53 * checked for an update
54 * \param[in] addonCheckType build list of OUTDATED or UPDATES
55 * \param[out] result list of addon versions that are going to be installed
58 void BuildUpdateOrOutdatedList(const std::vector
<std::shared_ptr
<IAddon
>>& installed
,
59 std::vector
<std::shared_ptr
<IAddon
>>& result
,
60 AddonCheckType addonCheckType
) const;
63 * \brief Build the list of outdated addons and their available updates.
64 * \param installed vector of all addons installed on the system that are
65 * checked for an update
66 * \param[out] addonsWithUpdate target map
68 void BuildAddonsWithUpdateList(const std::vector
<std::shared_ptr
<IAddon
>>& installed
,
69 std::map
<std::string
, AddonWithUpdate
>& addonsWithUpdate
) const;
72 * \brief Checks if the origin-repository of a given addon is defined as official repo
73 * and can also verify if the origin-path (e.g. https://mirrors.kodi.tv ...)
75 * \note if this function is called on locally installed add-ons, for instance when populating
76 * 'My add-ons', the local installation path is returned as origin.
77 * thus parameter CheckAddonPath::CHOICE_NO needs to be passed in such cases
78 * \param addon pointer to addon to be checked
79 * \param checkAddonPath also check origin path
80 * \return true if the repository id of a given addon is defined as official
81 * and the addons origin matches the defined official origin of the repo id
83 static bool IsFromOfficialRepo(const std::shared_ptr
<IAddon
>& addon
,
84 CheckAddonPath checkAddonPath
);
87 * \brief Checks if the passed in repository is defined as official repo
88 * which includes ORIGIN_SYSTEM
89 * \param repoId repository id to check
90 * \return true if the repository id is defined as official, false otherwise
92 static bool IsOfficialRepo(const std::string
& repoId
);
95 * \brief Check if an update is available for a single addon
96 * \param addon that is checked for an update
97 * \param[out] update pointer to the found update
98 * \return true if an installable update was found, false otherwise
100 bool DoAddonUpdateCheck(const std::shared_ptr
<IAddon
>& addon
,
101 std::shared_ptr
<IAddon
>& update
) const;
104 * \brief Retrieves the latest version of an addon from all installed repositories
105 * follows addon origin restriction rules
106 * \param addonId addon id we're looking the latest version for
107 * \param[out] addon pointer to the found addon
108 * \return true if a version was found, false otherwise
110 bool GetLatestAddonVersionFromAllRepos(const std::string
& addonId
,
111 std::shared_ptr
<IAddon
>& addon
) const;
114 * \brief Retrieves the latest official versions of addons to vector.
115 * Private versions are added obeying updateMode.
116 * (either OFFICIAL_ONLY or ANY_REPOSITORY)
117 * \param[out] addonList retrieved addon list in a vector
119 void GetLatestAddonVersions(std::vector
<std::shared_ptr
<IAddon
>>& addonList
) const;
122 * \brief Retrieves the latest official versions of addons to vector.
123 * Private versions (latest per repository) are added obeying updateMode.
124 * (either OFFICIAL_ONLY or ANY_REPOSITORY)
125 * \param[out] addonList retrieved addon list in a vector
127 void GetLatestAddonVersionsFromAllRepos(std::vector
<std::shared_ptr
<IAddon
>>& addonList
) const;
130 * \brief Find a dependency to install during an addon install or update
131 * If the dependency cannot be found in official versions we look in the
132 * installing/updating addon's (the parent's) origin repository
133 * \param dependsId addon id of the dependency we're looking for
134 * \param parentRepoId origin repository of the dependee
135 * \param [out] dependencyToInstall pointer to the found dependency, only use
136 * if function returns true
137 * \param [out] repoForDep the repository that dependency will install from finally
138 * \return true if the dependency was found, false otherwise
140 bool FindDependency(const std::string
& dependsId
,
141 const std::string
& parentRepoId
,
142 std::shared_ptr
<IAddon
>& dependencyToInstall
,
143 std::shared_ptr
<CRepository
>& repoForDep
) const;
146 * \brief Find a dependency addon in the repository of its parent
147 * \param dependsId addon id of the dependency we're looking for
148 * \param parentRepoId origin repository of the dependee
149 * \param [out] dependencyToInstall pointer to the found dependency, only use
150 * if function returns true
151 * \return true if the dependency was found, false otherwise
153 bool FindDependencyByParentRepo(const std::string
& dependsId
,
154 const std::string
& parentRepoId
,
155 std::shared_ptr
<IAddon
>& dependencyToInstall
) const;
158 * \brief Build compatible versions list based on the contents of m_allAddons
159 * \note content of m_allAddons depends on the preceding call to @ref LoadAddonsFromDatabase()
160 * \param[out] compatibleVersions target vector to be filled
162 void BuildCompatibleVersionsList(std::vector
<std::shared_ptr
<IAddon
>>& compatibleVersions
) const;
165 * \brief Return whether add-ons repo/version information was properly loaded after construction
166 * \return true on success, false otherwise
168 bool IsValid() const { return m_valid
; }
172 * \brief Load and configure add-on maps
173 * \return true on success, false otherwise
175 bool LoadAddonsFromDatabase(const std::string
& addonId
, const std::shared_ptr
<IAddon
>& repoAddon
);
178 * \brief Looks up an addon in a given repository map and
179 * checks if an update is available
180 * \param addonToCheck the addon we want to find and version check
181 * \param map the repository map we want to check against
182 * \param[out] pointer to the found update. if the addon is
183 * up-to-date on our system, this param will return 'nullptr'
184 * \return true if the addon was found in the desired map and
185 * its version is newer than our local version.
186 * false if the addon does NOT exist in the map or it is up to date.
188 bool FindAddonAndCheckForUpdate(const std::shared_ptr
<IAddon
>& addonToCheck
,
189 const std::map
<std::string
, std::shared_ptr
<IAddon
>>& map
,
190 std::shared_ptr
<IAddon
>& update
) const;
193 * \brief Adds the latest version of an addon to the desired map
194 * \param addonToAdd the addon whose latest version should be added
195 * \param map target map, e.g. latestOfficialVersions or latestPrivateVersions
197 void AddAddonIfLatest(const std::shared_ptr
<IAddon
>& addonToAdd
,
198 std::map
<std::string
, std::shared_ptr
<IAddon
>>& map
) const;
201 * \brief Adds the latest version of an addon to the desired map per repository
202 * used to populate 'latestVersionsByRepo'
203 * \param repoId the repository that addon comes from
204 * \param addonToAdd the addon whose latest version should be added
205 * \param map target map, latestVersionsByRepo
207 void AddAddonIfLatest(
208 const std::string
& repoId
,
209 const std::shared_ptr
<IAddon
>& addonToAdd
,
210 std::map
<std::string
, std::map
<std::string
, std::shared_ptr
<IAddon
>>>& map
) const;
213 * \brief Looks up an addon entry in a specific map
214 * \param addonId addon we want to retrieve
215 * \param map the map we're looking into for the wanted addon
216 * \param[out] addon pointer to the found addon, only use when function returns true
217 * \return true if the addon was found in the map, false otherwise
219 bool GetLatestVersionByMap(const std::string
& addonId
,
220 const std::map
<std::string
, std::shared_ptr
<IAddon
>>& map
,
221 std::shared_ptr
<IAddon
>& addon
) const;
223 const CAddonMgr
& m_addonMgr
;
224 CAddonDatabase m_addonDb
;
227 std::vector
<std::shared_ptr
<IAddon
>> m_allAddons
;
229 std::map
<std::string
, std::shared_ptr
<IAddon
>> m_latestOfficialVersions
;
230 std::map
<std::string
, std::shared_ptr
<IAddon
>> m_latestPrivateVersions
;
231 std::map
<std::string
, std::map
<std::string
, std::shared_ptr
<IAddon
>>> m_latestVersionsByRepo
;
232 std::map
<std::string
, std::multimap
<std::string
, std::shared_ptr
<IAddon
>>> m_addonsByRepoMap
;
235 }; /* namespace ADDON */