summaryrefslogtreecommitdiff
path: root/server/src/templatelist.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/templatelist.cc')
-rw-r--r--server/src/templatelist.cc83
1 files changed, 13 insertions, 70 deletions
diff --git a/server/src/templatelist.cc b/server/src/templatelist.cc
index bbaefc3..b952467 100644
--- a/server/src/templatelist.cc
+++ b/server/src/templatelist.cc
@@ -27,84 +27,27 @@
*/
#include "templatelist.h"
-#include <sys/types.h>
-#include <dirent.h>
+#include "templateheaderparser.h"
#include "debug.h"
-#include "templateheaderparser.h"
-static std::vector<std::string> listdir(std::string path)
+TemplateList::TemplateList(std::string path)
+ : EntityList("template")
{
- std::vector<std::string> files;
-
- DIR* dir = opendir(path.c_str());
- if(!dir) {
- PRACRO_ERR(dump, "Could not open directory: %s\n", path.c_str());
- return files;
- }
-
- struct dirent *d;
- while((d = readdir(dir)) != 0) {
- //if(d->d_type == DT_DIR) {
- std::string name = d->d_name;
- if(name.length() >= 4 && name.substr(name.length() - 4) == ".xml")
- files.push_back(name);
- //}
- }
- closedir(dir);
-
- return files;
+ rescan(path);
}
-TemplateList::TemplateList(std::string templatepath)
+void TemplateList::addFile(std::string file)
{
- MutexAutolock lock(mutex);
-
- this->templatepath = templatepath;
- std::vector<std::string> templates = listdir(templatepath);
- std::vector<std::string>::iterator i = templates.begin();
- while(i != templates.end()) {
- TemplateHeaderParser parser(templatepath + "/" + *i);
- try {
- parser.parse();
- Template *templ = parser.getTemplate();
- (*this)[templ->attributes["name"]][VersionStr(templ->attributes["version"])] = *i;
- } catch(Exception &e) {
- PRACRO_WARN(templatelist, "Skipping %s: %s\n", i->c_str(), e.what());
- }
-
- i++;
- }
-
- {
- iterator i = begin();
- while(i != end()) {
- TemplateListItem::iterator j = i->second.begin();
- while(j != i->second.end()) {
- PRACRO_DEBUG(templatelist, "%s - v%s file: %s\n",
- i->first.c_str(),
- ((std::string)j->first).c_str(),
- j->second.c_str());
- j++;
- }
- i++;
- }
+ PRACRO_DEBUG(templatelist, "Adding file: %s\n", file.c_str());
+ TemplateHeaderParser parser(file);
+ try {
+ parser.parse();
+ Template *templ = parser.getTemplate();
+ (*this)[templ->attributes["name"]][VersionStr(templ->attributes["version"])] = file;
+ } catch(Exception &e) {
+ PRACRO_WARN(templatelist, "Skipping %s: %s\n", file.c_str(), e.what());
}
-
-}
-
-std::string TemplateList::getLatestVersion(std::string templ) throw(Exception)
-{
- MutexAutolock lock(mutex);
-
- if(find(templ) == end()) throw Exception("Template ["+templ+"] does not exist");
- TemplateListItem mli = (*this)[templ];
- if(mli.size() == 0) return "";
- PRACRO_DEBUG(templatelist, "Search for %s - found %s v%s\n",
- templ.c_str(),
- (templatepath + "/" + mli.begin()->second).c_str(),
- ((std::string)mli.begin()->first).c_str());
- return templatepath + "/" + mli.begin()->second;
}
#ifdef TEST_TEMPLATELIST