Proper termination and initialization of the ConfigManager.

This commit is contained in:
BenDol 2014-04-02 00:30:17 +13:00
parent 547b18db9a
commit 5204e3ac03
4 changed files with 30 additions and 7 deletions

View File

@ -24,3 +24,6 @@ Module
dofile 'inputmessage'
dofile 'outputmessage'
@onUnload: |
g_settings = nil

View File

@ -90,6 +90,9 @@ void Application::init(std::vector<std::string>& args)
m_startupOptions = startupOptions;
// initialize configs
g_configs.init();
// initialize resources
g_resources.init(args[0].c_str());
@ -125,11 +128,8 @@ void Application::terminate()
Connection::terminate();
#endif
// save configurations
ConfigPtr settings = g_configs.getSettings();
if(settings) {
settings->save();
}
// release configs
g_configs.terminate();
// release resources
g_resources.terminate();

View File

@ -24,11 +24,29 @@
ConfigManager g_configs;
ConfigManager::ConfigManager()
void ConfigManager::init()
{
m_settings = ConfigPtr(new Config());
}
void ConfigManager::terminate()
{
if(m_settings) {
// ensure settings are saved
m_settings->save();
m_settings->unload();
m_settings = nullptr;
}
for(ConfigPtr config : m_configs) {
config->unload();
config = nullptr;
}
m_configs.clear();
}
ConfigPtr ConfigManager::getSettings()
{
return m_settings;
@ -79,6 +97,7 @@ bool ConfigManager::unload(const std::string& file)
if(config) {
config->unload();
m_configs.remove(config);
config = nullptr;
return true;
}
return false;

View File

@ -29,7 +29,8 @@
class ConfigManager
{
public:
ConfigManager();
void init();
void terminate();
ConfigPtr getSettings();
ConfigPtr get(const std::string& file);