From 8b49b22d92169a9c507c9bfde5ec9180ce419828 Mon Sep 17 00:00:00 2001 From: Muhammad Date: Sat, 1 Jun 2024 20:30:44 +0330 Subject: [PATCH] show custom config variables properly in config table --- v2rayN/v2rayN/Handler/ConfigHandler.cs | 24 ++++++++++++++++++++---- v2rayN/v2rayN/Models/ProfileItem.cs | 6 ++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index cd1819e0..0526f95e 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -563,7 +563,7 @@ namespace v2rayN.Handler /// public static int AddCustomServer(Config config, ProfileItem profileItem, bool blDelete) { - var fileName = profileItem.address; + var fileName = profileItem.jsonFileAddress; if (!File.Exists(fileName)) { return -1; @@ -586,7 +586,8 @@ namespace v2rayN.Handler return -1; } - profileItem.address = newFileName; + profileItem.address = profileItem.address.TrimEx(); + profileItem.jsonFileAddress = newFileName; profileItem.configType = EConfigType.Custom; if (Utils.IsNullOrEmpty(profileItem.remarks)) { @@ -1207,7 +1208,7 @@ namespace v2rayN.Handler { var objectString = JsonUtils.Serialize(configObject); var v2rayCon = JsonUtils.Deserialize(objectString); - if (v2rayCon?.inbounds?.Count > 0 && v2rayCon.outbounds?.Count > 0) + if (v2rayCon?.inbounds.Count > 0 && v2rayCon.outbounds.Count > 0) { var fileName = Utils.GetTempPath($"{Utils.GetGUID(false)}.json"); File.WriteAllText(fileName, objectString); @@ -1215,7 +1216,10 @@ namespace v2rayN.Handler var profileIt = new ProfileItem { coreType = ECoreType.Xray, - address = fileName, + jsonFileAddress = fileName, + address = GetCustomConfigAddress(v2rayCon) ?? "", + port = GetCustomConfigPort(v2rayCon) ?? 0, + network = v2rayCon.outbounds.FirstOrDefault()?.streamSettings.network ?? "", remarks = v2rayCon.remarks ?? "v2ray_custom", subid = subid, isSub = isSub @@ -1313,6 +1317,18 @@ namespace v2rayN.Handler } } + private static string? GetCustomConfigAddress(V2rayConfig v2RayConfig) + { + var outboundSettings = v2RayConfig.outbounds.FirstOrDefault()?.settings; + return outboundSettings?.vnext != null ? outboundSettings.vnext.FirstOrDefault()?.address : outboundSettings?.servers.FirstOrDefault()?.address; + } + + private static int? GetCustomConfigPort(V2rayConfig v2RayConfig) + { + var outboundSettings = v2RayConfig.outbounds.FirstOrDefault()?.settings; + return outboundSettings?.vnext != null ? outboundSettings.vnext.FirstOrDefault()?.port : outboundSettings?.servers.FirstOrDefault()?.port; + } + private static int AddBatchServers4SsSIP008(Config config, string clipboardData, string subid, bool isSub, List lstOriSub) { if (Utils.IsNullOrEmpty(clipboardData)) diff --git a/v2rayN/v2rayN/Models/ProfileItem.cs b/v2rayN/v2rayN/Models/ProfileItem.cs index 9118abff..7ec1f805 100644 --- a/v2rayN/v2rayN/Models/ProfileItem.cs +++ b/v2rayN/v2rayN/Models/ProfileItem.cs @@ -11,6 +11,7 @@ namespace v2rayN.Models configType = EConfigType.VMess; configVersion = 2; address = string.Empty; + jsonFileAddress = null; port = 0; id = string.Empty; alterId = 0; @@ -98,6 +99,11 @@ namespace v2rayN.Models /// 远程服务器地址 /// public string address { get; set; } + + /// + /// 远程服务器地址 + /// + public string? jsonFileAddress { get; set; } /// /// 远程服务器端口