1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#include "xmlProcessing.h"
#include <wx/filefn.h>
#include <wx/intl.h>
class RtsXmlParser : public xmlAccess::XmlParser
{
public:
RtsXmlParser(const TiXmlElement* rootElement) : xmlAccess::XmlParser(rootElement) {}
void readXmlRealConfig(xmlAccess::XmlRealConfig& outputCfg);
};
void readXmlRealConfig(const TiXmlDocument& doc, xmlAccess::XmlRealConfig& outputCfg);
bool writeXmRealSettings(const xmlAccess::XmlRealConfig& outputCfg, TiXmlDocument& doc);
void xmlAccess::readRealConfig(const wxString& filename, XmlRealConfig& config)
{
//load XML
if (!wxFileExists(filename))
throw XmlError(wxString(_("File does not exist:")) + wxT(" \"") + filename + wxT("\""));
TiXmlDocument doc;
if (!loadXmlDocument(filename, XML_REAL_CONFIG, doc))
throw XmlError(wxString(_("Error reading file:")) + wxT(" \"") + filename + wxT("\""));
RtsXmlParser parser(doc.RootElement());
parser.readXmlRealConfig(config); //read GUI layout configuration
if (parser.errorsOccured())
throw XmlError(wxString(_("Error parsing configuration file:")) + wxT(" \"") + filename + wxT("\"\n\n") +
parser.getErrorMessageFormatted(), XmlError::WARNING);
}
void xmlAccess::writeRealConfig(const XmlRealConfig& outputCfg, const wxString& filename)
{
TiXmlDocument doc;
getDefaultXmlDocument(XML_REAL_CONFIG, doc);
//populate and write XML tree
if ( !writeXmRealSettings(outputCfg, doc) || //add GUI layout configuration settings
!saveXmlDocument(filename, doc)) //save XML
throw XmlError(wxString(_("Error writing file:")) + wxT(" \"") + filename + wxT("\""));
return;
}
//--------------------------------------------------------------------------------
void RtsXmlParser::readXmlRealConfig(xmlAccess::XmlRealConfig& outputCfg)
{
//read directories for monitoring
const TiXmlElement* directoriesToWatch = TiXmlHandleConst(root).FirstChild("Directories").ToElement();
readXmlElementLogging("Folder", directoriesToWatch, outputCfg.directories);
//commandline to execute
readXmlElementLogging("Commandline", root, outputCfg.commandline);
//delay
readXmlElementLogging("Delay", root, outputCfg.delay);
}
bool writeXmRealSettings(const xmlAccess::XmlRealConfig& outputCfg, TiXmlDocument& doc)
{
TiXmlElement* root = doc.RootElement();
if (!root) return false;
//directories to monitor
TiXmlElement* directoriesToWatch = new TiXmlElement("Directories");
root->LinkEndChild(directoriesToWatch);
xmlAccess::addXmlElement("Folder", outputCfg.directories, directoriesToWatch);
//commandline to execute
xmlAccess::addXmlElement("Commandline", outputCfg.commandline, root);
//delay
xmlAccess::addXmlElement("Delay", outputCfg.delay, root);
return true;
}
|