config: move some settings to a global config
This commit is contained in:
178
src/config.c
178
src/config.c
@@ -88,6 +88,7 @@ static int cy;
|
||||
static int cw;
|
||||
static int ch;
|
||||
static ini_t config;
|
||||
static ini_t global;
|
||||
|
||||
#ifdef ENABLE_CONFIG_LOG
|
||||
int config_do_log = ENABLE_CONFIG_LOG;
|
||||
@@ -107,6 +108,35 @@ config_log(const char *fmt, ...)
|
||||
# define config_log(fmt, ...)
|
||||
#endif
|
||||
|
||||
/* Load global configuration */
|
||||
static void
|
||||
load_global(void)
|
||||
{
|
||||
ini_section_t cat = ini_find_section(global, "");
|
||||
char *p;
|
||||
|
||||
p = ini_section_get_string(cat, "language", NULL);
|
||||
if (p != NULL)
|
||||
lang_id = plat_language_code(p);
|
||||
else
|
||||
lang_id = plat_language_code(DEFAULT_LANGUAGE);
|
||||
|
||||
open_dir_usr_path = ini_section_get_int(cat, "open_dir_usr_path", 0);
|
||||
|
||||
confirm_reset = ini_section_get_int(cat, "confirm_reset", 1);
|
||||
confirm_exit = ini_section_get_int(cat, "confirm_exit", 1);
|
||||
confirm_save = ini_section_get_int(cat, "confirm_save", 1);
|
||||
|
||||
video_fullscreen_first = ini_section_get_int(cat, "video_fullscreen_first", 1);
|
||||
|
||||
inhibit_multimedia_keys = ini_section_get_int(cat, "inhibit_multimedia_keys", 0);
|
||||
|
||||
mouse_sensitivity = ini_section_get_double(cat, "mouse_sensitivity", 1.0);
|
||||
if (mouse_sensitivity < 0.1)
|
||||
mouse_sensitivity = 0.1;
|
||||
else if (mouse_sensitivity > 2.0)
|
||||
mouse_sensitivity = 2.0;
|
||||
}
|
||||
|
||||
/* Load "General" section. */
|
||||
static void
|
||||
@@ -128,12 +158,8 @@ load_general(void)
|
||||
|
||||
video_fullscreen_scale = ini_section_get_int(cat, "video_fullscreen_scale", 1);
|
||||
|
||||
video_fullscreen_first = ini_section_get_int(cat, "video_fullscreen_first", 1);
|
||||
|
||||
video_filter_method = ini_section_get_int(cat, "video_filter_method", 1);
|
||||
|
||||
inhibit_multimedia_keys = ini_section_get_int(cat, "inhibit_multimedia_keys", 0);
|
||||
|
||||
force_43 = !!ini_section_get_int(cat, "force_43", 0);
|
||||
scale = ini_section_get_int(cat, "scale", 1);
|
||||
if (scale > 9)
|
||||
@@ -179,26 +205,8 @@ load_general(void)
|
||||
hide_tool_bar = ini_section_get_int(cat, "hide_tool_bar", 0);
|
||||
sound_muted = ini_section_get_int(cat, "sound_muted", 0);
|
||||
|
||||
confirm_reset = ini_section_get_int(cat, "confirm_reset", 1);
|
||||
confirm_exit = ini_section_get_int(cat, "confirm_exit", 1);
|
||||
confirm_save = ini_section_get_int(cat, "confirm_save", 1);
|
||||
|
||||
p = ini_section_get_string(cat, "language", NULL);
|
||||
if (p != NULL)
|
||||
lang_id = plat_language_code(p);
|
||||
else
|
||||
lang_id = plat_language_code(DEFAULT_LANGUAGE);
|
||||
|
||||
mouse_sensitivity = ini_section_get_double(cat, "mouse_sensitivity", 1.0);
|
||||
if (mouse_sensitivity < 0.1)
|
||||
mouse_sensitivity = 0.1;
|
||||
else if (mouse_sensitivity > 2.0)
|
||||
mouse_sensitivity = 2.0;
|
||||
|
||||
enable_discord = !!ini_section_get_int(cat, "enable_discord", 0);
|
||||
|
||||
open_dir_usr_path = ini_section_get_int(cat, "open_dir_usr_path", 0);
|
||||
|
||||
video_framerate = ini_section_get_int(cat, "video_gl_framerate", -1);
|
||||
video_vsync = ini_section_get_int(cat, "video_gl_vsync", 0);
|
||||
|
||||
@@ -1800,7 +1808,21 @@ config_load(void)
|
||||
int i;
|
||||
ini_section_t c;
|
||||
|
||||
config_log("Loading config file '%s'..\n", cfg_path);
|
||||
config_log("Loading global config file '%s'...\n", global_cfg_path);
|
||||
|
||||
global = ini_read(global_cfg_path);
|
||||
|
||||
if (global == NULL) {
|
||||
global = ini_new();
|
||||
|
||||
lang_id = plat_language_code(DEFAULT_LANGUAGE);
|
||||
|
||||
config_log("Global config file not present or invalid!\n");
|
||||
} else {
|
||||
load_global();
|
||||
}
|
||||
|
||||
config_log("Loading VM config file '%s'...\n", cfg_path);
|
||||
|
||||
memset(hdd, 0, sizeof(hard_disk_t));
|
||||
memset(cdrom, 0, sizeof(cdrom_t) * CDROM_NUM);
|
||||
@@ -1812,8 +1834,7 @@ config_load(void)
|
||||
config = ini_read(cfg_path);
|
||||
|
||||
if (config == NULL) {
|
||||
config = ini_new();
|
||||
config_changed = 1;
|
||||
config = ini_new();
|
||||
|
||||
cpu_f = (cpu_family_t *) &cpu_families[0];
|
||||
cpu = 0;
|
||||
@@ -1873,9 +1894,7 @@ config_load(void)
|
||||
cassette_pcm = 0;
|
||||
cassette_ui_writeprot = 0;
|
||||
|
||||
lang_id = plat_language_code(DEFAULT_LANGUAGE);
|
||||
|
||||
config_log("Config file not present or invalid!\n");
|
||||
config_log("VM config file not present or invalid!\n");
|
||||
} else {
|
||||
load_general(); /* General */
|
||||
for (i = 0; i < MONITORS_NUM; i++)
|
||||
@@ -1913,29 +1932,74 @@ config_load(void)
|
||||
if (c != NULL)
|
||||
ini_rename_section(c, "3Dfx Voodoo Banshee");
|
||||
|
||||
/* Mark the configuration as changed. */
|
||||
config_changed = 1;
|
||||
|
||||
config_log("Config loaded.\n\n");
|
||||
config_log("VM config loaded.\n\n");
|
||||
}
|
||||
|
||||
/* Mark the configuration as changed. */
|
||||
config_changed = 1;
|
||||
|
||||
video_copy = (video_grayscale || invert_display) ? video_transform_copy : memcpy;
|
||||
}
|
||||
|
||||
/* Save global configuration */
|
||||
static void
|
||||
save_global(void)
|
||||
{
|
||||
ini_section_t cat = ini_find_or_create_section(global, "");
|
||||
char buffer[512] = { 0 };
|
||||
|
||||
if (lang_id == plat_language_code(DEFAULT_LANGUAGE))
|
||||
ini_section_delete_var(cat, "language");
|
||||
else {
|
||||
plat_language_code_r(lang_id, buffer, 511);
|
||||
ini_section_set_string(cat, "language", buffer);
|
||||
}
|
||||
|
||||
if (open_dir_usr_path)
|
||||
ini_section_set_int(cat, "open_dir_usr_path", open_dir_usr_path);
|
||||
else
|
||||
ini_section_delete_var(cat, "open_dir_usr_path");
|
||||
|
||||
if (confirm_reset != 1)
|
||||
ini_section_set_int(cat, "confirm_reset", confirm_reset);
|
||||
else
|
||||
ini_section_delete_var(cat, "confirm_reset");
|
||||
|
||||
if (confirm_exit != 1)
|
||||
ini_section_set_int(cat, "confirm_exit", confirm_exit);
|
||||
else
|
||||
ini_section_delete_var(cat, "confirm_exit");
|
||||
|
||||
if (confirm_save != 1)
|
||||
ini_section_set_int(cat, "confirm_save", confirm_save);
|
||||
else
|
||||
ini_section_delete_var(cat, "confirm_save");
|
||||
|
||||
if (video_fullscreen_first == 1)
|
||||
ini_section_delete_var(cat, "video_fullscreen_first");
|
||||
else
|
||||
ini_section_set_int(cat, "video_fullscreen_first", video_fullscreen_first);
|
||||
|
||||
if (inhibit_multimedia_keys == 1)
|
||||
ini_section_set_int(cat, "inhibit_multimedia_keys", inhibit_multimedia_keys);
|
||||
else
|
||||
ini_section_delete_var(cat, "inhibit_multimedia_keys");
|
||||
|
||||
if (mouse_sensitivity != 1.0)
|
||||
ini_section_set_double(cat, "mouse_sensitivity", mouse_sensitivity);
|
||||
else
|
||||
ini_section_delete_var(cat, "mouse_sensitivity");
|
||||
}
|
||||
|
||||
/* Save "General" section. */
|
||||
static void
|
||||
save_general(void)
|
||||
{
|
||||
ini_section_t cat = ini_find_or_create_section(config, "General");
|
||||
char temp[512];
|
||||
char buffer[512] = { 0 };
|
||||
|
||||
const char *va_name;
|
||||
|
||||
ini_section_set_int(cat, "inhibit_multimedia_keys", inhibit_multimedia_keys);
|
||||
if (inhibit_multimedia_keys == 0)
|
||||
ini_section_delete_var(cat, "inhibit_multimedia_keys");
|
||||
|
||||
ini_section_set_int(cat, "sound_muted", sound_muted);
|
||||
if (sound_muted == 0)
|
||||
ini_section_delete_var(cat, "sound_muted");
|
||||
@@ -1955,11 +2019,6 @@ save_general(void)
|
||||
else
|
||||
ini_section_set_int(cat, "video_fullscreen_scale", video_fullscreen_scale);
|
||||
|
||||
if (video_fullscreen_first == 1)
|
||||
ini_section_delete_var(cat, "video_fullscreen_first");
|
||||
else
|
||||
ini_section_set_int(cat, "video_fullscreen_first", video_fullscreen_first);
|
||||
|
||||
if (video_filter_method == 1)
|
||||
ini_section_delete_var(cat, "video_filter_method");
|
||||
else
|
||||
@@ -2041,43 +2100,11 @@ save_general(void)
|
||||
else
|
||||
ini_section_delete_var(cat, "hide_tool_bar");
|
||||
|
||||
if (confirm_reset != 1)
|
||||
ini_section_set_int(cat, "confirm_reset", confirm_reset);
|
||||
else
|
||||
ini_section_delete_var(cat, "confirm_reset");
|
||||
|
||||
if (confirm_exit != 1)
|
||||
ini_section_set_int(cat, "confirm_exit", confirm_exit);
|
||||
else
|
||||
ini_section_delete_var(cat, "confirm_exit");
|
||||
|
||||
if (confirm_save != 1)
|
||||
ini_section_set_int(cat, "confirm_save", confirm_save);
|
||||
else
|
||||
ini_section_delete_var(cat, "confirm_save");
|
||||
|
||||
if (mouse_sensitivity != 1.0)
|
||||
ini_section_set_double(cat, "mouse_sensitivity", mouse_sensitivity);
|
||||
else
|
||||
ini_section_delete_var(cat, "mouse_sensitivity");
|
||||
|
||||
if (lang_id == plat_language_code(DEFAULT_LANGUAGE))
|
||||
ini_section_delete_var(cat, "language");
|
||||
else {
|
||||
plat_language_code_r(lang_id, buffer, 511);
|
||||
ini_section_set_string(cat, "language", buffer);
|
||||
}
|
||||
|
||||
if (enable_discord)
|
||||
ini_section_set_int(cat, "enable_discord", enable_discord);
|
||||
else
|
||||
ini_section_delete_var(cat, "enable_discord");
|
||||
|
||||
if (open_dir_usr_path)
|
||||
ini_section_set_int(cat, "open_dir_usr_path", open_dir_usr_path);
|
||||
else
|
||||
ini_section_delete_var(cat, "open_dir_usr_path");
|
||||
|
||||
if (video_framerate != -1)
|
||||
ini_section_set_int(cat, "video_gl_framerate", video_framerate);
|
||||
else
|
||||
@@ -3133,6 +3160,9 @@ save_other_removable_devices(void)
|
||||
void
|
||||
config_save(void)
|
||||
{
|
||||
save_global(); /* Global */
|
||||
ini_write(global, global_cfg_path);
|
||||
|
||||
save_general(); /* General */
|
||||
for (uint8_t i = 0; i < MONITORS_NUM; i++)
|
||||
save_monitor(i); /* Monitors */
|
||||
|
||||
Reference in New Issue
Block a user