diff options
| author | louis <louis.braun@gmx.de> | 2015-05-30 16:43:59 +0200 |
|---|---|---|
| committer | louis <louis.braun@gmx.de> | 2015-05-30 16:43:59 +0200 |
| commit | 17871b8811baa9478b2b3247e340aa21bb64e06e (patch) | |
| tree | c3c2139244bbb11d4f0cf3d32e02c1137e29a1c2 /libcore/skinrepo.c | |
| parent | 0936766c7be02661f1cd678fdd1b6fb22b5d122c (diff) | |
| download | vdr-plugin-skindesigner-17871b8811baa9478b2b3247e340aa21bb64e06e.tar.gz vdr-plugin-skindesigner-17871b8811baa9478b2b3247e340aa21bb64e06e.tar.bz2 | |
implemented Skin Repositories
Diffstat (limited to 'libcore/skinrepo.c')
| -rw-r--r-- | libcore/skinrepo.c | 116 |
1 files changed, 111 insertions, 5 deletions
diff --git a/libcore/skinrepo.c b/libcore/skinrepo.c index 1d5e3e4..4822c5d 100644 --- a/libcore/skinrepo.c +++ b/libcore/skinrepo.c @@ -1,3 +1,5 @@ +#include <iostream> +#include <fstream> #include "skinrepo.h" #include "../libcore/helpers.h" @@ -8,27 +10,61 @@ using namespace std; cSkinRepo::cSkinRepo(void) { name = ""; repoType = rtUndefined; + action = eaUndefined; url = ""; + author = "unknown"; command = ""; + command2 = ""; tempfile = ""; result = -1; + skinPath = ""; + themesPath = ""; } cSkinRepo::~cSkinRepo() { } -void cSkinRepo::Install(string path) { +void cSkinRepo::Install(string path, string themesPath) { if (Running()) return; + action = eaInstall; + this->skinPath = path + name; + this->themesPath = themesPath; if (repoType == rtGit) { - command = *cString::sprintf("git clone --progress %s %s%s", url.c_str(), path.c_str(), name.c_str()); + command = *cString::sprintf("git clone --progress %s %s", url.c_str(), skinPath.c_str()); tempfile = *cString::sprintf("gitclone_%s_%ld.out", name.c_str(), time(0)); Start(); } else if (repoType == rtZipUrl) { + size_t hit = url.find_last_of('/'); + if (hit == string::npos) + return; + string filename = url.substr(hit+1); + + command = *cString::sprintf("wget -P /tmp/ %s", url.c_str()); + command2 = *cString::sprintf("unzip /tmp/%s -d %s", filename.c_str(), path.c_str()); + + Start(); + } +} + +void cSkinRepo::Update(string path) { + if (Running()) + return; + action = eaUpdate; + this->skinPath = path + name; + if (repoType == rtGit) { + + command = *cString::sprintf("cd %s; git pull", skinPath.c_str()); + tempfile = *cString::sprintf("gitpull_%s_%ld.out", name.c_str(), time(0)); + + Start(); + + } else if (repoType == rtZipUrl) { + //TODO } @@ -40,9 +76,66 @@ void cSkinRepo::Action(void) { if (tempfile.size() > 0) { command = *cString::sprintf("%s > /tmp/%s 2>&1", command.c_str(), tempfile.c_str()); } - dsyslog("skindesigner: executing %s", command.c_str()); + result = system (command.c_str()); - dsyslog("skindesigner: execution done, result: %d", result); + + if (result == 0 && command2.size() > 0) { + result = system (command2.c_str()); + } + + if (result == 0) { + if (action == eaInstall) + CreateThemeFiles(); + } +} + +void cSkinRepo::CreateThemeFiles(void) { + string availableThemesPath = skinPath + "/themes/"; + DIR *folder = NULL; + struct dirent *dirEntry; + folder = opendir(availableThemesPath.c_str()); + if (!folder) { + return; + } + vector<string> skinThemes; + while (dirEntry = readdir(folder)) { + string dirEntryName = dirEntry->d_name; + int dirEntryType = dirEntry->d_type; + if (!dirEntryName.compare(".") || !dirEntryName.compare("..") || dirEntryType != DT_DIR) + continue; + skinThemes.push_back(dirEntryName); + } + for (vector<string>::iterator it = skinThemes.begin(); it != skinThemes.end(); it++) { + string themeName = *it; + string themeFileName = themesPath; + themeFileName += name + "-" + themeName + ".theme"; + if (FileExists(themeFileName)) { + continue; + } + ofstream themeFile (themeFileName.c_str()); + if (themeFile.is_open()) { + themeFile << "Description = "; + themeFile << themeName << "\n"; + themeFile.close(); + } + } +} + +bool cSkinRepo::SuccessfullyUpdated(void) { + string logfilePath = "/tmp/" + tempfile; + bool updated = true; + string line; + ifstream logfile(logfilePath.c_str()); + if (logfile.is_open()) { + while ( getline (logfile, line) ) { + if (line.find("up-to-date") != string::npos) { + updated = false; + break; + } + } + logfile.close(); + } + return updated; } void cSkinRepo::Debug() { @@ -53,6 +146,7 @@ void cSkinRepo::Debug() { strRepoType = "ZipUrl"; dsyslog("skindesigner: --- skinrepo %s, Type %s ---", name.c_str(), strRepoType.c_str()); dsyslog("skindesigner: url %s", url.c_str()); + dsyslog("skindesigner: author %s", author.c_str()); if (specialFonts.size() > 0) { for (vector<string>::iterator it = specialFonts.begin(); it != specialFonts.end(); it++) { dsyslog("skindesigner: special font %s", (*it).c_str()); @@ -87,7 +181,6 @@ cSkinRepos::~cSkinRepos() { void cSkinRepos::Read(string path) { string filepath = path + repoFile; - esyslog("skindesigner: reading skinrepos from %s", filepath.c_str()); xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); xmlNodePtr root = NULL; @@ -132,6 +225,14 @@ cSkinRepo *cSkinRepos::GetRepo(string name) { return NULL; } +cSkinRepo *cSkinRepos::GetNextRepo(void) { + if (repoIt == repos.end()) + return NULL; + cSkinRepo *repo = *repoIt; + repoIt++; + return repo; +} + void cSkinRepos::Debug(void) { for (vector<cSkinRepo*>::iterator it = repos.begin(); it != repos.end(); it++) { @@ -171,6 +272,11 @@ void cSkinRepos::ReadRepository(xmlNodePtr node) { 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; |
