From aa4d3f72af79fe115a1bff3e3876d80e8e9bb786 Mon Sep 17 00:00:00 2001 From: Alireza Date: Sat, 16 Mar 2024 18:11:13 +0100 Subject: [PATCH] Enhanced custom profile --- v2rayN/v2rayN/Handler/ConfigHandler.cs | 67 +++++++++++++++++++++++++- v2rayN/v2rayN/Model/V2rayConfig.cs | 7 +++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index 4d18e528..89cdcf3d 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -1176,8 +1176,60 @@ namespace v2rayN.Handler } return false; } - + ProfileItem profileItem = new(); + + //Is v2ray array configuration + var v2rayArrayConfig = JsonUtile.Deserialize(clipboardData); + if (v2rayArrayConfig != null && v2rayArrayConfig.Length > 0) + { + if (isSub && !Utile.IsNullOrEmpty(subid)) + { + RemoveServerViaSubid(config, subid, isSub); + } + profileItem = new(); + int count = 0; + foreach (var v2rayJson in v2rayArrayConfig) + { + if (v2rayJson?.inbounds?.Count > 0 && v2rayJson.outbounds?.Count > 0) + { + var fileName = Utile.GetTempPath($"{Utile.GetGUID(false)}.json"); + var v2rayConfigString = JsonUtile.Serialize(v2rayJson); + File.WriteAllText(fileName, v2rayConfigString); + + profileItem.coreType = ECoreType.Xray; + profileItem.address = fileName; + profileItem.remarks = Utile.IsNullOrEmpty(v2rayJson.remarks) ? "v2ray_custom" : v2rayJson.remarks; + + Outbounds4Ray firstOutbound = v2rayJson.outbounds[0]; + if (firstOutbound?.settings.servers?.Count > 0) { + profileItem.port = firstOutbound.settings.servers?[0].port ?? 0; + } else if (firstOutbound?.settings.vnext?.Count > 0) { + profileItem.port = firstOutbound.settings.vnext?[0].port ?? 0; + } + if (firstOutbound?.streamSettings != null) { + profileItem.network = firstOutbound.streamSettings.network; + profileItem.streamSecurity = firstOutbound.streamSettings.security; + } + + profileItem.indexId = count.ToString(); + profileItem.subid = subid; + profileItem.isSub = isSub; + + if (Utile.IsNullOrEmpty(profileItem.address)) + { + continue; + } + + if (AddCustomServer(config, profileItem, true) == 0) + { + count++; + } + } + } + return count; + } + //Is v2ray configuration var v2rayConfig = JsonUtile.Deserialize(clipboardData); if (v2rayConfig?.inbounds?.Count > 0 @@ -1188,7 +1240,18 @@ namespace v2rayN.Handler profileItem.coreType = ECoreType.Xray; profileItem.address = fileName; - profileItem.remarks = "v2ray_custom"; + profileItem.remarks = Utile.IsNullOrEmpty(v2rayConfig.remarks) ? "v2ray_custom" : v2rayConfig.remarks; + + Outbounds4Ray firstOutbound = v2rayConfig.outbounds[0]; + if (firstOutbound?.settings.servers?.Count > 0) { + profileItem.port = firstOutbound.settings.servers?[0].port ?? 0; + } else if (firstOutbound?.settings.vnext?.Count > 0) { + profileItem.port = firstOutbound.settings.vnext?[0].port ?? 0; + } + if (firstOutbound?.streamSettings != null) { + profileItem.network = firstOutbound.streamSettings.network; + profileItem.streamSecurity = firstOutbound.streamSettings.security; + } } //Is Clash configuration else if (Contains(clipboardData, "port", "socks-port", "proxies")) diff --git a/v2rayN/v2rayN/Model/V2rayConfig.cs b/v2rayN/v2rayN/Model/V2rayConfig.cs index a301efef..6fe71dc8 100644 --- a/v2rayN/v2rayN/Model/V2rayConfig.cs +++ b/v2rayN/v2rayN/Model/V2rayConfig.cs @@ -7,6 +7,11 @@ namespace v2rayN.Model /// public class V2rayConfig { + /// + /// Remarks + /// + public String remarks { get; set; } + /// /// 日志配置 /// @@ -397,6 +402,8 @@ namespace v2rayN.Model public List domain { get; set; } public List protocol { get; set; } + + public string network { get; set; } } public class StreamSettings4Ray