From 531f18d827dd515befa8a91f5ac80c6b3872498d Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Thu, 19 Dec 2024 08:51:52 +0100 Subject: GUI: add basic configuration It is simply not feasible to write the text file by hand on Windows. --- src/utils.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index 0926848..ab5f2e7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -222,7 +222,7 @@ load_project_config_file (GError **error) // which is completely undocumented g_key_file_load_from_dirs (key_file, PROJECT_NAME G_DIR_SEPARATOR_S PROJECT_NAME ".conf", - paths, NULL, 0, &e); + paths, NULL, G_KEY_FILE_KEEP_COMMENTS, &e); g_free (paths); if (!e) return key_file; @@ -236,6 +236,25 @@ load_project_config_file (GError **error) return NULL; } +gboolean +save_project_config_file (GKeyFile *key_file, GError **error) +{ + gchar *dirname = + g_build_filename (g_get_user_config_dir (), PROJECT_NAME, NULL); + (void) g_mkdir_with_parents (dirname, 0755); + gchar *path = g_build_filename (dirname, PROJECT_NAME ".conf", NULL); + g_free (dirname); + + gsize length = 0; + gchar *data = g_key_file_to_data (key_file, &length, error); + if (!data) + return FALSE; + + gboolean result = g_file_set_contents (path, data, length, error); + g_free (data); + return result; +} + // --- Loading ----------------------------------------------------------------- void -- cgit v1.2.3-70-g09d2