From 0d5a9fcf4a0032500be76b7da7b83ee5961a45b0 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 23 Dec 2023 20:57:31 +0800 Subject: [PATCH 01/62] Previous and next proxy --- v2rayN/v2rayN/Handler/CoreConfigSingbox.cs | 4 +- v2rayN/v2rayN/Handler/CoreConfigV2ray.cs | 62 +++++++++++++++++++++- v2rayN/v2rayN/Handler/LazyConfig.cs | 9 ++++ v2rayN/v2rayN/Mode/SubItem.cs | 4 ++ 4 files changed, 76 insertions(+), 3 deletions(-) diff --git a/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs b/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs index d1e73c4e..c3607e87 100644 --- a/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs +++ b/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs @@ -45,7 +45,7 @@ namespace v2rayN.Handler GenInbounds(singboxConfig); - GenOutbounds(node, singboxConfig); + GenOutbound(node, singboxConfig); GenRouting(singboxConfig); @@ -202,7 +202,7 @@ namespace v2rayN.Handler #region outbound private - private int GenOutbounds(ProfileItem node, SingboxConfig singboxConfig) + private int GenOutbound(ProfileItem node, SingboxConfig singboxConfig) { try { diff --git a/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs b/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs index b592239a..1123cdcc 100644 --- a/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs +++ b/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs @@ -53,6 +53,8 @@ namespace v2rayN.Handler GenOutbound(node, v2rayConfig.outbounds[0]); + GenMoreOutbounds(node, v2rayConfig); + GenDns(v2rayConfig); GenStatistic(v2rayConfig); @@ -820,6 +822,64 @@ namespace v2rayN.Handler return 0; } + private int GenMoreOutbounds(ProfileItem node, V2rayConfig v2rayConfig) + { + if (node.subid.IsNullOrEmpty()) + { + return 0; + } + try + { + var subItem = LazyConfig.Instance.GetSubItem(node.subid); + if (subItem is null) + { + return 0; + } + + //current proxy + var outbound = v2rayConfig.outbounds[0]; + + //Previous proxy + var prevNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.prevProfile!); + if (prevNode is not null) + { + var txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound); + var prevOutbound = Utils.FromJson(txtOutbound); + GenOutbound(prevNode, prevOutbound); + prevOutbound.tag = $"{Global.ProxyTag}2"; + v2rayConfig.outbounds.Add(prevOutbound); + + outbound.streamSettings.sockopt = new() + { + dialerProxy = prevOutbound.tag + }; + } + + //Next proxy + var nextNode = LazyConfig.Instance.GetProfileItemViaRemarks(subItem.nextProfile!); + if (nextNode is not null) + { + var txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound); + var nextOutbound = Utils.FromJson(txtOutbound); + GenOutbound(nextNode, nextOutbound); + nextOutbound.tag = Global.ProxyTag; + v2rayConfig.outbounds.Insert(0, nextOutbound); + + outbound.tag = $"{Global.ProxyTag}1"; + nextOutbound.streamSettings.sockopt = new() + { + dialerProxy = outbound.tag + }; + } + } + catch (Exception ex) + { + Utils.SaveLog(ex.Message, ex); + } + + return 0; + } + #region Gen speedtest config public string GenerateClientSpeedtestConfigString(List selecteds, out string msg) @@ -833,7 +893,7 @@ namespace v2rayN.Handler } msg = ResUI.InitialConfiguration; - + string result = Utils.GetEmbedText(Global.V2raySampleClient); string txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound); if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty()) diff --git a/v2rayN/v2rayN/Handler/LazyConfig.cs b/v2rayN/v2rayN/Handler/LazyConfig.cs index b9f259de..6a98f916 100644 --- a/v2rayN/v2rayN/Handler/LazyConfig.cs +++ b/v2rayN/v2rayN/Handler/LazyConfig.cs @@ -130,6 +130,15 @@ namespace v2rayN.Handler return SqliteHelper.Instance.Table().FirstOrDefault(it => it.indexId == indexId); } + public ProfileItem? GetProfileItemViaRemarks(string remarks) + { + if (Utils.IsNullOrEmpty(remarks)) + { + return null; + } + return SqliteHelper.Instance.Table().FirstOrDefault(it => it.remarks == remarks); + } + public List RoutingItems() { return SqliteHelper.Instance.Table().Where(it => it.locked == false).OrderBy(t => t.sort).ToList(); diff --git a/v2rayN/v2rayN/Mode/SubItem.cs b/v2rayN/v2rayN/Mode/SubItem.cs index 3221e914..c3fe2c21 100644 --- a/v2rayN/v2rayN/Mode/SubItem.cs +++ b/v2rayN/v2rayN/Mode/SubItem.cs @@ -27,5 +27,9 @@ namespace v2rayN.Mode public long updateTime { get; set; } public string? convertTarget { get; set; } + + public string? prevProfile { get; set; } + + public string? nextProfile { get; set; } } } \ No newline at end of file From 51576b54c3dc8eae969837433ce4f2e26388db1c Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 24 Dec 2023 10:34:55 +0800 Subject: [PATCH 02/62] Previous and next proxy setting --- v2rayN/v2rayN/App.xaml | 16 ++- v2rayN/v2rayN/Resx/ResUI.Designer.cs | 27 +++++ v2rayN/v2rayN/Resx/ResUI.resx | 9 ++ v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx | 9 ++ v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx | 9 ++ v2rayN/v2rayN/ViewModels/SubEditViewModel.cs | 2 + v2rayN/v2rayN/Views/AddServer2Window.xaml | 13 ++- v2rayN/v2rayN/Views/SubEditWindow.xaml | 104 ++++++++++++------- v2rayN/v2rayN/Views/SubEditWindow.xaml.cs | 2 + 9 files changed, 148 insertions(+), 43 deletions(-) diff --git a/v2rayN/v2rayN/App.xaml b/v2rayN/v2rayN/App.xaml index 3fc23de2..791d89da 100644 --- a/v2rayN/v2rayN/App.xaml +++ b/v2rayN/v2rayN/App.xaml @@ -1,9 +1,9 @@  @@ -34,6 +34,12 @@ Left="8" Right="8" Top="8" /> + + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index ef2bb980..4d7adae7 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -447,6 +447,15 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 Next proxy remarks 的本地化字符串。 + /// + public static string LvNextProfile { + get { + return ResourceManager.GetString("LvNextProfile", resourceCulture); + } + } + /// /// 查找类似 Port 的本地化字符串。 /// @@ -456,6 +465,24 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 Previous proxy remakrs 的本地化字符串。 + /// + public static string LvPrevProfile { + get { + return ResourceManager.GetString("LvPrevProfile", resourceCulture); + } + } + + /// + /// 查找类似 Please make sure the remarks exists and is unique 的本地化字符串。 + /// + public static string LvPrevProfileTip { + get { + return ResourceManager.GetString("LvPrevProfileTip", resourceCulture); + } + } + /// /// 查找类似 Remarks 的本地化字符串。 /// diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index b99e2368..0756f3f5 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -1153,4 +1153,13 @@ Congestion control + + Previous proxy remakrs + + + Next proxy remarks + + + Please make sure the remarks exists and is unique + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx index 0432350d..25a7e3f0 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -1150,4 +1150,13 @@ 拥塞控制算法 + + 前置代理别名 + + + 落地代理別名 + + + 请确保别名存在并唯一 + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx index 06120c4f..f68bd3f0 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx @@ -1138,4 +1138,13 @@ 新增[Tuic]伺服器 + + 前置代理別名 + + + 落地代理別名 + + + 請確保別名存在並且唯一 + \ No newline at end of file diff --git a/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs b/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs index dcc30d50..d15e9a78 100644 --- a/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/SubEditViewModel.cs @@ -69,6 +69,8 @@ namespace v2rayN.ViewModels item.sort = SelectedSource.sort; item.filter = SelectedSource.filter; item.convertTarget = SelectedSource.convertTarget; + item.prevProfile = SelectedSource.prevProfile; + item.nextProfile = SelectedSource.nextProfile; } if (ConfigHandler.AddSubItem(_config, item) == 0) diff --git a/v2rayN/v2rayN/Views/AddServer2Window.xaml b/v2rayN/v2rayN/Views/AddServer2Window.xaml index 9ef69639..20dc079d 100644 --- a/v2rayN/v2rayN/Views/AddServer2Window.xaml +++ b/v2rayN/v2rayN/Views/AddServer2Window.xaml @@ -97,17 +97,17 @@ Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" - Orientation="Vertical"> + Orientation="Horizontal">