Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 1130 lines (1012 sloc) 32.53 kb
074db86 merged: addons-fw branch
elupus authored
1 /*
2 * Copyright (C) 2005-2009 Team XBMC
3 * http://www.xbmc.org
4 *
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 */
21 #include "AddonManager.h"
22 #include "Addon.h"
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
23 #include "AddonDatabase.h"
1b2781c added: basic cpluff support
alcoheca authored
24 #include "DllLibCPluff.h"
074db86 merged: addons-fw branch
elupus authored
25 #include "StringUtils.h"
26 #include "RegExp.h"
27 #include "XMLUtils.h"
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
28 #include "utils/JobManager.h"
29 #include "utils/SingleLock.h"
074db86 merged: addons-fw branch
elupus authored
30 #include "FileItem.h"
822ca91 added: translatable <description>, <title>, <summary> and <disclaimer> i...
spiff_ authored
31 #include "LangInfo.h"
074db86 merged: addons-fw branch
elupus authored
32 #include "Settings.h"
33 #include "GUISettings.h"
34 #include "DownloadQueueManager.h"
1b2781c added: basic cpluff support
alcoheca authored
35 #include "AdvancedSettings.h"
dacdca0 changed: moved CAddonStatusHandler to separate files
alcoheca authored
36 #include "log.h"
074db86 merged: addons-fw branch
elupus authored
37
38 #ifdef HAS_VISUALISATION
055f806 cosmetic/tidyup move all addon classes to /xbmc/addons/
alcoheca authored
39 #include "DllVisualisation.h"
40 #include "Visualisation.h"
074db86 merged: addons-fw branch
elupus authored
41 #endif
42 #ifdef HAS_SCREENSAVER
055f806 cosmetic/tidyup move all addon classes to /xbmc/addons/
alcoheca authored
43 #include "DllScreenSaver.h"
44 #include "ScreenSaver.h"
074db86 merged: addons-fw branch
elupus authored
45 #endif
46 //#ifdef HAS_SCRAPERS
055f806 cosmetic/tidyup move all addon classes to /xbmc/addons/
alcoheca authored
47 #include "Scraper.h"
074db86 merged: addons-fw branch
elupus authored
48 //#endif
606248f added: addon repository class
spiff_ authored
49 #include "Repository.h"
553d213 changed: finished moving skins to addon framework
alcoheca authored
50 #include "Skin.h"
af8cb2a Revert "wip"
alcoheca authored
51
88e9b6f changed: expand std namespace
spiff_ authored
52 using namespace std;
53
074db86 merged: addons-fw branch
elupus authored
54 namespace ADDON
55 {
56
b6f0f59 cleanup: Don't expose the AddonManager's privates when not required.
jmarshallnz authored
57 cp_log_severity_t clog_to_cp(int lvl);
58 void cp_fatalErrorHandler(const char *msg);
59 void cp_logger(cp_log_severity_t level, const char *msg, const char *apid, void *user_data);
074db86 merged: addons-fw branch
elupus authored
60
61 /**********************************************************
62 * CAddonMgr
63 *
64 */
65
88e9b6f changed: expand std namespace
spiff_ authored
66 map<TYPE, IAddonMgrCallback*> CAddonMgr::m_managers;
074db86 merged: addons-fw branch
elupus authored
67
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
68 AddonPtr CAddonMgr::Factory(const cp_extension_t *props)
1b2781c added: basic cpluff support
alcoheca authored
69 {
bb4e01c Support creating userdirs in addons. This also has the benefit of being ...
ceros7 authored
70 /* Check if user directories need to be created */
71 const cp_cfg_element_t *settings = GetExtElement(props->plugin->extensions->configuration, "settings");
72 if (settings)
73 CheckUserDirs(settings);
74
1b2781c added: basic cpluff support
alcoheca authored
75 const TYPE type = TranslateType(props->ext_point_id);
76 switch (type)
77 {
78 case ADDON_PLUGIN:
79 case ADDON_SCRIPT:
80 return AddonPtr(new CAddon(props->plugin));
81 case ADDON_SCRAPER:
82 return AddonPtr(new CScraper(props->plugin));
83 case ADDON_VIZ:
84 case ADDON_SCREENSAVER:
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
85 { // begin temporary platform handling for Dlls
86 // ideally platforms issues will be handled by C-Pluff
87 // this is not an attempt at a solution
88 CStdString value;
89 #if defined(_LINUX) && !defined(__APPLE__)
90 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_linux")) && value.empty())
91 break;
92 #elif defined(_WIN32) && defined(HAS_SDL_OPENGL)
93 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_wingl")) && value.empty())
94 break;
95 #elif defined(_WIN32) && defined(HAS_DX)
96 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_windx")) && value.empty())
97 break;
98 #elif defined(__APPLE__)
99 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_osx")) && value.empty())
100 break;
101 #elif defined(_XBOX)
102 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_xbox")) && value.empty())
103 break;
104 #endif
105 if (type == ADDON_VIZ)
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his hard w...
davilla authored
106 {
107 #if defined(HAS_VISUALISATION)
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
108 return AddonPtr(new CVisualisation(props->plugin));
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his hard w...
davilla authored
109 #endif
110 }
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
111 else
112 return AddonPtr(new CScreenSaver(props->plugin));
113 }
5ff028a added: skin support via cpluff
alcoheca authored
114 case ADDON_SKIN:
115 return AddonPtr(new CSkinInfo(props->plugin));
1b2781c added: basic cpluff support
alcoheca authored
116 case ADDON_SCRAPER_LIBRARY:
d289db4 fixed: script libraries weren't created in CAddonMgr::Factory
jmarshallnz authored
117 case ADDON_SCRIPT_LIBRARY:
1b2781c added: basic cpluff support
alcoheca authored
118 case ADDON_VIZ_LIBRARY:
119 return AddonPtr(new CAddonLibrary(props->plugin));
9ea9065 changed: Move repositories to cpluff
jmarshallnz authored
120 case ADDON_REPOSITORY:
121 return AddonPtr(new CRepository(props->plugin));
1b2781c added: basic cpluff support
alcoheca authored
122 default:
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
123 break;
1b2781c added: basic cpluff support
alcoheca authored
124 }
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
125 return AddonPtr();
1b2781c added: basic cpluff support
alcoheca authored
126 }
127
bb4e01c Support creating userdirs in addons. This also has the benefit of being ...
ceros7 authored
128 bool CAddonMgr::CheckUserDirs(const cp_cfg_element_t *settings)
129 {
130 if (!settings)
131 return false;
132
133 const cp_cfg_element_t *userdirs = GetExtElement((cp_cfg_element_t *)settings, "userdirs");
134 if (!userdirs)
135 return false;
136
137 DEQUEELEMENTS elements;
138 bool status = GetExtElementDeque(elements, (cp_cfg_element_t *)userdirs, "userdir");
139 if (!status)
140 return false;
141
142 IDEQUEELEMENTS itr = elements.begin();
143 while (itr != elements.end())
144 {
145 CStdString path = GetExtValue(*itr++, "@path");
146 if (!CFile::Exists(path))
147 {
148 if (!CUtil::CreateDirectoryEx(path))
149 {
150 CLog::Log(LOGERROR, "CAddonMgr::CheckUserDirs: Unable to create directory %s.", path.c_str());
151 return false;
152 }
153 }
154 }
155
156 return true;
157 }
158
074db86 merged: addons-fw branch
elupus authored
159 CAddonMgr::CAddonMgr()
160 {
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
161 m_watch.StartZero();
074db86 merged: addons-fw branch
elupus authored
162 }
163
164 CAddonMgr::~CAddonMgr()
165 {
37a994e added: Deinit to the addons manager to ensure we unload cpluff prior to ...
jmarshallnz authored
166 DeInit();
074db86 merged: addons-fw branch
elupus authored
167 }
168
47a8196 changed: matched other singelton calls
alcoheca authored
169 CAddonMgr &CAddonMgr::Get()
074db86 merged: addons-fw branch
elupus authored
170 {
47a8196 changed: matched other singelton calls
alcoheca authored
171 static CAddonMgr sAddonMgr;
172 return sAddonMgr;
074db86 merged: addons-fw branch
elupus authored
173 }
174
175 IAddonMgrCallback* CAddonMgr::GetCallbackForType(TYPE type)
176 {
177 if (m_managers.find(type) == m_managers.end())
178 return NULL;
179 else
180 return m_managers[type];
181 }
182
183 bool CAddonMgr::RegisterAddonMgrCallback(const TYPE type, IAddonMgrCallback* cb)
184 {
185 if (cb == NULL)
186 return false;
187
188 m_managers.erase(type);
189 m_managers[type] = cb;
190
191 return true;
192 }
193
194 void CAddonMgr::UnregisterAddonMgrCallback(TYPE type)
195 {
196 m_managers.erase(type);
197 }
198
1b2781c added: basic cpluff support
alcoheca authored
199 bool CAddonMgr::Init()
200 {
201 m_cpluff = new DllLibCPluff;
202 m_cpluff->Load();
203
204 if (!m_cpluff->IsLoaded())
205 {
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
206 CLog::Log(LOGERROR, "ADDONS: Fatal Error, could not load libcpluff");
207 return false;
1b2781c added: basic cpluff support
alcoheca authored
208 }
209
210 m_cpluff->set_fatal_error_handler(cp_fatalErrorHandler);
211
212 cp_status_t status;
213 status = m_cpluff->init();
214 if (status != CP_OK)
215 {
216 CLog::Log(LOGERROR, "ADDONS: Fatal Error, cp_init() returned status: %i", status);
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
217 return false;
1b2781c added: basic cpluff support
alcoheca authored
218 }
219
220 //TODO could separate addons into different contexts
221 // would allow partial unloading of addon framework
222 m_cp_context = m_cpluff->create_context(&status);
223 assert(m_cp_context);
7cef07e cleanup: remove unused XBMCIsHome function, now that they're no longer t...
jmarshallnz authored
224 status = m_cpluff->register_pcollection(m_cp_context, _P("special://home/addons"));
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
225 status = m_cpluff->register_pcollection(m_cp_context, _P("special://xbmc/addons"));
226 if (status != CP_OK)
227 {
228 CLog::Log(LOGERROR, "ADDONS: Fatal Error, cp_register_pcollection() returned status: %i", status);
229 return false;
1b2781c added: basic cpluff support
alcoheca authored
230 }
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
231
185686a added: even more missing from r29798
alcoheca authored
232 status = m_cpluff->register_logger(m_cp_context, cp_logger,
7188808 changed: bail out immeditaly if CAddonMgr::Init returns false
alcoheca authored
233 &CAddonMgr::Get(), clog_to_cp(g_advancedSettings.m_logLevel));
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
234 if (status != CP_OK)
235 {
236 CLog::Log(LOGERROR, "ADDONS: Fatal Error, cp_register_logger() returned status: %i", status);
237 return false;
238 }
1b2781c added: basic cpluff support
alcoheca authored
239
f0b69e1 changed: move the cpluff plugin scanner call to findaddons
spiff_ authored
240 FindAddons();
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
241 return true;
1b2781c added: basic cpluff support
alcoheca authored
242 }
243
37a994e added: Deinit to the addons manager to ensure we unload cpluff prior to ...
jmarshallnz authored
244 void CAddonMgr::DeInit()
245 {
246 if (m_cpluff)
247 m_cpluff->destroy();
248 m_cpluff = NULL;
249 }
250
cc3b982 fixed: don't crash if an (visualization) addon is disabled
elupus authored
251 bool CAddonMgr::HasAddons(const TYPE &type, const CONTENT_TYPE &content/*= CONTENT_NONE*/, bool enabledOnly/*= true*/)
074db86 merged: addons-fw branch
elupus authored
252 {
2c2e61e changed: initial move of scrapers to cpluff. since deps aren't handled, ...
spiff_ authored
253 if (type == ADDON_SCREENSAVER || type == ADDON_SKIN || type == ADDON_VIZ || type == ADDON_SCRIPT || type == ADDON_REPOSITORY || type == ADDON_SCRAPER)
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
254 {
255 cp_status_t status;
256 int num;
257 CStdString ext_point(TranslateType(type));
2ff4a7d fixed: didn't release all ref counted objects returned from cpluff
alcoheca authored
258 cp_extension_t **exts = m_cpluff->get_extensions_info(m_cp_context, ext_point.c_str(), &status, &num);
259 m_cpluff->release_info(m_cp_context, exts);
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
260 if (status == CP_OK)
261 return (num > 0);
262 }
263
af8cb2a Revert "wip"
alcoheca authored
264 if (m_addons.empty())
265 {
266 VECADDONS add;
267 GetAllAddons(add,false);
268 }
269
270 if (content == CONTENT_NONE)
271 return (m_addons.find(type) != m_addons.end());
074db86 merged: addons-fw branch
elupus authored
272
273 VECADDONS addons;
cc3b982 fixed: don't crash if an (visualization) addon is disabled
elupus authored
274 return GetAddons(type, addons, content, enabledOnly);
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
275
074db86 merged: addons-fw branch
elupus authored
276 }
277
278 bool CAddonMgr::GetAllAddons(VECADDONS &addons, bool enabledOnly/*= true*/)
279 {
af8cb2a Revert "wip"
alcoheca authored
280 VECADDONS temp;
7188808 changed: bail out immeditaly if CAddonMgr::Init returns false
alcoheca authored
281 if (CAddonMgr::Get().GetAddons(ADDON_PLUGIN, temp, CONTENT_NONE, enabledOnly))
af8cb2a Revert "wip"
alcoheca authored
282 addons.insert(addons.end(), temp.begin(), temp.end());
7188808 changed: bail out immeditaly if CAddonMgr::Init returns false
alcoheca authored
283 if (CAddonMgr::Get().GetAddons(ADDON_SCRAPER, temp, CONTENT_NONE, enabledOnly))
af8cb2a Revert "wip"
alcoheca authored
284 addons.insert(addons.end(), temp.begin(), temp.end());
7188808 changed: bail out immeditaly if CAddonMgr::Init returns false
alcoheca authored
285 if (CAddonMgr::Get().GetAddons(ADDON_SCREENSAVER, temp, CONTENT_NONE, enabledOnly))
af8cb2a Revert "wip"
alcoheca authored
286 addons.insert(addons.end(), temp.begin(), temp.end());
7188808 changed: bail out immeditaly if CAddonMgr::Init returns false
alcoheca authored
287 if (CAddonMgr::Get().GetAddons(ADDON_SCRIPT, temp, CONTENT_NONE, enabledOnly))
af8cb2a Revert "wip"
alcoheca authored
288 addons.insert(addons.end(), temp.begin(), temp.end());
7188808 changed: bail out immeditaly if CAddonMgr::Init returns false
alcoheca authored
289 if (CAddonMgr::Get().GetAddons(ADDON_SKIN, temp, CONTENT_NONE, enabledOnly))
553d213 changed: finished moving skins to addon framework
alcoheca authored
290 addons.insert(addons.end(), temp.begin(), temp.end());
7188808 changed: bail out immeditaly if CAddonMgr::Init returns false
alcoheca authored
291 if (CAddonMgr::Get().GetAddons(ADDON_VIZ, temp, CONTENT_NONE, enabledOnly))
af8cb2a Revert "wip"
alcoheca authored
292 addons.insert(addons.end(), temp.begin(), temp.end());
293 return !addons.empty();
074db86 merged: addons-fw branch
elupus authored
294 }
295
296 bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, const CONTENT_TYPE &content/*= CONTENT_NONE*/, bool enabledOnly/*= true*/)
297 {
4e5b98a added: locks to addon manager
spiff_ authored
298 CSingleLock lock(m_critSection);
af8cb2a Revert "wip"
alcoheca authored
299 addons.clear();
2c2e61e changed: initial move of scrapers to cpluff. since deps aren't handled, ...
spiff_ authored
300 if (type == ADDON_SCREENSAVER || type == ADDON_SKIN || type == ADDON_VIZ || type == ADDON_REPOSITORY || type == ADDON_SCRIPT || type == ADDON_SCRAPER)
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
301 {
302 cp_status_t status;
303 int num;
304 CStdString ext_point(TranslateType(type));
305 cp_extension_t **exts = m_cpluff->get_extensions_info(m_cp_context, ext_point.c_str(), &status, &num);
306 for(int i=0; i <num; i++)
307 {
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
308 AddonPtr addon(Factory(exts[i]));
2c2e61e changed: initial move of scrapers to cpluff. since deps aren't handled, ...
spiff_ authored
309 if (addon && (content == CONTENT_NONE || addon->Supports(content)))
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
310 addons.push_back(addon);
311 }
312 m_cpluff->release_info(m_cp_context, exts);
6933a8d fixed: compile warning
jmarshallnz authored
313 return addons.size() > 0;
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
314 }
315
af8cb2a Revert "wip"
alcoheca authored
316 if (m_addons.find(type) != m_addons.end())
317 {
318 IVECADDONS itr = m_addons[type].begin();
319 while (itr != m_addons[type].end())
320 { // filter out what we're not looking for
dea84cb changed: Disabled() -> Enabled() - more intuitive
spiff_ authored
321 if ((enabledOnly && !(*itr)->Enabled())
af8cb2a Revert "wip"
alcoheca authored
322 || (content != CONTENT_NONE && !(*itr)->Supports(content)))
323 {
324 ++itr;
325 continue;
326 }
327 addons.push_back(*itr);
328 ++itr;
329 }
330 }
331 return !addons.empty();
074db86 merged: addons-fw branch
elupus authored
332 }
333
cc3b982 fixed: don't crash if an (visualization) addon is disabled
elupus authored
334 bool CAddonMgr::GetAddon(const CStdString &str, AddonPtr &addon, const TYPE &type/*=ADDON_UNKNOWN*/, bool enabledOnly/*= true*/)
074db86 merged: addons-fw branch
elupus authored
335 {
4e5b98a added: locks to addon manager
spiff_ authored
336 CSingleLock lock(m_critSection);
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
337 if (type != ADDON_UNKNOWN
338 && type != ADDON_SCREENSAVER
5ff028a added: skin support via cpluff
alcoheca authored
339 && type != ADDON_SKIN
f14b201 changed: support visualizations via cpluff
alcoheca authored
340 && type != ADDON_VIZ
9ea9065 changed: Move repositories to cpluff
jmarshallnz authored
341 && type != ADDON_REPOSITORY
79ac8ab changed: Move scripts to cpluff
jmarshallnz authored
342 && type != ADDON_SCRIPT
2c2e61e changed: initial move of scrapers to cpluff. since deps aren't handled, ...
spiff_ authored
343 && type != ADDON_SCRAPER
a16721e changed: move scraper libraries to cpluff
spiff_ authored
344 && type != ADDON_SCRAPER_LIBRARY
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
345 && m_addons.find(type) == m_addons.end())
074db86 merged: addons-fw branch
elupus authored
346 return false;
347
c22f535 cosmetics
alcoheca authored
348 cp_status_t status;
349 cp_plugin_info_t *cpaddon = NULL;
350 cpaddon = m_cpluff->get_plugin_info(m_cp_context, str.c_str(), &status);
351 if (status == CP_OK && cpaddon->extensions)
352 {
353 addon = Factory(cpaddon->extensions);
354 m_cpluff->release_info(m_cp_context, cpaddon);
355 return true;
356 }
357 if (cpaddon)
358 m_cpluff->release_info(m_cp_context, cpaddon);
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
359
7411555 changed: renamed UUID to ID. we now accept any string as an identifier,
alcoheca authored
360 if (m_idMap[str])
361 {
362 addon = m_idMap[str];
cc3b982 fixed: don't crash if an (visualization) addon is disabled
elupus authored
363 if(enabledOnly)
dea84cb changed: Disabled() -> Enabled() - more intuitive
spiff_ authored
364 return addon->Enabled();
cc3b982 fixed: don't crash if an (visualization) addon is disabled
elupus authored
365 else
366 return true;
7411555 changed: renamed UUID to ID. we now accept any string as an identifier,
alcoheca authored
367 }
074db86 merged: addons-fw branch
elupus authored
368
369 VECADDONS &addons = m_addons[type];
370 IVECADDONS adnItr = addons.begin();
371 while (adnItr != addons.end())
372 {
373 //FIXME scrapers were previously registered by filename
7411555 changed: renamed UUID to ID. we now accept any string as an identifier,
alcoheca authored
374 if ((*adnItr)->Name() == str || (type == ADDON_SCRAPER && (*adnItr)->LibName() == str))
074db86 merged: addons-fw branch
elupus authored
375 {
376 addon = (*adnItr);
cc3b982 fixed: don't crash if an (visualization) addon is disabled
elupus authored
377 if(enabledOnly)
dea84cb changed: Disabled() -> Enabled() - more intuitive
spiff_ authored
378 return addon->Enabled();
cc3b982 fixed: don't crash if an (visualization) addon is disabled
elupus authored
379 else
380 return true;
074db86 merged: addons-fw branch
elupus authored
381 }
382 adnItr++;
383 }
384
385 return false;
386 }
387
388 //TODO handle all 'default' cases here, not just scrapers & vizs
389 bool CAddonMgr::GetDefault(const TYPE &type, AddonPtr &addon, const CONTENT_TYPE &content)
390 {
391 if (type != ADDON_SCRAPER && type != ADDON_VIZ)
392 return false;
393
394 CStdString setting;
395 if (type == ADDON_VIZ)
396 setting = g_guiSettings.GetString("musicplayer.visualisation");
397 else
398 {
399 switch (content)
400 {
401 case CONTENT_MOVIES:
402 {
403 setting = g_guiSettings.GetString("scrapers.moviedefault");
404 break;
405 }
406 case CONTENT_TVSHOWS:
407 {
408 setting = g_guiSettings.GetString("scrapers.tvshowdefault");
409 break;
410 }
411 case CONTENT_MUSICVIDEOS:
412 {
413 setting = g_guiSettings.GetString("scrapers.musicvideodefault");
414 break;
415 }
416 case CONTENT_ALBUMS:
417 case CONTENT_ARTISTS:
418 {
419 setting = g_guiSettings.GetString("musiclibrary.scraper");
420 break;
421 }
422 default:
423 return false;
424 }
425 }
2ca76f9 changed: all addons should be store below either special://home/addons o...
alcoheca authored
426 return GetAddon(setting, addon, type);
074db86 merged: addons-fw branch
elupus authored
427 }
428
7411555 changed: renamed UUID to ID. we now accept any string as an identifier,
alcoheca authored
429 CStdString CAddonMgr::GetString(const CStdString &id, const int number)
074db86 merged: addons-fw branch
elupus authored
430 {
7411555 changed: renamed UUID to ID. we now accept any string as an identifier,
alcoheca authored
431 AddonPtr addon = m_idMap[id];
074db86 merged: addons-fw branch
elupus authored
432 if (addon)
433 return addon->GetString(number);
434
435 return "";
436 }
437
af8cb2a Revert "wip"
alcoheca authored
438 void CAddonMgr::FindAddons()
439 {
4e5b98a added: locks to addon manager
spiff_ authored
440 CSingleLock lock(m_critSection);
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
441 m_addons.clear();
442 m_idMap.clear();
c8f3bba fixed: dependency resolving
spiff_ authored
443
444 // store any addons with unresolved deps, then recheck at the end
445 map<CStdString, AddonPtr> unresolved;
446
7cef07e cleanup: remove unused XBMCIsHome function, now that they're no longer t...
jmarshallnz authored
447 LoadAddons("special://home/addons",unresolved);
c8f3bba fixed: dependency resolving
spiff_ authored
448 LoadAddons("special://xbmc/addons",unresolved);
449
450 for (map<CStdString,AddonPtr>::iterator it = unresolved.begin();
451 it != unresolved.end(); ++it)
452 {
453 if (DependenciesMet(it->second))
454 {
455 if (!UpdateIfKnown(it->second))
456 {
457 m_addons[it->second->Type()].push_back(it->second);
458 m_idMap.insert(make_pair(it->first,it->second));
459 }
460 }
461 }
f0b69e1 changed: move the cpluff plugin scanner call to findaddons
spiff_ authored
462 if (m_cpluff && m_cp_context)
463 m_cpluff->scan_plugins(m_cp_context, 0);
535b4e7 changed: load addons from user directory first, then load from system di...
elupus authored
464 }
465
c8f3bba fixed: dependency resolving
spiff_ authored
466 void CAddonMgr::LoadAddons(const CStdString &path,
467 map<CStdString, AddonPtr>& unresolved)
535b4e7 changed: load addons from user directory first, then load from system di...
elupus authored
468 {
af8cb2a Revert "wip"
alcoheca authored
469 // parse the user & system dirs for addons of the requested type
470 CFileItemList items;
535b4e7 changed: load addons from user directory first, then load from system di...
elupus authored
471 CDirectory::GetDirectory(path, items);
af8cb2a Revert "wip"
alcoheca authored
472
473 // for all folders found
474 for (int i = 0; i < items.Size(); ++i)
475 {
476 CFileItemPtr item = items[i];
477
478 if(!item->m_bIsFolder)
479 continue;
480
481 // read description.xml and populate the addon
482 AddonPtr addon;
483 if (!AddonFromInfoXML(item->m_strPath, addon))
484 continue;
485
535b4e7 changed: load addons from user directory first, then load from system di...
elupus authored
486 // only load if addon with same id isn't already loaded
c8f3bba fixed: dependency resolving
spiff_ authored
487 if(m_idMap.find(addon->ID()) != m_idMap.end() ||
488 unresolved.find(addon->ID()) != unresolved.end())
535b4e7 changed: load addons from user directory first, then load from system di...
elupus authored
489 {
490 CLog::Log(LOGDEBUG, "ADDON: already loaded id %s, bypassing package", addon->ID().c_str());
491 continue;
492 }
493
af8cb2a Revert "wip"
alcoheca authored
494 // refuse to store addons with missing library
495 CStdString library(CUtil::AddFileToFolder(addon->Path(), addon->LibName()));
496 if (!CFile::Exists(library))
497 {
498 CLog::Log(LOGDEBUG, "ADDON: Missing library file %s, bypassing package", library.c_str());
499 continue;
500 }
501
502 if (!DependenciesMet(addon))
503 {
c8f3bba fixed: dependency resolving
spiff_ authored
504 unresolved.insert(make_pair(addon->ID(),addon));
af8cb2a Revert "wip"
alcoheca authored
505 continue;
506 }
507 else
508 { // everything ok, add to available addons if new
509 if (UpdateIfKnown(addon))
510 continue;
511 else
512 {
513 m_addons[addon->Type()].push_back(addon);
88e9b6f changed: expand std namespace
spiff_ authored
514 m_idMap.insert(make_pair(addon->ID(), addon));
af8cb2a Revert "wip"
alcoheca authored
515 }
516 }
517 }
518 }
519
520 bool CAddonMgr::UpdateIfKnown(AddonPtr &addon)
521 {
522 if (m_addons.find(addon->Type()) != m_addons.end())
523 {
524 for (unsigned i = 0; i < m_addons[addon->Type()].size(); i++)
525 {
526 if (m_addons[addon->Type()][i]->ID() == addon->ID())
527 {
528 //TODO inform any manager first, and request removal
529 //TODO choose most recent version if varying
530 m_addons[addon->Type()][i] = addon;
531 CStdString id = addon->ID();
532 m_idMap.erase(id);
88e9b6f changed: expand std namespace
spiff_ authored
533 m_idMap.insert(make_pair(addon->ID(), addon));
af8cb2a Revert "wip"
alcoheca authored
534 return true;
535 }
536 }
537 }
538 return false;
539 }
540
541 bool CAddonMgr::DependenciesMet(AddonPtr &addon)
542 {
543 if (!addon)
544 return false;
545
4e5b98a added: locks to addon manager
spiff_ authored
546 CSingleLock lock(m_critSection);
af8cb2a Revert "wip"
alcoheca authored
547 ADDONDEPS deps = addon->GetDeps();
548 ADDONDEPS::iterator itr = deps.begin();
549 while (itr != deps.end())
550 {
551 CStdString id;
552 id = (*itr).first;
553 AddonVersion min = (*itr).second.first;
554 AddonVersion max = (*itr).second.second;
555 if (m_idMap.count(id))
556 {
557 AddonPtr dep = m_idMap[id];
558 // we're guaranteed to have at least max OR min here
559 if (!min.str.IsEmpty() && !max.str.IsEmpty())
c8f3bba fixed: dependency resolving
spiff_ authored
560 {
561 if (dep->Version() < min || dep->Version() > max)
562 return false;
563 }
af8cb2a Revert "wip"
alcoheca authored
564 else if (!min.str.IsEmpty())
c8f3bba fixed: dependency resolving
spiff_ authored
565 {
566 if (dep->Version() < min)
567 return false;
568 }
af8cb2a Revert "wip"
alcoheca authored
569 else
c8f3bba fixed: dependency resolving
spiff_ authored
570 {
571 if (dep->Version() > max)
572 return false;
573 }
af8cb2a Revert "wip"
alcoheca authored
574 }
575 itr++;
576 }
c8f3bba fixed: dependency resolving
spiff_ authored
577 return true;
af8cb2a Revert "wip"
alcoheca authored
578 }
579
580 bool CAddonMgr::AddonFromInfoXML(const CStdString &path, AddonPtr &addon)
581 {
582 // First check that we can load description.xml
583 CStdString strPath(CUtil::AddFileToFolder(path, ADDON_METAFILE));
584 if(!CFile::Exists(strPath))
585 return false;
586
587 TiXmlDocument xmlDoc;
588 if (!xmlDoc.LoadFile(strPath))
589 {
590 CLog::Log(LOGERROR, "Unable to load: %s, Line %d\n%s", strPath.c_str(), xmlDoc.ErrorRow(), xmlDoc.ErrorDesc());
591 return false;
592 }
593
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
594 const TiXmlElement *element = xmlDoc.RootElement();
af8cb2a Revert "wip"
alcoheca authored
595 if (!element || strcmpi(element->Value(), "addoninfo") != 0)
596 {
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
597 CLog::Log(LOGERROR, "ADDON: Error loading %s: cannot find <addon> root element", xmlDoc.Value());
af8cb2a Revert "wip"
alcoheca authored
598 return false;
599 }
600
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
601 return AddonFromInfoXML(element, addon, strPath);
602 }
603
604 bool CAddonMgr::AddonFromInfoXML(const TiXmlElement *rootElement,
605 AddonPtr &addon, const CStdString &strPath)
606 {
af8cb2a Revert "wip"
alcoheca authored
607 /* Steps required to meet package requirements
608 * 1. id exists and is valid
609 * 2. type exists and is valid
610 * 3. version exists
611 * 4. a license is specified
612 * 5. operating system matches ours
613 * 6. summary exists
614 * 7. for scrapers & plugins, support at least one type of content
615 *
616 * NOTE: addon dependencies are handled in ::FindAddons()
617 */
618
619 /* Validate id */
620 CStdString id;
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
621 const TiXmlElement *element = rootElement->FirstChildElement("id");
af8cb2a Revert "wip"
alcoheca authored
622 if (!element)
623 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
624 CLog::Log(LOGERROR, "ADDON: %s missing <id> element, ignoring", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
625 return false;
626 }
627 id = element->GetText();
628 //FIXME since we no longer required uuids, should we bother validating anything?
629 if (id.IsEmpty())
630 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
631 CLog::Log(LOGERROR, "ADDON: %s has invalid <id> element, ignoring", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
632 return false;
633 }
634
635 /* Validate type */
636 TYPE type;
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
637 element = rootElement->FirstChildElement("type");
af8cb2a Revert "wip"
alcoheca authored
638 if (!element)
639 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
640 CLog::Log(LOGERROR, "ADDON: %s missing <type> element, ignoring", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
641 return false;
642 }
643 type = TranslateType(element->GetText());
644 if (type == ADDON_UNKNOWN)
645 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
646 CLog::Log(LOGERROR, "ADDON: %s has invalid type identifier: '%d'", rootElement->GetDocument()->Value(), type);
af8cb2a Revert "wip"
alcoheca authored
647 return false;
648 }
649
650 /* Retrieve Name */
651 CStdString name;
822ca91 added: translatable <description>, <title>, <summary> and <disclaimer> i...
spiff_ authored
652 if (!GetTranslatedString(rootElement,"title",name))
af8cb2a Revert "wip"
alcoheca authored
653 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
654 CLog::Log(LOGERROR, "ADDON: %s missing <title> element, ignoring", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
655 return false;
656 }
657
658 /* Retrieve version */
659 CStdString version;
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
660 element = rootElement->FirstChildElement("version");
af8cb2a Revert "wip"
alcoheca authored
661 if (!element)
662 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
663 CLog::Log(LOGERROR, "ADDON: %s missing <version> element, ignoring", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
664 return false;
665 }
666 /* Validate version */
667 version = element->GetText();
668 CRegExp versionRE;
669 versionRE.RegComp(ADDON_VERSION_RE.c_str());
670 if (versionRE.RegFind(version.c_str()) != 0)
671 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
672 CLog::Log(LOGERROR, "ADDON: %s has invalid <version> element, ignoring", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
673 return false;
674 }
675
676 /* Path, ID & Version are valid */
677 AddonProps addonProps(id, type, version);
678 addonProps.name = name;
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
679 CUtil::GetDirectory(strPath,addonProps.path);
a594abe changed: move addon thumbs back to a fixed image (icon.png). We still h...
jmarshallnz authored
680 /* Set Icon */
681 addonProps.icon = "icon.png";
e90479d added: addon changelog support
spiff_ authored
682 /* Set Changelog */
683 addonProps.changelog = CUtil::AddFileToFolder(addonProps.path,"changelog.txt");
d9e6ddf added: fanart support for addons
spiff_ authored
684 /* Set Fanart */
d3c62cd fixed: Addon changelogs weren't being read.
jmarshallnz authored
685 addonProps.fanart = CUtil::AddFileToFolder(addonProps.path,"fanart.jpg");
af8cb2a Revert "wip"
alcoheca authored
686
687 /* Retrieve license */
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
688 element = rootElement->FirstChildElement("license");
af8cb2a Revert "wip"
alcoheca authored
689 /* if (!element)
690 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
691 CLog::Log(LOGERROR, "ADDON: %s missing <license> element, ignoring", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
692 return false;
693 }
694 addonProps.license = element->GetText();*/
695
696 /* Retrieve platforms which this addon supports */
697 CStdString platform;
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
698 element = rootElement->FirstChildElement("platforms")->FirstChildElement("platform");
af8cb2a Revert "wip"
alcoheca authored
699 if (!element)
700 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
701 CLog::Log(LOGERROR, "ADDON: %s missing <platforms> element, ignoring", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
702 return false;
703 }
704
705 bool all(false);
88e9b6f changed: expand std namespace
spiff_ authored
706 set<CStdString> platforms;
af8cb2a Revert "wip"
alcoheca authored
707 do
708 {
709 CStdString platform = element->GetText();
710 if (platform == "all")
711 {
712 all = true;
713 break;
714 }
715 platforms.insert(platform);
716 element = element->NextSiblingElement("platform");
717 } while (element != NULL);
718
719 if (!all)
720 {
721 #if defined(_LINUX) && !defined(__APPLE__)
722 if (!platforms.count("linux"))
723 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
724 CLog::Log(LOGNOTICE, "ADDON: %s is not supported under Linux, ignoring", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
725 return false;
726 }
78d5324 added: separate addon platforms for windows+dx and windows+opengl
spiff_ authored
727 #elif defined(_WIN32) && defined(HAS_SDL_OPENGL)
728 if (!platforms.count("windows-gl") && !platforms.count("windows"))
af8cb2a Revert "wip"
alcoheca authored
729 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
730 CLog::Log(LOGNOTICE, "ADDON: %s is not supported under Windows/OpenGL, ignoring", rootElement->GetDocument()->Value());
78d5324 added: separate addon platforms for windows+dx and windows+opengl
spiff_ authored
731 return false;
732 }
733 #elif defined(_WIN32) && defined(HAS_DX)
734 if (!platforms.count("windows-dx") && !platforms.count("windows"))
735 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
736 CLog::Log(LOGNOTICE, "ADDON: %s is not supported under Windows/DirectX, ignoring", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
737 return false;
738 }
739 #elif defined(__APPLE__)
740 if (!platforms.count("osx"))
741 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
742 CLog::Log(LOGNOTICE, "ADDON: %s is not supported under OSX, ignoring", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
743 return false;
744 }
745 #elif defined(_XBOX)
746 if (!platforms.count("xbox"))
747 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
748 CLog::Log(LOGNOTICE, "ADDON: %s is not supported under XBOX, ignoring", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
749 return false;
750 }
751 #endif
752 }
753
754 /* Retrieve summary */
d10c108 fixed: missing addon summary.
jmarshallnz authored
755 if (!GetTranslatedString(rootElement,"summary",addonProps.summary))
af8cb2a Revert "wip"
alcoheca authored
756 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
757 CLog::Log(LOGERROR, "ADDON: %s missing <summary> element, ignoring", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
758 return false;
759 }
760
761 if (addonProps.type == ADDON_SCRAPER || addonProps.type == ADDON_PLUGIN)
762 {
763 /* Retrieve content types that this addon supports */
764 CStdString platform;
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
765 if (rootElement->FirstChildElement("supportedcontent"))
af8cb2a Revert "wip"
alcoheca authored
766 {
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
767 element = rootElement->FirstChildElement("supportedcontent")->FirstChildElement("content");
af8cb2a Revert "wip"
alcoheca authored
768 }
769 if (!element)
770 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
771 CLog::Log(LOGERROR, "ADDON: %s missing <supportedcontent> element, ignoring", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
772 return false;
773 }
774
88e9b6f changed: expand std namespace
spiff_ authored
775 set<CONTENT_TYPE> contents;
af8cb2a Revert "wip"
alcoheca authored
776 do
777 {
778 CONTENT_TYPE content = TranslateContent(element->GetText());
779 if (content != CONTENT_NONE)
780 {
781 contents.insert(content);
782 }
783 element = element->NextSiblingElement("content");
784 } while (element != NULL);
785
786 if (contents.empty())
787 {
788 CLog::Log(LOGERROR, "ADDON: %s %s supports no available content-types, ignoring", TranslateType(addonProps.type).c_str(), addonProps.name.c_str());
789 return false;
790 }
791 else
792 {
793 addonProps.contents = contents;
794 }
795 }
796
797 /*** Beginning of optional fields ***/
309adab changed: Read addon icon from the <icon> tag rather than assuming defaul...
jmarshallnz authored
798 /* Retrieve icon */
799 element = rootElement->FirstChildElement("icon");
800 if (element)
801 addonProps.icon = element->GetText();
802
af8cb2a Revert "wip"
alcoheca authored
803 /* Retrieve description */
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
804 element = rootElement->FirstChildElement("description");
822ca91 added: translatable <description>, <title>, <summary> and <disclaimer> i...
spiff_ authored
805 GetTranslatedString(rootElement,"description",addonProps.description);
af8cb2a Revert "wip"
alcoheca authored
806
807 /* Retrieve author */
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
808 element = rootElement->FirstChildElement("author");
af8cb2a Revert "wip"
alcoheca authored
809 if (element)
810 addonProps.author = element->GetText();
811
812 /* Retrieve disclaimer */
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
813 element = rootElement->FirstChildElement("disclaimer");
822ca91 added: translatable <description>, <title>, <summary> and <disclaimer> i...
spiff_ authored
814 GetTranslatedString(rootElement,"disclaimer",addonProps.disclaimer);
af8cb2a Revert "wip"
alcoheca authored
815
816 /* Retrieve library file name */
817 // will be replaced with default library name if unspecified
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
818 element = rootElement->FirstChildElement("library");
af8cb2a Revert "wip"
alcoheca authored
819 if (element)
820 addonProps.libname = element->GetText();
821
822 //TODO move this to addon specific class, if it's needed at all..
823 #ifdef _WIN32
824 /* Retrieve WIN32 library file name in case it is present
825 * This is required for no overwrite to the fixed WIN32 add-on's
826 * during compile time
827 */
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
828 element = rootElement->FirstChildElement("librarywin32");
af8cb2a Revert "wip"
alcoheca authored
829 if (element) // If it is found overwrite standard library name
830 addonProps.libname = element->GetText();
831 #endif
832
833 /* Retrieve dependencies that this addon requires */
4ccec44 changed: refactor addon info loading to make it reusable elsewhere
spiff_ authored
834 element = rootElement->FirstChildElement("dependencies");
af8cb2a Revert "wip"
alcoheca authored
835 if (element)
836 {
837 element = element->FirstChildElement("dependency");
838 if (!element)
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
839 CLog::Log(LOGDEBUG, "ADDON: %s missing at least one <dependency> element, will ignore this dependency", rootElement->GetDocument()->Value());
af8cb2a Revert "wip"
alcoheca authored
840 else
841 {
842 do
843 {
8a457f5 fixed: somebody must have had a blond moment - you can't check a stdstri...
spiff_ authored
844 const char* min = element->Attribute("minversion");
845 const char* max = element->Attribute("maxversion");
846 const char* id = element->GetText();
847 if (!id || (!min && !max))
af8cb2a Revert "wip"
alcoheca authored
848 {
349765e cleanup: Removed unnecessary code and changed logging code in addons to ...
jmarshallnz authored
849 CLog::Log(LOGDEBUG, "ADDON: %s malformed <dependency> element, will ignore this dependency", rootElement->GetDocument()->Value());
8a457f5 fixed: somebody must have had a blond moment - you can't check a stdstri...
spiff_ authored
850 element = element->NextSiblingElement("dependency");
af8cb2a Revert "wip"
alcoheca authored
851 continue;
852 }
8a457f5 fixed: somebody must have had a blond moment - you can't check a stdstri...
spiff_ authored
853 addonProps.dependencies.insert(make_pair(CStdString(id), make_pair(AddonVersion(min?min:""), AddonVersion(max?max:""))));
af8cb2a Revert "wip"
alcoheca authored
854 element = element->NextSiblingElement("dependency");
855 } while (element != NULL);
856 }
857 }
858
859 /*** end of optional fields ***/
860
861 /* Create an addon object and store in a shared_ptr */
eca3c5b changed: refactor
spiff_ authored
862 addon = AddonFromProps(addonProps);
863
864 return addon.get() != NULL;
865 }
866
822ca91 added: translatable <description>, <title>, <summary> and <disclaimer> i...
spiff_ authored
867 bool CAddonMgr::GetTranslatedString(const TiXmlElement *xmldoc, const char *tag, CStdString& data)
868 {
869 const TiXmlElement *element = xmldoc->FirstChildElement(tag);
870 const TiXmlElement *enelement = NULL;
871 while (element)
872 {
873 const char* lang = element->Attribute("lang");
874 if (lang && strcmp(lang,g_langInfo.GetDVDAudioLanguage().c_str()) == 0)
875 break;
876 if (!lang || strcmp(lang,"en") == 0)
877 enelement = element;
878 element = element->NextSiblingElement(tag);
879 }
880 if (!element)
881 element = enelement;
882 if (element)
883 data = element->GetText();
884
885 return element != NULL;
886 }
887
096e8a3 changed: Move description information into addon.xml via the xbmc.addon....
jmarshallnz authored
888 const char *CAddonMgr::GetTranslatedString(const cp_cfg_element_t *root, const char *tag)
889 {
890 if (!root)
891 return NULL;
892
893 const cp_cfg_element_t *eng = NULL;
894 for (unsigned int i = 0; i < root->num_children; i++)
895 {
896 const cp_cfg_element_t &child = root->children[i];
897 if (strcmp(tag, child.name) == 0)
898 { // see if we have a "lang" attribute
899 const char *lang = m_cpluff->lookup_cfg_value((cp_cfg_element_t*)&child, "@lang");
900 if (lang && 0 == strcmp(lang,g_langInfo.GetDVDAudioLanguage().c_str()))
901 return child.value;
902 if (!lang || 0 == strcmp(lang, "en"))
903 eng = &child;
904 }
905 }
906 return (eng) ? eng->value : NULL;
907 }
908
eca3c5b changed: refactor
spiff_ authored
909 AddonPtr CAddonMgr::AddonFromProps(AddonProps& addonProps)
910 {
911 switch (addonProps.type)
af8cb2a Revert "wip"
alcoheca authored
912 {
913 case ADDON_PLUGIN:
914 case ADDON_SCRIPT:
eca3c5b changed: refactor
spiff_ authored
915 return AddonPtr(new CAddon(addonProps));
af8cb2a Revert "wip"
alcoheca authored
916 case ADDON_SCRAPER:
eca3c5b changed: refactor
spiff_ authored
917 return AddonPtr(new CScraper(addonProps));
553d213 changed: finished moving skins to addon framework
alcoheca authored
918 case ADDON_SKIN:
919 return AddonPtr(new CSkinInfo(addonProps));
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his hard w...
davilla authored
920 #if defined(HAS_VISUALISATION)
af8cb2a Revert "wip"
alcoheca authored
921 case ADDON_VIZ:
eca3c5b changed: refactor
spiff_ authored
922 return AddonPtr(new CVisualisation(addonProps));
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his hard w...
davilla authored
923 #endif
af8cb2a Revert "wip"
alcoheca authored
924 case ADDON_SCREENSAVER:
eca3c5b changed: refactor
spiff_ authored
925 return AddonPtr(new CScreenSaver(addonProps));
af8cb2a Revert "wip"
alcoheca authored
926 case ADDON_SCRAPER_LIBRARY:
927 case ADDON_VIZ_LIBRARY:
6433385 added: script-library addon-type
spiff_ authored
928 case ADDON_SCRIPT_LIBRARY:
eca3c5b changed: refactor
spiff_ authored
929 return AddonPtr(new CAddonLibrary(addonProps));
606248f added: addon repository class
spiff_ authored
930 case ADDON_REPOSITORY:
931 return AddonPtr(new CRepository(addonProps));
af8cb2a Revert "wip"
alcoheca authored
932 default:
eca3c5b changed: refactor
spiff_ authored
933 break;
af8cb2a Revert "wip"
alcoheca authored
934 }
eca3c5b changed: refactor
spiff_ authored
935 return AddonPtr();
af8cb2a Revert "wip"
alcoheca authored
936 }
937
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
938 void CAddonMgr::UpdateRepos()
939 {
940 CSingleLock lock(m_critSection);
941 if (m_watch.GetElapsedSeconds() < 600)
942 return;
943 m_watch.StartZero();
944 VECADDONS addons;
945 GetAddons(ADDON_REPOSITORY,addons);
946 for (unsigned int i=0;i<addons.size();++i)
947 {
948 RepositoryPtr repo = boost::dynamic_pointer_cast<CRepository>(addons[i]);
949 if (repo->LastUpdate()+CDateTimeSpan(0,6,0,0) < CDateTime::GetCurrentDateTime())
950 {
951 CLog::Log(LOGDEBUG,"Checking repository %s for updates",repo->Name().c_str());
9617e5e cosmetics
spiff_ authored
952 CJobManager::GetInstance().AddJob(new CRepositoryUpdateJob(repo),this);
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
953 }
954 }
955 }
956
957 void CAddonMgr::OnJobComplete(unsigned int jobID, bool success, CJob* job)
958 {
959 if (!success)
960 return;
961
962 ((CRepositoryUpdateJob*)job)->m_repo->SetUpdated(CDateTime::GetCurrentDateTime());
963 }
964
1b2781c added: basic cpluff support
alcoheca authored
965 /*
966 * libcpluff interaction
967 */
968
bb4e01c Support creating userdirs in addons. This also has the benefit of being ...
ceros7 authored
969 const cp_cfg_element_t *CAddonMgr::GetExtElement(cp_cfg_element_t *base, const char *path)
970 {
971 const cp_cfg_element_t *element = NULL;
972 if (base)
973 element = m_cpluff->lookup_cfg_element(base, path);
974 return element;
975 }
976
977 /* Returns all duplicate elements from a base element */
978 bool CAddonMgr::GetExtElementDeque(DEQUEELEMENTS &elements, cp_cfg_element_t *base, const char *path)
979 {
980 if (!base)
981 return false;
982
983 unsigned int i = 0;
984 while (true)
985 {
986 if (i >= base->num_children)
987 break;
988 CStdString temp = (base->children+i)->name;
989 if (!temp.compare(path))
990 elements.push_back(base->children+i);
991 i++;
992 }
993
994 if (elements.empty()) return false;
995 return true;
996 }
997
096e8a3 changed: Move description information into addon.xml via the xbmc.addon....
jmarshallnz authored
998 const cp_extension_t *CAddonMgr::GetExtension(const cp_plugin_info_t *props, const char *extension)
999 {
1000 if (!props)
1001 return NULL;
1002 for (unsigned int i = 0; i < props->num_extensions; ++i)
1003 {
1004 if (0 == strcmp(props->extensions[i].ext_point_id, extension))
1005 return &props->extensions[i];
1006 }
1007 return NULL;
1008 }
1009
a16721e changed: move scraper libraries to cpluff
spiff_ authored
1010 ADDONDEPS CAddonMgr::GetDeps(const CStdString &id)
1011 {
1012 ADDONDEPS result;
1013 cp_status_t status;
1014
1015 cp_plugin_info_t *info = m_cpluff->get_plugin_info(m_cp_context,id.c_str(),&status);
1016 if (info)
1017 {
1018 for (unsigned int i=0;i<info->num_imports;++i)
1019 result.insert(make_pair(CStdString(info->imports[i].plugin_id),
1020 make_pair(AddonVersion(info->version),
1021 AddonVersion(info->version))));
1022 }
1023
1024 return result;
1025 }
1026
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
1027 CStdString CAddonMgr::GetExtValue(cp_cfg_element_t *base, const char *path)
1028 {
1029 const char *value = NULL;
1030 if (base && (value = m_cpluff->lookup_cfg_value(base, path)))
1031 return CStdString(value);
1032 else return CStdString();
1033 }
1034
a16721e changed: move scraper libraries to cpluff
spiff_ authored
1035 vector<CStdString> CAddonMgr::GetExtValues(cp_cfg_element_t *base, const char *path)
1036 {
1037 vector<CStdString> result;
1038 cp_cfg_element_t *parent = m_cpluff->lookup_cfg_element(base,path);
1039 for (unsigned int i=0;parent && i<parent->num_children;++i)
1040 result.push_back(parent->children[i].value);
1041
1042 return result;
1043 }
1044
5bca9c0 cleanup: Rename and document the cpluff versions of loading addon descri...
jmarshallnz authored
1045 bool CAddonMgr::LoadAddonDescription(const CStdString &path, AddonPtr &addon)
92afa2e fixed: Addons weren't installed correctly
jmarshallnz authored
1046 {
1047 cp_status_t status;
1048 cp_plugin_info_t *info = m_cpluff->load_plugin_descriptor(m_cp_context, _P(path).c_str(), &status);
1049 if (info)
1050 {
1051 addon = Factory(info->extensions);
1052 m_cpluff->release_info(m_cp_context, info);
1053 return addon.get();
1054 }
1055 return false;
1056 }
1057
5bca9c0 cleanup: Rename and document the cpluff versions of loading addon descri...
jmarshallnz authored
1058 bool CAddonMgr::AddonsFromRepoXML(const TiXmlElement *root, VECADDONS &addons)
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
1059 {
1060 // create a context for these addons
1061 cp_status_t status;
1062 cp_context_t *context = m_cpluff->create_context(&status);
1063 if (!root || !context)
1064 return false;
1065
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
1066 // each addon XML should have a UTF-8 declaration
1067 TiXmlDeclaration decl("1.0", "UTF-8", "");
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
1068 const TiXmlElement *element = root->FirstChildElement("addon");
1069 while (element)
1070 {
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
1071 // dump the XML back to text
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
1072 std::string xml;
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
1073 xml << decl;
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
1074 xml << *element;
1075 cp_status_t status;
cd2be2f added: Expose cp_load_plugin_descriptor and separate out the from_memory...
jmarshallnz authored
1076 cp_plugin_info_t *info = m_cpluff->load_plugin_descriptor_from_memory(context, xml.c_str(), xml.size(), &status);
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
1077 if (info)
1078 {
1079 AddonPtr addon = Factory(info->extensions);
1080 m_cpluff->release_info(context, info);
1081 // FIXME: sanity check here that the addon satisfies our requirements?
ed51e37 fixed: check for NULL before adding the addon in AddonsFromInfoXML
jmarshallnz authored
1082 if (addon.get())
1083 addons.push_back(addon);
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
1084 }
1085 element = element->NextSiblingElement("addon");
1086 }
1087 m_cpluff->destroy_context(context);
1088 return true;
1089 }
1090
1b2781c added: basic cpluff support
alcoheca authored
1091 int cp_to_clog(cp_log_severity_t lvl)
1092 {
1093 if( lvl == CP_LOG_DEBUG )
1094 return 0;
1095 else if (lvl == CP_LOG_INFO)
1096 return 1;
1097 else if (lvl == CP_LOG_WARNING)
1098 return 3;
1099 else
1100 return 4;
1101 }
1102
1103 cp_log_severity_t clog_to_cp(int lvl)
1104 {
1105 if (lvl >= 4)
1106 return CP_LOG_ERROR;
1107 else if (lvl == 3)
1108 return CP_LOG_WARNING;
1109 else if (lvl >= 1)
1110 return CP_LOG_INFO;
1111 else
1112 return CP_LOG_DEBUG;
1113 }
1114
b6f0f59 cleanup: Don't expose the AddonManager's privates when not required.
jmarshallnz authored
1115 void cp_fatalErrorHandler(const char *msg)
1116 {
1117 CLog::Log(LOGERROR, "ADDONS: CPluffFatalError(%s)", msg);
1118 }
1119
1120 void cp_logger(cp_log_severity_t level, const char *msg, const char *apid, void *user_data)
1b2781c added: basic cpluff support
alcoheca authored
1121 {
1122 if(!apid)
5b793b6 added: missing change from r29798
alcoheca authored
1123 CLog::Log(cp_to_clog(level), "ADDON: cpluff: '%s'", msg);
1b2781c added: basic cpluff support
alcoheca authored
1124 else
5b793b6 added: missing change from r29798
alcoheca authored
1125 CLog::Log(cp_to_clog(level), "ADDON: cpluff: '%s' reports '%s'", apid, msg);
1b2781c added: basic cpluff support
alcoheca authored
1126 }
1127
074db86 merged: addons-fw branch
elupus authored
1128 } /* namespace ADDON */
1129
Something went wrong with that request. Please try again.