From 8b5f34d787b72a5e0d7c140aa94ee6e4d05390d1 Mon Sep 17 00:00:00 2001 From: Avestura Date: Mon, 22 Jan 2024 00:32:36 +0330 Subject: [PATCH] feat: fix error when testing shadowsocks with other sign_box core types --- v2rayN/v2rayN/Handler/CoreHandler.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/v2rayN/v2rayN/Handler/CoreHandler.cs b/v2rayN/v2rayN/Handler/CoreHandler.cs index ff30ab8b..6e79f53c 100644 --- a/v2rayN/v2rayN/Handler/CoreHandler.cs +++ b/v2rayN/v2rayN/Handler/CoreHandler.cs @@ -67,19 +67,33 @@ namespace v2rayN.Handler } } - public int LoadCoreConfigSpeedtest(List selecteds) + private ECoreType PickCoreTypeBasedOnSelecteds(List selecteds) + { + return selecteds.Exists(x => x.configType == EConfigType.Shadowsocks) ? ECoreType.Xray : + selecteds.Exists(t => t.configType == EConfigType.Hysteria2 || t.configType == EConfigType.Tuic || t.configType == EConfigType.Wireguard) ? ECoreType.sing_box : + ECoreType.Xray; + } + + public int LoadCoreConfigSpeedtest(List selecteds, ECoreType? coreType = null) { int pid = -1; - var coreType = selecteds.Exists(t => t.configType == EConfigType.Hysteria2 || t.configType == EConfigType.Tuic || t.configType == EConfigType.Wireguard) ? ECoreType.sing_box : ECoreType.Xray; + var coreTypeToPick = coreType ?? PickCoreTypeBasedOnSelecteds(selecteds); string configPath = Utils.GetConfigPath(Global.CoreSpeedtestConfigFileName); - if (CoreConfigHandler.GenerateClientSpeedtestConfig(_config, configPath, selecteds, coreType, out string msg) != 0) + if (CoreConfigHandler.GenerateClientSpeedtestConfig(_config, configPath, selecteds, coreTypeToPick, out string msg) != 0) { ShowMsg(false, msg); } else { ShowMsg(false, msg); - pid = CoreStartSpeedtest(configPath, coreType); + pid = CoreStartSpeedtest(configPath, coreTypeToPick); + var shouldTestAlternativeCoreType = pid == -1 && !coreType.HasValue; + + if(shouldTestAlternativeCoreType) + { + var alternatecoreType = coreTypeToPick == ECoreType.Xray ? ECoreType.sing_box : ECoreType.Xray; + pid = LoadCoreConfigSpeedtest(selecteds, alternatecoreType); + } } return pid; }