From 23a04e930847a6c451cf4d913236c749119a9dd8 Mon Sep 17 00:00:00 2001 From: DHR60 Date: Fri, 27 Feb 2026 21:36:32 +0800 Subject: [PATCH] Respect user-set core type --- v2rayN/ServiceLib/Handler/CoreConfigHandler.cs | 6 ++---- v2rayN/ServiceLib/Manager/CoreManager.cs | 2 +- v2rayN/ServiceLib/Models/ServerTestItem.cs | 2 ++ v2rayN/ServiceLib/Services/SpeedtestService.cs | 12 ++++++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs b/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs index a38faafa..a83495ee 100644 --- a/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs @@ -94,11 +94,9 @@ public static class CoreConfigHandler { var result = new RetResult(); var context = await BuildCoreConfigContext(config, new()); - var ids = selecteds.Where(serverTestItem => !serverTestItem.IndexId.IsNullOrEmpty()) - .Select(serverTestItem => serverTestItem.IndexId); - var nodes = await AppManager.Instance.GetProfileItemsByIndexIds(ids); - foreach (var node in nodes) + foreach (var testItem in selecteds) { + var node = testItem.Profile; var actNode = await FillNodeContext(context, node, true); if (node.IndexId == actNode.IndexId) { diff --git a/v2rayN/ServiceLib/Manager/CoreManager.cs b/v2rayN/ServiceLib/Manager/CoreManager.cs index 159af85e..bff08a73 100644 --- a/v2rayN/ServiceLib/Manager/CoreManager.cs +++ b/v2rayN/ServiceLib/Manager/CoreManager.cs @@ -105,7 +105,7 @@ public class CoreManager public async Task LoadCoreConfigSpeedtest(List selecteds) { - var coreType = selecteds.Any(t => Global.SingboxOnlyConfigType.Contains(t.ConfigType)) ? ECoreType.sing_box : ECoreType.Xray; + var coreType = selecteds.FirstOrDefault()?.CoreType == ECoreType.sing_box ? ECoreType.sing_box : ECoreType.Xray; var fileName = string.Format(Global.CoreSpeedtestConfigFileName, Utils.GetGuid(false)); var configPath = Utils.GetBinConfigPath(fileName); var result = await CoreConfigHandler.GenerateClientSpeedtestConfig(_config, configPath, selecteds, coreType); diff --git a/v2rayN/ServiceLib/Models/ServerTestItem.cs b/v2rayN/ServiceLib/Models/ServerTestItem.cs index c16a598f..beef2438 100644 --- a/v2rayN/ServiceLib/Models/ServerTestItem.cs +++ b/v2rayN/ServiceLib/Models/ServerTestItem.cs @@ -9,4 +9,6 @@ public class ServerTestItem public EConfigType ConfigType { get; set; } public bool AllowTest { get; set; } public int QueueNum { get; set; } + public required ProfileItem Profile { get; set; } + public ECoreType CoreType { get; set; } } diff --git a/v2rayN/ServiceLib/Services/SpeedtestService.cs b/v2rayN/ServiceLib/Services/SpeedtestService.cs index 207f7dfc..9bacfda8 100644 --- a/v2rayN/ServiceLib/Services/SpeedtestService.cs +++ b/v2rayN/ServiceLib/Services/SpeedtestService.cs @@ -62,8 +62,9 @@ public class SpeedtestService(Config config, Func updateF private async Task> GetClearItem(ESpeedActionType actionType, List selecteds) { var lstSelected = new List(); - foreach (var it in selecteds) + for (var i = 0; i < selecteds.Count; i++) { + var it = selecteds[i]; if (it.ConfigType.IsComplexType()) { continue; @@ -74,13 +75,16 @@ public class SpeedtestService(Config config, Func updateF continue; } + var profile = await AppManager.Instance.GetProfileItem(it.IndexId) ?? it; lstSelected.Add(new ServerTestItem() { IndexId = it.IndexId, Address = it.Address, Port = it.Port, ConfigType = it.ConfigType, - QueueNum = selecteds.IndexOf(it) + QueueNum = i, + Profile = profile, + CoreType = AppManager.Instance.GetCoreType(profile, it.ConfigType), }); } @@ -353,8 +357,8 @@ public class SpeedtestService(Config config, Func updateF private List> GetTestBatchItem(List lstSelected, int pageSize) { List> lstTest = new(); - var lst1 = lstSelected.Where(t => Global.XraySupportConfigType.Contains(t.ConfigType)).ToList(); - var lst2 = lstSelected.Where(t => Global.SingboxOnlyConfigType.Contains(t.ConfigType)).ToList(); + var lst1 = lstSelected.Where(t => Global.XraySupportConfigType.Contains(t.ConfigType) && t.CoreType == ECoreType.Xray).ToList(); + var lst2 = lstSelected.Where(t => Global.SingboxSupportConfigType.Contains(t.ConfigType) && t.CoreType == ECoreType.sing_box).ToList(); for (var num = 0; num < (int)Math.Ceiling(lst1.Count * 1.0 / pageSize); num++) {