From f6dc9d183362101d0c8a9fb0a679858c4e17b28c Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:35:10 +0800 Subject: [PATCH] Code clean --- .../ConfigHandlerCustomSubscriptionTests.cs | 5 ++--- .../ServiceLib/Handler/SubscriptionHandler.cs | 2 -- v2rayN/ServiceLib/Helper/HttpClientHelper.cs | 1 + .../Manager/EndpointResolveManager.cs | 6 ++--- v2rayN/ServiceLib/Manager/TaskManager.cs | 2 -- .../Models/CoreConfigs/V2rayConfig.cs | 2 ++ v2rayN/ServiceLib/Models/Dto/SsSIP008.cs | 2 ++ .../ViewModels/AddServer2ViewModel.cs | 2 -- .../ViewModels/BackupAndRestoreViewModel.cs | 2 -- .../ViewModels/CheckUpdateViewModel.cs | 2 -- .../ViewModels/DNSSettingViewModel.cs | 2 -- .../ViewModels/FullConfigTemplateViewModel.cs | 2 -- .../GlobalHotkeySettingViewModel.cs | 2 -- .../ViewModels/ProfilesViewModel.cs | 18 +++++++-------- .../ViewModels/RoutingRuleSettingViewModel.cs | 4 +--- .../ViewModels/RoutingSettingViewModel.cs | 4 +--- .../ViewModels/StatusBarViewModel.cs | 2 +- .../ServiceLib/ViewModels/SubEditViewModel.cs | 4 +--- .../ViewModels/SubSettingViewModel.cs | 4 +--- .../ViewModels/ThemeSettingViewModel.cs | 1 - .../v2rayN.Desktop/Views/MainWindow.axaml.cs | 1 - .../Views/ProfilesView.axaml.cs | 1 - .../Services/V2rayRuntime.Settings.cs | 22 +++++++++---------- .../Tests/ParityValidationTests.cs | 4 ++-- .../Tests/UpdatePreReleaseSettingsTests.cs | 1 + .../Tests/WebAuthRateLimitTests.cs | 4 ++++ .../Tests/WebInstanceLockProcessTests.cs | 2 ++ .../v2rayN.WebAPI/Tests/WebLauncherTests.cs | 1 + .../Tests/WebRestartCoordinatorTests.cs | 2 ++ v2rayN/v2rayN/Manager/WindowsManager.cs | 1 - .../ViewModels/ThemeSettingViewModel.cs | 1 - v2rayN/v2rayN/Views/AddServerWindow.xaml | 1 - v2rayN/v2rayN/Views/StatusBarView.xaml.cs | 2 +- 33 files changed, 48 insertions(+), 64 deletions(-) diff --git a/v2rayN/ServiceLib.Tests/Handler/ConfigHandlerCustomSubscriptionTests.cs b/v2rayN/ServiceLib.Tests/Handler/ConfigHandlerCustomSubscriptionTests.cs index be35a9ad..b8f4efd3 100644 --- a/v2rayN/ServiceLib.Tests/Handler/ConfigHandlerCustomSubscriptionTests.cs +++ b/v2rayN/ServiceLib.Tests/Handler/ConfigHandlerCustomSubscriptionTests.cs @@ -1,4 +1,3 @@ - using ServiceLib.Tests.CoreConfig; namespace ServiceLib.Tests.Handler; @@ -32,7 +31,7 @@ public class ConfigHandlerCustomSubscriptionTests oldProfile.IsSub = true; await SQLiteHelper.Instance.InsertAsync(oldProfile); - var count = await ConfigDbHandler.AddBatchServers( FullXrayConfigs, subId, true); + var count = await ConfigDbHandler.AddBatchServers(FullXrayConfigs, subId, true); var profiles = await ConfigDbQuery.ProfileItems(subId) ?? []; await count.Should().BeEqualTo(2); @@ -66,7 +65,7 @@ public class ConfigHandlerCustomSubscriptionTests await SQLiteHelper.Instance.InsertAsync(existing); var invalidSubscription = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("not a valid profile")); - var count = await ConfigDbHandler.AddBatchServers( invalidSubscription, subId, true); + var count = await ConfigDbHandler.AddBatchServers(invalidSubscription, subId, true); var profiles = await ConfigDbQuery.ProfileItems(subId) ?? []; await (count < 1).Should().BeTrue(); diff --git a/v2rayN/ServiceLib/Handler/SubscriptionHandler.cs b/v2rayN/ServiceLib/Handler/SubscriptionHandler.cs index 8b347a77..f4b5c487 100644 --- a/v2rayN/ServiceLib/Handler/SubscriptionHandler.cs +++ b/v2rayN/ServiceLib/Handler/SubscriptionHandler.cs @@ -1,5 +1,3 @@ - - namespace ServiceLib.Handler; public class SubscriptionHandler( diff --git a/v2rayN/ServiceLib/Helper/HttpClientHelper.cs b/v2rayN/ServiceLib/Helper/HttpClientHelper.cs index 38aefef5..53839a0a 100644 --- a/v2rayN/ServiceLib/Helper/HttpClientHelper.cs +++ b/v2rayN/ServiceLib/Helper/HttpClientHelper.cs @@ -8,6 +8,7 @@ public class HttpClientHelper // private readonly SocketsHttpHandler _directHandler = CreateSocketsHttpHandler(false); private readonly Lazy _directHandlerLazy = new(() => CreateSocketsHttpHandler(false)); + private Uri _proxyUri = null!; public static HttpClientHelper Instance => _instance.Value; diff --git a/v2rayN/ServiceLib/Manager/EndpointResolveManager.cs b/v2rayN/ServiceLib/Manager/EndpointResolveManager.cs index 5c8dbcce..6e4f01db 100644 --- a/v2rayN/ServiceLib/Manager/EndpointResolveManager.cs +++ b/v2rayN/ServiceLib/Manager/EndpointResolveManager.cs @@ -152,7 +152,7 @@ public class EndpointResolveManager stream.WriteByte((byte)(value & 0xFF)); } - #endregion + #endregion Build DNS Query #region Parse DNS Response @@ -427,7 +427,7 @@ public class EndpointResolveManager data[offset + 1]); } - #endregion + #endregion Parse DNS Response } public interface IDnsResolver @@ -620,7 +620,7 @@ public class EndpointResolveManager ushort queryType, CancellationToken cancellationToken) { - for (var attempt = 1;; attempt++) + for (var attempt = 1; ; attempt++) { var query = DnsWire.BuildQuery(name, queryType); diff --git a/v2rayN/ServiceLib/Manager/TaskManager.cs b/v2rayN/ServiceLib/Manager/TaskManager.cs index ece852e2..0fb101a0 100644 --- a/v2rayN/ServiceLib/Manager/TaskManager.cs +++ b/v2rayN/ServiceLib/Manager/TaskManager.cs @@ -1,5 +1,3 @@ - - namespace ServiceLib.Manager; public class TaskManager diff --git a/v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs b/v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs index a98754eb..3fa5aa16 100644 --- a/v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs +++ b/v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs @@ -512,7 +512,9 @@ public class MaskSettings4Ray // udphop public string? mode { get; set; } + public string? interval { get; set; } + // public List? remoteIPs { get; set; } public string? remotePorts { get; set; } diff --git a/v2rayN/ServiceLib/Models/Dto/SsSIP008.cs b/v2rayN/ServiceLib/Models/Dto/SsSIP008.cs index 32951d7a..efe8f71b 100644 --- a/v2rayN/ServiceLib/Models/Dto/SsSIP008.cs +++ b/v2rayN/ServiceLib/Models/Dto/SsSIP008.cs @@ -9,8 +9,10 @@ public class SsServer { public string? remarks { get; set; } public string? server { get; set; } + [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] public int server_port { get; set; } + public string? method { get; set; } public string? password { get; set; } public string? plugin { get; set; } diff --git a/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs index 4832528e..7fb17a36 100644 --- a/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs @@ -1,5 +1,3 @@ - - namespace ServiceLib.ViewModels; public partial class AddServer2ViewModel : MyReactiveObject, ICloseable diff --git a/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs b/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs index 8b6f3094..c528572b 100644 --- a/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs @@ -1,5 +1,3 @@ - - namespace ServiceLib.ViewModels; public partial class BackupAndRestoreViewModel : MyReactiveObject diff --git a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs index 2b58028e..ae799b49 100644 --- a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs @@ -1,5 +1,3 @@ - - namespace ServiceLib.ViewModels; public partial class CheckUpdateViewModel : MyReactiveObject diff --git a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs index f092f1c4..2c54d7ee 100644 --- a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs @@ -1,5 +1,3 @@ - - namespace ServiceLib.ViewModels; public partial class DNSSettingViewModel : MyReactiveObject, ICloseable diff --git a/v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs b/v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs index 925e9c61..c696ac04 100644 --- a/v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs @@ -1,5 +1,3 @@ - - namespace ServiceLib.ViewModels; public partial class FullConfigTemplateViewModel : MyReactiveObject, ICloseable diff --git a/v2rayN/ServiceLib/ViewModels/GlobalHotkeySettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/GlobalHotkeySettingViewModel.cs index 8438731f..bf414fa5 100644 --- a/v2rayN/ServiceLib/ViewModels/GlobalHotkeySettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/GlobalHotkeySettingViewModel.cs @@ -1,5 +1,3 @@ - - namespace ServiceLib.ViewModels; public class GlobalHotkeySettingViewModel : MyReactiveObject, ICloseable diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index 680051d6..5655f687 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -609,7 +609,7 @@ public partial class ProfilesViewModel : MyReactiveObject private async Task GenGroupAllServer() { - var ret = await ConfigDbHandler.AddGroupAllServer( SelectedSub); + var ret = await ConfigDbHandler.AddGroupAllServer(SelectedSub); if (ret.Success != true) { NoticeManager.Instance.Enqueue(ResUI.OperationFailed); @@ -621,7 +621,7 @@ public partial class ProfilesViewModel : MyReactiveObject private async Task GenGroupRegionServer() { - var ret = await ConfigDbHandler.AddGroupRegionServer( SelectedSub); + var ret = await ConfigDbHandler.AddGroupRegionServer(SelectedSub); if (ret.Success != true) { NoticeManager.Instance.Enqueue(ResUI.OperationFailed); @@ -641,7 +641,7 @@ public partial class ProfilesViewModel : MyReactiveObject _dicHeaderSort.TryAdd(colName, true); _dicHeaderSort.TryGetValue(colName, out var asc); - if (await ConfigDbHandler.SortServers( _config.SubIndexId, colName, asc) != 0) + if (await ConfigDbHandler.SortServers(_config.SubIndexId, colName, asc) != 0) { return; } @@ -651,7 +651,7 @@ public partial class ProfilesViewModel : MyReactiveObject public async Task RemoveInvalidServerResult() { - var count = await ConfigDbHandler.RemoveInvalidServerResult( _config.SubIndexId); + var count = await ConfigDbHandler.RemoveInvalidServerResult(_config.SubIndexId); await RefreshServers(); NoticeManager.Instance.Enqueue(string.Format(ResUI.RemoveInvalidServerResultTip, count)); } @@ -665,7 +665,7 @@ public partial class ProfilesViewModel : MyReactiveObject return; } - await ConfigDbHandler.MoveToGroup( lstSelected, SelectedMoveToGroup.Id); + await ConfigDbHandler.MoveToGroup(lstSelected, SelectedMoveToGroup.Id); NoticeManager.Instance.Enqueue(ResUI.OperationSuccess); await RefreshServers(); @@ -683,7 +683,7 @@ public partial class ProfilesViewModel : MyReactiveObject return; } - if (await ConfigDbHandler.MoveServer( lstProfile, index, eMove) == 0) + if (await ConfigDbHandler.MoveServer(lstProfile, index, eMove) == 0) { await RefreshServers(); } @@ -695,7 +695,7 @@ public partial class ProfilesViewModel : MyReactiveObject if (startIndex >= 0 && targetIndex >= 0 && startIndex != targetIndex) { var lstProfile = ProfileItems?.Select(t => t.IndexId).ToList() ?? []; - if (await ConfigDbHandler.MoveServer( lstProfile, startIndex, EMove.Position, targetIndex) == 0) + if (await ConfigDbHandler.MoveServer(lstProfile, startIndex, EMove.Position, targetIndex) == 0) { await RefreshServers(); } @@ -717,7 +717,7 @@ public partial class ProfilesViewModel : MyReactiveObject .Select(item => item.IndexId) .ToList(); - var result = await ConfigDbHandler.MoveServersTo( + var result = await ConfigDbHandler.MoveServersTo( orderedProfileIds, sourceIndices, insertIndex); @@ -920,7 +920,7 @@ public partial class ProfilesViewModel : MyReactiveObject { return; } - await ConfigDbHandler.DeleteSubItem( item.Id); + await ConfigDbHandler.DeleteSubItem(item.Id); await RefreshSubscriptions(); await SubSelectedChangedAsync(); diff --git a/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs index ecc87927..8d7a023a 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs @@ -1,5 +1,3 @@ - - namespace ServiceLib.ViewModels; public partial class RoutingRuleSettingViewModel : MyReactiveObject, ICloseable @@ -233,7 +231,7 @@ public partial class RoutingRuleSettingViewModel : MyReactiveObject, ICloseable item.RuleNum = _rules.Count; item.RuleSet = JsonUtils.Serialize(_rules, false); - if (await ConfigDbHandler.SaveRoutingItem( item) == 0) + if (await ConfigDbHandler.SaveRoutingItem(item) == 0) { NoticeManager.Instance.Enqueue(ResUI.OperationSuccess); RequestClose?.Invoke(this, EventArgs.Empty); diff --git a/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs index a3963088..e4283fd0 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs @@ -1,5 +1,3 @@ - - namespace ServiceLib.ViewModels; public partial class RoutingSettingViewModel : MyReactiveObject @@ -174,7 +172,7 @@ public partial class RoutingSettingViewModel : MyReactiveObject return; } - if (await ConfigDbHandler.SetDefaultRouting( item) == 0) + if (await ConfigDbHandler.SetDefaultRouting(item) == 0) { await RefreshRoutingItems(); IsModified = true; diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index 1bcb8bc7..242020ff 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -51,7 +51,7 @@ public partial class StatusBarViewModel : MyReactiveObject public ReactiveCommand SystemProxySetCmd { get; } public ReactiveCommand SystemProxyNothingCmd { get; } public ReactiveCommand SystemProxyPacCmd { get; } - + [Reactive] public partial int SystemProxySelected { get; set; } diff --git a/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs b/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs index 914d6a29..d2b78b66 100644 --- a/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs @@ -1,5 +1,3 @@ - - namespace ServiceLib.ViewModels; public partial class SubEditViewModel : MyReactiveObject, ICloseable @@ -89,7 +87,7 @@ public partial class SubEditViewModel : MyReactiveObject, ICloseable SelectedSource.PrevProfile = PrevProfile; SelectedSource.NextProfile = NextProfile; - if (await ConfigDbHandler.AddSubItem( SelectedSource) == 0) + if (await ConfigDbHandler.AddSubItem(SelectedSource) == 0) { NoticeManager.Instance.Enqueue(ResUI.OperationSuccess); RequestClose?.Invoke(this, EventArgs.Empty); diff --git a/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs index 43ab4215..c1ab797d 100644 --- a/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs @@ -1,5 +1,3 @@ - - namespace ServiceLib.ViewModels; public partial class SubSettingViewModel : MyReactiveObject @@ -92,7 +90,7 @@ public partial class SubSettingViewModel : MyReactiveObject foreach (var it in SelectedSources ?? [SelectedSource]) { - await ConfigDbHandler.DeleteSubItem( it.Id); + await ConfigDbHandler.DeleteSubItem(it.Id); } await RefreshSubItems(); NoticeManager.Instance.Enqueue(ResUI.OperationSuccess); diff --git a/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs b/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs index 2dc454db..6c6a850f 100644 --- a/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs +++ b/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs @@ -1,6 +1,5 @@ using Semi.Avalonia; - namespace v2rayN.Desktop.ViewModels; public partial class ThemeSettingViewModel : MyReactiveObject diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index 0d0a6185..5c8e910a 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -574,7 +574,6 @@ public partial class MainWindow : WindowBase }; }).DisposeWith(currentLayoutDisposables); break; - } RestoreUI(); diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs index 3cb3c8ee..8deeef6c 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs @@ -317,7 +317,6 @@ public partial class ProfilesView : ReactiveUserControl } } - private void BtnAutofitColumnWidth_Click(object? sender, RoutedEventArgs e) { AutofitColumnWidth(); diff --git a/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Settings.cs b/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Settings.cs index 58c9036c..4b0b92aa 100644 --- a/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Settings.cs +++ b/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Settings.cs @@ -563,7 +563,7 @@ public sealed partial class V2rayRuntime || current.DomainDNSAddress != input.DomainDNSAddress || current.Remarks != (input.Remarks ?? current.Remarks); var item = ApplyDnsProfileInput(current, coreType, input); - return (Result: await ConfigDbHandler.SaveDNSItems( item), Changed: changed); + return (Result: await ConfigDbHandler.SaveDNSItems(item), Changed: changed); }); if (result.Result == -2) { @@ -696,7 +696,7 @@ public sealed partial class V2rayRuntime item.RuleNum = parsedRules.Count; } var result = parsedRules.Count == 0 - ? await ConfigDbHandler.SaveRoutingItem( item) + ? await ConfigDbHandler.SaveRoutingItem(item) : await ConfigDbHandler.AddBatchRoutingRules(item, JsonUtils.Serialize(parsedRules, false)); return (Result: result, Item: (RoutingItem?)item, Changed: changed); }); @@ -735,7 +735,7 @@ public sealed partial class V2rayRuntime var fallback = remaining.FirstOrDefault(); if (fallback is not null) { - if (await ConfigDbHandler.SetDefaultRouting( fallback) != 0) + if (await ConfigDbHandler.SetDefaultRouting(fallback) != 0) { throw new IOException("ServiceLib could not select the fallback routing profile."); } @@ -772,7 +772,7 @@ public sealed partial class V2rayRuntime return (Result: -2, Changed: false); } var changed = !item.IsActive; - return (Result: changed ? await ConfigDbHandler.SetDefaultRouting( item) : 0, Changed: changed); + return (Result: changed ? await ConfigDbHandler.SetDefaultRouting(item) : 0, Changed: changed); }); if (result.Result == -2) { @@ -993,7 +993,7 @@ public sealed partial class V2rayRuntime } var before = await GetActiveRoutingSignatureAsync(); - var result = await _mutations.RunAsync(() => ConfigDbHandler.InitRouting( true)); + var result = await _mutations.RunAsync(() => ConfigDbHandler.InitRouting(true)); if (result != 0) { return OperationView.Fail("routing_import_failed", ApiMessageKeys.RoutingSaveFailed); @@ -1048,7 +1048,7 @@ public sealed partial class V2rayRuntime return -2; } var item = ApplyCoreConfigTemplateInput(current, coreType, input); - return await ConfigDbHandler.SaveFullConfigTemplate( item); + return await ConfigDbHandler.SaveFullConfigTemplate(item); }); if (result == -2) { @@ -1160,7 +1160,7 @@ public sealed partial class V2rayRuntime await SQLiteHelper.Instance.DeleteAllAsync(); foreach (var item in stage.DnsItems) { - if (await ConfigDbHandler.SaveDNSItems( item) != 0) + if (await ConfigDbHandler.SaveDNSItems(item) != 0) { throw new IOException($"The {item.CoreType} DNS profile could not be saved."); } @@ -1168,7 +1168,7 @@ public sealed partial class V2rayRuntime // Default routing uses embedded data only; this call performs no network I/O // because the route template source was cleared in the staged plan. - if (await ConfigDbHandler.InitRouting( false) != 0) + if (await ConfigDbHandler.InitRouting(false) != 0) { throw new IOException("The built-in routing profiles could not be initialized."); } @@ -1177,7 +1177,7 @@ public sealed partial class V2rayRuntime { foreach (var item in stage.DnsItems) { - if (await ConfigDbHandler.SaveDNSItems( item) != 0) + if (await ConfigDbHandler.SaveDNSItems(item) != 0) { throw new IOException($"The {item.CoreType} DNS profile could not be saved."); } @@ -1216,7 +1216,7 @@ public sealed partial class V2rayRuntime var defaultItem = stage.Routing.DefaultRemarks is { } remarks ? stage.Routing.Items.FirstOrDefault(item => item.Remarks == remarks) : null; - if (defaultItem is not null && await ConfigDbHandler.SetDefaultRouting( defaultItem) != 0) + if (defaultItem is not null && await ConfigDbHandler.SetDefaultRouting(defaultItem) != 0) { throw new IOException("The first staged routing profile could not be activated."); } @@ -1226,7 +1226,7 @@ public sealed partial class V2rayRuntime { var existingDefault = currentRoutes.FirstOrDefault(item => item.Id == existingDefaultId); if (existingDefault is not null && !existingDefault.IsActive - && await ConfigDbHandler.SetDefaultRouting( existingDefault) != 0) + && await ConfigDbHandler.SetDefaultRouting(existingDefault) != 0) { throw new IOException("The migrated default routing profile could not be activated."); } diff --git a/v2rayN/v2rayN.WebAPI/Tests/ParityValidationTests.cs b/v2rayN/v2rayN.WebAPI/Tests/ParityValidationTests.cs index 4e7e61a0..5fa3e1a9 100644 --- a/v2rayN/v2rayN.WebAPI/Tests/ParityValidationTests.cs +++ b/v2rayN/v2rayN.WebAPI/Tests/ParityValidationTests.cs @@ -24,7 +24,7 @@ public class ParityValidationTests await code.Should().BeEqualTo("ok"); await profile.IsValid().Should().BeFalse(); - var result = await ConfigDbHandler.AddShadowsocksServer( profile, toFile: false); + var result = await ConfigDbHandler.AddShadowsocksServer(profile, toFile: false); await result.Should().BeEqualTo(0); await profile.ConfigVersion.Should().BeEqualTo(4); @@ -41,7 +41,7 @@ public class ParityValidationTests await code.Should().BeEqualTo("ok"); await profile.IsValid().Should().BeTrue(); - var result = await ConfigDbHandler.AddShadowsocksServer( profile, toFile: false); + var result = await ConfigDbHandler.AddShadowsocksServer(profile, toFile: false); await result.Should().BeEqualTo(0); } diff --git a/v2rayN/v2rayN.WebAPI/Tests/UpdatePreReleaseSettingsTests.cs b/v2rayN/v2rayN.WebAPI/Tests/UpdatePreReleaseSettingsTests.cs index 6f945b69..c1858ca8 100644 --- a/v2rayN/v2rayN.WebAPI/Tests/UpdatePreReleaseSettingsTests.cs +++ b/v2rayN/v2rayN.WebAPI/Tests/UpdatePreReleaseSettingsTests.cs @@ -155,6 +155,7 @@ public class UpdatePreReleaseSettingsTests private readonly FieldInfo _configField = typeof(ConfigState) .GetField("_current", BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new MissingFieldException(typeof(ConfigState).FullName, "_current"); + private readonly object? _previousConfig; private readonly string? _previousLocalData; private readonly string _configPath; diff --git a/v2rayN/v2rayN.WebAPI/Tests/WebAuthRateLimitTests.cs b/v2rayN/v2rayN.WebAPI/Tests/WebAuthRateLimitTests.cs index a9007b76..2bfe4c4f 100644 --- a/v2rayN/v2rayN.WebAPI/Tests/WebAuthRateLimitTests.cs +++ b/v2rayN/v2rayN.WebAPI/Tests/WebAuthRateLimitTests.cs @@ -146,6 +146,7 @@ public class WebAuthRateLimitTests await proxy.StopAsync(); } } + private static WebApplication CreatePartitionTestApp() { var builder = WebApplication.CreateBuilder(); @@ -198,9 +199,12 @@ public class WebAuthRateLimitTests private sealed class FixedProxy(Uri address) : IWebProxy { public ICredentials? Credentials { get; set; } + public Uri GetProxy(Uri destination) => address; + public bool IsBypassed(Uri host) => false; } + private sealed class TemporaryDirectory : IDisposable { public TemporaryDirectory() diff --git a/v2rayN/v2rayN.WebAPI/Tests/WebInstanceLockProcessTests.cs b/v2rayN/v2rayN.WebAPI/Tests/WebInstanceLockProcessTests.cs index d934a707..0e6eb63b 100644 --- a/v2rayN/v2rayN.WebAPI/Tests/WebInstanceLockProcessTests.cs +++ b/v2rayN/v2rayN.WebAPI/Tests/WebInstanceLockProcessTests.cs @@ -99,8 +99,10 @@ public class WebInstanceLockProcessTests { private readonly DirectoryInfo _directory = Directory.CreateTempSubdirectory("v2rayn-instance-lock-tests-"); public string Path => _directory.FullName; + public void Dispose() => _directory.Delete(recursive: true); } + private sealed class LockProcess : IAsyncDisposable { private static readonly TimeSpan Timeout = TimeSpan.FromSeconds(20); diff --git a/v2rayN/v2rayN.WebAPI/Tests/WebLauncherTests.cs b/v2rayN/v2rayN.WebAPI/Tests/WebLauncherTests.cs index dc13c190..caf5e26c 100644 --- a/v2rayN/v2rayN.WebAPI/Tests/WebLauncherTests.cs +++ b/v2rayN/v2rayN.WebAPI/Tests/WebLauncherTests.cs @@ -6,6 +6,7 @@ public class WebLauncherTests { // Keep fixture PIDs outside Linux's assignable range so host services cannot affect stop tests. private const int FakeOwnerProcessId = int.MaxValue - 1; + private const int OtherProcessId = int.MaxValue; [Test] diff --git a/v2rayN/v2rayN.WebAPI/Tests/WebRestartCoordinatorTests.cs b/v2rayN/v2rayN.WebAPI/Tests/WebRestartCoordinatorTests.cs index c4ac12bd..914c3dde 100644 --- a/v2rayN/v2rayN.WebAPI/Tests/WebRestartCoordinatorTests.cs +++ b/v2rayN/v2rayN.WebAPI/Tests/WebRestartCoordinatorTests.cs @@ -351,7 +351,9 @@ public class WebRestartCoordinatorTests public bool HasExited { get; } = hasExited; public bool Killed { get; private set; } public bool Disposed { get; private set; } + public void KillTree() => Killed = true; + public void Dispose() => Disposed = true; } diff --git a/v2rayN/v2rayN/Manager/WindowsManager.cs b/v2rayN/v2rayN/Manager/WindowsManager.cs index 6d3a3a24..0fd2450a 100644 --- a/v2rayN/v2rayN/Manager/WindowsManager.cs +++ b/v2rayN/v2rayN/Manager/WindowsManager.cs @@ -1,7 +1,6 @@ using System.Drawing; using System.Windows.Media.Imaging; - namespace v2rayN.Manager; public sealed class WindowsManager diff --git a/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs index 92db2a9b..d1e8ecc3 100644 --- a/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs @@ -3,7 +3,6 @@ using MaterialDesignColors.ColorManipulation; using MaterialDesignThemes.Wpf; using Microsoft.Win32; - namespace v2rayN.ViewModels; public partial class ThemeSettingViewModel : MyReactiveObject diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml b/v2rayN/v2rayN/Views/AddServerWindow.xaml index b468c0cf..e2139156 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml @@ -1138,7 +1138,6 @@ Style="{StaticResource DefTextBox}" /> - vm.SystemProxySetCmd, v => v.menuSystemProxySet).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SystemProxyNothingCmd, v => v.menuSystemProxyNothing).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SystemProxyPacCmd, v => v.menuSystemProxyPac).DisposeWith(disposables); - + //tray menu this.BindCommand(ViewModel, vm => vm.AddServerViaClipboardCmd, v => v.menuAddServerViaClipboard2).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.AddServerViaScanCmd, v => v.menuAddServerViaScan2).DisposeWith(disposables);