From 4345c58b458765ce261e13fb21cb6d9e15969b0e Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Tue, 12 Aug 2025 20:23:37 +0800 Subject: [PATCH] Bug fix for FullConfigTemplate xray --- .../CoreConfig/CoreConfigSingboxService.cs | 17 ++++++++--------- .../CoreConfig/CoreConfigV2rayService.cs | 14 ++++++-------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs index 4b315c39..3fb32524 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs @@ -80,8 +80,7 @@ public class CoreConfigSingboxService ret.Msg = string.Format(ResUI.SuccessfulConfiguration, ""); ret.Success = true; - var fullConfigTemplate = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.sing_box); - ret.Data = await ApplyFullConfigTemplate(fullConfigTemplate, singboxConfig); + ret.Data = await ApplyFullConfigTemplate(singboxConfig); return ret; } catch (Exception ex) @@ -434,8 +433,7 @@ public class CoreConfigSingboxService ret.Success = true; - var fullConfigTemplate = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.sing_box); - ret.Data = await ApplyFullConfigTemplate(fullConfigTemplate, singboxConfig); + ret.Data = await ApplyFullConfigTemplate(singboxConfig); return ret; } catch (Exception ex) @@ -2219,15 +2217,16 @@ public class CoreConfigSingboxService return 0; } - private async Task ApplyFullConfigTemplate(FullConfigTemplateItem fullConfigTemplate, SingboxConfig singboxConfig) + private async Task ApplyFullConfigTemplate(SingboxConfig singboxConfig) { - var fullConfigTemplateItem = fullConfigTemplate.Config; - if (_config.TunModeItem.EnableTun) + var fullConfigTemplate = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.sing_box); + if (fullConfigTemplate == null || !fullConfigTemplate.Enabled) { - fullConfigTemplateItem = fullConfigTemplate.TunConfig; + return JsonUtils.Serialize(singboxConfig); } - if (!fullConfigTemplate.Enabled || fullConfigTemplateItem.IsNullOrEmpty()) + var fullConfigTemplateItem = _config.TunModeItem.EnableTun ? fullConfigTemplate.TunConfig : fullConfigTemplate.Config; + if (fullConfigTemplateItem.IsNullOrEmpty()) { return JsonUtils.Serialize(singboxConfig); } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs index 96388ed3..43911046 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs @@ -3,7 +3,6 @@ using System.Net.NetworkInformation; using System.Text.Json; using System.Text.Json.Nodes; using System.Text.Json.Serialization; -using ServiceLib.Models; namespace ServiceLib.Services.CoreConfig; @@ -69,9 +68,7 @@ public class CoreConfigV2rayService ret.Msg = string.Format(ResUI.SuccessfulConfiguration, ""); ret.Success = true; - - var fullConfigTemplate = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.Xray); - ret.Data = await ApplyFullConfigTemplate(fullConfigTemplate, v2rayConfig); + ret.Data = await ApplyFullConfigTemplate(v2rayConfig); return ret; } catch (Exception ex) @@ -201,8 +198,7 @@ public class CoreConfigV2rayService ret.Success = true; - var fullConfigTemplate = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.Xray); - ret.Data = await ApplyFullConfigTemplate(fullConfigTemplate, v2rayConfig, true); + ret.Data = await ApplyFullConfigTemplate(v2rayConfig, true); return ret; } catch (Exception ex) @@ -1844,9 +1840,10 @@ public class CoreConfigV2rayService return await Task.FromResult(0); } - private async Task ApplyFullConfigTemplate(FullConfigTemplateItem fullConfigTemplate, V2rayConfig v2rayConfig, bool handleBalancerAndRules = false) + private async Task ApplyFullConfigTemplate(V2rayConfig v2rayConfig, bool handleBalancerAndRules = false) { - if (!fullConfigTemplate.Enabled || fullConfigTemplate.Config.IsNullOrEmpty()) + var fullConfigTemplate = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.Xray); + if (fullConfigTemplate == null || !fullConfigTemplate.Enabled || fullConfigTemplate.Config.IsNullOrEmpty()) { return JsonUtils.Serialize(v2rayConfig); } @@ -1918,6 +1915,7 @@ public class CoreConfigV2rayService } customOutboundsNode.Add(JsonUtils.DeepCopy(outbound)); } + fullConfigTemplateNode["outbounds"] = customOutboundsNode; return await Task.FromResult(JsonUtils.Serialize(fullConfigTemplateNode)); }