config: store the config file instantly after setting a new value

This commit is contained in:
Sebastian Krzyszkowiak 2019-06-26 22:44:48 +02:00
parent 94de1c5975
commit 5757c5170a
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF

View file

@ -32,8 +32,22 @@ SYMBOL_EXPORT void InitConfig(struct Game* game) {
al_set_new_file_interface(iface);
}
static void StoreConfig(struct Game* game) {
const ALLEGRO_FILE_INTERFACE* iface = al_get_new_file_interface();
al_set_standard_file_interface();
ALLEGRO_PATH* path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH);
ALLEGRO_PATH* data = al_create_path("SuperDerpy.ini");
al_make_directory(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
al_join_paths(path, data);
al_save_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP), game->_priv.config);
al_destroy_path(path);
al_destroy_path(data);
al_set_new_file_interface(iface);
}
SYMBOL_EXPORT void SetConfigOption(struct Game* game, char* section, char* name, char* value) {
al_set_config_value(game->_priv.config, section, name, value);
StoreConfig(game);
}
SYMBOL_EXPORT const char* GetConfigOption(struct Game* game, char* section, char* name) {
@ -49,15 +63,5 @@ SYMBOL_EXPORT const char* GetConfigOptionDefault(struct Game* game, char* sectio
}
SYMBOL_EXPORT void DeinitConfig(struct Game* game) {
const ALLEGRO_FILE_INTERFACE* iface = al_get_new_file_interface();
al_set_standard_file_interface();
ALLEGRO_PATH* path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH);
ALLEGRO_PATH* data = al_create_path("SuperDerpy.ini");
al_make_directory(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
al_join_paths(path, data);
al_save_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP), game->_priv.config);
al_destroy_path(path);
al_destroy_path(data);
al_destroy_config(game->_priv.config);
al_set_new_file_interface(iface);
}