Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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