diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-05-02 11:23:05 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-05-02 11:23:05 +0000 |
commit | b8dbdb628ba7a07a785e494d0ed76ebfe9e06615 (patch) | |
tree | 173d22e656ac771e473cdb7c1d035963d39c27e1 /src/configuration.cpp | |
parent | b05628214d64e579504c87da72e79c024245a631 (diff) | |
download | mana-b8dbdb628ba7a07a785e494d0ed76ebfe9e06615.tar.gz mana-b8dbdb628ba7a07a785e494d0ed76ebfe9e06615.tar.bz2 mana-b8dbdb628ba7a07a785e494d0ed76ebfe9e06615.tar.xz mana-b8dbdb628ba7a07a785e494d0ed76ebfe9e06615.zip |
Made config.xml, tmw.log and chatlog.txt always appear in ~/.tmw on *nix.
Diffstat (limited to 'src/configuration.cpp')
-rw-r--r-- | src/configuration.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/configuration.cpp b/src/configuration.cpp index b73e9427..8cacd065 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -43,6 +43,17 @@ void Configuration::init(const std::string &filename) { + configPath = filename; + + // Do not attempt to read config from non-existant file + FILE *testFile = fopen(configPath.c_str(), "r"); + if (!testFile) { + return; + } + else { + fclose(testFile); + } + xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0); if (!doc) return; @@ -50,7 +61,7 @@ void Configuration::init(const std::string &filename) xmlNodePtr node = xmlDocGetRootElement(doc); if (!node || !xmlStrEqual(node->name, BAD_CAST "configuration")) { - logger.log("Warning: No configuration file (%s)", filename.c_str()); + logger->log("Warning: No configuration file (%s)", filename.c_str()); return; } @@ -74,9 +85,9 @@ void Configuration::init(const std::string &filename) xmlFreeDoc(doc); } -bool Configuration::write(const std::string &filename) +bool Configuration::write() { - xmlTextWriterPtr writer = xmlNewTextWriterFilename(filename.c_str(), 0); + xmlTextWriterPtr writer = xmlNewTextWriterFilename(configPath.c_str(), 0); if (writer) { @@ -88,7 +99,7 @@ bool Configuration::write(const std::string &filename) for (iter = options.begin(); iter != options.end(); iter++) { - logger.log("Configuration::write(%s, \"%s\")", + logger->log("Configuration::write(%s, \"%s\")", iter->first.c_str(), iter->second.c_str()); xmlTextWriterStartElement(writer, BAD_CAST "option"); |