From 0e9464022a6f5f908227f6129d3972c05a14f19e Mon Sep 17 00:00:00 2001 From: rexmyl Date: Fri, 2 Jun 2023 02:47:50 +0800 Subject: [PATCH] quickselect --- v2rayN/v2rayN/Handler/QuickSelectHandler.cs | 72 ++++++++++ v2rayN/v2rayN/Handler/SpeedtestHandler.cs | 24 ++++ v2rayN/v2rayN/Mode/ESpeedActionType.cs | 5 + v2rayN/v2rayN/Mode/SelectItem.cs | 81 +++++++++++ v2rayN/v2rayN/Resx/ResUI.Designer.cs | 12 ++ v2rayN/v2rayN/Resx/ResUI.fa-Ir.resx | 11 ++ v2rayN/v2rayN/Resx/ResUI.resx | 6 + v2rayN/v2rayN/Resx/ResUI.ru.resx | 9 ++ v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx | 9 ++ .../v2rayN/ViewModels/MainWindowViewModel.cs | 136 ++++++++++++++++++ v2rayN/v2rayN/Views/MainWindow.xaml | 20 +++ v2rayN/v2rayN/Views/MainWindow.xaml.cs | 12 ++ 12 files changed, 397 insertions(+) create mode 100644 v2rayN/v2rayN/Handler/QuickSelectHandler.cs create mode 100644 v2rayN/v2rayN/Mode/SelectItem.cs diff --git a/v2rayN/v2rayN/Handler/QuickSelectHandler.cs b/v2rayN/v2rayN/Handler/QuickSelectHandler.cs new file mode 100644 index 00000000..f186f5e7 --- /dev/null +++ b/v2rayN/v2rayN/Handler/QuickSelectHandler.cs @@ -0,0 +1,72 @@ +using System; +using v2rayN.Mode; + +namespace v2rayN.Handler +{ + internal class QuickSelectHandler + { + public List Items { get; } + public List validItems { get; set; } + public QuickSelectHandler() + { + Items = new List(); + validItems = new List(); + } + public bool selectContent; + + public void add(string indexid) + { + Items.Add(new SelectItem(indexid)); + } + public void itemAdd(string indexid,string delay) + { + var item = Items.Find(it=>it.indexId == indexid); + if (item == null) + { + var additem = new SelectItem(indexid); + Items.Add(additem); + additem.push(delay); + } + else + { + item.push(delay); + } + } + public List select() + { + List invaliditems = new List(); + var itv0 = Items.FindAll(it => it.E == -1); + var itv2or3 = Items.FindAll(it => it.ValidValue == 2 || it.ValidValue == 3); + var itv1 = Items.FindAll(it => it.ValidValue == 1); + validItems.AddRange(itv2or3); + foreach(var i in itv0) + { + invaliditems.Add(i.indexId); + } + if (itv2or3.Any()) + { + selectContent = true; + foreach (var i in itv1) + { + invaliditems.Add(i.indexId); + } + } + else + { + selectContent = false; + validItems.AddRange(itv1.FindAll(it => !it.getDelay(2).Trim().Equals("-1"))); + foreach (var i in itv1.FindAll(it => it.getDelay(2).Trim().Equals("-1"))) + { + invaliditems.Add(i.indexId); + } + } + return invaliditems; + } + + public void clear() + { + Items.Clear(); + validItems.Clear(); + } + } +} diff --git a/v2rayN/v2rayN/Handler/SpeedtestHandler.cs b/v2rayN/v2rayN/Handler/SpeedtestHandler.cs index bb1d3b66..2a4f02f0 100644 --- a/v2rayN/v2rayN/Handler/SpeedtestHandler.cs +++ b/v2rayN/v2rayN/Handler/SpeedtestHandler.cs @@ -68,6 +68,13 @@ namespace v2rayN.Handler ProfileExHandler.Instance.SetTestDelay(it.indexId, "0"); ProfileExHandler.Instance.SetTestSpeed(it.indexId, "0"); break; +<<<<<<< HEAD + case ESpeedActionType.QuickSelect: + UpdateFunc(it.indexId, ResUI.Speedtesting, ""); + ProfileExHandler.Instance.SetTestDelay(it.indexId, "0"); + break; +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 } } @@ -92,6 +99,12 @@ namespace v2rayN.Handler case ESpeedActionType.Mixedtest: Task.Run(RunMixedtestAsync); break; +<<<<<<< HEAD + case ESpeedActionType.QuickSelect: + Task.Run(RunQuickSelectAsync); + break; +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 } } @@ -333,6 +346,17 @@ namespace v2rayN.Handler await RunSpeedTestMulti(); } +<<<<<<< HEAD + private async Task RunQuickSelectAsync() + { + await RunRealPing(); + await RunRealPing(); + await RunRealPing(); + UpdateFunc("#", "ok"); + } + +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 public async Task GetRealPingTime(DownloadHandle downloadHandle, IWebProxy webProxy) { int responseTime = await downloadHandle.GetRealPingTime(_config.speedTestItem.speedPingTestUrl, webProxy, 10); diff --git a/v2rayN/v2rayN/Mode/ESpeedActionType.cs b/v2rayN/v2rayN/Mode/ESpeedActionType.cs index 4864061b..1620511c 100644 --- a/v2rayN/v2rayN/Mode/ESpeedActionType.cs +++ b/v2rayN/v2rayN/Mode/ESpeedActionType.cs @@ -6,6 +6,11 @@ Tcping, Realping, Speedtest, +<<<<<<< HEAD + Mixedtest, + QuickSelect +======= Mixedtest +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 } } \ No newline at end of file diff --git a/v2rayN/v2rayN/Mode/SelectItem.cs b/v2rayN/v2rayN/Mode/SelectItem.cs new file mode 100644 index 00000000..ce848b9b --- /dev/null +++ b/v2rayN/v2rayN/Mode/SelectItem.cs @@ -0,0 +1,81 @@ +using System; + +namespace v2rayN.Mode +{ + internal class SelectItem + { + public string indexId { get; } + private string[] delay = new string[3]; + private int idx = -1; + private int validvalue = 0; + public int ValidValue + { + get { return validvalue; } + } + public SelectItem(string id) { + indexId = id; + } + private int e = 0; + public int E + { + get { return e; } + } + + public string getDelay(int i) + { if (i >= 0 && i <= 2) + { + return delay[i]; + } + else { return ""; } + } + + public void push(string dl) + { + if(idx<2) + { + delay[++idx] = dl; + if (!dl.Trim().Equals("-1")) + { + validvalue++; + } + if(idx == 2) + { + e = 0; + foreach(var v in delay) + { + if(v != null && !v.Trim().Equals("-1")) + { + e += int.Parse(v); + } + } + if (validvalue == 0) + { + e = -1; + } + else + { + e /= validvalue; + } + } + } + } + + public string pop() + { + if (idx >= 0) + { + if (!delay[idx].Trim().Equals("-1")) + { + validvalue--; + } + return delay[idx--]; + } + return ""; + } + + + + + + } +} diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index 8dacf39f..5a1ac8d2 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -1627,6 +1627,18 @@ namespace v2rayN.Resx { } /// +<<<<<<< HEAD + /// 查找类似 flash filtering 的本地化字符串。 + /// + public static string quickSelect { + get { + return ResourceManager.GetString("quickSelect", resourceCulture); + } + } + + /// +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 /// 查找类似 Global hotkey {0} registered failed, reason {1} 的本地化字符串。 /// public static string RegisterGlobalHotkeyFailed { diff --git a/v2rayN/v2rayN/Resx/ResUI.fa-Ir.resx b/v2rayN/v2rayN/Resx/ResUI.fa-Ir.resx index 39f211d2..765766bc 100644 --- a/v2rayN/v2rayN/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/v2rayN/Resx/ResUI.fa-Ir.resx @@ -1009,4 +1009,15 @@ فعال‌سازی شتاب‌دهنده سخت‌افزاری (نیاز به راه‌اندازی مجدد) +<<<<<<< HEAD + + Filtre en un clic + + + 一键筛选 +一键筛选 +Filtre en un clic + +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index 5b513251..4ba1fbcc 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -1141,4 +1141,10 @@ Domain +<<<<<<< HEAD + + flash filtering + +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.ru.resx b/v2rayN/v2rayN/Resx/ResUI.ru.resx index 30e796ab..2a65353e 100644 --- a/v2rayN/v2rayN/Resx/ResUI.ru.resx +++ b/v2rayN/v2rayN/Resx/ResUI.ru.resx @@ -1054,4 +1054,13 @@ Включить аппаратное ускорение (требуется перезагрузка) +<<<<<<< HEAD + + Фильтр одним нажатием клавиш + + + Фильтр одним нажатием клавиш + +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 \ 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 8de8f034..6752801f 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -1138,4 +1138,13 @@ IP 或 IP CIDR +<<<<<<< HEAD + + 一键筛选 + + + 一键筛选 + +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 \ No newline at end of file diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index fa56d071..9d63e4b9 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -30,6 +30,10 @@ namespace v2rayN.ViewModels private CoreHandler _coreHandler; private StatisticsHandler _statistics; +<<<<<<< HEAD + private QuickSelectHandler _quickSelectHandler; +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 private List _lstProfile; private string _subId = string.Empty; private string _serverFilter = string.Empty; @@ -110,6 +114,10 @@ namespace v2rayN.ViewModels public ReactiveCommand MoveBottomCmd { get; } //servers ping +<<<<<<< HEAD + public ReactiveCommand QuickSelectCmd { get; } +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 public ReactiveCommand MixedTestServerCmd { get; } public ReactiveCommand PingServerCmd { get; } @@ -255,6 +263,10 @@ namespace v2rayN.ViewModels Locator.CurrentMutable.RegisterLazySingleton(() => new NoticeHandler(snackbarMessageQueue), typeof(NoticeHandler)); _noticeHandler = Locator.Current.GetService(); _config = LazyConfig.Instance.GetConfig(); +<<<<<<< HEAD + _quickSelectHandler = new QuickSelectHandler(); +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 //ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false); Init(); @@ -393,6 +405,14 @@ namespace v2rayN.ViewModels }, canEditRemove); //servers ping +<<<<<<< HEAD + QuickSelectCmd = ReactiveCommand.Create(() => + { + QuickSelect(); + }); + +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 MixedTestServerCmd = ReactiveCommand.Create(() => { ServerSpeedtest(ESpeedActionType.Mixedtest); @@ -666,6 +686,95 @@ namespace v2rayN.ViewModels })); } +<<<<<<< HEAD + private void UpdateSpeedtestAndSelectUselessResultHandler(string indexId, string delay, string speed) + { + Application.Current.Dispatcher.Invoke((Action)(() => + { + SetTestResultAndSelect(indexId, delay, speed); + })); + } + + private void SetTestResultAndSelect(string indexId, string delay, string speed) + { + if (Utils.IsNullOrEmpty(indexId)) + { + _noticeHandler?.SendMessage(delay, true); + _noticeHandler?.Enqueue(delay); + return; + } + else if (indexId.Equals("#")) + { + if (delay.Equals("ok")) + { + List invaliditems = _quickSelectHandler.select(); + List items = new List(); + foreach(var it in invaliditems) + { + var ite = LazyConfig.Instance.GetProfileItem(it); + if (ite is not null) + { + items.Add(ite); + } + } + RemoveServerByItems(items); + if (_quickSelectHandler.selectContent) + { + foreach(var it in _quickSelectHandler.validItems) + { + var ite = _profileItems.Where(i => i.indexId == it.indexId).FirstOrDefault(); + if (!Utils.IsNullOrEmpty(delay)) + { + ite.delay = it.E; + ite.delayVal = $"{it.E.ToString()} {Global.DelayUnit}"; + ProfileExHandler.Instance.SetTestDelay(it.indexId, it.E.ToString()); + } + _profileItems.Replace(ite, Utils.DeepCopy(ite)); + } + } + else + { + foreach (var it in _quickSelectHandler.validItems) + { + var ite = _profileItems.Where(i => i.indexId == it.indexId).FirstOrDefault(); + if (!Utils.IsNullOrEmpty(delay)) + { + ite.delay = int.Parse(it.getDelay(2)); + ite.delayVal = $"{it.getDelay(2)} {Global.DelayUnit}"; + ProfileExHandler.Instance.SetTestDelay(it.indexId, it.getDelay(2)); + } + _profileItems.Replace(ite, Utils.DeepCopy(ite)); + } + } + SortServer(EServerColName.delayVal.ToString()); + SetDefaultServer(_profileItems.First().indexId); + _noticeHandler?.SendMessage(ResUI.OperationSuccess, true); + _noticeHandler?.Enqueue(ResUI.OperationSuccess); + } + return; + } + var item = _profileItems.Where(it => it.indexId == indexId).FirstOrDefault(); + if (item != null) + { + if (!Utils.IsNullOrEmpty(delay)) + { + int.TryParse(delay, out int temp); + item.delay = temp; + item.delayVal = $"{delay} {Global.DelayUnit}"; + if (int.TryParse(delay,out int tmp)) { + _quickSelectHandler.itemAdd(item.indexId, delay); + } + } + if (!Utils.IsNullOrEmpty(speed)) + { + item.speedVal = $"{speed} {Global.SpeedUnit}"; + } + _profileItems.Replace(item, Utils.DeepCopy(item)); + } + } + +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 private void SetTestResult(string indexId, string delay, string speed) { if (Utils.IsNullOrEmpty(indexId)) @@ -1019,6 +1128,20 @@ namespace v2rayN.ViewModels } } +<<<<<<< HEAD + public void RemoveServerByItems(List lst) + { + var exists = lst.Exists(t => t.indexId == _config.indexId); + ConfigHandler.RemoveServer(_config, lst); + RefreshServers(); + if (exists) + { + Reload(); + } + } + +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 public void RemoveServer() { if (GetProfileItems(out List lstSelecteds, true) < 0) @@ -1226,6 +1349,19 @@ namespace v2rayN.ViewModels } } } +<<<<<<< HEAD + public void QuickSelect() + { + SelectedProfiles = _profileItems; + if (GetProfileItems(out List lstSelecteds, false) < 0) + { + return; + } + _quickSelectHandler.clear(); + new SpeedtestHandler(_config, _coreHandler, lstSelecteds, ESpeedActionType.QuickSelect, UpdateSpeedtestAndSelectUselessResultHandler); + } +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 public void ServerSpeedtest(ESpeedActionType actionType) { diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml index 81495c84..afa55667 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml +++ b/v2rayN/v2rayN/Views/MainWindow.xaml @@ -13,9 +13,15 @@ xmlns:tb="clr-namespace:H.NotifyIcon;assembly=H.NotifyIcon.Wpf" xmlns:vms="clr-namespace:v2rayN.ViewModels" Title="v2rayN" +<<<<<<< HEAD + Width="950" + Height="700" + MinWidth="950" +======= Width="900" Height="700" MinWidth="900" +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 MinHeight="700" x:TypeArguments="vms:MainWindowViewModel" Background="{DynamicResource MaterialDesignPaper}" @@ -381,6 +387,20 @@ +<<<<<<< HEAD + + +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index db5ca106..e8225f22 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -1,5 +1,9 @@ using ReactiveUI; using Splat; +<<<<<<< HEAD +using System; +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 using System.ComponentModel; using System.Reactive.Disposables; using System.Runtime.InteropServices; @@ -95,6 +99,10 @@ namespace v2rayN.Views this.BindCommand(ViewModel, vm => vm.MoveBottomCmd, v => v.menuMoveBottom).DisposeWith(disposables); //servers ping +<<<<<<< HEAD + this.BindCommand(ViewModel, vm => vm.QuickSelectCmd, v => v.btnQuickOp).DisposeWith(disposables); +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 this.BindCommand(ViewModel, vm => vm.MixedTestServerCmd, v => v.menuMixedTestServer).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.PingServerCmd, v => v.menuPingServer).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.TcpingServerCmd, v => v.menuTcpingServer).DisposeWith(disposables); @@ -630,5 +638,9 @@ namespace v2rayN.Views } #endregion Drag and Drop +<<<<<<< HEAD + +======= +>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488 } } \ No newline at end of file