fix: Save different GPGFormat executable files independently

This commit is contained in:
Gadfly 2024-06-21 16:03:45 +08:00
parent d3d6889e25
commit 8c0ff1f613
No known key found for this signature in database
3 changed files with 29 additions and 14 deletions

View file

@ -2,18 +2,17 @@
namespace SourceGit.Models
{
public class GPGFormat(string name, string value, string desc, string program, bool needFindProgram)
public class GPGFormat(string name, string value, string desc, string program)
{
public string Name { get; set; } = name;
public string Value { get; set; } = value;
public string Desc { get; set; } = desc;
public string Program { get; set; } = program;
public bool NeedFindProgram { get; set; } = needFindProgram;
public static readonly List<GPGFormat> Supported = [
new GPGFormat("OPENPGP", "openpgp", "DEFAULT", "gpg", true),
new GPGFormat("X.509", "x509", "", "gpgsm", true),
new GPGFormat("SSH", "ssh", "Requires Git >= 2.34.0", "ssh-keygen", false),
new GPGFormat("OPENPGP", "openpgp", "DEFAULT", "gpg"),
new GPGFormat("X.509", "x509", "", "gpgsm"),
new GPGFormat("SSH", "ssh", "Requires Git >= 2.34.0", "ssh-keygen"),
];
}
}

View file

@ -412,14 +412,12 @@
<TextBlock Grid.Row="1" Grid.Column="0"
Text="{DynamicResource Text.Preference.GPG.Path}"
HorizontalAlignment="Right"
Margin="0,0,16,0"
IsVisible="{Binding #me.GPGFormat.NeedFindProgram}"/>
Margin="0,0,16,0"/>
<TextBox Grid.Row="1" Grid.Column="1"
Height="28"
CornerRadius="3"
Text="{Binding #me.GPGExecutableFile, Mode=TwoWay}"
Watermark="{DynamicResource Text.Preference.GPG.Path.Placeholder}"
IsVisible="{Binding #me.GPGFormat.NeedFindProgram}">
Watermark="{DynamicResource Text.Preference.GPG.Path.Placeholder}">
<TextBox.InnerRightContent>
<Button Classes="icon_button" Width="30" Height="30" Click="SelectGPGExecutable">
<Path Data="{StaticResource Icons.Folder.Open}" Fill="{DynamicResource Brush.FG1}"/>

View file

@ -162,14 +162,18 @@ namespace SourceGit.Views
if (config.TryGetValue("gpg.format", out var gpgFormat))
GPGFormat = Models.GPGFormat.Supported.Find(x => x.Value == gpgFormat) ?? Models.GPGFormat.Supported[0];
if (GPGFormat.Value == "opengpg" && config.TryGetValue("gpg.program", out var opengpg))
GPGExecutableFile = opengpg;
else if (config.TryGetValue($"gpg.{GPGFormat.Value}.program", out var gpgProgram))
GPGExecutableFile = gpgProgram;
foreach (var supportedSingleFormat in Models.GPGFormat.Supported)
{
_gpgExecutableFiles[supportedSingleFormat.Value] = config.GetValueOrDefault($"gpg.{supportedSingleFormat.Value}.program");
}
if (config.TryGetValue("gpg.program", out var defaultGpgProgram))
_gpgExecutableFiles[Models.GPGFormat.Supported[0].Value] = defaultGpgProgram;
GPGExecutableFile = _gpgExecutableFiles[GPGFormat.Value];
ver = new Commands.Version().Query();
}
this.PropertyChanged += PreferencePropertyChanged;
InitializeComponent();
GitVersion = ver;
}
@ -189,7 +193,7 @@ namespace SourceGit.Views
SetIfChanged(config, "commit.gpgsign", EnableGPGCommitSigning ? "true" : "false");
SetIfChanged(config, "tag.gpgsign", EnableGPGTagSigning ? "true" : "false");
SetIfChanged(config, "gpg.format", GPGFormat.Value);
SetIfChanged(config, $"gpg.{GPGFormat.Value}.program", GPGFormat.Value != "ssh" ? GPGExecutableFile : null);
SetIfChanged(config, $"gpg.{GPGFormat.Value}.program", GPGExecutableFile);
Close();
}
@ -296,5 +300,19 @@ namespace SourceGit.Views
if (changed)
new Commands.Config(null).Set(key, value);
}
private void PreferencePropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
{
if (e.Property == GPGExecutableFileProperty)
_gpgExecutableFiles[GPGFormat.Value] = (string)e.NewValue;
else if (e.Property == GPGFormatProperty)
{
var newValue = _gpgExecutableFiles[GPGFormat.Value];
if (GPGExecutableFile != newValue)
GPGExecutableFile = newValue;
}
}
private readonly Dictionary<string, string> _gpgExecutableFiles = new();
}
}