Permalink
Browse files

Support creating userdirs in addons. This also has the benefit of bei…

…ng able to use duplicate elements in addon.xml.

git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@30185 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
  • Loading branch information...
1 parent 308a81d commit bb4e01cac833a466eced476364ca6b7e81d9fc4d ceros7 committed May 15, 2010
Showing with 78 additions and 1 deletion.
  1. +7 −1 addons/visualization.projectm/addon.xml
  2. +65 −0 xbmc/addons/AddonManager.cpp
  3. +6 −0 xbmc/addons/AddonManager.h
@@ -8,5 +8,11 @@
point="xbmc.player.musicviz"
library_linux="projectM.vis"
library_wingl="projectM_win32.vis"
- library_osx="projectM.vis" />
+ library_osx="projectM.vis">
+ <settings>
+ <userdirs>
+ <userdir path="special://userdata/addon_data/visualization.projectm"/>
+ </userdirs>
+ </settings>
+ </extension>
</addon>
@@ -66,6 +66,11 @@ map<TYPE, IAddonMgrCallback*> CAddonMgr::m_managers;
AddonPtr CAddonMgr::Factory(const cp_extension_t *props)
{
+ /* Check if user directories need to be created */
+ const cp_cfg_element_t *settings = GetExtElement(props->plugin->extensions->configuration, "settings");
+ if (settings)
+ CheckUserDirs(settings);
+
const TYPE type = TranslateType(props->ext_point_id);
switch (type)
{
@@ -112,6 +117,37 @@ AddonPtr CAddonMgr::Factory(const cp_extension_t *props)
return AddonPtr();
}
+bool CAddonMgr::CheckUserDirs(const cp_cfg_element_t *settings)
+{
+ if (!settings)
+ return false;
+
+ const cp_cfg_element_t *userdirs = GetExtElement((cp_cfg_element_t *)settings, "userdirs");
+ if (!userdirs)
+ return false;
+
+ DEQUEELEMENTS elements;
+ bool status = GetExtElementDeque(elements, (cp_cfg_element_t *)userdirs, "userdir");
+ if (!status)
+ return false;
+
+ IDEQUEELEMENTS itr = elements.begin();
+ while (itr != elements.end())
+ {
+ CStdString path = GetExtValue(*itr++, "@path");
+ if (!CFile::Exists(path))
+ {
+ if (!CUtil::CreateDirectoryEx(path))
+ {
+ CLog::Log(LOGERROR, "CAddonMgr::CheckUserDirs: Unable to create directory %s.", path.c_str());
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
CAddonMgr::CAddonMgr()
{
FindAddons();
@@ -898,6 +934,35 @@ void CAddonMgr::OnJobComplete(unsigned int jobID, bool success, CJob* job)
* libcpluff interaction
*/
+const cp_cfg_element_t *CAddonMgr::GetExtElement(cp_cfg_element_t *base, const char *path)
+{
+ const cp_cfg_element_t *element = NULL;
+ if (base)
+ element = m_cpluff->lookup_cfg_element(base, path);
+ return element;
+}
+
+/* Returns all duplicate elements from a base element */
+bool CAddonMgr::GetExtElementDeque(DEQUEELEMENTS &elements, cp_cfg_element_t *base, const char *path)
+{
+ if (!base)
+ return false;
+
+ unsigned int i = 0;
+ while (true)
+ {
+ if (i >= base->num_children)
+ break;
+ CStdString temp = (base->children+i)->name;
+ if (!temp.compare(path))
+ elements.push_back(base->children+i);
+ i++;
+ }
+
+ if (elements.empty()) return false;
+ return true;
+}
+
CStdString CAddonMgr::GetExtValue(cp_cfg_element_t *base, const char *path)
{
const char *value = NULL;
@@ -28,6 +28,7 @@
#include "utils/Stopwatch.h"
#include <vector>
#include <map>
+#include <deque>
class DllLibCPluff;
extern "C"
@@ -41,6 +42,8 @@ namespace ADDON
typedef std::vector<AddonPtr>::iterator IVECADDONS;
typedef std::map<TYPE, VECADDONS> MAPADDONS;
typedef std::map<TYPE, VECADDONS>::iterator IMAPADDONS;
+ typedef std::deque<cp_cfg_element_t*> DEQUEELEMENTS;
+ typedef std::deque<cp_cfg_element_t*>::iterator IDEQUEELEMENTS;
const CStdString ADDON_METAFILE = "description.xml";
const CStdString ADDON_VIS_EXT = "*.vis";
@@ -104,6 +107,8 @@ namespace ADDON
/* libcpluff */
bool GetExtensions(const TYPE &type, VECADDONS &addons, const CONTENT_TYPE &content);
+ const cp_cfg_element_t *GetExtElement(cp_cfg_element_t *base, const char *path);
+ bool GetExtElementDeque(DEQUEELEMENTS &elements, cp_cfg_element_t *base, const char *path);
CStdString GetExtValue(cp_cfg_element_t *base, const char *path);
void CPluffFatalError(const char *msg);
void CPluffLog(cp_log_severity_t level, const char *msg, const char *apid, void *user_data);
@@ -121,6 +126,7 @@ namespace ADDON
bool DependenciesMet(AddonPtr &addon);
bool UpdateIfKnown(AddonPtr &addon);
AddonPtr Factory(const cp_extension_t *props);
+ bool CheckUserDirs(const cp_cfg_element_t *element);
// private construction, and no assignements; use the provided singleton methods
CAddonMgr();

0 comments on commit bb4e01c

Please sign in to comment.