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
|
||||
g_resources.searchAndAddPackages('/', '.otpkg', true)
|
||||
|
||||
-- load configurations
|
||||
-- load settings
|
||||
g_configs.loadSettings("/config.otml")
|
||||
|
||||
g_modules.discoverModules()
|
||||
|
|
|
@ -59,7 +59,6 @@ ConfigPtr ConfigManager::get(const std::string& file)
|
|||
return config;
|
||||
}
|
||||
}
|
||||
g_logger.error(stdext::format("Unable to find configuration for '%s' ", file));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -76,19 +75,41 @@ ConfigPtr ConfigManager::loadSettings(const std::string file)
|
|||
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)
|
||||
{
|
||||
if(file.empty()) {
|
||||
g_logger.error("Must provide a configuration file to load.");
|
||||
return nullptr;
|
||||
}
|
||||
else {
|
||||
ConfigPtr config = ConfigPtr(new Config());
|
||||
if(config->load(file)) {
|
||||
m_configs.push_back(config);
|
||||
return config;
|
||||
ConfigPtr config = get(file);
|
||||
if(!config) {
|
||||
config = ConfigPtr(new Config());
|
||||
|
||||
if(config->load(file)) {
|
||||
m_configs.push_back(config);
|
||||
}
|
||||
else {
|
||||
// cannot load config
|
||||
config = nullptr;
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ConfigManager::unload(const std::string& file)
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
ConfigPtr getSettings();
|
||||
ConfigPtr get(const std::string& file);
|
||||
|
||||
ConfigPtr create(const std::string& file);
|
||||
ConfigPtr loadSettings(const std::string file);
|
||||
ConfigPtr load(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", "load", &ConfigManager::load, &g_configs);
|
||||
g_lua.bindSingletonFunction("g_configs", "unload", &ConfigManager::unload, &g_configs);
|
||||
g_lua.bindSingletonFunction("g_configs", "create", &ConfigManager::create, &g_configs);
|
||||
|
||||
// Logger
|
||||
g_lua.registerSingletonClass("g_logger");
|
||||
|
|
Loading…
Reference in New Issue