pull/2148/head
2dust 2022-03-15 19:17:32 +08:00
parent 6517f66876
commit 0463c1a6e7
6 changed files with 28 additions and 36 deletions

View File

@ -66,12 +66,7 @@ namespace v2rayN.Forms
} }
private void btnOK_Click(object sender, EventArgs e) private void btnOK_Click(object sender, EventArgs e)
{ {
if (config.groupItem.Count <= 0)
{
AddGroup();
}
if (ConfigHandler.SaveGroupItem(ref config) == 0) if (ConfigHandler.SaveGroupItem(ref config) == 0)
{ {
this.DialogResult = DialogResult.OK; this.DialogResult = DialogResult.OK;

View File

@ -82,7 +82,7 @@ namespace v2rayN.Forms
RefreshRoutingsMenu(); RefreshRoutingsMenu();
RestoreUI(); RestoreUI();
LoadV2ray(); _ = LoadV2ray();
HideForm(); HideForm();
@ -602,7 +602,7 @@ namespace v2rayN.Forms
if (fm.ShowDialog() == DialogResult.OK) if (fm.ShowDialog() == DialogResult.OK)
{ {
RefreshServers(); RefreshServers();
LoadV2ray(); _ = LoadV2ray();
} }
} }
@ -691,7 +691,7 @@ namespace v2rayN.Forms
ConfigHandler.RemoveServer(config, lvSelecteds); ConfigHandler.RemoveServer(config, lvSelecteds);
RefreshServers(); RefreshServers();
LoadV2ray(); _ = LoadV2ray();
} }
private void menuRemoveDuplicateServer_Click(object sender, EventArgs e) private void menuRemoveDuplicateServer_Click(object sender, EventArgs e)
@ -700,7 +700,7 @@ namespace v2rayN.Forms
ConfigHandler.DedupServerList(ref config, ref lstVmess); ConfigHandler.DedupServerList(ref config, ref lstVmess);
int newCount = lstVmess.Count; int newCount = lstVmess.Count;
RefreshServers(); RefreshServers();
LoadV2ray(); _ = LoadV2ray();
UI.Show(string.Format(UIRes.I18N("RemoveDuplicateServerResult"), oldCount, newCount)); UI.Show(string.Format(UIRes.I18N("RemoveDuplicateServerResult"), oldCount, newCount));
} }
@ -847,7 +847,7 @@ namespace v2rayN.Forms
if (fm.ShowDialog() == DialogResult.OK) if (fm.ShowDialog() == DialogResult.OK)
{ {
RefreshServers(); RefreshServers();
LoadV2ray(); _ = LoadV2ray();
} }
} }
@ -858,7 +858,7 @@ namespace v2rayN.Forms
{ {
RefreshRoutingsMenu(); RefreshRoutingsMenu();
RefreshServers(); RefreshServers();
LoadV2ray(); _ = LoadV2ray();
} }
} }
@ -869,7 +869,7 @@ namespace v2rayN.Forms
{ {
RefreshRoutingsMenu(); RefreshRoutingsMenu();
RefreshServers(); RefreshServers();
LoadV2ray(); _ = LoadV2ray();
} }
} }
@ -888,7 +888,7 @@ namespace v2rayN.Forms
private void tsbReload_Click(object sender, EventArgs e) private void tsbReload_Click(object sender, EventArgs e)
{ {
Global.reloadV2ray = true; Global.reloadV2ray = true;
LoadV2ray(); _ = LoadV2ray();
} }
private void tsbClose_Click(object sender, EventArgs e) private void tsbClose_Click(object sender, EventArgs e)
@ -913,7 +913,7 @@ namespace v2rayN.Forms
if (ConfigHandler.SetDefaultServer(ref config, lstVmess[index]) == 0) if (ConfigHandler.SetDefaultServer(ref config, lstVmess[index]) == 0)
{ {
RefreshServers(); RefreshServers();
LoadV2ray(); _ = LoadV2ray();
} }
return 0; return 0;
} }
@ -1267,7 +1267,7 @@ namespace v2rayN.Forms
if (success) if (success)
{ {
Global.reloadV2ray = true; Global.reloadV2ray = true;
LoadV2ray(); _ = LoadV2ray();
} }
} }
#endregion #endregion
@ -1396,7 +1396,7 @@ namespace v2rayN.Forms
AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfullyMore")); AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfullyMore"));
Global.reloadV2ray = true; Global.reloadV2ray = true;
LoadV2ray(); _ = LoadV2ray();
AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfully")); AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfully"));
} }
@ -1412,7 +1412,7 @@ namespace v2rayN.Forms
if (success) if (success)
{ {
Global.reloadV2ray = true; Global.reloadV2ray = true;
LoadV2ray(); _ = LoadV2ray();
} }
}); });
} }
@ -1425,7 +1425,7 @@ namespace v2rayN.Forms
if (success) if (success)
{ {
Global.reloadV2ray = true; Global.reloadV2ray = true;
LoadV2ray(); _ = LoadV2ray();
} }
}); });
} }
@ -1576,7 +1576,7 @@ namespace v2rayN.Forms
if (ConfigHandler.SetDefaultRouting(ref config, index) == 0) if (ConfigHandler.SetDefaultRouting(ref config, index) == 0)
{ {
RefreshRoutingsMenu(); RefreshRoutingsMenu();
LoadV2ray(); _ = LoadV2ray();
} }
} }
catch catch

View File

@ -68,11 +68,6 @@ namespace v2rayN.Forms
private void btnOK_Click(object sender, EventArgs e) private void btnOK_Click(object sender, EventArgs e)
{ {
if (config.subItem.Count <= 0)
{
AddSub();
}
if (ConfigHandler.SaveSubItem(ref config) == 0) if (ConfigHandler.SaveSubItem(ref config) == 0)
{ {
this.DialogResult = DialogResult.OK; this.DialogResult = DialogResult.OK;

View File

@ -764,7 +764,7 @@ namespace v2rayN.Handler
/// <returns></returns> /// <returns></returns>
public static int SaveSubItem(ref Config config) public static int SaveSubItem(ref Config config)
{ {
if (config.subItem == null || config.subItem.Count <= 0) if (config.subItem == null)
{ {
return -1; return -1;
} }
@ -926,7 +926,7 @@ namespace v2rayN.Handler
} }
if (!config.vmess.Exists(it => it.indexId == vmessItem.indexId)) if (!config.vmess.Exists(it => it.indexId == vmessItem.indexId))
{ {
var maxSort = config.vmess.Max(t => t.sort); var maxSort = config.vmess.Any() ? config.vmess.Max(t => t.sort) : 0;
vmessItem.sort = maxSort++; vmessItem.sort = maxSort++;
config.vmess.Add(vmessItem); config.vmess.Add(vmessItem);
@ -970,7 +970,7 @@ namespace v2rayN.Handler
/// <returns></returns> /// <returns></returns>
public static int SaveGroupItem(ref Config config) public static int SaveGroupItem(ref Config config)
{ {
if (config.groupItem == null || config.groupItem.Count <= 0) if (config.groupItem == null)
{ {
return -1; return -1;
} }
@ -989,12 +989,13 @@ namespace v2rayN.Handler
public static int RemoveGroupItem(ref Config config, string groupId) public static int RemoveGroupItem(ref Config config, string groupId)
{ {
if (Utils.IsNullOrEmpty(groupId) || config.vmess.Count <= 0) if (Utils.IsNullOrEmpty(groupId))
{ {
return -1; return -1;
} }
foreach (var item in config.vmess) var items = config.vmess.Where(t => t.groupId == groupId).ToList();
foreach (var item in items)
{ {
if (item.groupId.Equals(groupId)) if (item.groupId.Equals(groupId))
{ {

View File

@ -6,6 +6,7 @@ using System.Net.Http;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Forms; using System.Windows.Forms;
using v2rayN.Base;
using v2rayN.Mode; using v2rayN.Mode;
namespace v2rayN.Handler namespace v2rayN.Handler
@ -177,10 +178,10 @@ namespace v2rayN.Handler
for (int k = 1; k <= config.subItem.Count; k++) for (int k = 1; k <= config.subItem.Count; k++)
{ {
string id = config.subItem[k - 1].id.Trim(); string id = config.subItem[k - 1].id.TrimEx();
string url = config.subItem[k - 1].url.Trim(); string url = config.subItem[k - 1].url.TrimEx();
string userAgent = config.subItem[k - 1].userAgent.Trim(); string userAgent = config.subItem[k - 1].userAgent.TrimEx();
string groupId = config.subItem[k - 1].groupId.Trim(); string groupId = config.subItem[k - 1].groupId.TrimEx();
string hashCode = $"{k}->"; string hashCode = $"{k}->";
if (config.subItem[k - 1].enabled == false) if (config.subItem[k - 1].enabled == false)
{ {

View File

@ -569,7 +569,7 @@ namespace v2rayN.Mode
public string groupId public string groupId
{ {
get; set; get; set;
} } = string.Empty;
} }
[Serializable] [Serializable]
@ -703,7 +703,7 @@ namespace v2rayN.Mode
public string groupId public string groupId
{ {
get; set; get; set;
} } = string.Empty;
} }
[Serializable] [Serializable]