diff options
author | louis <louis.braun@gmx.de> | 2015-07-11 13:28:19 +0200 |
---|---|---|
committer | louis <louis.braun@gmx.de> | 2015-07-11 13:28:19 +0200 |
commit | bffafedbd3474901f005b43e3ddf37eef7752e9f (patch) | |
tree | 384063b2413fd5a349b6d2a0358904e8f1e35c10 /libcore | |
parent | 9611291e38d29459201ab13d090be87c0ad82928 (diff) | |
download | vdr-plugin-skindesigner-bffafedbd3474901f005b43e3ddf37eef7752e9f.tar.gz vdr-plugin-skindesigner-bffafedbd3474901f005b43e3ddf37eef7752e9f.tar.bz2 |
changed skinrepository from static file to github repository
Diffstat (limited to 'libcore')
-rw-r--r-- | libcore/helpers.c | 4 | ||||
-rw-r--r-- | libcore/libxmlwrapper.c | 9 | ||||
-rw-r--r-- | libcore/libxmlwrapper.h | 2 | ||||
-rw-r--r-- | libcore/skinrepo.c | 253 | ||||
-rw-r--r-- | libcore/skinrepo.h | 16 |
5 files changed, 144 insertions, 140 deletions
diff --git a/libcore/helpers.c b/libcore/helpers.c index 6af7bcb..9fb0bdf 100644 --- a/libcore/helpers.c +++ b/libcore/helpers.c @@ -152,9 +152,7 @@ bool FirstFileInFolder(string &path, string &extension, string &fileName) { void CreateFolder(string &path) { cString command = cString::sprintf("mkdir -p %s", path.c_str()); int ok = system(*command); - if (!ok) { - esyslog("skindesigner: error creating folder %s", path.c_str()); - } + if (!ok) {} } // trim from start diff --git a/libcore/libxmlwrapper.c b/libcore/libxmlwrapper.c index 565c12c..0a93dfd 100644 --- a/libcore/libxmlwrapper.c +++ b/libcore/libxmlwrapper.c @@ -37,7 +37,7 @@ void cLibXMLWrapper::DeleteDocument(void) { nodeStack.pop();
}
-bool cLibXMLWrapper::ReadXMLFile(const char *path) {
+bool cLibXMLWrapper::ReadXMLFile(const char *path, bool validate) {
if (!ctxt) {
esyslog("skindesigner: Failed to allocate parser context");
return false;
@@ -46,7 +46,11 @@ bool cLibXMLWrapper::ReadXMLFile(const char *path) { dsyslog("skindesigner: reading XML Template %s failed", path);
return false;
}
- doc = xmlCtxtReadFile(ctxt, path, NULL, XML_PARSE_NOENT | XML_PARSE_DTDVALID);
+ if (validate)
+ doc = xmlCtxtReadFile(ctxt, path, NULL, XML_PARSE_NOENT | XML_PARSE_DTDVALID);
+ else
+ doc = xmlCtxtReadFile(ctxt, path, NULL, XML_PARSE_NOENT);
+
if (!doc) {
dsyslog("skindesigner: reading XML Template %s failed", path);
return false;
@@ -180,5 +184,6 @@ bool cLibXMLWrapper::GetNodeValue(string &value) { xmlFree(val);
return true;
}
+ value = "";
return false;
}
diff --git a/libcore/libxmlwrapper.h b/libcore/libxmlwrapper.h index cb1872f..0ace267 100644 --- a/libcore/libxmlwrapper.h +++ b/libcore/libxmlwrapper.h @@ -24,7 +24,7 @@ private: stack<xmlNodePtr> nodeStack;
protected:
void DeleteDocument(void);
- bool ReadXMLFile(const char *path);
+ bool ReadXMLFile(const char *path, bool validate = true);
bool SetDocument(void);
bool Validate(void);
bool CheckNodeName(const char *name);
diff --git a/libcore/skinrepo.c b/libcore/skinrepo.c index c6943f9..5979e57 100644 --- a/libcore/skinrepo.c +++ b/libcore/skinrepo.c @@ -24,6 +24,16 @@ cSkinRepo::cSkinRepo(void) { cSkinRepo::~cSkinRepo() { } +bool cSkinRepo::Valid(void) { + if (!name.size()) + return false; + if (repoType == rtUndefined) + return false; + if (!url.size()) + return false; + return true; +} + void cSkinRepo::Install(string path, string themesPath) { if (Running()) return; @@ -178,8 +188,8 @@ void cSkinRepo::Debug() { // --- cSkinRepos ------------------------------------------------------------- cSkinRepos::cSkinRepos(void) { - repoFile = "skinrepositories.xml"; - doc = NULL; + skinRepoUrl = "https://github.com/louisbraun/skinrepository.git"; + repoFolder = "skinrepositories/"; } cSkinRepos::~cSkinRepos() { @@ -188,41 +198,40 @@ cSkinRepos::~cSkinRepos() { } } -void cSkinRepos::Read(string path) { - string filepath = path + repoFile; - xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); - xmlNodePtr root = NULL; - - doc = xmlCtxtReadFile(ctxt, filepath.c_str(), NULL, XML_PARSE_NOENT); - if (doc == NULL) { - esyslog("skindesigner: ERROR: skinrepository file %s not loaded successfully.", filepath.c_str()); - return; - } - - root = xmlDocGetRootElement(doc); - if (root == NULL) { - return; +void cSkinRepos::Init(string path) { + string repoPath = path + repoFolder; + if (FolderExists(repoPath)) { + PullRepoGit(repoPath); + } else { + InitRepoGit(repoPath); } +} - if (xmlStrcmp(root->name, (const xmlChar *) "skinrepositories")) { +void cSkinRepos::Read(string path) { + string repoPath = path + repoFolder; + DIR *folder = NULL; + struct dirent *dirEntry; + folder = opendir(repoPath.c_str()); + if (!folder) { + esyslog("skindesigner: no skinrepository folder available in %s", repoPath.c_str()); return; } - - xmlNodePtr node = root->xmlChildrenNode; - while (node != NULL) { - if (node->type != XML_ELEMENT_NODE) { - node = node->next; + while (dirEntry = readdir(folder)) { + string fileName = dirEntry->d_name; + if (!fileName.compare(".") || !fileName.compare("..") || !fileName.compare(".git")) continue; - } - if (xmlStrcmp(node->name, (const xmlChar *) "skinrepo")) { + string filePath = repoPath + fileName; + if (! ReadXMLFile(filePath.c_str(), false) ) { + esyslog("skindesigner: error reading skinrepo %s", filePath.c_str()); continue; } - ReadRepository(node->xmlChildrenNode); - node = node->next; + if (! SetDocument() ) + continue; + if (!ParseRepository()) + esyslog("skindesigner: error parsing skinrepository %s", filePath.c_str()); + DeleteDocument(); } - if (doc) xmlFreeDoc(doc); - xmlFreeParserCtxt(ctxt); } cSkinRepo *cSkinRepos::GetRepo(string name) { @@ -249,122 +258,112 @@ void cSkinRepos::Debug(void) { } } -void cSkinRepos::ReadRepository(xmlNodePtr node) { - if (!node) - return; +bool cSkinRepos::ParseRepository(void) { + if (!LevelDown()) + return false; + cSkinRepo *repo = new cSkinRepo(); - while (node != NULL) { - if (node->type != XML_ELEMENT_NODE) { - node = node->next; - continue; - } - - xmlChar *value = NULL; - //Repo Name - if (!xmlStrcmp(node->name, (const xmlChar *) "name")) { - value = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - if (value) - repo->SetName((const char *)value); - //Repo Type - } else if (!xmlStrcmp(node->name, (const xmlChar *) "type")) { - value = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - if (value) { + + do { + string value = ""; + if (CheckNodeName("name")) { + if (GetNodeValue(value)) { + repo->SetName(value); + } + } else if (CheckNodeName("type")) { + if (GetNodeValue(value)) { eRepoType repoType = rtUndefined; - if (!xmlStrcmp(value, (const xmlChar *) "git")) + if (!value.compare("git")) repoType = rtGit; - else if (!xmlStrcmp(value, (const xmlChar *) "zip")) + else if (!value.compare("zip")) repoType = rtZipUrl; repo->SetRepoType(repoType); } - //Repo URL - } else if (!xmlStrcmp(node->name, (const xmlChar *) "url")) { - value = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - if (value) - repo->SetUrl((const char *)value); - //Skin Author - } else if (!xmlStrcmp(node->name, (const xmlChar *) "author")) { - value = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); - if (value) - repo->SetAuthor((const char *)value); - //Repo Specialfonts - } else if (!xmlStrcmp(node->name, (const xmlChar *) "specialfonts")) { - xmlNodePtr child = node->xmlChildrenNode; - while (child != NULL) { - if (child->type != XML_ELEMENT_NODE) { - child = child->next; - continue; - } - if (!xmlStrcmp(child->name, (const xmlChar *) "font")) { - xmlChar *fontvalue = NULL; - fontvalue = xmlNodeListGetString(doc, child->xmlChildrenNode, 1); - if (fontvalue) { - repo->SetSpecialFont((const char *)fontvalue); - xmlFree(fontvalue); - } - } - child = child->next; + } else if (CheckNodeName("url")) { + if (GetNodeValue(value)) { + repo->SetUrl(value); + } + } else if (CheckNodeName("author")) { + if (GetNodeValue(value)) { + repo->SetAuthor(value); } - //Repo supported Plugins - } else if (!xmlStrcmp(node->name, (const xmlChar *) "supportedplugins")) { - xmlNodePtr child = node->xmlChildrenNode; - while (child != NULL) { - if (child->type != XML_ELEMENT_NODE) { - child = child->next; - continue; + } else if (CheckNodeName("specialfonts")) { + if (!LevelDown()) + continue; + do { + if (CheckNodeName("font")) { + if (GetNodeValue(value)) { + repo->SetSpecialFont(value); + } } - if (!xmlStrcmp(child->name, (const xmlChar *) "plugin")) { - xmlChar *plugvalue = NULL; - plugvalue = xmlNodeListGetString(doc, child->xmlChildrenNode, 1); - if (plugvalue) { - repo->SetSupportedPlugin((const char *)plugvalue); - xmlFree(plugvalue); + } while (NextNode()); + LevelUp(); + } else if (CheckNodeName("supportedplugins")) { + if (!LevelDown()) + continue; + do { + if (CheckNodeName("plugin")) { + if (GetNodeValue(value)) { + repo->SetSupportedPlugin(value); } } - child = child->next; + } while (NextNode()); + LevelUp(); + } else if (CheckNodeName("screenshots")) { + if (!LevelDown()) { + continue; } - //Repo Screenshots - } else if (!xmlStrcmp(node->name, (const xmlChar *) "screenshots")) { - xmlNodePtr child = node->xmlChildrenNode; - while (child != NULL) { - if (child->type != XML_ELEMENT_NODE) { - child = child->next; - continue; - } - if (!xmlStrcmp(child->name, (const xmlChar *) "screenshot")) { - xmlNodePtr subchild = child->xmlChildrenNode; + do { + if (CheckNodeName("screenshot")) { + if (!LevelDown()) { + continue; + } string desc = ""; string url = ""; - while (subchild != NULL) { - if (subchild->type != XML_ELEMENT_NODE) { - subchild = subchild->next; - continue; + do { + if (CheckNodeName("description")) { + GetNodeValue(desc); + } else if (CheckNodeName("url")) { + GetNodeValue(url); } - xmlChar *screenshotvalue = NULL; - if (!xmlStrcmp(subchild->name, (const xmlChar *) "description")) { - screenshotvalue = xmlNodeListGetString(doc, subchild->xmlChildrenNode, 1); - if (screenshotvalue) { - desc = (const char *)screenshotvalue; - xmlFree(screenshotvalue); - } - } else if (!xmlStrcmp(subchild->name, (const xmlChar *) "url")) { - screenshotvalue = xmlNodeListGetString(doc, subchild->xmlChildrenNode, 1); - if (screenshotvalue) { - url = (const char *)screenshotvalue; - xmlFree(screenshotvalue); - } - } - subchild = subchild->next; - } - repo->SetScreenshot(desc, url); + } while (NextNode()); + LevelUp(); + if (desc.size() && url.size()) + repo->SetScreenshot(desc, url); } - child = child->next; - } + } while (NextNode()); + LevelUp(); } - if (value) - xmlFree(value); - node = node->next; + } while (NextNode()); + LevelUp(); + if (repo->Valid()) { + repos.push_back(repo); + return true; + } + return false; +} +void cSkinRepos::InitRepoGit(string path) { + dsyslog("skindesigner: initiating skin repository %s", path.c_str()); + CreateFolder(path); + + cString command = cString::sprintf("git clone --depth=1 %s %s", skinRepoUrl.c_str(), path.c_str()); + int result = system (*command); + + if (result == 0) { + dsyslog("skindesigner: skinrepository successfully initiated"); + } else { + esyslog("skindesigner: ERROR initiating skinrepository. Command: %s", *command); } - repos.push_back(repo); } +void cSkinRepos::PullRepoGit(string path) { + dsyslog("skindesigner: updating skin repository %s", path.c_str()); + cString command = *cString::sprintf("cd %s; git pull", path.c_str()); + int result = system (*command); + if (result == 0) { + dsyslog("skindesigner: skinrepository successfully updated"); + } else { + esyslog("skindesigner: ERROR updating skinrepository. Command: %s", *command); + } +} diff --git a/libcore/skinrepo.h b/libcore/skinrepo.h index 9466a2a..d4cc88f 100644 --- a/libcore/skinrepo.h +++ b/libcore/skinrepo.h @@ -5,9 +5,7 @@ #include <vector> #include <map> #include <set> -#include <libxml/parser.h> -#include <libxml/tree.h> -#include <libxml/xmlerror.h> +#include "../libcore/libxmlwrapper.h" #include <vdr/plugin.h> using namespace std; @@ -55,6 +53,7 @@ public: void SetSpecialFont(string font) { specialFonts.push_back(font); }; void SetSupportedPlugin(string plugin) { supportedPlugins.push_back(plugin); }; void SetScreenshot(string desc, string url) { screenshots.push_back(pair<string, string>(desc, url)); }; + bool Valid(void); eRepoType Type(void) { return repoType; }; string Name(void) { return name; }; string Author(void) { return author; }; @@ -72,16 +71,19 @@ public: // --- cSkinRepos ------------------------------------------------------------- -class cSkinRepos { +class cSkinRepos : public cLibXMLWrapper { private: - string repoFile; - xmlDocPtr doc; + string skinRepoUrl; + string repoFolder; vector<cSkinRepo*> repos; vector<cSkinRepo*>::iterator repoIt; - void ReadRepository(xmlNodePtr node); + bool ParseRepository(void); + void InitRepoGit(string path); + void PullRepoGit(string path); public: cSkinRepos(void); virtual ~cSkinRepos(void); + void Init(string path); void Read(string path); int Count(void) { return repos.size(); }; cSkinRepo *GetRepo(string name); |