mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-22 02:48:25 -05:00
Started cleanup of module structure
This commit is contained in:
@@ -27,86 +27,109 @@
|
||||
#include <openspace/util/constants.h>
|
||||
|
||||
#include <ghoul/lua/lua_helper.h>
|
||||
#include <ghoul/misc/exception.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "ConfigurationManager";
|
||||
using std::string;
|
||||
|
||||
const std::string _keyBasePath = "BASE_PATH";
|
||||
namespace {
|
||||
const string _configurationFile = "openspace.cfg";
|
||||
const string _keyBasePath = "BASE_PATH";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
const std::string ConfigurationManager::KeyPaths = "Paths";
|
||||
const std::string ConfigurationManager::KeyCache = "CACHE";
|
||||
const std::string ConfigurationManager::KeyCachePath = KeyPaths + "." + KeyCache;
|
||||
const std::string ConfigurationManager::KeyFonts = "Fonts";
|
||||
const std::string ConfigurationManager::KeyConfigSgct = "SGCTConfig";
|
||||
const std::string ConfigurationManager::KeyLuaDocumentationType = "LuaDocumentationFile.Type";
|
||||
const std::string ConfigurationManager::KeyLuaDocumentationFile = "LuaDocumentationFile.File";
|
||||
const std::string ConfigurationManager::KeyPropertyDocumentationType = "PropertyDocumentationFile.Type";
|
||||
const std::string ConfigurationManager::KeyPropertyDocumentationFile = "PropertyDocumentationFile.File";
|
||||
const std::string ConfigurationManager::KeyConfigScene = "Scene";
|
||||
const std::string ConfigurationManager::KeyEnableGui = "EnableGUI";
|
||||
const std::string ConfigurationManager::KeyStartupScript = "StartupScripts";
|
||||
const std::string ConfigurationManager::KeySettingsScript = "SettingsScripts";
|
||||
const std::string ConfigurationManager::KeySpiceTimeKernel = "SpiceKernel.Time";
|
||||
const std::string ConfigurationManager::KeySpiceLeapsecondKernel = "SpiceKernel.LeapSecond";
|
||||
const std::string ConfigurationManager::KeyLogLevel = "Logging.LogLevel";
|
||||
const std::string ConfigurationManager::KeyLogImmediateFlush = "Logging.ImmediateFlush";
|
||||
const std::string ConfigurationManager::KeyLogs = "Logging.Logs";
|
||||
const std::string ConfigurationManager::KeyCapabilitiesVerbosity = "Logging.CapabilitiesVerbosity";
|
||||
const std::string ConfigurationManager::KeyDisableMasterRendering = "DisableRenderingOnMaster";
|
||||
const std::string ConfigurationManager::KeyDownloadRequestURL = "DownloadRequestURL";
|
||||
const string ConfigurationManager::KeyPaths = "Paths";
|
||||
const string ConfigurationManager::KeyCache = "CACHE";
|
||||
const string ConfigurationManager::KeyFonts = "Fonts";
|
||||
const string ConfigurationManager::KeyConfigSgct = "SGCTConfig";
|
||||
const string ConfigurationManager::KeyLuaDocumentationType = "LuaDocumentationFile.Type";
|
||||
const string ConfigurationManager::KeyLuaDocumentationFile = "LuaDocumentationFile.File";
|
||||
const string ConfigurationManager::KeyPropertyDocumentationType =
|
||||
"PropertyDocumentationFile.Type";
|
||||
const string ConfigurationManager::KeyPropertyDocumentationFile =
|
||||
"PropertyDocumentationFile.File";
|
||||
const string ConfigurationManager::KeyConfigScene = "Scene";
|
||||
const string ConfigurationManager::KeyEnableGui = "EnableGUI";
|
||||
const string ConfigurationManager::KeyStartupScript = "StartupScripts";
|
||||
const string ConfigurationManager::KeySettingsScript = "SettingsScripts";
|
||||
const string ConfigurationManager::KeySpiceTimeKernel = "SpiceKernel.Time";
|
||||
const string ConfigurationManager::KeySpiceLeapsecondKernel = "SpiceKernel.LeapSecond";
|
||||
const string ConfigurationManager::KeyLogLevel = "Logging.LogLevel";
|
||||
const string ConfigurationManager::KeyLogImmediateFlush = "Logging.ImmediateFlush";
|
||||
const string ConfigurationManager::KeyLogs = "Logging.Logs";
|
||||
const string ConfigurationManager::KeyCapabilitiesVerbosity =
|
||||
"Logging.CapabilitiesVerbosity";
|
||||
const string ConfigurationManager::KeyDisableMasterRendering = "DisableRenderingOnMaster";
|
||||
const string ConfigurationManager::KeyDownloadRequestURL = "DownloadRequestURL";
|
||||
|
||||
bool ConfigurationManager::loadFromFile(const std::string& filename) {
|
||||
string ConfigurationManager::findConfiguration(const string& filename) {
|
||||
using ghoul::filesystem::Directory;
|
||||
|
||||
Directory directory = FileSys.currentDirectory();
|
||||
std::string configurationName = _configurationFile;
|
||||
|
||||
while (true) {
|
||||
std::string&& fullPath = FileSys.pathByAppendingComponent(directory,
|
||||
configurationName);
|
||||
bool exists = FileSys.fileExists(fullPath);
|
||||
if (exists)
|
||||
return fullPath;
|
||||
|
||||
Directory nextDirectory = directory.parentDirectory(true);
|
||||
|
||||
if (directory.path() == nextDirectory.path()) {
|
||||
// We have reached the root of the file system and did not find the file
|
||||
throw ghoul::RuntimeError(
|
||||
"Could not find configuration file '" + filename + "'",
|
||||
"ConfigurationManager"
|
||||
);
|
||||
}
|
||||
directory = nextDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigurationManager::loadFromFile(const string& filename) {
|
||||
using ghoul::filesystem::FileSystem;
|
||||
if (!FileSys.fileExists(filename)) {
|
||||
LERROR("Could not find file '" << filename << "'");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!FileSys.fileExists(filename))
|
||||
throw ghoul::FileNotFoundError(filename, "ConfigurationManager");
|
||||
|
||||
// ${BASE_PATH}
|
||||
std::string&& basePathToken = FileSystem::TokenOpeningBraces + _keyBasePath
|
||||
string basePathToken = FileSystem::TokenOpeningBraces + _keyBasePath
|
||||
+ FileSystem::TokenClosingBraces;
|
||||
|
||||
// Retrieving the directory in which the configuration file lies
|
||||
std::string absolutePath = FileSys.absolutePath(filename);
|
||||
std::string basePath = ghoul::filesystem::File(absolutePath).directoryName();
|
||||
string absolutePath = FileSys.absolutePath(filename);
|
||||
string basePath = ghoul::filesystem::File(absolutePath).directoryName();
|
||||
FileSys.registerPathToken(basePathToken, basePath);
|
||||
|
||||
// Loading the configuration file into ourselves
|
||||
try {
|
||||
ghoul::lua::loadDictionaryFromFile(filename, *this);
|
||||
}
|
||||
catch (...) {
|
||||
LERROR("Loading dictionary from file failed");
|
||||
return false;
|
||||
}
|
||||
ghoul::lua::loadDictionaryFromFile(filename, *this);
|
||||
|
||||
// Register all the paths
|
||||
ghoul::Dictionary dictionary;
|
||||
const bool success = getValue(KeyPaths, dictionary);
|
||||
if (!success) {
|
||||
LERROR("Configuration does not contain the key '" << KeyPaths << "'");
|
||||
return false;
|
||||
}
|
||||
// const bool hasPath = hasKeyAndValue<std::string>(KeyPaths);
|
||||
// if (!hasPath) {
|
||||
// throw ghoul::RuntimeError(
|
||||
// "Configuration does not contain the key '" + KeyPaths + "'",
|
||||
// "ConfifgurationManager"
|
||||
// );
|
||||
// }
|
||||
ghoul::Dictionary dictionary = value<ghoul::Dictionary>(KeyPaths);
|
||||
|
||||
std::vector<std::string> pathKeys = dictionary.keys();
|
||||
for (std::string key : pathKeys) {
|
||||
std::string p;
|
||||
if (dictionary.getValue(key, p)) {
|
||||
std::string fullKey
|
||||
= FileSystem::TokenOpeningBraces + key
|
||||
+ FileSystem::TokenClosingBraces;
|
||||
LDEBUG("Registering path " << fullKey << ": " << p);
|
||||
std::string fullKey =
|
||||
FileSystem::TokenOpeningBraces + key + FileSystem::TokenClosingBraces;
|
||||
LDEBUGC("ConfigurationManager", "Registering path " << fullKey << ": " << p);
|
||||
|
||||
bool override = (basePathToken == fullKey);
|
||||
|
||||
if (override)
|
||||
LINFO("Overriding base path with '" << p << "'");
|
||||
LINFOC("ConfigurationManager", "Overriding base path with '" << p << "'");
|
||||
FileSys.registerPathToken(std::move(fullKey), std::move(p), override);
|
||||
}
|
||||
}
|
||||
@@ -125,7 +148,7 @@ bool ConfigurationManager::loadFromFile(const std::string& filename) {
|
||||
bool ConfigurationManager::checkCompleteness() const {
|
||||
std::vector<std::string> requiredTokens = {
|
||||
KeyPaths,
|
||||
KeyCachePath,
|
||||
KeyPaths + "." + KeyCache,
|
||||
KeyFonts,
|
||||
KeyConfigSgct
|
||||
};
|
||||
@@ -134,8 +157,12 @@ bool ConfigurationManager::checkCompleteness() const {
|
||||
for (const std::string& token : requiredTokens) {
|
||||
bool success = hasKey(token);
|
||||
|
||||
if (!success)
|
||||
LFATAL("Configuration file did not contain required key '" << token << "'");
|
||||
if (!success) {
|
||||
LFATALC(
|
||||
"ConfigurationManager",
|
||||
"Configuration file did not contain required key '" << token << "'"
|
||||
);
|
||||
}
|
||||
|
||||
totalSuccess &= success;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user