From 0f8d86f081c1ac72ed1cee0e997ba1375c8b506b Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 19 Feb 2023 11:23:45 +0800 Subject: [PATCH 1/2] Refactoring sorting and delayed storage --- v2rayN/v2rayN/Handler/ProfileExHandler.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/v2rayN/v2rayN/Handler/ProfileExHandler.cs b/v2rayN/v2rayN/Handler/ProfileExHandler.cs index 4d7b15c8..74957b04 100644 --- a/v2rayN/v2rayN/Handler/ProfileExHandler.cs +++ b/v2rayN/v2rayN/Handler/ProfileExHandler.cs @@ -32,7 +32,7 @@ namespace v2rayN.Handler sort = 0 }; _lstProfileEx.Add(profileEx); - SqliteHelper.Instance.Replace(profileEx); + //SqliteHelper.Instance.Replace(profileEx); } public void ClearAll() @@ -45,7 +45,11 @@ namespace v2rayN.Handler { try { - SqliteHelper.Instance.UpdateAll(_lstProfileEx); + foreach (var item in _lstProfileEx) + { + SqliteHelper.Instance.Replace(item); + } + //SqliteHelper.Instance.UpdateAll(_lstProfileEx); } catch (Exception ex) { From 653af71596ae98ada905356afb962f65c3dcfe05 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 19 Feb 2023 14:55:44 +0800 Subject: [PATCH 2/2] Add log switch in tun mode --- v2rayN/v2rayN/Handler/ShareHandler.cs | 4 +- v2rayN/v2rayN/Handler/TunHandler.cs | 50 ++++++++++++++++++- v2rayN/v2rayN/Mode/ConfigItems.cs | 1 + v2rayN/v2rayN/Resx/ResUI.Designer.cs | 4 +- v2rayN/v2rayN/Resx/ResUI.resx | 2 +- v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx | 2 +- v2rayN/v2rayN/Sample/tun_singbox | 2 +- v2rayN/v2rayN/Tool/FileManager.cs | 2 +- .../ViewModels/OptionSettingViewModel.cs | 3 ++ v2rayN/v2rayN/Views/OptionSettingWindow.xaml | 16 +++++- .../v2rayN/Views/OptionSettingWindow.xaml.cs | 1 + 11 files changed, 76 insertions(+), 11 deletions(-) diff --git a/v2rayN/v2rayN/Handler/ShareHandler.cs b/v2rayN/v2rayN/Handler/ShareHandler.cs index ed93607b..13b162bc 100644 --- a/v2rayN/v2rayN/Handler/ShareHandler.cs +++ b/v2rayN/v2rayN/Handler/ShareHandler.cs @@ -32,7 +32,7 @@ namespace v2rayN.Handler EConfigType.VLESS => ShareVLESS(item), _ => null, }; - + return url; } catch (Exception ex) @@ -274,7 +274,7 @@ namespace v2rayN.Handler { msg = string.Empty; ProfileItem profileItem = new ProfileItem(); - + try { //载入配置文件 diff --git a/v2rayN/v2rayN/Handler/TunHandler.cs b/v2rayN/v2rayN/Handler/TunHandler.cs index ef0e99ff..91340244 100644 --- a/v2rayN/v2rayN/Handler/TunHandler.cs +++ b/v2rayN/v2rayN/Handler/TunHandler.cs @@ -3,6 +3,7 @@ using System.IO; using System.Reactive.Linq; using v2rayN.Handler; using v2rayN.Mode; +using v2rayN.Resx; namespace v2rayN.Base { @@ -60,6 +61,7 @@ namespace v2rayN.Base { return; } + CoreStartTest(); CoreStart(); } } @@ -101,6 +103,7 @@ namespace v2rayN.Base configStr = configStr.Replace("$stack$", $"{_config.tunModeItem.stack}"); //logs + configStr = configStr.Replace("$log_disabled$", $"aaa{(!_config.tunModeItem.enabledLog).ToString().ToLower()}"); if (_config.tunModeItem.showWindow) { configStr = configStr.Replace("$log_output$", $""); @@ -225,7 +228,8 @@ namespace v2rayN.Base } if (Utils.IsNullOrEmpty(fileName)) { - + string msg = string.Format(ResUI.NotFoundCore, Utils.GetBinPath("", coreInfo.coreType), string.Join(", ", coreInfo.coreExes.ToArray()), coreInfo.coreUrl); + Utils.SaveLog(msg); } return fileName; } @@ -235,7 +239,7 @@ namespace v2rayN.Base try { string fileName = CoreFindexe(); - if (fileName == "") + if (Utils.IsNullOrEmpty(fileName)) { return; } @@ -293,5 +297,47 @@ namespace v2rayN.Base Utils.SaveLog(ex.Message, ex); } } + + private int CoreStartTest() + { + Utils.SaveLog("Tun mode configuration file test start"); + try + { + string fileName = CoreFindexe(); + if (fileName == "") + { + return -1; + } + Process p = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = fileName, + Arguments = $"run -c \"{Utils.GetConfigPath(_tunConfigName)}\"", + WorkingDirectory = Utils.GetConfigPath(), + UseShellExecute = false, + CreateNoWindow = true, + RedirectStandardError = true, + Verb = "runas", + } + }; + p.Start(); + if (p.WaitForExit(2000)) + { + throw new Exception(p.StandardError.ReadToEnd()); + } + KillProcess(p); + return 0; + } + catch (Exception ex) + { + Utils.SaveLog(ex.Message, ex); + return -1; + } + finally + { + Utils.SaveLog("Tun mode configuration file test end"); + } + } } } \ No newline at end of file diff --git a/v2rayN/v2rayN/Mode/ConfigItems.cs b/v2rayN/v2rayN/Mode/ConfigItems.cs index e2620071..4deb94c8 100644 --- a/v2rayN/v2rayN/Mode/ConfigItems.cs +++ b/v2rayN/v2rayN/Mode/ConfigItems.cs @@ -160,6 +160,7 @@ namespace v2rayN.Mode { public bool enableTun { get; set; } public bool showWindow { get; set; } + public bool enabledLog { get; set; } public bool strictRoute { get; set; } public string stack { get; set; } public int mtu { get; set; } diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index b951e8e2..9e089f77 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -2564,7 +2564,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Record local logs 的本地化字符串。 + /// 查找类似 Enable Log 的本地化字符串。 /// public static string TbSettingsLogEnabled { get { @@ -3068,7 +3068,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 *QUIC securty 的本地化字符串。 + /// 查找类似 *QUIC security 的本地化字符串。 /// public static string TransportRequestHostTip4 { get { diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index f5053547..55f3ea6e 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -815,7 +815,7 @@ Keep older when deduplication - Record local logs + Enable Log Log Level diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx index e06c5ed2..e2ec6f2b 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -815,7 +815,7 @@ 去重时保留序号较小的项 - 记录本地日志(默认关闭) + 启用日志(默认关闭) 日志等级 diff --git a/v2rayN/v2rayN/Sample/tun_singbox b/v2rayN/v2rayN/Sample/tun_singbox index 6278c0b4..128a058a 100644 --- a/v2rayN/v2rayN/Sample/tun_singbox +++ b/v2rayN/v2rayN/Sample/tun_singbox @@ -1,6 +1,6 @@ { "log": { - "disabled": false, + "disabled": $log_disabled$, "level": "debug", $log_output$ "timestamp": true diff --git a/v2rayN/v2rayN/Tool/FileManager.cs b/v2rayN/v2rayN/Tool/FileManager.cs index aed9f060..c87f88da 100644 --- a/v2rayN/v2rayN/Tool/FileManager.cs +++ b/v2rayN/v2rayN/Tool/FileManager.cs @@ -19,7 +19,7 @@ namespace v2rayN.Tool } return false; } - + public static void UncompressFile(string fileName, byte[] content) { try diff --git a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs index 34ec6053..6aeef8f2 100644 --- a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs @@ -75,6 +75,7 @@ namespace v2rayN.ViewModels #region Tun mode [Reactive] public bool TunShowWindow { get; set; } + [Reactive] public bool TunEnabledLog { get; set; } [Reactive] public bool TunStrictRoute { get; set; } [Reactive] public string TunStack { get; set; } [Reactive] public int TunMtu { get; set; } @@ -168,6 +169,7 @@ namespace v2rayN.ViewModels #region Tun mode TunShowWindow = _config.tunModeItem.showWindow; + TunEnabledLog = _config.tunModeItem.enabledLog; TunStrictRoute = _config.tunModeItem.strictRoute; TunStack = _config.tunModeItem.stack; TunMtu = _config.tunModeItem.mtu; @@ -340,6 +342,7 @@ namespace v2rayN.ViewModels //tun mode _config.tunModeItem.showWindow = TunShowWindow; + _config.tunModeItem.enabledLog = TunEnabledLog; _config.tunModeItem.strictRoute = TunStrictRoute; _config.tunModeItem.stack = TunStack; _config.tunModeItem.mtu = TunMtu; diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml index 9317d418..a355244e 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml @@ -816,7 +816,7 @@ + + + vm.TunShowWindow, v => v.togShowWindow.IsChecked).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.TunEnabledLog, v => v.togEnabledLog.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.TunStrictRoute, v => v.togStrictRoute.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.TunStack, v => v.cmbStack.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.TunMtu, v => v.cmbMtu.Text).DisposeWith(disposables);