From 82443a64cda5e63af677ce9e4115cc1d61a980df Mon Sep 17 00:00:00 2001 From: DHR60 Date: Wed, 21 Jan 2026 12:03:23 +0800 Subject: [PATCH] Refactor flow --- v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs | 9 --------- v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs | 8 ++++++++ v2rayN/ServiceLib/Handler/Fmt/VLESSFmt.cs | 5 +++++ v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs | 2 -- v2rayN/ServiceLib/Models/ProfileItem.cs | 2 -- .../CoreConfig/Singbox/SingboxOutboundService.cs | 2 -- .../Services/CoreConfig/V2ray/V2rayOutboundService.cs | 2 -- 7 files changed, 13 insertions(+), 17 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs index 1ff712b7..bfafce13 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs @@ -21,12 +21,6 @@ public class BaseFmt protected static int ToUriQuery(ProfileItem item, string? securityDef, ref Dictionary dicQuery) { - var protocolExtra = item.GetProtocolExtra(); - if (!protocolExtra.Flow.IsNullOrEmpty()) - { - dicQuery.Add("flow", protocolExtra.Flow); - } - if (item.StreamSecurity.IsNotEmpty()) { dicQuery.Add("security", item.StreamSecurity); @@ -209,9 +203,6 @@ public class BaseFmt protected static int ResolveUriQuery(NameValueCollection query, ref ProfileItem item) { - var protocolExtra = item.GetProtocolExtra(); - protocolExtra.Flow = GetQueryValue(query, "flow"); - item.SetProtocolExtra(protocolExtra); item.StreamSecurity = GetQueryValue(query, "security"); item.Sni = GetQueryValue(query, "sni"); item.Alpn = GetQueryDecoded(query, "alpn"); diff --git a/v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs index c58d6802..5180a883 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs @@ -10,6 +10,7 @@ public class TrojanFmt : BaseFmt { ConfigType = EConfigType.Trojan }; + var protocolExtra = item.GetProtocolExtra(); var url = Utils.TryUri(str); if (url == null) @@ -23,8 +24,10 @@ public class TrojanFmt : BaseFmt item.Password = Utils.UrlDecode(url.UserInfo); var query = Utils.ParseQueryString(url.Query); + protocolExtra.Flow = GetQueryValue(query, "flow"); ResolveUriQuery(query, ref item); + item.SetProtocolExtra(protocolExtra); return item; } @@ -34,12 +37,17 @@ public class TrojanFmt : BaseFmt { return null; } + var protocolExtra = item.GetProtocolExtra(); var remark = string.Empty; if (item.Remarks.IsNotEmpty()) { remark = "#" + Utils.UrlEncode(item.Remarks); } var dicQuery = new Dictionary(); + if (!protocolExtra.Flow.IsNullOrEmpty()) + { + dicQuery.Add("flow", protocolExtra.Flow); + } ToUriQuery(item, null, ref dicQuery); return ToUri(EConfigType.Trojan, item.Address, item.Port, item.Password, dicQuery, remark); diff --git a/v2rayN/ServiceLib/Handler/Fmt/VLESSFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/VLESSFmt.cs index da6c5bd5..a48c3c05 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/VLESSFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/VLESSFmt.cs @@ -25,6 +25,7 @@ public class VLESSFmt : BaseFmt var query = Utils.ParseQueryString(url.Query); protocolExtra.VlessEncryption = GetQueryValue(query, "encryption", Global.None); + protocolExtra.Flow = GetQueryValue(query, "flow"); item.StreamSecurity = GetQueryValue(query, "security"); ResolveUriQuery(query, ref item); @@ -49,6 +50,10 @@ public class VLESSFmt : BaseFmt var dicQuery = new Dictionary(); dicQuery.Add("encryption", !protocolExtra.VlessEncryption.IsNullOrEmpty() ? protocolExtra.VlessEncryption : Global.None); + if (!protocolExtra.Flow.IsNullOrEmpty()) + { + dicQuery.Add("flow", protocolExtra.Flow); + } ToUriQuery(item, Global.None, ref dicQuery); return ToUri(EConfigType.VLESS, item.Address, item.Port, item.Password, dicQuery, remark); diff --git a/v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs b/v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs index b5718bf5..ee3cd5a0 100644 --- a/v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs +++ b/v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs @@ -1,5 +1,3 @@ -using ServiceLib.Common; - namespace ServiceLib.Manager; /// diff --git a/v2rayN/ServiceLib/Models/ProfileItem.cs b/v2rayN/ServiceLib/Models/ProfileItem.cs index 4142de93..847eab60 100644 --- a/v2rayN/ServiceLib/Models/ProfileItem.cs +++ b/v2rayN/ServiceLib/Models/ProfileItem.cs @@ -1,5 +1,3 @@ -using ServiceLib.Common; - namespace ServiceLib.Models; [Serializable] diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs index fbbb5191..ed49cb66 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs @@ -1,5 +1,3 @@ -using System.Linq; - namespace ServiceLib.Services.CoreConfig; public partial class CoreConfigSingboxService diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs index 8dfb4cc0..d5d18b3a 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs @@ -1,5 +1,3 @@ -using System.Linq; - namespace ServiceLib.Services.CoreConfig; public partial class CoreConfigV2rayService