|
From: Yoda-JM <yo...@us...> - 2010-07-26 11:59:39
|
Module: performous
Branch: controllers
Commit: 241801fb0807d83816b1be34297531fa52d73c65
Author: Vincent Le Ligeour <yo...@us...>
Date: Mon Jul 26 13:59:10 2010 +0200
Moved default config file searching inside fs.* files
---
game/configuration.cc | 26 ++++++++------------------
game/fs.cc | 14 ++++++++++++++
game/fs.hh | 3 +++
3 files changed, 25 insertions(+), 18 deletions(-)
diff --git a/game/configuration.cc b/game/configuration.cc
index 194c25f..f108d4b 100644
--- a/game/configuration.cc
+++ b/game/configuration.cc
@@ -1,6 +1,5 @@
#include "configuration.hh"
-#include "config.hh"
#include "fs.hh"
#include "util.hh"
#include <boost/filesystem.hpp>
@@ -311,24 +310,15 @@ void readConfigXML(fs::path const& file, int mode) {
void readConfig() {
// Find config schema
- std::string schemafile;
- {
- typedef std::vector<std::string> ConfigList;
- ConfigList config_list;
- char const* root = getenv("PERFORMOUS_ROOT");
- if (root) config_list.push_back(std::string(root) + "/" SHARED_DATA_DIR CONFIG_SCHEMA);
- fs::path exec = plugin::execname();
- if (!exec.empty()) config_list.push_back(exec.parent_path().string() + "/../" SHARED_DATA_DIR CONFIG_SCHEMA);
- ConfigList::const_iterator it = std::find_if(config_list.begin(), config_list.end(), static_cast<bool(&)(fs::path const&)>(fs::exists));
- if (it == config_list.end()) {
- std::ostringstream oss;
- oss << "No config schema file found. The following locations were tried:\n";
- std::copy(config_list.begin(), config_list.end(), std::ostream_iterator<std::string>(oss, "\n"));
- oss << "Install the file or define environment variable PERFORMOUS_ROOT\n";
- throw std::runtime_error(oss.str());
- }
- schemafile = *it;
+ fs::path schemafile;
+ try {
+ schemafile = getDefaultConfig(fs::path(CONFIG_SCHEMA));
origin = fs::path(schemafile).parent_path().parent_path(); // Assuming that two times parent from config file = origin
+ } catch(...) {
+ std::ostringstream oss;
+ oss << "No config schema file found.\n";
+ oss << "Install the file or define environment variable PERFORMOUS_ROOT\n";
+ throw std::runtime_error(oss.str());
}
readConfigXML(schemafile, 0); // Read schema and defaults
readConfigXML(systemConfFile, 1); // Update defaults with system config
diff --git a/game/fs.cc b/game/fs.cc
index 79895c2..14dd390 100644
--- a/game/fs.cc
+++ b/game/fs.cc
@@ -178,6 +178,20 @@ Paths const& getPaths(bool refresh) {
return paths;
}
+fs::path getDefaultConfig(fs::path const &configFile) {
+ typedef std::vector<std::string> ConfigList;
+ ConfigList config_list;
+ char const* root = getenv("PERFORMOUS_ROOT");
+ if (root) config_list.push_back(std::string(root) + "/" SHARED_DATA_DIR + configFile.string());
+ fs::path exec = plugin::execname();
+ if (!exec.empty()) config_list.push_back(exec.parent_path().string() + "/../" SHARED_DATA_DIR + configFile.string());
+ ConfigList::const_iterator it = std::find_if(config_list.begin(), config_list.end(), static_cast<bool(&)(fs::path const&)>(fs::exists));
+ if (it == config_list.end()) {
+ throw std::runtime_error("Could not find default config file " + configFile.string());
+ }
+ return *it;
+}
+
Paths getPathsConfig(std::string const& confOption) {
Paths ret;
Paths const& paths = getPaths();
diff --git a/game/fs.hh b/game/fs.hh
index 6d8baa2..d0ae238 100644
--- a/game/fs.hh
+++ b/game/fs.hh
@@ -33,6 +33,9 @@ std::string getThemePath(std::string const& filename);
/** Get full path to a share file **/
std::string getPath(fs::path const& filename);
+/** Get full path to a default conguration file **/
+fs::path getDefaultConfig(fs::path const &configFile);
+
typedef std::vector<fs::path> Paths;
/** Get all shared data paths in preference order **/
|