From f02234099f6317a0f13ea9c468f6ae071380d2ff Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 18 Nov 2014 17:17:56 +0100 Subject: [PATCH] Added code that checks for completeness (as defined in configurationmanager.cpp) of the configuration file --- .../openspace/engine/configurationmanager.h | 3 +++ include/openspace/util/constants.h | 3 ++- src/engine/configurationmanager.cpp | 26 +++++++++++++++++++ src/engine/openspaceengine.cpp | 24 ++++++----------- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/include/openspace/engine/configurationmanager.h b/include/openspace/engine/configurationmanager.h index 15e29ed8bf..4abad9d362 100644 --- a/include/openspace/engine/configurationmanager.h +++ b/include/openspace/engine/configurationmanager.h @@ -32,6 +32,9 @@ namespace openspace { class ConfigurationManager : public ghoul::Dictionary { public: bool loadFromFile(const std::string& filename); + +private: + bool checkCompleteness() const; }; } // namespace openspace diff --git a/include/openspace/util/constants.h b/include/openspace/util/constants.h index 6d5f8a7259..d834e834fe 100644 --- a/include/openspace/util/constants.h +++ b/include/openspace/util/constants.h @@ -31,7 +31,6 @@ namespace openspace { namespace constants { namespace fonts { - const std::string keyFonts = "Fonts"; const std::string keySGCT = "SGCTFont"; const std::string keyMono = "Mono"; const std::string keyLight = "Light"; @@ -39,6 +38,8 @@ namespace fonts { namespace configurationmanager { const std::string keyPaths = "Paths"; + const std::string keyCachePath = "Paths.CACHE"; + const std::string keyFonts = "Fonts"; const std::string keyConfigSgct = "SGCTConfig"; const std::string keyConfigScene = "Scene"; const std::string keyStartupScript = "StartupScripts"; diff --git a/src/engine/configurationmanager.cpp b/src/engine/configurationmanager.cpp index 8343383e28..b91b11f0c5 100644 --- a/src/engine/configurationmanager.cpp +++ b/src/engine/configurationmanager.cpp @@ -29,6 +29,8 @@ #include #include +#include + namespace { const std::string _loggerCat = "ConfigurationManager"; @@ -86,6 +88,10 @@ bool ConfigurationManager::loadFromFile(const std::string& filename) { } } + bool complete = checkCompleteness(); + if (!complete) + return false; + // Remove the Paths dictionary from the configuration manager as those paths might // change later and we don't want to be forced to keep our local copy up to date removeKey(keyPaths); @@ -93,5 +99,25 @@ bool ConfigurationManager::loadFromFile(const std::string& filename) { return true; } +bool ConfigurationManager::checkCompleteness() const { + std::list requiredTokens = { + constants::configurationmanager::keyPaths, + constants::configurationmanager::keyCachePath, + constants::configurationmanager::keyFonts, + constants::configurationmanager::keyConfigSgct + }; + + bool totalSuccess = true; + for (auto token : requiredTokens) { + bool success = hasKey(token); + + if (!success) + LFATAL("Configuration file did not contain required key '" << token << "'"); + + totalSuccess &= success; + } + + return totalSuccess; +} } // namespace openspace diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index db0128ba1b..555380eba4 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -68,6 +68,7 @@ namespace { const std::string _loggerCat = "OpenSpaceEngine"; const std::string _configurationFile = "openspace.cfg"; const std::string _sgctDefaultConfigFile = "${SGCT}/single.xml"; + const std::string _defaultCacheLocation = "${BASE_PATH}/cache"; const std::string _sgctConfigArgumentCommand = "-config"; @@ -213,12 +214,7 @@ void OpenSpaceEngine::loadFonts() { sgct_text::FontManager::FontPath local = sgct_text::FontManager::FontPath::FontPath_Local; ghoul::Dictionary fonts; - bool success = configurationManager().getValue(constants::fonts::keyFonts, fonts); - if (!success) { - LERROR("Could not find key '" << constants::fonts::keyFonts << - "' in configuration file for font declaration"); - return; - } + configurationManager().getValue(constants::configurationmanager::keyFonts, fonts); for (auto key : fonts.keys()) { std::string font; @@ -282,19 +278,12 @@ bool OpenSpaceEngine::create(int argc, char** argv, const bool configLoadSuccess = _engine->configurationManager().loadFromFile( configurationFilePath); if (!configLoadSuccess) { - LERROR("Loading of configuration file '" << configurationFilePath << "' failed"); + LFATAL("Loading of configuration file '" << configurationFilePath << "' failed"); return false; } - // make sure cache is registered, false since we don't want to override - auto tokens = FileSys.tokens(); - const std::string cacheToken = "${CACHE}"; - auto cacheIterator = std::find(tokens.begin(), tokens.end(), cacheToken); - if (cacheIterator == tokens.end()){ - FileSys.registerPathToken(cacheToken, "${BASE_PATH}/cache"); - } - // Create directories that doesn't exsist + auto tokens = FileSys.tokens(); for (auto token : tokens) { if (!FileSys.directoryExists(token)) { std::string p = absPath(token); @@ -305,7 +294,10 @@ bool OpenSpaceEngine::create(int argc, char** argv, } // Create the cachemanager - FileSys.createCacheManager(cacheToken); + std::string cacheDirectory; + _engine->configurationManager().getValue( + constants::configurationmanager::keyCachePath, cacheDirectory); + FileSys.createCacheManager(cacheDirectory); _engine->_console = new LuaConsole(); _engine->_syncBuffer = new SyncBuffer(1024);