From 37540822b0dc4f2f94f07ba79ec4fadebe1d6228 Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Fri, 27 May 2016 02:33:02 +0100 Subject: [PATCH] Implement the store function, we'll need it for a UI Signed-off-by: Ikey Doherty --- src/shim/lsi.c | 35 +++++++++++++++++++++++++++++++++++ src/shim/lsi.h | 7 +++++++ 2 files changed, 42 insertions(+) diff --git a/src/shim/lsi.c b/src/shim/lsi.c index ac3b0cb..c5a0766 100644 --- a/src/shim/lsi.c +++ b/src/shim/lsi.c @@ -151,6 +151,41 @@ bool lsi_config_load(LsiConfig *config) return true; } +static inline const char *lsi_bool_to_string(bool b) +{ + if (b) { + return "true"; + } + return "false"; +} + +bool lsi_config_store(LsiConfig *config) +{ + autofree(FILE) *fp = NULL; + autofree(char) *conf = NULL; + + if (!config) { + return false; + } + + conf = lsi_get_user_config_file(); + if (!conf) { + return false; + } + + fp = fopen(conf, "w"); + if (!fp) { + return false; + } + if (fprintf(fp, + "[Steam]\nuse-native-runtime = %s\nforce-32bit = %s\n", + lsi_bool_to_string(config->use_native_runtime), + lsi_bool_to_string(config->force_32)) < 0) { + return false; + } + return true; +} + void lsi_config_load_defaults(LsiConfig *config) { assert(config != NULL); diff --git a/src/shim/lsi.h b/src/shim/lsi.h index 72ed44e..8280a66 100644 --- a/src/shim/lsi.h +++ b/src/shim/lsi.h @@ -44,6 +44,13 @@ bool lsi_config_load(LsiConfig *config); */ void lsi_config_load_defaults(LsiConfig *config); +/** + * Attempt to write the user config to disk. + * On failure, this function will return false, and errno will be set + * appropriately. + */ +bool lsi_config_store(LsiConfig *config); + /** * Determine if the host system is 64-bit. *