quickselect

This commit is contained in:
rexmyl 2023-06-02 02:47:50 +08:00
parent bc957fea71
commit 0e9464022a
12 changed files with 397 additions and 0 deletions

View file

@ -0,0 +1,72 @@
using System;
using v2rayN.Mode;
namespace v2rayN.Handler
{
internal class QuickSelectHandler
{
public List<SelectItem> Items { get; }
public List<SelectItem> validItems { get; set; }
public QuickSelectHandler()
{
Items = new List<SelectItem>();
validItems = new List<SelectItem>();
}
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<string> select()
{
List<string> invaliditems = new List<string>();
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();
}
}
}

View file

@ -68,6 +68,13 @@ namespace v2rayN.Handler
ProfileExHandler.Instance.SetTestDelay(it.indexId, "0"); ProfileExHandler.Instance.SetTestDelay(it.indexId, "0");
ProfileExHandler.Instance.SetTestSpeed(it.indexId, "0"); ProfileExHandler.Instance.SetTestSpeed(it.indexId, "0");
break; 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: case ESpeedActionType.Mixedtest:
Task.Run(RunMixedtestAsync); Task.Run(RunMixedtestAsync);
break; break;
<<<<<<< HEAD
case ESpeedActionType.QuickSelect:
Task.Run(RunQuickSelectAsync);
break;
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
} }
} }
@ -333,6 +346,17 @@ namespace v2rayN.Handler
await RunSpeedTestMulti(); await RunSpeedTestMulti();
} }
<<<<<<< HEAD
private async Task RunQuickSelectAsync()
{
await RunRealPing();
await RunRealPing();
await RunRealPing();
UpdateFunc("#", "ok");
}
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
public async Task<string> GetRealPingTime(DownloadHandle downloadHandle, IWebProxy webProxy) public async Task<string> GetRealPingTime(DownloadHandle downloadHandle, IWebProxy webProxy)
{ {
int responseTime = await downloadHandle.GetRealPingTime(_config.speedTestItem.speedPingTestUrl, webProxy, 10); int responseTime = await downloadHandle.GetRealPingTime(_config.speedTestItem.speedPingTestUrl, webProxy, 10);

View file

@ -6,6 +6,11 @@
Tcping, Tcping,
Realping, Realping,
Speedtest, Speedtest,
<<<<<<< HEAD
Mixedtest,
QuickSelect
=======
Mixedtest Mixedtest
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
} }
} }

View file

@ -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 "";
}
}
}

View file

@ -1627,6 +1627,18 @@ namespace v2rayN.Resx {
} }
/// <summary> /// <summary>
<<<<<<< HEAD
/// 查找类似 flash filtering 的本地化字符串。
/// </summary>
public static string quickSelect {
get {
return ResourceManager.GetString("quickSelect", resourceCulture);
}
}
/// <summary>
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
/// 查找类似 Global hotkey {0} registered failed, reason {1} 的本地化字符串。 /// 查找类似 Global hotkey {0} registered failed, reason {1} 的本地化字符串。
/// </summary> /// </summary>
public static string RegisterGlobalHotkeyFailed { public static string RegisterGlobalHotkeyFailed {

View file

@ -1009,4 +1009,15 @@
<data name="TbSettingsEnableHWA" xml:space="preserve"> <data name="TbSettingsEnableHWA" xml:space="preserve">
<value>فعال‌سازی شتاب‌دهنده سخت‌افزاری (نیاز به راه‌اندازی مجدد)</value> <value>فعال‌سازی شتاب‌دهنده سخت‌افزاری (نیاز به راه‌اندازی مجدد)</value>
</data> </data>
<<<<<<< HEAD
<data name="flashSelect" xml:space="preserve">
<value>Filtre en un clic</value>
</data>
<data name="quickSelect" xml:space="preserve">
<value>一键筛选
一键筛选
Filtre en un clic</value>
</data>
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
</root> </root>

View file

@ -1141,4 +1141,10 @@
<data name="TbRoutingRuleDomain" xml:space="preserve"> <data name="TbRoutingRuleDomain" xml:space="preserve">
<value>Domain</value> <value>Domain</value>
</data> </data>
<<<<<<< HEAD
<data name="quickSelect" xml:space="preserve">
<value>flash filtering</value>
</data>
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
</root> </root>

View file

@ -1054,4 +1054,13 @@
<data name="TbSettingsEnableHWA" xml:space="preserve"> <data name="TbSettingsEnableHWA" xml:space="preserve">
<value>Включить аппаратное ускорение (требуется перезагрузка)</value> <value>Включить аппаратное ускорение (требуется перезагрузка)</value>
</data> </data>
<<<<<<< HEAD
<data name="flashSelect" xml:space="preserve">
<value>Фильтр одним нажатием клавиш</value>
</data>
<data name="quickSelect" xml:space="preserve">
<value>Фильтр одним нажатием клавиш</value>
</data>
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
</root> </root>

View file

@ -1138,4 +1138,13 @@
<data name="TbRoutingRuleIP" xml:space="preserve"> <data name="TbRoutingRuleIP" xml:space="preserve">
<value>IP 或 IP CIDR</value> <value>IP 或 IP CIDR</value>
</data> </data>
<<<<<<< HEAD
<data name="flashSelect" xml:space="preserve">
<value>一键筛选</value>
</data>
<data name="quickSelect" xml:space="preserve">
<value>一键筛选</value>
</data>
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
</root> </root>

View file

@ -30,6 +30,10 @@ namespace v2rayN.ViewModels
private CoreHandler _coreHandler; private CoreHandler _coreHandler;
private StatisticsHandler _statistics; private StatisticsHandler _statistics;
<<<<<<< HEAD
private QuickSelectHandler _quickSelectHandler;
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
private List<ProfileItem> _lstProfile; private List<ProfileItem> _lstProfile;
private string _subId = string.Empty; private string _subId = string.Empty;
private string _serverFilter = string.Empty; private string _serverFilter = string.Empty;
@ -110,6 +114,10 @@ namespace v2rayN.ViewModels
public ReactiveCommand<Unit, Unit> MoveBottomCmd { get; } public ReactiveCommand<Unit, Unit> MoveBottomCmd { get; }
//servers ping //servers ping
<<<<<<< HEAD
public ReactiveCommand<Unit, Unit> QuickSelectCmd { get; }
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
public ReactiveCommand<Unit, Unit> MixedTestServerCmd { get; } public ReactiveCommand<Unit, Unit> MixedTestServerCmd { get; }
public ReactiveCommand<Unit, Unit> PingServerCmd { get; } public ReactiveCommand<Unit, Unit> PingServerCmd { get; }
@ -255,6 +263,10 @@ namespace v2rayN.ViewModels
Locator.CurrentMutable.RegisterLazySingleton(() => new NoticeHandler(snackbarMessageQueue), typeof(NoticeHandler)); Locator.CurrentMutable.RegisterLazySingleton(() => new NoticeHandler(snackbarMessageQueue), typeof(NoticeHandler));
_noticeHandler = Locator.Current.GetService<NoticeHandler>(); _noticeHandler = Locator.Current.GetService<NoticeHandler>();
_config = LazyConfig.Instance.GetConfig(); _config = LazyConfig.Instance.GetConfig();
<<<<<<< HEAD
_quickSelectHandler = new QuickSelectHandler();
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
//ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false); //ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false);
Init(); Init();
@ -393,6 +405,14 @@ namespace v2rayN.ViewModels
}, canEditRemove); }, canEditRemove);
//servers ping //servers ping
<<<<<<< HEAD
QuickSelectCmd = ReactiveCommand.Create(() =>
{
QuickSelect();
});
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
MixedTestServerCmd = ReactiveCommand.Create(() => MixedTestServerCmd = ReactiveCommand.Create(() =>
{ {
ServerSpeedtest(ESpeedActionType.Mixedtest); 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<string> invaliditems = _quickSelectHandler.select();
List<ProfileItem> items = new List<ProfileItem>();
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) private void SetTestResult(string indexId, string delay, string speed)
{ {
if (Utils.IsNullOrEmpty(indexId)) if (Utils.IsNullOrEmpty(indexId))
@ -1019,6 +1128,20 @@ namespace v2rayN.ViewModels
} }
} }
<<<<<<< HEAD
public void RemoveServerByItems(List<ProfileItem> lst)
{
var exists = lst.Exists(t => t.indexId == _config.indexId);
ConfigHandler.RemoveServer(_config, lst);
RefreshServers();
if (exists)
{
Reload();
}
}
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
public void RemoveServer() public void RemoveServer()
{ {
if (GetProfileItems(out List<ProfileItem> lstSelecteds, true) < 0) if (GetProfileItems(out List<ProfileItem> lstSelecteds, true) < 0)
@ -1226,6 +1349,19 @@ namespace v2rayN.ViewModels
} }
} }
} }
<<<<<<< HEAD
public void QuickSelect()
{
SelectedProfiles = _profileItems;
if (GetProfileItems(out List<ProfileItem> lstSelecteds, false) < 0)
{
return;
}
_quickSelectHandler.clear();
new SpeedtestHandler(_config, _coreHandler, lstSelecteds, ESpeedActionType.QuickSelect, UpdateSpeedtestAndSelectUselessResultHandler);
}
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
public void ServerSpeedtest(ESpeedActionType actionType) public void ServerSpeedtest(ESpeedActionType actionType)
{ {

View file

@ -13,9 +13,15 @@
xmlns:tb="clr-namespace:H.NotifyIcon;assembly=H.NotifyIcon.Wpf" xmlns:tb="clr-namespace:H.NotifyIcon;assembly=H.NotifyIcon.Wpf"
xmlns:vms="clr-namespace:v2rayN.ViewModels" xmlns:vms="clr-namespace:v2rayN.ViewModels"
Title="v2rayN" Title="v2rayN"
<<<<<<< HEAD
Width="950"
Height="700"
MinWidth="950"
=======
Width="900" Width="900"
Height="700" Height="700"
MinWidth="900" MinWidth="900"
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
MinHeight="700" MinHeight="700"
x:TypeArguments="vms:MainWindowViewModel" x:TypeArguments="vms:MainWindowViewModel"
Background="{DynamicResource MaterialDesignPaper}" Background="{DynamicResource MaterialDesignPaper}"
@ -381,6 +387,20 @@
</Grid> </Grid>
</StackPanel> </StackPanel>
</materialDesign:PopupBox> </materialDesign:PopupBox>
<<<<<<< HEAD
<Separator/>
<Button x:Name="btnQuickOp"
>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon
Margin="0,0,8,0"
VerticalAlignment="Center"
Kind="Flash" />
<TextBlock Text="{x:Static resx:ResUI.quickSelect}" />
</StackPanel>
</Button>
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
</ToolBar> </ToolBar>
</ToolBarTray> </ToolBarTray>
<WrapPanel Margin="2" DockPanel.Dock="Top"> <WrapPanel Margin="2" DockPanel.Dock="Top">

View file

@ -1,5 +1,9 @@
using ReactiveUI; using ReactiveUI;
using Splat; using Splat;
<<<<<<< HEAD
using System;
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
using System.ComponentModel; using System.ComponentModel;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -95,6 +99,10 @@ namespace v2rayN.Views
this.BindCommand(ViewModel, vm => vm.MoveBottomCmd, v => v.menuMoveBottom).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.MoveBottomCmd, v => v.menuMoveBottom).DisposeWith(disposables);
//servers ping //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.MixedTestServerCmd, v => v.menuMixedTestServer).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.PingServerCmd, v => v.menuPingServer).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.PingServerCmd, v => v.menuPingServer).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.TcpingServerCmd, v => v.menuTcpingServer).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.TcpingServerCmd, v => v.menuTcpingServer).DisposeWith(disposables);
@ -630,5 +638,9 @@ namespace v2rayN.Views
} }
#endregion Drag and Drop #endregion Drag and Drop
<<<<<<< HEAD
=======
>>>>>>> bc957fea71fac743870efdaecacb22c70bef9488
} }
} }