From 14216ab98f4a2d2ef72c26a62c267d910a9fe754 Mon Sep 17 00:00:00 2001 From: k1mlka Date: Thu, 26 Sep 2024 17:03:38 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E7=BD=91=E7=BB=9C=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E9=A1=B5=E9=9D=A2=E5=9F=9F=E5=90=8D=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI/ViewModels/AcceleratorPageViewModel.cs | 6 ++- .../AcceleratorPageViewModel.props.cs | 17 +++++++ .../UI/Views/Controls/NetworkCheck.axaml | 45 ++++++++++++++++++- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs b/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs index 8e67da5e5d0..5486ab841b1 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs @@ -95,9 +95,11 @@ public AcceleratorPageViewModel() .IsExecuting .ToPropertyEx(this, x => x.IsNATChecking); + var canDNSCheck = this.WhenAnyValue(x => x.DomainPendingTest) + .Select(domain => domain == string.Empty || DomainRegExp().IsMatch(domain)); DNSCheckCommand = ReactiveCommand.CreateFromTask(async () => { - var testDomain = DomainPendingTest == string.Empty ? "store.steampowered.com" : DomainPendingTest; + var testDomain = DomainPendingTest == string.Empty ? DefaultTestDomain : DomainPendingTest; try { long delayMs; @@ -124,7 +126,7 @@ public AcceleratorPageViewModel() DNSTestDelay = string.Empty; DNSTestResult = "error"; } - }); + }, canDNSCheck); DNSCheckCommand .IsExecuting .ToPropertyEx(this, x => x.IsDNSChecking); diff --git a/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.props.cs b/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.props.cs index 7ae8707dd4a..9427e2e1ee8 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.props.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.props.cs @@ -4,6 +4,20 @@ namespace BD.WTTS.UI.ViewModels; public sealed partial class AcceleratorPageViewModel : TabItemViewModel { + [GeneratedRegex(DomainValidationAttribute.RegPattern)] + private static partial Regex DomainRegExp(); + + public class DomainValidationAttribute : RegularExpressionAttribute + { + public const string RegPattern = @"^[^/]+\.[^/]{2,}$"; + + public override string FormatErrorMessage(string name) => "请填入不带分隔符 \"/\" 的域名"; + + public DomainValidationAttribute() : base(RegPattern) + { + } + } + public enum NatTypeSimple { Unknown, @@ -14,6 +28,8 @@ public enum NatTypeSimple public override string Name => Strings.Welcome; + public string DefaultTestDomain { get; } = "store.steampowered.com"; + [Reactive] public string SelectedSTUNAddress { get; set; } @@ -34,6 +50,7 @@ public enum NatTypeSimple [ObservableAsProperty] public bool IsIPv6Checking { get; } + [DomainValidation] [Reactive] public string DomainPendingTest { get; set; } = string.Empty; diff --git a/src/BD.WTTS.Client.Plugins.Accelerator/UI/Views/Controls/NetworkCheck.axaml b/src/BD.WTTS.Client.Plugins.Accelerator/UI/Views/Controls/NetworkCheck.axaml index 952f15c5adf..0b5c0cd73ef 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator/UI/Views/Controls/NetworkCheck.axaml +++ b/src/BD.WTTS.Client.Plugins.Accelerator/UI/Views/Controls/NetworkCheck.axaml @@ -213,7 +213,50 @@ + Watermark="{Binding DefaultTestDomain}"> + + + +