mirror of
https://github.com/2dust/v2rayN.git
synced 2026-11-18 18:35:00 +03:00
Code clean
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
namespace ServiceLib.Handler;
|
||||
|
||||
public class SubscriptionHandler(
|
||||
|
||||
@@ -8,6 +8,7 @@ public class HttpClientHelper
|
||||
|
||||
// private readonly SocketsHttpHandler _directHandler = CreateSocketsHttpHandler(false);
|
||||
private readonly Lazy<SocketsHttpHandler> _directHandlerLazy = new(() => CreateSocketsHttpHandler(false));
|
||||
|
||||
private Uri _proxyUri = null!;
|
||||
|
||||
public static HttpClientHelper Instance => _instance.Value;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
namespace ServiceLib.Manager;
|
||||
|
||||
public class TaskManager
|
||||
|
||||
@@ -512,7 +512,9 @@ public class MaskSettings4Ray
|
||||
|
||||
// udphop
|
||||
public string? mode { get; set; }
|
||||
|
||||
public string? interval { get; set; }
|
||||
|
||||
// public List<string>? remoteIPs { get; set; }
|
||||
public string? remotePorts { get; set; }
|
||||
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
namespace ServiceLib.ViewModels;
|
||||
|
||||
public partial class AddServer2ViewModel : MyReactiveObject, ICloseable
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
namespace ServiceLib.ViewModels;
|
||||
|
||||
public partial class BackupAndRestoreViewModel : MyReactiveObject
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
namespace ServiceLib.ViewModels;
|
||||
|
||||
public partial class CheckUpdateViewModel : MyReactiveObject
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
namespace ServiceLib.ViewModels;
|
||||
|
||||
public partial class DNSSettingViewModel : MyReactiveObject, ICloseable
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
namespace ServiceLib.ViewModels;
|
||||
|
||||
public partial class FullConfigTemplateViewModel : MyReactiveObject, ICloseable
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
namespace ServiceLib.ViewModels;
|
||||
|
||||
public class GlobalHotkeySettingViewModel : MyReactiveObject, ICloseable
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -920,7 +920,7 @@ public partial class ProfilesViewModel : MyReactiveObject
|
||||
{
|
||||
return;
|
||||
}
|
||||
await ConfigDbHandler.DeleteSubItem( item.Id);
|
||||
await ConfigDbHandler.DeleteSubItem(item.Id);
|
||||
|
||||
await RefreshSubscriptions();
|
||||
await SubSelectedChangedAsync();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Semi.Avalonia;
|
||||
|
||||
|
||||
namespace v2rayN.Desktop.ViewModels;
|
||||
|
||||
public partial class ThemeSettingViewModel : MyReactiveObject
|
||||
|
||||
@@ -574,7 +574,6 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
|
||||
};
|
||||
}).DisposeWith(currentLayoutDisposables);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
RestoreUI();
|
||||
|
||||
@@ -317,7 +317,6 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void BtnAutofitColumnWidth_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
AutofitColumnWidth();
|
||||
|
||||
@@ -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<DNSItem>();
|
||||
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.");
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Drawing;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
|
||||
namespace v2rayN.Manager;
|
||||
|
||||
public sealed class WindowsManager
|
||||
|
||||
@@ -3,7 +3,6 @@ using MaterialDesignColors.ColorManipulation;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Microsoft.Win32;
|
||||
|
||||
|
||||
namespace v2rayN.ViewModels;
|
||||
|
||||
public partial class ThemeSettingViewModel : MyReactiveObject
|
||||
|
||||
@@ -1138,7 +1138,6 @@
|
||||
Style="{StaticResource DefTextBox}" />
|
||||
</StackPanel>
|
||||
</materialDesign:PopupBox>
|
||||
|
||||
</Grid>
|
||||
|
||||
<Separator
|
||||
|
||||
Reference in New Issue
Block a user