2 * Copyright (C) 2011-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "threads/Event.h"
12 #include "utils/Job.h"
30 using RepositoryPtr
= std::shared_ptr
<CRepository
>;
33 using AddonPtr
= std::shared_ptr
<IAddon
>;
34 using VECADDONS
= std::vector
<AddonPtr
>;
36 enum class BackgroundJob
: bool
42 enum class ModalJob
: bool
48 enum class AutoUpdateJob
: bool
54 enum class DependencyJob
: bool
60 enum class InstallModalPrompt
: bool
66 enum class AllowCheckForUpdates
: bool
72 enum class RecurseOrphaned
: bool
78 class CAddonInstaller
: public IJobCallback
81 static CAddonInstaller
&GetInstance();
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
);
88 /*! \brief Installs the addon while showing a modal progress dialog
89 \param addonID the addon ID of the item to install.
90 \param addon [out] the installed addon for later use.
91 \param promptForInstall Whether or not to prompt the user before installing the addon.
92 \return true on successful install, false otherwise.
95 bool InstallModal(const std::string
& addonID
,
96 ADDON::AddonPtr
& addon
,
97 InstallModalPrompt promptForInstall
);
99 /*! \brief Install an addon if it is available in a repository
100 \param addonID the addon ID of the item to install
101 \param background whether to install in the background or not.
102 \param modal whether to show a modal dialog when not installing in background
103 \return true on successful install, false on failure.
106 bool InstallOrUpdate(const std::string
& addonID
, BackgroundJob background
, ModalJob modal
);
108 /*! \brief Install a dependency from a specific repository
109 \param dependsId the dependency to install
110 \param repo the repository to install the addon from
111 \return true on successful install, false on failure.
114 bool InstallOrUpdateDependency(const ADDON::AddonPtr
& dependsId
,
115 const ADDON::RepositoryPtr
& repo
);
117 /*! \brief Remove a single dependency from the system
118 \param dependsId the dependency to remove
119 \return true on successful uninstall, false on failure.
121 bool RemoveDependency(const std::shared_ptr
<IAddon
>& dependsId
) const;
124 * \brief Removes all orphaned add-ons recursively. Removal may orphan further
125 * add-ons/dependencies, so loop until no orphaned is left on the system
126 * \return Names of add-ons that have effectively been removed
128 std::vector
<std::string
> RemoveOrphanedDepsRecursively() const;
130 /*! \brief Installs a vector of addons
131 * \param addons the list of addons to install
132 * \param wait if the method should wait for all the DoInstall jobs to finish or if it should return right away
133 * \param allowCheckForUpdates indicates if content update checks are allowed
134 * after installation of a repository addon from the vector
137 void InstallAddons(const ADDON::VECADDONS
& addons
,
139 AllowCheckForUpdates allowCheckForUpdates
);
141 /*! \brief Install an addon from the given zip path
142 \param path the zip file to install from
143 \return true if successful, false otherwise
146 bool InstallFromZip(const std::string
&path
);
148 /*! Install an addon with a specific version and repository */
149 bool Install(const std::string
& addonId
,
150 const ADDON::CAddonVersion
& version
,
151 const std::string
& repoId
);
153 /*! Uninstall an addon, remove addon data if requested */
154 bool UnInstall(const ADDON::AddonPtr
& addon
, bool removeData
);
156 /*! \brief Check whether dependencies of an addon exist or are installable.
157 Iterates through the addon's dependencies, checking they're installed or installable.
158 Each dependency must also satisfies CheckDependencies in turn.
159 \param addon the addon to check
160 \param database the database instance to update. Defaults to NULL.
161 \return true if dependencies are available, false otherwise.
163 bool CheckDependencies(const ADDON::AddonPtr
& addon
, CAddonDatabase
* database
= nullptr);
165 /*! \brief Check whether dependencies of an addon exist or are installable.
166 Iterates through the addon's dependencies, checking they're installed or installable.
167 Each dependency must also satisfies CheckDependencies in turn.
168 \param addon the addon to check
169 \param failedDep Dependency addon that isn't available
170 \param database the database instance to update. Defaults to NULL.
171 \return true if dependencies are available, false otherwise.
173 bool CheckDependencies(const ADDON::AddonPtr
& addon
,
174 std::pair
<std::string
, std::string
>& failedDep
,
175 CAddonDatabase
* database
= nullptr);
177 /*! \brief Check if an installation job for a given add-on is already queued up
178 * \param ID The ID of the add-on
179 * \return true if a job exists, false otherwise
181 bool HasJob(const std::string
& ID
) const;
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
;
189 explicit CDownloadJob(unsigned int id
) : jobID(id
) { }
192 unsigned int progress
= 0;
193 bool downloadFinshed
= false;
196 typedef std::map
<std::string
, CDownloadJob
> JobMap
;
199 // private construction, and no assignments; use the provided singleton methods
201 CAddonInstaller(const CAddonInstaller
&) = delete;
202 CAddonInstaller
const& operator=(CAddonInstaller
const&) = delete;
203 ~CAddonInstaller() override
;
205 /*! \brief Install an addon from a repository or zip
206 * \param addon the AddonPtr describing the addon
207 * \param repo the repository to install addon from
208 * \param background whether to install in the background or not.
209 * \param modal whether to install in modal mode or not.
210 * \param autoUpdate whether the addon is installed in auto update mode.
211 * (i.e. no notification)
212 * \param dependsInstall whether this is the installation of a dependency addon
213 * \param allowCheckForUpdates whether content update check after installation of
214 * a repository addon is allowed
215 * \return true on successful install, false on failure.
217 bool DoInstall(const ADDON::AddonPtr
& addon
,
218 const ADDON::RepositoryPtr
& repo
,
219 BackgroundJob background
,
221 AutoUpdateJob autoUpdate
,
222 DependencyJob dependsInstall
,
223 AllowCheckForUpdates allowCheckForUpdates
);
225 /*! \brief Check whether dependencies of an addon exist or are installable.
226 Iterates through the addon's dependencies, checking they're installed or installable.
227 Each dependency must also satisfies CheckDependencies in turn.
228 \param addon the addon to check
229 \param preDeps previous dependencies encountered during recursion. aids in avoiding infinite recursion
230 \param database database instance to update
231 \param failedDep Dependency addon that isn't available
232 \return true if dependencies are available, false otherwise.
234 bool CheckDependencies(const ADDON::AddonPtr
&addon
, std::vector
<std::string
>& preDeps
, CAddonDatabase
&database
, std::pair
<std::string
, std::string
> &failedDep
);
236 void PrunePackageCache();
237 int64_t EnumeratePackageFolder(std::map
<std::string
, std::unique_ptr
<CFileItemList
>>& result
);
239 mutable CCriticalSection m_critSection
;
240 JobMap m_downloadJobs
;
244 }; // namespace ADDON