From 56559e6509bf4519b27f887fc016a644b59913f0 Mon Sep 17 00:00:00 2001 From: YFdyh000 Date: Sun, 19 Apr 2020 06:22:51 +0800 Subject: [PATCH] treat index in menuRemoveDuplicateServer --- v2rayN/v2rayN/Forms/MainForm.cs | 10 ++++++++++ v2rayN/v2rayN/Tool/Utils.cs | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index f264e43d..7d8cda03 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -627,12 +627,22 @@ namespace v2rayN.Forms private void menuRemoveDuplicateServer_Click(object sender, EventArgs e) { + VmessItem activeVm = null; + if (config.index >= 0) { + activeVm = config.vmess[config.index]; + } Utils.DedupServerList(config.vmess, out List servers, config.keepOlderDedupl); int oldCount = config.vmess.Count; int newCount = servers.Count; if (servers != null) { config.vmess = servers; + + if (activeVm != null) + { + int index = Utils.ServerVmIndexof(config.vmess, activeVm); + if (index >= 0) config.index = index; // restore to the correct value + } } //刷新 RefreshServers(); diff --git a/v2rayN/v2rayN/Tool/Utils.cs b/v2rayN/v2rayN/Tool/Utils.cs index 06dc979b..7ca0dd12 100644 --- a/v2rayN/v2rayN/Tool/Utils.cs +++ b/v2rayN/v2rayN/Tool/Utils.cs @@ -318,6 +318,10 @@ namespace v2rayN return $"{string.Format("{0:f1}", result)} {unit}"; } + public static int ServerVmIndexof(List source, Mode.VmessItem findIt) + { + return source.IndexOf(findIt); + } public static void DedupServerList(List source, out List result, bool keepOlder) { List list = new List();