diff --git a/libfwupdplugin/fu-plugin.c b/libfwupdplugin/fu-plugin.c index a42da042b..c0bc7e2cf 100644 --- a/libfwupdplugin/fu-plugin.c +++ b/libfwupdplugin/fu-plugin.c @@ -2339,6 +2339,36 @@ fu_plugin_get_config_value(FuPlugin *self, const gchar *key) return g_key_file_get_string(keyfile, fu_plugin_get_name(self), key, NULL); } +/** + * fu_plugin_set_config_value: + * @self: a #FuPlugin + * @key: a settings key + * @value: (nullable): a settings value + * @error: (nullable): optional return location for an error + * + * Sets a plugin config value. + * + * Returns: %TRUE for success + * + * Since: 1.7.0 + **/ +gboolean +fu_plugin_set_config_value(FuPlugin *self, const gchar *key, const gchar *value, GError **error) +{ + g_autofree gchar *conf_path = fu_plugin_get_config_filename(self); + g_autoptr(GKeyFile) keyfile = NULL; + + g_return_val_if_fail(FU_IS_PLUGIN(self), FALSE); + g_return_val_if_fail(key != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + keyfile = g_key_file_new(); + if (!g_key_file_load_from_file(keyfile, conf_path, G_KEY_FILE_KEEP_COMMENTS, error)) + return FALSE; + g_key_file_set_string(keyfile, fu_plugin_get_name(self), key, value); + return g_key_file_save_to_file(keyfile, conf_path, error); +} + /** * fu_plugin_get_config_value_boolean: * @self: a #FuPlugin diff --git a/libfwupdplugin/fu-plugin.h b/libfwupdplugin/fu-plugin.h index a5e68c6d8..f9798c656 100644 --- a/libfwupdplugin/fu-plugin.h +++ b/libfwupdplugin/fu-plugin.h @@ -131,4 +131,6 @@ fu_plugin_get_config_value(FuPlugin *self, const gchar *key); gboolean fu_plugin_get_config_value_boolean(FuPlugin *self, const gchar *key); gboolean +fu_plugin_set_config_value(FuPlugin *self, const gchar *key, const gchar *value, GError **error); +gboolean fu_plugin_has_custom_flag(FuPlugin *self, const gchar *flag); diff --git a/libfwupdplugin/fwupdplugin.map b/libfwupdplugin/fwupdplugin.map index 39773b0c4..f8cd37519 100644 --- a/libfwupdplugin/fwupdplugin.map +++ b/libfwupdplugin/fwupdplugin.map @@ -873,5 +873,6 @@ LIBFWUPDPLUGIN_1.7.0 { fu_plugin_runner_prepare; fu_plugin_runner_reload; fu_plugin_runner_write_firmware; + fu_plugin_set_config_value; local: *; } LIBFWUPDPLUGIN_1.6.2;