summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/AddonInstaller.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2015-03-04 00:23:39 +0100
committermanuel <manuel@mausz.at>2015-03-04 00:23:39 +0100
commit9d11b08ad61b1f0d6d7023ce403285d8662efaed (patch)
tree5bc0c947d9e10d3e8c9dc1e6b26f3d6599f0cea1 /xbmc/addons/AddonInstaller.h
parentc159d9f91f1573901868100a9464527a5a71575b (diff)
downloadkodi-pvr-build-9d11b08ad61b1f0d6d7023ce403285d8662efaed.tar.gz
kodi-pvr-build-9d11b08ad61b1f0d6d7023ce403285d8662efaed.tar.bz2
kodi-pvr-build-9d11b08ad61b1f0d6d7023ce403285d8662efaed.zip
sync with upstream
Diffstat (limited to 'xbmc/addons/AddonInstaller.h')
-rw-r--r--xbmc/addons/AddonInstaller.h229
1 files changed, 0 insertions, 229 deletions
diff --git a/xbmc/addons/AddonInstaller.h b/xbmc/addons/AddonInstaller.h
deleted file mode 100644
index aca93d8..0000000
--- a/xbmc/addons/AddonInstaller.h
+++ /dev/null
@@ -1,229 +0,0 @@
1#pragma once
2/*
3 * Copyright (C) 2011-2013 Team XBMC
4 * http://xbmc.org
5 *
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include "utils/FileOperationJob.h"
23#include "addons/Addon.h"
24#include "utils/Stopwatch.h"
25#include "threads/Event.h"
26
27class CAddonDatabase;
28
29enum {
30 AUTO_UPDATES_ON = 0,
31 AUTO_UPDATES_NOTIFY,
32 AUTO_UPDATES_NEVER,
33 AUTO_UPDATES_MAX
34};
35
36class CAddonInstaller : public IJobCallback
37{
38public:
39 static CAddonInstaller &Get();
40
41 bool IsDownloading() const;
42 void GetInstallList(ADDON::VECADDONS &addons) const;
43 bool GetProgress(const std::string &addonID, unsigned int &percent) const;
44 bool Cancel(const std::string &addonID);
45
46 /*! \brief Installs the addon while showing a modal progress dialog
47 \param addonID the addon ID of the item to install.
48 \param addon [out] the installed addon for later use.
49 \param promptForInstall Whether or not to prompt the user before installing the addon.
50 \return true on successful install, false otherwise.
51 \sa Install
52 */
53 bool InstallModal(const std::string &addonID, ADDON::AddonPtr &addon, bool promptForInstall = true);
54
55 /*! \brief Install an addon if it is available in a repository
56 \param addonID the addon ID of the item to install
57 \param force whether to force the install even if the addon is already installed (eg for updating). Defaults to false.
58 \param referer string to use for referer for http fetch. Set to previous version when updating, parent when fetching a dependency
59 \param background whether to install in the background or not. Defaults to true.
60 \param modal whether to show a modal dialog when not installing in background
61 \return true on successful install, false on failure.
62 \sa DoInstall
63 */
64 bool Install(const std::string &addonID, bool force = false, const std::string &referer="", bool background = true, bool modal = false);
65
66 /*! \brief Install an addon from the given zip path
67 \param path the zip file to install from
68 \return true if successful, false otherwise
69 \sa DoInstall
70 */
71 bool InstallFromZip(const std::string &path);
72
73 /*! \brief Install a set of addons from the official repository (if needed)
74 \param addonIDs a set of addon IDs to install
75 */
76 void InstallFromXBMCRepo(const std::set<std::string> &addonIDs);
77
78 /*! \brief Check whether dependencies of an addon exist or are installable.
79 Iterates through the addon's dependencies, checking they're installed or installable.
80 Each dependency must also satisfies CheckDependencies in turn.
81 \param addon the addon to check
82 \param database the database instance to update. Defaults to NULL.
83 \return true if dependencies are available, false otherwise.
84 */
85 bool CheckDependencies(const ADDON::AddonPtr &addon, CAddonDatabase *database = NULL);
86
87 /*! \brief Update all repositories (if needed)
88 Runs through all available repositories and queues an update of them if they
89 need it (according to the set timeouts) or if forced. Optionally busy wait
90 until the repository updates are complete.
91 \param force whether we should run an update regardless of the normal update cycle. Defaults to false.
92 \param wait whether we should busy wait for the updates to be performed. Defaults to false.
93 */
94
95 /*! \brief Check if an installation job for a given add-on is already queued up
96 * \param ID The ID of the add-on
97 * \return true if a job exists, false otherwise
98 */
99 bool HasJob(const std::string& ID) const;
100
101 /*! \brief Fetch the last repository update time.
102 \return the last time a repository was updated.
103 */
104 CDateTime LastRepoUpdate() const;
105 void UpdateRepos(bool force = false, bool wait = false);
106
107 void OnJobComplete(unsigned int jobID, bool success, CJob* job);
108 void OnJobProgress(unsigned int jobID, unsigned int progress, unsigned int total, const CJob *job);
109
110 class CDownloadJob
111 {
112 public:
113 CDownloadJob(unsigned int id)
114 {
115 jobID = id;
116 progress = 0;
117 }
118 unsigned int jobID;
119 unsigned int progress;
120 };
121
122 typedef std::map<std::string, CDownloadJob> JobMap;
123
124private:
125 // private construction, and no assignements; use the provided singleton methods
126 CAddonInstaller();
127 CAddonInstaller(const CAddonInstaller&);
128 CAddonInstaller const& operator=(CAddonInstaller const&);
129 virtual ~CAddonInstaller();
130
131 /*! \brief Install an addon from a repository or zip
132 \param addon the AddonPtr describing the addon
133 \param hash the hash to verify the install. Defaults to "".
134 \param update whether this is an update of an existing addon, or a new install. Defaults to false.
135 \param referer string to use for referer for http fetch. Defaults to "".
136 \param background whether to install in the background or not. Defaults to true.
137 \return true on successful install, false on failure.
138 */
139 bool DoInstall(const ADDON::AddonPtr &addon, const std::string &hash = "", bool update = false, const std::string &referer = "", bool background = true, bool modal = false);
140
141 /*! \brief Check whether dependencies of an addon exist or are installable.
142 Iterates through the addon's dependencies, checking they're installed or installable.
143 Each dependency must also satisfies CheckDependencies in turn.
144 \param addon the addon to check
145 \param preDeps previous dependencies encountered during recursion. aids in avoiding infinite recursion
146 \param database database instance to update
147 \return true if dependencies are available, false otherwise.
148 */
149 bool CheckDependencies(const ADDON::AddonPtr &addon, std::vector<std::string>& preDeps, CAddonDatabase &database);
150
151 void PrunePackageCache();
152 int64_t EnumeratePackageFolder(std::map<std::string,CFileItemList*>& result);
153
154 CCriticalSection m_critSection;
155 JobMap m_downloadJobs;
156 CStopWatch m_repoUpdateWatch; ///< repository updates are done based on this counter
157 unsigned int m_repoUpdateJob; ///< the job ID of the repository updates
158 CEvent m_repoUpdateDone; ///< event set when the repository updates are complete
159};
160
161class CAddonInstallJob : public CFileOperationJob
162{
163public:
164 CAddonInstallJob(const ADDON::AddonPtr &addon, const std::string &hash = "", bool update = false, const std::string &referer = "");
165
166 virtual bool DoWork();
167
168 /*! \brief return the id of the addon being installed
169 \return id of the installing addon
170 */
171 std::string AddonID() const;
172
173 /*! \brief Find which repository hosts an add-on
174 * \param addon The add-on to find the repository for
175 * \return The hosting repository
176 */
177 static ADDON::AddonPtr GetRepoForAddon(const ADDON::AddonPtr& addon);
178
179 /*! \brief Find the add-on and itshash for the given add-on ID
180 * \param addonID ID of the add-on to find
181 * \param addon Add-on with the given add-on ID
182 * \param hash Hash of the add-on
183 * \return True if the add-on and its hash were found, false otherwise.
184 */
185 static bool GetAddonWithHash(const std::string& addonID, ADDON::AddonPtr& addon, std::string& hash);
186
187private:
188 bool OnPreInstall();
189 void OnPostInstall(bool reloadAddon);
190 bool Install(const std::string &installFrom, const ADDON::AddonPtr& repo = ADDON::AddonPtr());
191 bool DownloadPackage(const std::string &path, const std::string &dest);
192
193 /*! \brief Delete an addon following install failure
194 \param addonFolder - the folder to delete
195 */
196 bool DeleteAddon(const std::string &addonFolder);
197
198 bool DoFileOperation(FileAction action, CFileItemList &items, const std::string &file, bool useSameJob = true);
199
200 /*! \brief Queue a notification for addon installation/update failure
201 \param addonID - addon id
202 \param fileName - filename which is shown in case the addon id is unknown
203 \param message - error message to be displayed
204 */
205 void ReportInstallError(const std::string& addonID, const std::string& fileName, const std::string& message = "");
206
207 ADDON::AddonPtr m_addon;
208 std::string m_hash;
209 bool m_update;
210 std::string m_referer;
211};
212
213class CAddonUnInstallJob : public CFileOperationJob
214{
215public:
216 CAddonUnInstallJob(const ADDON::AddonPtr &addon);
217
218 virtual bool DoWork();
219
220private:
221 /*! \brief Delete an addon following install failure
222 \param addonFolder - the folder to delete
223 */
224 bool DeleteAddon(const std::string &addonFolder);
225
226 void OnPostUnInstall();
227
228 ADDON::AddonPtr m_addon;
229};