xbmc
AddonInstaller.h
1 /*
2  * Copyright (C) 2011-2018 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 "threads/Event.h"
12 #include "utils/Job.h"
13 
14 #include <map>
15 #include <memory>
16 #include <string>
17 #include <utility>
18 #include <vector>
19 
20 class CFileItemList;
21 
22 namespace ADDON
23 {
24 
25 class CAddonVersion;
26 
27 class CAddonDatabase;
28 
29 class CRepository;
30 using RepositoryPtr = std::shared_ptr<CRepository>;
31 
32 class IAddon;
33 using AddonPtr = std::shared_ptr<IAddon>;
34 using VECADDONS = std::vector<AddonPtr>;
35 
36 enum class BackgroundJob : bool
37 {
38  CHOICE_YES = true,
39  CHOICE_NO = false,
40 };
41 
42 enum class ModalJob : bool
43 {
44  CHOICE_YES = true,
45  CHOICE_NO = false,
46 };
47 
48 enum class AutoUpdateJob : bool
49 {
50  CHOICE_YES = true,
51  CHOICE_NO = false,
52 };
53 
54 enum class DependencyJob : bool
55 {
56  CHOICE_YES = true,
57  CHOICE_NO = false,
58 };
59 
60 enum class InstallModalPrompt : bool
61 {
62  CHOICE_YES = true,
63  CHOICE_NO = false,
64 };
65 
66 enum class AllowCheckForUpdates : bool
67 {
68  CHOICE_YES = true,
69  CHOICE_NO = false,
70 };
71 
72 enum class RecurseOrphaned : bool
73 {
74  CHOICE_YES = true,
75  CHOICE_NO = false,
76 };
77 
79 {
80 public:
81  static CAddonInstaller &GetInstance();
82 
83  bool IsDownloading() const;
84  void GetInstallList(ADDON::VECADDONS &addons) const;
85  bool GetProgress(const std::string& addonID, unsigned int& percent, bool& downloadFinshed) const;
86  bool Cancel(const std::string &addonID);
87 
95  bool InstallModal(const std::string& addonID,
96  ADDON::AddonPtr& addon,
97  InstallModalPrompt promptForInstall);
98 
106  bool InstallOrUpdate(const std::string& addonID, BackgroundJob background, ModalJob modal);
107 
114  bool InstallOrUpdateDependency(const ADDON::AddonPtr& dependsId,
115  const ADDON::RepositoryPtr& repo);
116 
121  bool RemoveDependency(const std::shared_ptr<IAddon>& dependsId) const;
122 
128  std::vector<std::string> RemoveOrphanedDepsRecursively() const;
129 
137  void InstallAddons(const ADDON::VECADDONS& addons,
138  bool wait,
139  AllowCheckForUpdates allowCheckForUpdates);
140 
146  bool InstallFromZip(const std::string &path);
147 
149  bool Install(const std::string& addonId,
150  const ADDON::CAddonVersion& version,
151  const std::string& repoId);
152 
154  bool UnInstall(const ADDON::AddonPtr& addon, bool removeData);
155 
163  bool CheckDependencies(const ADDON::AddonPtr& addon, CAddonDatabase* database = nullptr);
164 
173  bool CheckDependencies(const ADDON::AddonPtr& addon,
174  std::pair<std::string, std::string>& failedDep,
175  CAddonDatabase* database = nullptr);
176 
181  bool HasJob(const std::string& ID) const;
182 
183  void OnJobComplete(unsigned int jobID, bool success, CJob* job) override;
184  void OnJobProgress(unsigned int jobID, unsigned int progress, unsigned int total, const CJob *job) override;
185 
187  {
188  public:
189  explicit CDownloadJob(unsigned int id) : jobID(id) { }
190 
191  unsigned int jobID;
192  unsigned int progress = 0;
193  bool downloadFinshed = false;
194  };
195 
196  typedef std::map<std::string, CDownloadJob> JobMap;
197 
198 private:
199  // private construction, and no assignments; use the provided singleton methods
200  CAddonInstaller();
201  CAddonInstaller(const CAddonInstaller&) = delete;
202  CAddonInstaller const& operator=(CAddonInstaller const&) = delete;
203  ~CAddonInstaller() override;
204 
217  bool DoInstall(const ADDON::AddonPtr& addon,
218  const ADDON::RepositoryPtr& repo,
219  BackgroundJob background,
220  ModalJob modal,
221  AutoUpdateJob autoUpdate,
222  DependencyJob dependsInstall,
223  AllowCheckForUpdates allowCheckForUpdates);
224 
234  bool CheckDependencies(const ADDON::AddonPtr &addon, std::vector<std::string>& preDeps, CAddonDatabase &database, std::pair<std::string, std::string> &failedDep);
235 
236  void PrunePackageCache();
237  int64_t EnumeratePackageFolder(std::map<std::string, std::unique_ptr<CFileItemList>>& result);
238 
239  mutable CCriticalSection m_critSection;
240  JobMap m_downloadJobs;
241  CEvent m_idle;
242 };
243 
244 }; // namespace ADDON
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
Definition: AddonDatabase.h:61
Definition: AddonInstaller.h:78
Definition: AddonVersion.h:27
Base class for jobs that are executed asynchronously.
Definition: Job.h:109
Represents a list of files.
Definition: FileItem.h:713
Definition: AddonInstaller.h:186
Callback interface for asynchronous jobs.
Definition: Job.h:31
Definition: Addon.cpp:39