From d189f4b44378a6818234260aafde65bece87817f Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 30 Aug 2024 10:12:40 +0800 Subject: [PATCH] Add custom config Socks port to the group https://github.com/2dust/v2rayN/issues/5576 --- v2rayN/ServiceLib/Handler/ConfigHandler.cs | 8 +++++++- v2rayN/ServiceLib/Handler/CoreHandler.cs | 2 +- v2rayN/ServiceLib/Models/ProfileItem.cs | 2 +- v2rayN/ServiceLib/Models/SubItem.cs | 2 ++ v2rayN/ServiceLib/Resx/ResUI.Designer.cs | 11 ++++++++++- v2rayN/ServiceLib/Resx/ResUI.resx | 5 ++++- v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx | 3 +++ v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx | 3 +++ v2rayN/v2rayN/Views/SubEditWindow.xaml | 19 +++++++++++++++++++ v2rayN/v2rayN/Views/SubEditWindow.xaml.cs | 1 + 10 files changed, 51 insertions(+), 5 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index 5b289ee4..8d2bfe6d 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -1282,7 +1282,10 @@ namespace ServiceLib.Handler { return -1; } - var subRemarks = LazyConfig.Instance.GetSubItem(subid)?.remarks; + + var subItem = LazyConfig.Instance.GetSubItem(subid); + var subRemarks = subItem?.remarks; + var preSocksPort = subItem?.preSocksPort; List? lstProfiles = null; //Is sing-box array configuration @@ -1306,6 +1309,7 @@ namespace ServiceLib.Handler { it.subid = subid; it.isSub = isSub; + it.preSocksPort = preSocksPort; if (AddCustomServer(config, it, true) == 0) { count++; @@ -1362,6 +1366,7 @@ namespace ServiceLib.Handler } profileItem.subid = subid; profileItem.isSub = isSub; + profileItem.preSocksPort = preSocksPort; if (AddCustomServer(config, profileItem, true) == 0) { return 1; @@ -1501,6 +1506,7 @@ namespace ServiceLib.Handler item.convertTarget = subItem.convertTarget; item.prevProfile = subItem.prevProfile; item.nextProfile = subItem.nextProfile; + item.preSocksPort = subItem.preSocksPort; } if (Utils.IsNullOrEmpty(item.id)) diff --git a/v2rayN/ServiceLib/Handler/CoreHandler.cs b/v2rayN/ServiceLib/Handler/CoreHandler.cs index 78185563..bb97d375 100644 --- a/v2rayN/ServiceLib/Handler/CoreHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreHandler.cs @@ -218,7 +218,7 @@ namespace ServiceLib.Handler coreType = preCoreType, configType = EConfigType.Socks, address = Global.Loopback, - port = node.preSocksPort + port = node.preSocksPort.Value, }; _config.runningCoreType = preCoreType; } diff --git a/v2rayN/ServiceLib/Models/ProfileItem.cs b/v2rayN/ServiceLib/Models/ProfileItem.cs index 8c9092c6..0e9a1a24 100644 --- a/v2rayN/ServiceLib/Models/ProfileItem.cs +++ b/v2rayN/ServiceLib/Models/ProfileItem.cs @@ -178,7 +178,7 @@ namespace ServiceLib.Models public ECoreType? coreType { get; set; } - public int preSocksPort { get; set; } + public int? preSocksPort { get; set; } public string fingerprint { get; set; } diff --git a/v2rayN/ServiceLib/Models/SubItem.cs b/v2rayN/ServiceLib/Models/SubItem.cs index 5c361d93..4eb894b8 100644 --- a/v2rayN/ServiceLib/Models/SubItem.cs +++ b/v2rayN/ServiceLib/Models/SubItem.cs @@ -31,5 +31,7 @@ namespace ServiceLib.Models public string? prevProfile { get; set; } public string? nextProfile { get; set; } + + public int? preSocksPort { get; set; } } } \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index 778d30e9..25f52f6b 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -2330,7 +2330,7 @@ namespace ServiceLib.Resx { } /// - /// 查找类似 txtPreSocksPort 的本地化字符串。 + /// 查找类似 Socks port 的本地化字符串。 /// public static string TbPreSocksPort { get { @@ -2338,6 +2338,15 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 Custom config socks port 的本地化字符串。 + /// + public static string TbPreSocksPort4Sub { + get { + return ResourceManager.GetString("TbPreSocksPort4Sub", resourceCulture); + } + } + /// /// 查找类似 PrivateKey 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index 4b7150e4..e40c318f 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -668,7 +668,7 @@ Encryption - txtPreSocksPort + Socks port * After setting this value, an socks service will be started using Xray/sing-box(Tun) to provide functions such as speed display @@ -1276,4 +1276,7 @@ You are currently running a standalone package, please manually download the SelfContained.7z file to unzip and overwrite it! + + Custom config socks port + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index 97408e05..c0e9deb9 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -1273,4 +1273,7 @@ 您当前运行的是独立包,请手动下载 SelfContained.7z文件解压覆盖 + + 自定义配置的Socks端口 + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index 9b174a9f..67679f3d 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -1153,4 +1153,7 @@ 您目前運行的是獨立包,請手動下載 SelfContained.7z檔案解壓縮覆蓋 + + 自訂配置的Socks端口 + \ No newline at end of file diff --git a/v2rayN/v2rayN/Views/SubEditWindow.xaml b/v2rayN/v2rayN/Views/SubEditWindow.xaml index bd76691c..de7e0162 100644 --- a/v2rayN/v2rayN/Views/SubEditWindow.xaml +++ b/v2rayN/v2rayN/Views/SubEditWindow.xaml @@ -69,6 +69,7 @@ + @@ -281,6 +282,24 @@ materialDesign:HintAssist.Hint="{x:Static resx:ResUI.LvPrevProfileTip}" AcceptsReturn="True" Style="{StaticResource MyOutlinedTextBox}" /> + + + diff --git a/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs b/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs index ae27980b..1773ee57 100644 --- a/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs @@ -33,6 +33,7 @@ namespace v2rayN.Views this.Bind(ViewModel, vm => vm.SelectedSource.convertTarget, v => v.cmbConvertTarget.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.prevProfile, v => v.txtPrevProfile.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.nextProfile, v => v.txtNextProfile.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.SelectedSource.preSocksPort, v => v.txtPreSocksPort.Text).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); });