Fix delete duplicate server

pull/3598/head
2dust 2023-03-30 14:09:14 +08:00
parent 785a30e623
commit 9dc6ba182a
2 changed files with 7 additions and 9 deletions

View File

@ -800,16 +800,15 @@ namespace v2rayN.Handler
return 0;
}
public static int DedupServerList(ref Config config, ref List<ProfileItem> lstProfile)
public static Tuple<int, int> DedupServerList(Config config, string subId)
{
List<ProfileItem> source = lstProfile;
bool keepOlder = config.guiItem.keepOlderDedupl;
var lstProfile = LazyConfig.Instance.ProfileItems(subId);
List<ProfileItem> lstKeep = new();
List<ProfileItem> 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<int, int>(lstProfile.Count, lstKeep.Count);
}
public static int AddServerCommon(ref Config config, ProfileItem profileItem, bool toFile = true)

View File

@ -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()
{