mirror of https://github.com/2dust/v2rayN
Optimize Duplicate Server
parent
1138d660b2
commit
cb01809093
|
@ -587,13 +587,9 @@ namespace v2rayN.Forms
|
||||||
|
|
||||||
private void menuRemoveDuplicateServer_Click(object sender, EventArgs e)
|
private void menuRemoveDuplicateServer_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Utils.DedupServerList(config.vmess, out List<VmessItem> servers, config.keepOlderDedupl);
|
|
||||||
int oldCount = config.vmess.Count;
|
int oldCount = config.vmess.Count;
|
||||||
int newCount = servers.Count;
|
ConfigHandler.DedupServerList(ref config);
|
||||||
if (servers != null)
|
int newCount = config.vmess.Count;
|
||||||
{
|
|
||||||
config.vmess = servers;
|
|
||||||
}
|
|
||||||
RefreshServers();
|
RefreshServers();
|
||||||
LoadV2ray();
|
LoadV2ray();
|
||||||
UI.Show(string.Format(UIRes.I18N("RemoveDuplicateServerResult"), oldCount, newCount));
|
UI.Show(string.Format(UIRes.I18N("RemoveDuplicateServerResult"), oldCount, newCount));
|
||||||
|
|
|
@ -987,6 +987,63 @@ namespace v2rayN.Handler
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int DedupServerList(ref Config config)
|
||||||
|
{
|
||||||
|
var itemId = config.getItemId();
|
||||||
|
|
||||||
|
List<Mode.VmessItem> source = config.vmess;
|
||||||
|
bool keepOlder = config.keepOlderDedupl;
|
||||||
|
|
||||||
|
List<Mode.VmessItem> list = new List<Mode.VmessItem>();
|
||||||
|
if (!keepOlder) source.Reverse(); // Remove the early items first
|
||||||
|
|
||||||
|
bool _isAdded(Mode.VmessItem o, Mode.VmessItem n)
|
||||||
|
{
|
||||||
|
return o.configVersion == n.configVersion &&
|
||||||
|
o.configType == n.configType &&
|
||||||
|
o.address == n.address &&
|
||||||
|
o.port == n.port &&
|
||||||
|
o.id == n.id &&
|
||||||
|
o.alterId == n.alterId &&
|
||||||
|
o.security == n.security &&
|
||||||
|
o.network == n.network &&
|
||||||
|
o.headerType == n.headerType &&
|
||||||
|
o.requestHost == n.requestHost &&
|
||||||
|
o.path == n.path &&
|
||||||
|
o.streamSecurity == n.streamSecurity;
|
||||||
|
// skip (will remove) different remarks
|
||||||
|
}
|
||||||
|
foreach (Mode.VmessItem item in source)
|
||||||
|
{
|
||||||
|
if (!list.Exists(i => _isAdded(i, item)))
|
||||||
|
{
|
||||||
|
list.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!keepOlder) list.Reverse();
|
||||||
|
config.vmess = list;
|
||||||
|
|
||||||
|
var index_ = config.vmess.FindIndex(it => it.getItemId() == itemId);
|
||||||
|
if (index_ >= 0)
|
||||||
|
{
|
||||||
|
config.index = index_;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (config.vmess.Count > 0)
|
||||||
|
{
|
||||||
|
config.index = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
config.index = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Global.reloadV2ray = true;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region UI
|
#region UI
|
||||||
|
|
|
@ -348,37 +348,7 @@ namespace v2rayN
|
||||||
return $"{string.Format("{0:f1}", result)} {unit}";
|
return $"{string.Format("{0:f1}", result)} {unit}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DedupServerList(List<Mode.VmessItem> source, out List<Mode.VmessItem> result, bool keepOlder)
|
|
||||||
{
|
|
||||||
List<Mode.VmessItem> list = new List<Mode.VmessItem>();
|
|
||||||
if (!keepOlder) source.Reverse(); // Remove the early items first
|
|
||||||
|
|
||||||
bool _isAdded(Mode.VmessItem o, Mode.VmessItem n)
|
|
||||||
{
|
|
||||||
return o.configVersion == n.configVersion &&
|
|
||||||
o.configType == n.configType &&
|
|
||||||
o.address == n.address &&
|
|
||||||
o.port == n.port &&
|
|
||||||
o.id == n.id &&
|
|
||||||
o.alterId == n.alterId &&
|
|
||||||
o.security == n.security &&
|
|
||||||
o.network == n.network &&
|
|
||||||
o.headerType == n.headerType &&
|
|
||||||
o.requestHost == n.requestHost &&
|
|
||||||
o.path == n.path &&
|
|
||||||
o.streamSecurity == n.streamSecurity;
|
|
||||||
// skip (will remove) different remarks
|
|
||||||
}
|
|
||||||
foreach (Mode.VmessItem item in source)
|
|
||||||
{
|
|
||||||
if (!list.Exists(i => _isAdded(i, item)))
|
|
||||||
{
|
|
||||||
list.Add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!keepOlder) list.Reverse();
|
|
||||||
result = list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string UrlEncode(string url)
|
public static string UrlEncode(string url)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue