summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-11-01 13:44:38 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-11-01 17:13:46 +0100
commit5922e27d2bc4d2b5ab906afbe2bc029ac90cb2ed (patch)
tree19d2d94b8c90ccb9a24529102431e6a68c0b7a4b /src/common
parentfba5a19e5885e3f4ddca2c249a96fbbe24c846b8 (diff)
downloadmanaserv-5922e27d2bc4d2b5ab906afbe2bc029ac90cb2ed.tar.gz
manaserv-5922e27d2bc4d2b5ab906afbe2bc029ac90cb2ed.tar.xz
manaserv-5922e27d2bc4d2b5ab906afbe2bc029ac90cb2ed.zip
Have one place where the Configuration is initialized
Also, removed the fallback to the standard config file path when a config file path is specified on the command line. Surely that's not what you would want to happen. Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/common')
-rw-r--r--src/common/configuration.cpp15
-rw-r--r--src/common/configuration.h6
2 files changed, 15 insertions, 6 deletions
diff --git a/src/common/configuration.cpp b/src/common/configuration.cpp
index 89b77e3..15ce676 100644
--- a/src/common/configuration.cpp
+++ b/src/common/configuration.cpp
@@ -29,20 +29,25 @@
#include "utils/xml.h"
#include "utils/string.h"
+#define DEFAULT_CONFIG_FILE "manaserv.xml"
+
/**< Persistent configuration. */
static std::map< std::string, std::string > options;
/**< Location of config file. */
static std::string configPath;
-bool Configuration::initialize(const std::string &filename)
+bool Configuration::initialize(const std::string &fileName)
{
- configPath = filename;
+ if (fileName.empty())
+ configPath = DEFAULT_CONFIG_FILE;
+ else
+ configPath = fileName;
- XML::Document doc(filename, false);
+ XML::Document doc(configPath, false);
xmlNodePtr node = doc.rootNode();
if (!node || !xmlStrEqual(node->name, BAD_CAST "configuration")) {
- LOG_WARN("No configuration file '" << filename.c_str() << "'.");
+ LOG_WARN("No configuration file '" << configPath.c_str() << "'.");
return false;
}
@@ -60,6 +65,8 @@ bool Configuration::initialize(const std::string &filename)
options[key] = value;
}
+ LOG_INFO("Using config file: " << configPath);
+
return true;
}
diff --git a/src/common/configuration.h b/src/common/configuration.h
index dbb0a7d..e7fe8ed 100644
--- a/src/common/configuration.h
+++ b/src/common/configuration.h
@@ -28,10 +28,12 @@ namespace Configuration
{
/**
* Loads the configuration options into memory.
- * @param filename path to the configuration file .
+ *
+ * @param filename path to the configuration file. When empty, the default
+ * config file 'manaserv.xml' is used.
* @return whether the configuration file could be read
*/
- bool initialize(const std::string &filename);
+ bool initialize(const std::string &fileName = std::string());
void deinitialize();