From 14334b08d2728a99cab5477ee6e090a8d226059e Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 9 Oct 2024 17:29:53 +0800 Subject: [PATCH] enhance: do not save `gpg.openpgp.program` if `gpg.program` exists and the value has not been changed (#544) --- src/Views/Preference.axaml.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Views/Preference.axaml.cs b/src/Views/Preference.axaml.cs index af70ee8e..2f08e0db 100644 --- a/src/Views/Preference.axaml.cs +++ b/src/Views/Preference.axaml.cs @@ -137,7 +137,22 @@ namespace SourceGit.Views SetIfChanged(config, "gpg.format", GPGFormat.Value, "openpgp"); if (!GPGFormat.Value.Equals("ssh", StringComparison.Ordinal)) - SetIfChanged(config, $"gpg.{GPGFormat.Value}.program", GPGExecutableFile, ""); + { + var oldGPG = string.Empty; + if (GPGFormat.Value == "openpgp" && config.TryGetValue("gpg.program", out var openpgp)) + oldGPG = openpgp; + else if (config.TryGetValue($"gpg.{GPGFormat.Value}.program", out var gpgProgram)) + oldGPG = gpgProgram; + + bool changed = false; + if (!string.IsNullOrEmpty(oldGPG)) + changed = oldGPG != GPGExecutableFile; + else if (!string.IsNullOrEmpty(GPGExecutableFile)) + changed = true; + + if (changed) + new Commands.Config(null).Set($"gpg.{GPGFormat.Value}.program", GPGExecutableFile); + } base.OnClosing(e); }