libsuperderpy/src/config.c

68 lines
2.5 KiB
C
Raw Normal View History

2012-02-28 13:09:12 +01:00
/*! \file config.c
* \brief Configuration manager code.
*/
2012-03-04 13:32:42 +01:00
/*
* Copyright (c) Sebastian Krzyszkowiak <dos@dosowisko.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
2017-07-22 18:22:12 +02:00
* the Free Software Foundation; either version 3 of the License, or
2012-03-04 13:32:42 +01:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2017-07-22 18:22:12 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2012-03-04 13:32:42 +01:00
*/
2016-09-08 00:32:21 +02:00
#include "config.h"
#include "internal.h"
#include <allegro5/allegro.h>
2012-02-24 13:03:30 +01:00
SYMBOL_EXPORT void InitConfig(struct Game* game) {
2018-02-18 18:41:12 +01:00
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");
2012-09-03 02:25:32 +02:00
al_join_paths(path, data);
game->_priv.config = al_load_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
if (!game->_priv.config) {
game->_priv.config = al_create_config();
}
2012-09-03 02:25:32 +02:00
al_destroy_path(path);
al_destroy_path(data);
2018-02-18 18:41:12 +01:00
al_set_new_file_interface(iface);
2012-02-24 13:03:30 +01:00
}
SYMBOL_EXPORT void SetConfigOption(struct Game* game, char* section, char* name, char* value) {
al_set_config_value(game->_priv.config, section, name, value);
2012-02-26 00:47:41 +01:00
}
SYMBOL_EXPORT const char* GetConfigOption(struct Game* game, char* section, char* name) {
return al_get_config_value(game->_priv.config, section, name);
2012-02-24 13:03:30 +01:00
}
SYMBOL_EXPORT const char* GetConfigOptionDefault(struct Game* game, char* section, char* name, const char* def) {
const char* ret = GetConfigOption(game, section, name);
if (!ret) {
return def;
}
return ret;
2012-02-26 00:47:41 +01:00
}
SYMBOL_EXPORT void DeinitConfig(struct Game* game) {
2018-02-18 18:41:12 +01:00
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");
2012-09-03 02:25:32 +02:00
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);
2012-09-03 02:25:32 +02:00
al_destroy_path(path);
al_destroy_path(data);
al_destroy_config(game->_priv.config);
2018-02-18 18:41:12 +01:00
al_set_new_file_interface(iface);
2012-02-26 00:47:41 +01:00
}