xbmc
AddonRepos.h
1 /*
2  * Copyright (C) 2005-2020 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "addons/AddonDatabase.h"
12 
13 #include <map>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 namespace ADDON
19 {
20 
21 class CAddonVersion;
22 class CAddonMgr;
23 class CRepository;
24 class IAddon;
25 enum class AddonCheckType : bool;
26 
27 enum class CheckAddonPath
28 {
29  CHOICE_YES = true,
30  CHOICE_NO = false,
31 };
32 
37 {
38  std::shared_ptr<IAddon> m_installed;
39  std::shared_ptr<IAddon> m_update;
40 };
41 
49 {
50 public:
51  CAddonRepos(); // load all add-ons from all installed repositories
52  explicit CAddonRepos(const std::string& addonId); // load a specific add-on id only
53  explicit CAddonRepos(const std::shared_ptr<IAddon>& repoAddon); // load add-ons of a specific repo
54 
64  void BuildUpdateOrOutdatedList(const std::vector<std::shared_ptr<IAddon>>& installed,
65  std::vector<std::shared_ptr<IAddon>>& result,
66  AddonCheckType addonCheckType) const;
67 
74  void BuildAddonsWithUpdateList(const std::vector<std::shared_ptr<IAddon>>& installed,
75  std::map<std::string, AddonWithUpdate>& addonsWithUpdate) const;
76 
89  static bool IsFromOfficialRepo(const std::shared_ptr<IAddon>& addon,
90  CheckAddonPath checkAddonPath);
91 
98  static bool IsOfficialRepo(const std::string& repoId);
99 
106  bool DoAddonUpdateCheck(const std::shared_ptr<IAddon>& addon,
107  std::shared_ptr<IAddon>& update) const;
108 
116  bool GetLatestAddonVersionFromAllRepos(const std::string& addonId,
117  std::shared_ptr<IAddon>& addon) const;
118 
125  void GetLatestAddonVersions(std::vector<std::shared_ptr<IAddon>>& addonList) const;
126 
133  void GetLatestAddonVersionsFromAllRepos(std::vector<std::shared_ptr<IAddon>>& addonList) const;
134 
146  bool FindDependency(const std::string& dependsId,
147  const std::string& parentRepoId,
148  std::shared_ptr<IAddon>& dependencyToInstall,
149  std::shared_ptr<CRepository>& repoForDep) const;
150 
159  bool FindDependencyByParentRepo(const std::string& dependsId,
160  const std::string& parentRepoId,
161  std::shared_ptr<IAddon>& dependencyToInstall) const;
162 
168  void BuildCompatibleVersionsList(std::vector<std::shared_ptr<IAddon>>& compatibleVersions) const;
169 
174  bool IsValid() const { return m_valid; }
175 
176 private:
181  bool LoadAddonsFromDatabase(const std::string& addonId, const std::shared_ptr<IAddon>& repoAddon);
182 
194  bool FindAddonAndCheckForUpdate(const std::shared_ptr<IAddon>& addonToCheck,
195  const std::map<std::string, std::shared_ptr<IAddon>>& map,
196  std::shared_ptr<IAddon>& update) const;
197 
203  void AddAddonIfLatest(const std::shared_ptr<IAddon>& addonToAdd,
204  std::map<std::string, std::shared_ptr<IAddon>>& map) const;
205 
213  void AddAddonIfLatest(
214  const std::string& repoId,
215  const std::shared_ptr<IAddon>& addonToAdd,
216  std::map<std::string, std::map<std::string, std::shared_ptr<IAddon>>>& map) const;
217 
225  bool GetLatestVersionByMap(const std::string& addonId,
226  const std::map<std::string, std::shared_ptr<IAddon>>& map,
227  std::shared_ptr<IAddon>& addon) const;
228 
229  const CAddonMgr& m_addonMgr;
230  CAddonDatabase m_addonDb;
231  bool m_valid{false};
232 
233  std::vector<std::shared_ptr<IAddon>> m_allAddons;
234 
235  std::map<std::string, std::shared_ptr<IAddon>> m_latestOfficialVersions;
236  std::map<std::string, std::shared_ptr<IAddon>> m_latestPrivateVersions;
237  std::map<std::string, std::map<std::string, std::shared_ptr<IAddon>>> m_latestVersionsByRepo;
238  std::map<std::string, std::multimap<std::string, std::shared_ptr<IAddon>>> m_addonsByRepoMap;
239 };
240 
241 }; /* namespace ADDON */
Class - CAddonMgr Holds references to all addons, enabled or otherwise.
Definition: AddonManager.h:79
Definition: AddonDatabase.h:61
bool IsValid() const
Return whether add-ons repo/version information was properly loaded after construction.
Definition: AddonRepos.h:174
Class - CAddonRepos Reads information about installed official/third party repos and their contained ...
Definition: AddonRepos.h:48
Struct - CAddonWithUpdate.
Definition: AddonRepos.h:36
Definition: Addon.cpp:39