From 9dc6ba182a11f2e682de02bf3f7f0d4b1a3b8bc2 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Thu, 30 Mar 2023 14:09:14 +0800 Subject: [PATCH] Fix delete duplicate server --- v2rayN/v2rayN/Handler/ConfigHandler.cs | 11 +++++------ v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs | 5 ++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index f1e1db48..125aa535 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -800,16 +800,15 @@ namespace v2rayN.Handler return 0; } - public static int DedupServerList(ref Config config, ref List lstProfile) + public static Tuple DedupServerList(Config config, string subId) { - List source = lstProfile; - bool keepOlder = config.guiItem.keepOlderDedupl; + var lstProfile = LazyConfig.Instance.ProfileItems(subId); List lstKeep = new(); List lstRemove = new(); - if (!keepOlder) source.Reverse(); // Remove the early items first + if (config.guiItem.keepOlderDedupl) lstProfile.Reverse(); - foreach (ProfileItem item in source) + foreach (ProfileItem item in lstProfile) { if (!lstKeep.Exists(i => CompareProfileItem(i, item, false))) { @@ -822,7 +821,7 @@ namespace v2rayN.Handler } RemoveServer(config, lstRemove); - return lstKeep.Count; + return new Tuple(lstProfile.Count, lstKeep.Count); } public static int AddServerCommon(ref Config config, ProfileItem profileItem, bool toFile = true) diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index 2a59b74a..86255d79 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -971,11 +971,10 @@ namespace v2rayN.ViewModels private void RemoveDuplicateServer() { - int oldCount = _lstProfile.Count; - int newCount = ConfigHandler.DedupServerList(ref _config, ref _lstProfile); + var tuple = ConfigHandler.DedupServerList(_config, _subId); RefreshServers(); Reload(); - _noticeHandler?.Enqueue(string.Format(ResUI.RemoveDuplicateServerResult, oldCount, newCount)); + _noticeHandler?.Enqueue(string.Format(ResUI.RemoveDuplicateServerResult, tuple.Item1, tuple.Item2)); } private void CopyServer() {