gui/settings: Read settings file on startup
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
a5f0da7a60
commit
d292879837
|
@ -10,7 +10,7 @@ static struct file gui_settings_file = FILE_INIT("settings", 0);
|
||||||
|
|
||||||
static void __settings_save_item(gpointer key, gpointer value, gpointer data)
|
static void __settings_save_item(gpointer key, gpointer value, gpointer data)
|
||||||
{
|
{
|
||||||
file_writef(&gui_settings_file, "%s %u\n", (const char *)key,
|
file_writef(&gui_settings_file, "%s %u\n", (const gchar *)key,
|
||||||
GPOINTER_TO_UINT(value));
|
GPOINTER_TO_UINT(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,11 +24,26 @@ static void __settings_save()
|
||||||
file_close(&gui_settings_file);
|
file_close(&gui_settings_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void __settings_read()
|
||||||
|
{
|
||||||
|
unsigned int num, i, value;
|
||||||
|
gchar *key;
|
||||||
|
|
||||||
|
file_readf(&gui_settings_file, "%u\n", &num);
|
||||||
|
for (i = 0; i < num; i++) {
|
||||||
|
file_readf(&gui_settings_file, "%m[^ ] %u\n", &key, &value);
|
||||||
|
g_hash_table_insert(gui_settings, key, GUINT_TO_POINTER(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void gui_settings_init()
|
void gui_settings_init()
|
||||||
{
|
{
|
||||||
gui_settings = g_hash_table_new_full(g_str_hash, g_str_equal,
|
gui_settings = g_hash_table_new_full(g_str_hash, g_str_equal,
|
||||||
g_free, NULL);
|
g_free, NULL);
|
||||||
|
|
||||||
|
if (file_open(&gui_settings_file, OPEN_READ))
|
||||||
|
__settings_read();
|
||||||
|
file_close(&gui_settings_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_settings_deinit()
|
void gui_settings_deinit()
|
||||||
|
|
|
@ -31,6 +31,13 @@ static void test_settings()
|
||||||
test_equal(gui_settings_get("test.value1"), 0);
|
test_equal(gui_settings_get("test.value1"), 0);
|
||||||
test_equal(gui_settings_get("test.value2"), 0);
|
test_equal(gui_settings_get("test.value2"), 0);
|
||||||
test_equal(file_exists(&f), (bool)true);
|
test_equal(file_exists(&f), (bool)true);
|
||||||
|
|
||||||
|
gui_settings_init();
|
||||||
|
test_not_equal((void *)test_get_gui_settings(), NULL);
|
||||||
|
test_equal(gui_settings_get("test.value1"), 42);
|
||||||
|
test_equal(gui_settings_get("test.value2"), 84);
|
||||||
|
|
||||||
|
gui_settings_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
DECLARE_UNIT_TESTS(
|
DECLARE_UNIT_TESTS(
|
||||||
|
|
Loading…
Reference in New Issue