Can now create new configs on the fly using: local config = g_configs.create(file)
This commit is contained in:
parent
5204e3ac03
commit
2d84fae2c8
2
init.lua
2
init.lua
|
@ -27,7 +27,7 @@ g_resources.setupUserWriteDir(g_app.getCompactName())
|
||||||
-- search all packages
|
-- search all packages
|
||||||
g_resources.searchAndAddPackages('/', '.otpkg', true)
|
g_resources.searchAndAddPackages('/', '.otpkg', true)
|
||||||
|
|
||||||
-- load configurations
|
-- load settings
|
||||||
g_configs.loadSettings("/config.otml")
|
g_configs.loadSettings("/config.otml")
|
||||||
|
|
||||||
g_modules.discoverModules()
|
g_modules.discoverModules()
|
||||||
|
|
|
@ -59,7 +59,6 @@ ConfigPtr ConfigManager::get(const std::string& file)
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_logger.error(stdext::format("Unable to find configuration for '%s' ", file));
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,20 +75,42 @@ ConfigPtr ConfigManager::loadSettings(const std::string file)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigPtr ConfigManager::create(const std::string& file)
|
||||||
|
{
|
||||||
|
ConfigPtr config = load(file);
|
||||||
|
if(!config) {
|
||||||
|
config = ConfigPtr(new Config());
|
||||||
|
|
||||||
|
config->load(file);
|
||||||
|
config->save();
|
||||||
|
|
||||||
|
m_configs.push_back(config);
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
ConfigPtr ConfigManager::load(const std::string& file)
|
ConfigPtr ConfigManager::load(const std::string& file)
|
||||||
{
|
{
|
||||||
if(file.empty()) {
|
if(file.empty()) {
|
||||||
g_logger.error("Must provide a configuration file to load.");
|
g_logger.error("Must provide a configuration file to load.");
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ConfigPtr config = ConfigPtr(new Config());
|
ConfigPtr config = get(file);
|
||||||
|
if(!config) {
|
||||||
|
config = ConfigPtr(new Config());
|
||||||
|
|
||||||
if(config->load(file)) {
|
if(config->load(file)) {
|
||||||
m_configs.push_back(config);
|
m_configs.push_back(config);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// cannot load config
|
||||||
|
config = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ConfigManager::unload(const std::string& file)
|
bool ConfigManager::unload(const std::string& file)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,7 @@ public:
|
||||||
ConfigPtr getSettings();
|
ConfigPtr getSettings();
|
||||||
ConfigPtr get(const std::string& file);
|
ConfigPtr get(const std::string& file);
|
||||||
|
|
||||||
|
ConfigPtr create(const std::string& file);
|
||||||
ConfigPtr loadSettings(const std::string file);
|
ConfigPtr loadSettings(const std::string file);
|
||||||
ConfigPtr load(const std::string& file);
|
ConfigPtr load(const std::string& file);
|
||||||
bool unload(const std::string& file);
|
bool unload(const std::string& file);
|
||||||
|
|
|
@ -141,6 +141,7 @@ void Application::registerLuaFunctions()
|
||||||
g_lua.bindSingletonFunction("g_configs", "loadSettings", &ConfigManager::loadSettings, &g_configs);
|
g_lua.bindSingletonFunction("g_configs", "loadSettings", &ConfigManager::loadSettings, &g_configs);
|
||||||
g_lua.bindSingletonFunction("g_configs", "load", &ConfigManager::load, &g_configs);
|
g_lua.bindSingletonFunction("g_configs", "load", &ConfigManager::load, &g_configs);
|
||||||
g_lua.bindSingletonFunction("g_configs", "unload", &ConfigManager::unload, &g_configs);
|
g_lua.bindSingletonFunction("g_configs", "unload", &ConfigManager::unload, &g_configs);
|
||||||
|
g_lua.bindSingletonFunction("g_configs", "create", &ConfigManager::create, &g_configs);
|
||||||
|
|
||||||
// Logger
|
// Logger
|
||||||
g_lua.registerSingletonClass("g_logger");
|
g_lua.registerSingletonClass("g_logger");
|
||||||
|
|
Loading…
Reference in New Issue