diff --git a/src/Converters/StringConverters.cs b/src/Converters/StringConverters.cs index e2c788ae..364d856b 100644 --- a/src/Converters/StringConverters.cs +++ b/src/Converters/StringConverters.cs @@ -1,12 +1,13 @@ using System; using System.Globalization; +using System.Text.RegularExpressions; using Avalonia.Data.Converters; using Avalonia.Styling; namespace SourceGit.Converters { - public static class StringConverters + public static partial class StringConverters { public class ToLocaleConverter : IValueConverter { @@ -73,18 +74,22 @@ namespace SourceGit.Converters public static readonly FuncValueConverter UnderRecommendGitVersion = new(v => { - if (string.IsNullOrEmpty(v)) - return true; - var versionParts = v.Split(new[] { '.', '-' }, StringSplitOptions.RemoveEmptyEntries); - if (versionParts.Length < 3) - return true; - if (!int.TryParse(versionParts[0], out var major) || - !int.TryParse(versionParts[1], out var minor) || - !int.TryParse(versionParts[2], out var build)) - return true; - var gitVersion = new Version(major, minor, build); - var targetVersion = new Version(2, 23, 0); - return gitVersion < targetVersion; + var match = REG_GIT_VERSION().Match(v ?? ""); + if (match.Success) + { + var major = int.Parse(match.Groups[1].Value); + var minor = int.Parse(match.Groups[2].Value); + var build = int.Parse(match.Groups[3].Value); + + return new Version(major, minor, build) < MINIMAL_GIT_VERSION; + } + + return true; }); + + [GeneratedRegex(@"^[\s\w]*(\d+)\.(\d+)\.(\d+).*$")] + private static partial Regex REG_GIT_VERSION(); + + private static readonly Version MINIMAL_GIT_VERSION = new Version(2, 23, 0); } } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index b379bb96..e0c6cf95 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -308,7 +308,7 @@ User Name Global git user name Git version - Git version is empty or lower than the recommended 2.23.0, exceptions may occur + Git (>= 2.23.0) is required by this app GPG SIGNING Commit GPG signing Install Path diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 0c3ac3d1..5f0dfbe9 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -308,7 +308,7 @@ 用户名 默认GIT用户名 Git 版本 - Git 版本为空或低于推荐的2.23.0,可能出现异常 + 本软件要求GIT最低版本为2.23.0 GPG签名 启用提交签名 可执行文件位置 diff --git a/src/Views/Preference.axaml b/src/Views/Preference.axaml index 39afd4ea..6500e3e1 100644 --- a/src/Views/Preference.axaml +++ b/src/Views/Preference.axaml @@ -251,13 +251,18 @@ Text="{DynamicResource Text.Preference.Git.Version}" HorizontalAlignment="Right" Margin="0,0,16,0"/> - - - - - - + + + + + + +