mirror of
https://projects.vdr-developer.org/git/vdr-plugin-skindesigner.git
synced 2023-10-19 15:58:31 +00:00
changed skinrepository from static file to github repository
This commit is contained in:
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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::Init(string path) {
|
||||
string repoPath = path + repoFolder;
|
||||
if (FolderExists(repoPath)) {
|
||||
PullRepoGit(repoPath);
|
||||
} else {
|
||||
InitRepoGit(repoPath);
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
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;
|
||||
}
|
||||
|
||||
root = xmlDocGetRootElement(doc);
|
||||
if (root == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (xmlStrcmp(root->name, (const xmlChar *) "skinrepositories")) {
|
||||
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;
|
||||
string filePath = repoPath + fileName;
|
||||
if (! ReadXMLFile(filePath.c_str(), false) ) {
|
||||
esyslog("skindesigner: error reading skinrepo %s", filePath.c_str());
|
||||
continue;
|
||||
}
|
||||
if (xmlStrcmp(node->name, (const xmlChar *) "skinrepo")) {
|
||||
if (! SetDocument() )
|
||||
continue;
|
||||
}
|
||||
ReadRepository(node->xmlChildrenNode);
|
||||
node = node->next;
|
||||
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);
|
||||
} else if (CheckNodeName("url")) {
|
||||
if (GetNodeValue(value)) {
|
||||
repo->SetUrl(value);
|
||||
}
|
||||
} else if (CheckNodeName("author")) {
|
||||
if (GetNodeValue(value)) {
|
||||
repo->SetAuthor(value);
|
||||
}
|
||||
} else if (CheckNodeName("specialfonts")) {
|
||||
if (!LevelDown())
|
||||
continue;
|
||||
do {
|
||||
if (CheckNodeName("font")) {
|
||||
if (GetNodeValue(value)) {
|
||||
repo->SetSpecialFont(value);
|
||||
}
|
||||
}
|
||||
child = child->next;
|
||||
}
|
||||
//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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
repos.push_back(repo);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user