aboutsummaryrefslogtreecommitdiff
path: root/src/common/Configuration/Config.cpp
diff options
context:
space:
mode:
authorDDuarte <dnpd.dd@gmail.com>2016-03-27 23:47:20 +0100
committerDDuarte <dnpd.dd@gmail.com>2016-03-27 23:49:08 +0100
commit6487e2f2d6a1ddbeff77362219658376b8a3f9f0 (patch)
tree0e14f192b6fd25dbf3505d242a15d933cb0ef75c /src/common/Configuration/Config.cpp
parentb2bd181a5f5e183c0f22695f0ea094c8045b3f08 (diff)
Core/Startup: Warn when a config key isn't found in the config files
Example: "Missing name Guild.SaveInterval in config file worldserver.conf, add "Guild.SaveInterval = 15" to this file" (cherry picked from commit 06b3bca0d2bf6f049128da110681a5244d90225a) # Conflicts: # src/common/Configuration/Config.cpp
Diffstat (limited to 'src/common/Configuration/Config.cpp')
-rw-r--r--src/common/Configuration/Config.cpp44
1 files changed, 36 insertions, 8 deletions
diff --git a/src/common/Configuration/Config.cpp b/src/common/Configuration/Config.cpp
index fba438dbd33..aafd902c558 100644
--- a/src/common/Configuration/Config.cpp
+++ b/src/common/Configuration/Config.cpp
@@ -21,6 +21,7 @@
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include "Config.h"
+#include "Log.h"
using namespace boost::property_tree;
@@ -69,11 +70,18 @@ bool ConfigMgr::Reload(std::string& error)
std::string ConfigMgr::GetStringDefault(std::string const& name, const std::string& def) const
{
- std::string value = _config.get<std::string>(ptree::path_type(name, '/'), def);
-
- value.erase(std::remove(value.begin(), value.end(), '"'), value.end());
-
- return value;
+ try
+ {
+ std::string value = _config.get<std::string>(ptree::path_type(name, '/'));
+ value.erase(std::remove(value.begin(), value.end(), '"'), value.end());
+ return value;
+ }
+ catch (boost::property_tree::ptree_bad_path)
+ {
+ TC_LOG_WARN("server.loading", "Missing name %s in config file %s, add \"%s = %s\" to this file",
+ name.c_str(), _filename.c_str(), name.c_str(), def.c_str());
+ return def;
+ }
}
bool ConfigMgr::GetBoolDefault(std::string const& name, bool def) const
@@ -84,20 +92,40 @@ bool ConfigMgr::GetBoolDefault(std::string const& name, bool def) const
val.erase(std::remove(val.begin(), val.end(), '"'), val.end());
return (val == "true" || val == "TRUE" || val == "yes" || val == "YES" || val == "1");
}
- catch (std::exception const& /*ex*/)
+ catch (boost::property_tree::ptree_bad_path)
{
+ TC_LOG_WARN("server.loading", "Missing name %s in config file %s, add \"%s = %d\" to this file",
+ name.c_str(), _filename.c_str(), name.c_str(), def ? 1 : 0);
return def;
}
}
int ConfigMgr::GetIntDefault(std::string const& name, int def) const
{
- return _config.get<int>(ptree::path_type(name, '/'), def);
+ try
+ {
+ return _config.get<int>(ptree::path_type(name, '/'));
+ }
+ catch (boost::property_tree::ptree_bad_path)
+ {
+ TC_LOG_WARN("server.loading", "Missing name %s in config file %s, add \"%s = %d\" to this file",
+ name.c_str(), _filename.c_str(), name.c_str(), def);
+ return def;
+ }
}
float ConfigMgr::GetFloatDefault(std::string const& name, float def) const
{
- return _config.get<float>(ptree::path_type(name, '/'), def);
+ try
+ {
+ return _config.get<float>(ptree::path_type(name, '/'));
+ }
+ catch (boost::property_tree::ptree_bad_path)
+ {
+ TC_LOG_WARN("server.loading", "Missing name %s in config file %s, add \"%s = %f\" to this file",
+ name.c_str(), _filename.c_str(), name.c_str(), def);
+ return def;
+ }
}
std::string const& ConfigMgr::GetFilename()