From 8fc430d124d4b85183448c45837d0ca851e5c66b Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Thu, 5 Jan 2023 19:05:16 +0800 Subject: [PATCH] add tun mode custom config template --- v2rayN/v2rayN/Handler/StatisticsHandler.cs | 2 +- v2rayN/v2rayN/Handler/TunHandler.cs | 9 +++++ v2rayN/v2rayN/Mode/ConfigItems.cs | 1 + v2rayN/v2rayN/Resx/ResUI.Designer.cs | 9 +++++ v2rayN/v2rayN/Resx/ResUI.resx | 3 ++ v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx | 3 ++ v2rayN/v2rayN/Tool/Utils.cs | 14 ++++---- .../ViewModels/OptionSettingViewModel.cs | 3 ++ v2rayN/v2rayN/Views/MainWindow.xaml.cs | 2 +- v2rayN/v2rayN/Views/OptionSettingWindow.xaml | 33 +++++++++++++++++-- .../v2rayN/Views/OptionSettingWindow.xaml.cs | 8 +++++ 11 files changed, 76 insertions(+), 11 deletions(-) diff --git a/v2rayN/v2rayN/Handler/StatisticsHandler.cs b/v2rayN/v2rayN/Handler/StatisticsHandler.cs index c6c61c8d..3928aa3d 100644 --- a/v2rayN/v2rayN/Handler/StatisticsHandler.cs +++ b/v2rayN/v2rayN/Handler/StatisticsHandler.cs @@ -150,7 +150,7 @@ namespace v2rayN.Handler if (_serverStatItem == null) { - _serverStatItem = _lstServerStat.FirstOrDefault(t => t.indexId == indexId); + _serverStatItem = _lstServerStat.FirstOrDefault(t => t.indexId == indexId); if (_serverStatItem == null) { _serverStatItem = new ServerStatItem diff --git a/v2rayN/v2rayN/Handler/TunHandler.cs b/v2rayN/v2rayN/Handler/TunHandler.cs index de73894f..2f0746fa 100644 --- a/v2rayN/v2rayN/Handler/TunHandler.cs +++ b/v2rayN/v2rayN/Handler/TunHandler.cs @@ -72,7 +72,16 @@ namespace v2rayN.Base private bool Init() { coreInfo = LazyConfig.Instance.GetCoreInfo(ECoreType.sing_box); + //Template string configStr = Utils.GetEmbedText(Global.TunSingboxFileName); + if (!Utils.IsNullOrEmpty(_config.tunModeItem.customTemplate) && File.Exists(_config.tunModeItem.customTemplate)) + { + var customTemplate = File.ReadAllText(_config.tunModeItem.customTemplate); + if (!Utils.IsNullOrEmpty(customTemplate)) + { + configStr = customTemplate; + } + } if (Utils.IsNullOrEmpty(configStr)) { return false; diff --git a/v2rayN/v2rayN/Mode/ConfigItems.cs b/v2rayN/v2rayN/Mode/ConfigItems.cs index 35da19c2..62b53974 100644 --- a/v2rayN/v2rayN/Mode/ConfigItems.cs +++ b/v2rayN/v2rayN/Mode/ConfigItems.cs @@ -102,6 +102,7 @@ namespace v2rayN.Mode public bool strictRoute { get; set; } public string stack { get; set; } public int mtu { get; set; } + public string customTemplate { get; set; } public List directIP { get; set; } public List directProcess { get; set; } diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index d37516f9..d0c00c01 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -2644,6 +2644,15 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 Custom Template 的本地化字符串。 + /// + public static string TbSettingsTunModeCustomTemplate { + get { + return ResourceManager.GetString("TbSettingsTunModeCustomTemplate", resourceCulture); + } + } + /// /// 查找类似 Direct IP CIDR, separated by commas (,) 的本地化字符串。 /// diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index d1158a43..2df7f7c8 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -1063,4 +1063,7 @@ Move to group + + Custom Template + \ 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 6caf0c56..fa1ae295 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -1063,4 +1063,7 @@ 移至订阅分组 + + 自定义配置模板 + \ No newline at end of file diff --git a/v2rayN/v2rayN/Tool/Utils.cs b/v2rayN/v2rayN/Tool/Utils.cs index b5824ea0..d72b0126 100644 --- a/v2rayN/v2rayN/Tool/Utils.cs +++ b/v2rayN/v2rayN/Tool/Utils.cs @@ -752,14 +752,14 @@ namespace v2rayN return false; } } - + /// - /// Auto Start via TaskService - /// - /// - /// - /// - /// + /// Auto Start via TaskService + /// + /// + /// + /// + /// public static void AutoStart(string taskName, string fileName, string description) { if (string.IsNullOrEmpty(taskName)) diff --git a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs index 7c84cd01..c1a4968b 100644 --- a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs @@ -70,6 +70,7 @@ namespace v2rayN.ViewModels [Reactive] public bool TunStrictRoute { get; set; } [Reactive] public string TunStack { get; set; } [Reactive] public int TunMtu { get; set; } + [Reactive] public string TunCustomTemplate { get; set; } [Reactive] public string TunDirectIP { get; set; } [Reactive] public string TunDirectProcess { get; set; } #endregion @@ -150,6 +151,7 @@ namespace v2rayN.ViewModels TunStrictRoute = _config.tunModeItem.strictRoute; TunStack = _config.tunModeItem.stack; TunMtu = _config.tunModeItem.mtu; + TunCustomTemplate = _config.tunModeItem.customTemplate; TunDirectIP = Utils.List2String(_config.tunModeItem.directIP, true); TunDirectProcess = Utils.List2String(_config.tunModeItem.directProcess, true); @@ -308,6 +310,7 @@ namespace v2rayN.ViewModels _config.tunModeItem.strictRoute = TunStrictRoute; _config.tunModeItem.stack = TunStack; _config.tunModeItem.mtu = TunMtu; + _config.tunModeItem.customTemplate = TunCustomTemplate; _config.tunModeItem.directIP = Utils.String2List(TunDirectIP); _config.tunModeItem.directProcess = Utils.String2List(TunDirectProcess); diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index 4c738297..ff0573a1 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -529,7 +529,7 @@ namespace v2rayN.Views // (this will be automatically reflected to lstView.ItemsSource) e.Effects = DragDropEffects.Move; - ViewModel?.MoveServerTo(startIndex, item); + ViewModel?.MoveServerTo(startIndex, item); startIndex = -1; } diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml index 4640afb5..a35d5c8e 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml @@ -646,6 +646,7 @@ + + Margin="{StaticResource SettingItemMargin}" + HorizontalAlignment="Left" /> + Margin="{StaticResource SettingItemMargin}" + HorizontalAlignment="Left" /> + + + +