Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e58e0d6ac7 | ||
|
|
a2679e009d | ||
|
|
78d6bcd57a |
@@ -128,7 +128,7 @@ namespace v2rayN.Forms
|
||||
vmessItem.address = fileName;
|
||||
vmessItem.remarks = txtRemarks.Text;
|
||||
|
||||
if (ConfigHandler.AddCustomServer(ref config, vmessItem) == 0)
|
||||
if (ConfigHandler.AddCustomServer(ref config, vmessItem, false) == 0)
|
||||
{
|
||||
BindingServer();
|
||||
UI.Show(UIRes.I18N("SuccessfullyImportedCustomServer"));
|
||||
@@ -148,7 +148,7 @@ namespace v2rayN.Forms
|
||||
return;
|
||||
}
|
||||
|
||||
address = Path.Combine(Utils.GetTempPath(), address);
|
||||
address = Path.Combine(Utils.GetConfigPath(), address);
|
||||
Process.Start(address);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,7 @@ namespace v2rayN.Forms
|
||||
private void AddServerForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
this.Text = (eConfigType).ToString();
|
||||
|
||||
cmbSecurity.Items.AddRange(Global.vmessSecuritys.ToArray());
|
||||
cmbSecurity3.Items.AddRange(config.GetShadowsocksSecuritys().ToArray());
|
||||
|
||||
cmbFlow5.Items.AddRange(Global.xtlsFlows.ToArray());
|
||||
cmbFlow6.Items.AddRange(Global.xtlsFlows.ToArray());
|
||||
|
||||
|
||||
cmbCoreType.Items.AddRange(Global.coreTypes.ToArray());
|
||||
cmbCoreType.Items.Add(string.Empty);
|
||||
|
||||
@@ -31,12 +25,16 @@ namespace v2rayN.Forms
|
||||
case EConfigType.Vmess:
|
||||
panVmess.Dock = DockStyle.Fill;
|
||||
panVmess.Visible = true;
|
||||
|
||||
cmbSecurity.Items.AddRange(Global.vmessSecuritys.ToArray());
|
||||
break;
|
||||
case EConfigType.Shadowsocks:
|
||||
panSs.Dock = DockStyle.Fill;
|
||||
panSs.Visible = true;
|
||||
panTran.Visible = false;
|
||||
this.Height = this.Height - panTran.Height;
|
||||
|
||||
cmbSecurity3.Items.AddRange(LazyConfig.Instance.GetShadowsocksSecuritys().ToArray());
|
||||
break;
|
||||
case EConfigType.Socks:
|
||||
panSocks.Dock = DockStyle.Fill;
|
||||
@@ -48,11 +46,15 @@ namespace v2rayN.Forms
|
||||
panVless.Dock = DockStyle.Fill;
|
||||
panVless.Visible = true;
|
||||
transportControl.AllowXtls = true;
|
||||
|
||||
cmbFlow5.Items.AddRange(Global.xtlsFlows.ToArray());
|
||||
break;
|
||||
case EConfigType.Trojan:
|
||||
panTrojan.Dock = DockStyle.Fill;
|
||||
panTrojan.Visible = true;
|
||||
transportControl.AllowXtls = true;
|
||||
|
||||
cmbFlow6.Items.AddRange(Global.xtlsFlows.ToArray());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -586,7 +586,7 @@ namespace v2rayN.Forms
|
||||
else
|
||||
{
|
||||
fm = new AddServerForm();
|
||||
}
|
||||
}
|
||||
fm.vmessItem = index >= 0 ? lstVmess[index] : null;
|
||||
fm.groupId = groupId;
|
||||
fm.eConfigType = configType;
|
||||
@@ -688,8 +688,7 @@ namespace v2rayN.Forms
|
||||
private void menuRemoveDuplicateServer_Click(object sender, EventArgs e)
|
||||
{
|
||||
int oldCount = lstVmess.Count;
|
||||
ConfigHandler.DedupServerList(ref config, ref lstVmess);
|
||||
int newCount = lstVmess.Count;
|
||||
int newCount = ConfigHandler.DedupServerList(ref config, ref lstVmess);
|
||||
RefreshServers();
|
||||
_ = LoadV2ray();
|
||||
UI.Show(string.Format(UIRes.I18N("RemoveDuplicateServerResult"), oldCount, newCount));
|
||||
@@ -964,7 +963,7 @@ namespace v2rayN.Forms
|
||||
private void menuAddServers_Click(object sender, EventArgs e)
|
||||
{
|
||||
string clipboardData = Utils.GetClipboardData();
|
||||
int ret = MainFormHandler.Instance.AddBatchServers(config, clipboardData, "", groupId);
|
||||
int ret = ConfigHandler.AddBatchServers(ref config, clipboardData, "", groupId);
|
||||
if (ret > 0)
|
||||
{
|
||||
RefreshServers();
|
||||
@@ -994,7 +993,7 @@ namespace v2rayN.Forms
|
||||
}
|
||||
else
|
||||
{
|
||||
int ret = MainFormHandler.Instance.AddBatchServers(config, result, "", groupId);
|
||||
int ret = ConfigHandler.AddBatchServers(ref config, result, "", groupId);
|
||||
if (ret > 0)
|
||||
{
|
||||
RefreshServers();
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace v2rayN.Forms
|
||||
config.coreTypeItem.Add(new CoreTypeItem()
|
||||
{
|
||||
configType = it,
|
||||
coreType = ECoreType.v2fly
|
||||
coreType = ECoreType.Xray
|
||||
});
|
||||
}
|
||||
for (int k = 1; k <= config.coreTypeItem.Count; k++)
|
||||
|
||||
@@ -184,6 +184,28 @@ namespace v2rayN.Handler
|
||||
LazyConfig.Instance.SetConfig(ref config);
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// 保参数
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <returns></returns>
|
||||
public static int SaveConfig(ref Config config, bool reload = true)
|
||||
{
|
||||
Global.reloadV2ray = reload;
|
||||
|
||||
ToJsonFile(config);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 存储文件
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
private static void ToJsonFile(Config config)
|
||||
{
|
||||
Utils.ToJsonFile(config, Utils.GetPath(configRes));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -235,7 +257,7 @@ namespace v2rayN.Handler
|
||||
var index = config.FindIndexId(item.indexId);
|
||||
if (index >= 0)
|
||||
{
|
||||
config.vmess.RemoveAt(index);
|
||||
RemoveVmessItem(config, index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,29 +345,6 @@ namespace v2rayN.Handler
|
||||
return config.vmess[index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保参数
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <returns></returns>
|
||||
public static int SaveConfig(ref Config config, bool reload = true)
|
||||
{
|
||||
Global.reloadV2ray = reload;
|
||||
|
||||
ToJsonFile(config);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 存储文件
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
private static void ToJsonFile(Config config)
|
||||
{
|
||||
Utils.ToJsonFile(config, Utils.GetPath(configRes));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移动服务器
|
||||
/// </summary>
|
||||
@@ -423,7 +422,7 @@ namespace v2rayN.Handler
|
||||
/// <param name="config"></param>
|
||||
/// <param name="vmessItem"></param>
|
||||
/// <returns></returns>
|
||||
public static int AddCustomServer(ref Config config, VmessItem vmessItem)
|
||||
public static int AddCustomServer(ref Config config, VmessItem vmessItem, bool blDelete)
|
||||
{
|
||||
var fileName = vmessItem.address;
|
||||
if (!File.Exists(fileName))
|
||||
@@ -436,7 +435,11 @@ namespace v2rayN.Handler
|
||||
|
||||
try
|
||||
{
|
||||
File.Copy(fileName, Path.Combine(Utils.GetTempPath(), newFileName));
|
||||
File.Copy(fileName, Path.Combine(Utils.GetConfigPath(), newFileName));
|
||||
if (blDelete)
|
||||
{
|
||||
File.Delete(fileName);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -485,7 +488,7 @@ namespace v2rayN.Handler
|
||||
vmessItem.id = vmessItem.id.TrimEx();
|
||||
vmessItem.security = vmessItem.security.TrimEx();
|
||||
|
||||
if (!config.GetShadowsocksSecuritys().Contains(vmessItem.security))
|
||||
if (!LazyConfig.Instance.GetShadowsocksSecuritys().Contains(vmessItem.security))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -522,7 +525,6 @@ namespace v2rayN.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加服务器或编辑
|
||||
/// </summary>
|
||||
@@ -619,178 +621,6 @@ namespace v2rayN.Handler
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加服务器
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="clipboardData"></param>
|
||||
/// <param name="subid"></param>
|
||||
/// <returns>成功导入的数量</returns>
|
||||
public static int AddBatchServers(ref Config config, string clipboardData, string subid, List<VmessItem> lstOriSub, string groupId)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(clipboardData))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
//copy sub items
|
||||
if (!Utils.IsNullOrEmpty(subid))
|
||||
{
|
||||
RemoveServerViaSubid(ref config, subid);
|
||||
}
|
||||
//if (clipboardData.IndexOf("vmess") >= 0 && clipboardData.IndexOf("vmess") == clipboardData.LastIndexOf("vmess"))
|
||||
//{
|
||||
// clipboardData = clipboardData.Replace("\r\n", "").Replace("\n", "");
|
||||
//}
|
||||
int countServers = 0;
|
||||
|
||||
//string[] arrData = clipboardData.Split(new string[] { "\r\n" }, StringSplitOptions.None);
|
||||
string[] arrData = clipboardData.Split(Environment.NewLine.ToCharArray());
|
||||
foreach (string str in arrData)
|
||||
{
|
||||
//maybe sub
|
||||
if (Utils.IsNullOrEmpty(subid) && (str.StartsWith(Global.httpsProtocol) || str.StartsWith(Global.httpProtocol)))
|
||||
{
|
||||
if (AddSubItem(ref config, str) == 0)
|
||||
{
|
||||
countServers++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
VmessItem vmessItem = ShareHandler.ImportFromClipboardConfig(str, out string msg);
|
||||
if (vmessItem == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//exist sub items
|
||||
if (!Utils.IsNullOrEmpty(subid))
|
||||
{
|
||||
var existItem = lstOriSub?.FirstOrDefault(t => CompareVmessItem(t, vmessItem, true));
|
||||
if (existItem != null)
|
||||
{
|
||||
vmessItem = existItem;
|
||||
}
|
||||
vmessItem.subid = subid;
|
||||
}
|
||||
|
||||
//groupId
|
||||
vmessItem.groupId = groupId;
|
||||
|
||||
if (vmessItem.configType == EConfigType.Vmess)
|
||||
{
|
||||
if (AddServer(ref config, vmessItem, false) == 0)
|
||||
{
|
||||
countServers++;
|
||||
}
|
||||
}
|
||||
else if (vmessItem.configType == EConfigType.Shadowsocks)
|
||||
{
|
||||
if (AddShadowsocksServer(ref config, vmessItem, false) == 0)
|
||||
{
|
||||
countServers++;
|
||||
}
|
||||
}
|
||||
else if (vmessItem.configType == EConfigType.Socks)
|
||||
{
|
||||
if (AddSocksServer(ref config, vmessItem, false) == 0)
|
||||
{
|
||||
countServers++;
|
||||
}
|
||||
}
|
||||
else if (vmessItem.configType == EConfigType.Trojan)
|
||||
{
|
||||
if (AddTrojanServer(ref config, vmessItem, false) == 0)
|
||||
{
|
||||
countServers++;
|
||||
}
|
||||
}
|
||||
else if (vmessItem.configType == EConfigType.VLESS)
|
||||
{
|
||||
if (AddVlessServer(ref config, vmessItem, false) == 0)
|
||||
{
|
||||
countServers++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ToJsonFile(config);
|
||||
return countServers;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add sub
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public static int AddSubItem(ref Config config, string url)
|
||||
{
|
||||
//already exists
|
||||
if (config.subItem.FindIndex(e => e.url == url) >= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SubItem subItem = new SubItem
|
||||
{
|
||||
id = string.Empty,
|
||||
remarks = "import sub",
|
||||
url = url
|
||||
};
|
||||
config.subItem.Add(subItem);
|
||||
|
||||
return SaveSubItem(ref config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// save sub
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <returns></returns>
|
||||
public static int SaveSubItem(ref Config config)
|
||||
{
|
||||
if (config.subItem == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
foreach (SubItem item in config.subItem)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(item.id))
|
||||
{
|
||||
item.id = Utils.GetGUID(false);
|
||||
}
|
||||
}
|
||||
|
||||
ToJsonFile(config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除服务器
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="subid"></param>
|
||||
/// <returns></returns>
|
||||
public static int RemoveServerViaSubid(ref Config config, string subid)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(subid) || config.vmess.Count <= 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (int k = config.vmess.Count - 1; k >= 0; k--)
|
||||
{
|
||||
if (config.vmess[k].subid.Equals(subid))
|
||||
{
|
||||
config.vmess.RemoveAt(k);
|
||||
}
|
||||
}
|
||||
|
||||
ToJsonFile(config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int SortServers(ref Config config, ref List<VmessItem> lstVmess, EServerColName name, bool asc)
|
||||
{
|
||||
if (lstVmess.Count <= 0)
|
||||
@@ -884,14 +714,14 @@ namespace v2rayN.Handler
|
||||
var index = config.FindIndexId(item.indexId);
|
||||
if (index >= 0)
|
||||
{
|
||||
config.vmess.RemoveAt(index);
|
||||
RemoveVmessItem(config, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
//if (!keepOlder) list.Reverse();
|
||||
//config.vmess = list;
|
||||
|
||||
return 0;
|
||||
return list.Count;
|
||||
}
|
||||
|
||||
public static int AddServerCommon(ref Config config, VmessItem vmessItem)
|
||||
@@ -949,6 +779,291 @@ namespace v2rayN.Handler
|
||||
&& (remarks ? o.remarks == n.remarks : true);
|
||||
}
|
||||
|
||||
private static int RemoveVmessItem(Config config, int index)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (config.vmess[index].configType == EConfigType.Custom)
|
||||
{
|
||||
File.Delete(Utils.GetConfigPath(config.vmess[index].address));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.SaveLog("RemoveVmessItem", ex);
|
||||
}
|
||||
config.vmess.RemoveAt(index);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Batch add servers
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加服务器
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="clipboardData"></param>
|
||||
/// <param name="subid"></param>
|
||||
/// <returns>成功导入的数量</returns>
|
||||
private static int AddBatchServers(ref Config config, string clipboardData, string subid, List<VmessItem> lstOriSub, string groupId)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(clipboardData))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
//copy sub items
|
||||
if (!Utils.IsNullOrEmpty(subid))
|
||||
{
|
||||
RemoveServerViaSubid(ref config, subid);
|
||||
}
|
||||
//if (clipboardData.IndexOf("vmess") >= 0 && clipboardData.IndexOf("vmess") == clipboardData.LastIndexOf("vmess"))
|
||||
//{
|
||||
// clipboardData = clipboardData.Replace("\r\n", "").Replace("\n", "");
|
||||
//}
|
||||
int countServers = 0;
|
||||
|
||||
//string[] arrData = clipboardData.Split(new string[] { "\r\n" }, StringSplitOptions.None);
|
||||
string[] arrData = clipboardData.Split(Environment.NewLine.ToCharArray());
|
||||
foreach (string str in arrData)
|
||||
{
|
||||
//maybe sub
|
||||
if (Utils.IsNullOrEmpty(subid) && (str.StartsWith(Global.httpsProtocol) || str.StartsWith(Global.httpProtocol)))
|
||||
{
|
||||
if (AddSubItem(ref config, str) == 0)
|
||||
{
|
||||
countServers++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
VmessItem vmessItem = ShareHandler.ImportFromClipboardConfig(str, out string msg);
|
||||
if (vmessItem == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//exist sub items
|
||||
if (!Utils.IsNullOrEmpty(subid))
|
||||
{
|
||||
var existItem = lstOriSub?.FirstOrDefault(t => CompareVmessItem(t, vmessItem, true));
|
||||
if (existItem != null)
|
||||
{
|
||||
vmessItem = existItem;
|
||||
}
|
||||
vmessItem.subid = subid;
|
||||
}
|
||||
|
||||
//groupId
|
||||
vmessItem.groupId = groupId;
|
||||
|
||||
if (vmessItem.configType == EConfigType.Vmess)
|
||||
{
|
||||
if (AddServer(ref config, vmessItem, false) == 0)
|
||||
{
|
||||
countServers++;
|
||||
}
|
||||
}
|
||||
else if (vmessItem.configType == EConfigType.Shadowsocks)
|
||||
{
|
||||
if (AddShadowsocksServer(ref config, vmessItem, false) == 0)
|
||||
{
|
||||
countServers++;
|
||||
}
|
||||
}
|
||||
else if (vmessItem.configType == EConfigType.Socks)
|
||||
{
|
||||
if (AddSocksServer(ref config, vmessItem, false) == 0)
|
||||
{
|
||||
countServers++;
|
||||
}
|
||||
}
|
||||
else if (vmessItem.configType == EConfigType.Trojan)
|
||||
{
|
||||
if (AddTrojanServer(ref config, vmessItem, false) == 0)
|
||||
{
|
||||
countServers++;
|
||||
}
|
||||
}
|
||||
else if (vmessItem.configType == EConfigType.VLESS)
|
||||
{
|
||||
if (AddVlessServer(ref config, vmessItem, false) == 0)
|
||||
{
|
||||
countServers++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ToJsonFile(config);
|
||||
return countServers;
|
||||
}
|
||||
|
||||
private static int AddBatchServers4Custom(ref Config config, string clipboardData, string subid, List<VmessItem> lstOriSub, string groupId)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(clipboardData))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
VmessItem vmessItem = new VmessItem();
|
||||
//Is v2ray configuration
|
||||
V2rayConfig v2rayConfig = Utils.FromJson<V2rayConfig>(clipboardData);
|
||||
if (v2rayConfig != null
|
||||
&& v2rayConfig.inbounds != null
|
||||
&& v2rayConfig.inbounds.Count > 0
|
||||
&& v2rayConfig.outbounds != null
|
||||
&& v2rayConfig.outbounds.Count > 0)
|
||||
{
|
||||
var fileName = Utils.GetTempPath($"{Utils.GetGUID(false)}.json");
|
||||
File.WriteAllText(fileName, clipboardData);
|
||||
|
||||
vmessItem.coreType = ECoreType.Xray;
|
||||
vmessItem.address = fileName;
|
||||
vmessItem.remarks = "v2ray_custom";
|
||||
}
|
||||
//Is Clash configuration
|
||||
else if (clipboardData.IndexOf("port") >= 0
|
||||
&& clipboardData.IndexOf("socks-port") >= 0
|
||||
&& clipboardData.IndexOf("proxies") >= 0)
|
||||
{
|
||||
var fileName = Utils.GetTempPath($"{Utils.GetGUID(false)}.yaml");
|
||||
File.WriteAllText(fileName, clipboardData);
|
||||
|
||||
vmessItem.coreType = ECoreType.clash;
|
||||
vmessItem.address = fileName;
|
||||
vmessItem.remarks = "clash_custom";
|
||||
}
|
||||
|
||||
if (!Utils.IsNullOrEmpty(subid))
|
||||
{
|
||||
RemoveServerViaSubid(ref config, subid);
|
||||
}
|
||||
if (lstOriSub != null && lstOriSub.Count == 1)
|
||||
{
|
||||
vmessItem.indexId = lstOriSub[0].indexId;
|
||||
}
|
||||
vmessItem.subid = subid;
|
||||
vmessItem.groupId = groupId;
|
||||
|
||||
if (Utils.IsNullOrEmpty(vmessItem.address))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (AddCustomServer(ref config, vmessItem, true) == 0)
|
||||
{
|
||||
return 1;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static int AddBatchServers(ref Config config, string clipboardData, string subid, string groupId)
|
||||
{
|
||||
List<VmessItem> lstOriSub = null;
|
||||
if (!Utils.IsNullOrEmpty(subid))
|
||||
{
|
||||
lstOriSub = config.vmess.Where(it => it.subid == subid).ToList();
|
||||
}
|
||||
|
||||
int counter = AddBatchServers(ref config, clipboardData, subid, lstOriSub, groupId);
|
||||
if (counter < 1)
|
||||
{
|
||||
counter = AddBatchServers(ref config, Utils.Base64Decode(clipboardData), subid, lstOriSub, groupId);
|
||||
}
|
||||
|
||||
//maybe other sub
|
||||
if (counter < 1)
|
||||
{
|
||||
counter = AddBatchServers4Custom(ref config, clipboardData, subid, lstOriSub, groupId);
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sub & Group
|
||||
|
||||
/// <summary>
|
||||
/// add sub
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public static int AddSubItem(ref Config config, string url)
|
||||
{
|
||||
//already exists
|
||||
if (config.subItem.FindIndex(e => e.url == url) >= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SubItem subItem = new SubItem
|
||||
{
|
||||
id = string.Empty,
|
||||
remarks = "import sub",
|
||||
url = url
|
||||
};
|
||||
config.subItem.Add(subItem);
|
||||
|
||||
return SaveSubItem(ref config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// save sub
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <returns></returns>
|
||||
public static int SaveSubItem(ref Config config)
|
||||
{
|
||||
if (config.subItem == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
foreach (SubItem item in config.subItem)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(item.id))
|
||||
{
|
||||
item.id = Utils.GetGUID(false);
|
||||
}
|
||||
}
|
||||
|
||||
ToJsonFile(config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除服务器
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="subid"></param>
|
||||
/// <returns></returns>
|
||||
public static int RemoveServerViaSubid(ref Config config, string subid)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(subid) || config.vmess.Count <= 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (int k = config.vmess.Count - 1; k >= 0; k--)
|
||||
{
|
||||
if (config.vmess[k].subid.Equals(subid))
|
||||
{
|
||||
RemoveVmessItem(config, k);
|
||||
}
|
||||
}
|
||||
|
||||
ToJsonFile(config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// save Group
|
||||
/// </summary>
|
||||
@@ -999,6 +1114,8 @@ namespace v2rayN.Handler
|
||||
ToJsonFile(config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using v2rayN.Base;
|
||||
|
||||
namespace v2rayN.Handler
|
||||
@@ -139,6 +140,7 @@ namespace v2rayN.Handler
|
||||
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13);
|
||||
|
||||
WebClientEx ws = new WebClientEx();
|
||||
ws.Encoding = Encoding.UTF8;
|
||||
if (webProxy != null)
|
||||
{
|
||||
ws.Proxy = webProxy;
|
||||
@@ -197,7 +199,7 @@ namespace v2rayN.Handler
|
||||
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13);
|
||||
|
||||
WebClientEx ws = new WebClientEx();
|
||||
|
||||
ws.Encoding = Encoding.UTF8;
|
||||
return ws.DownloadString(new Uri(url));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using v2rayN.Mode;
|
||||
using System.Linq;
|
||||
|
||||
namespace v2rayN.Handler
|
||||
{
|
||||
@@ -20,5 +22,34 @@ namespace v2rayN.Handler
|
||||
{
|
||||
return _config;
|
||||
}
|
||||
|
||||
public List<string> GetShadowsocksSecuritys()
|
||||
{
|
||||
if (GetCoreType(null, EConfigType.Shadowsocks) == ECoreType.v2fly)
|
||||
{
|
||||
return Global.ssSecuritys;
|
||||
}
|
||||
|
||||
return Global.ssSecuritysInXray;
|
||||
}
|
||||
|
||||
public ECoreType GetCoreType(VmessItem vmessItem, EConfigType eConfigType)
|
||||
{
|
||||
if (vmessItem != null && vmessItem.coreType != null)
|
||||
{
|
||||
return (ECoreType)vmessItem.coreType;
|
||||
}
|
||||
|
||||
if (_config.coreTypeItem == null)
|
||||
{
|
||||
return ECoreType.Xray;
|
||||
}
|
||||
var item = _config.coreTypeItem.FirstOrDefault(it => it.configType == eConfigType);
|
||||
if (item == null)
|
||||
{
|
||||
return ECoreType.Xray;
|
||||
}
|
||||
return item.coreType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace v2rayN.Handler
|
||||
if (!Utils.IsNullOrEmpty(item.customIcon) && File.Exists(item.customIcon))
|
||||
{
|
||||
graphics.FillRectangle(drawBrush, new Rectangle(0, 0, width, height));
|
||||
graphics.DrawImage(new Bitmap(item.customIcon), 0, 0);
|
||||
graphics.DrawImage(new Bitmap(item.customIcon), 0, 0, width, height);
|
||||
customIcon = true;
|
||||
}
|
||||
}
|
||||
@@ -159,29 +159,12 @@ namespace v2rayN.Handler
|
||||
}
|
||||
}
|
||||
|
||||
public int AddBatchServers(Config config, string clipboardData, string subid, string groupId)
|
||||
{
|
||||
List<VmessItem> lstOriSub = null;
|
||||
if (!Utils.IsNullOrEmpty(subid))
|
||||
{
|
||||
lstOriSub = config.vmess.Where(it => it.subid == subid).ToList();
|
||||
}
|
||||
|
||||
int counter = ConfigHandler.AddBatchServers(ref config, clipboardData, subid, lstOriSub, groupId);
|
||||
if (counter < 1)
|
||||
{
|
||||
counter = ConfigHandler.AddBatchServers(ref config, Utils.Base64Decode(clipboardData), subid, lstOriSub, groupId);
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
public void BackupGuiNConfig(Config config, bool auto = false)
|
||||
{
|
||||
string fileName = $"guiNConfig_{DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff")}.json";
|
||||
if (auto)
|
||||
{
|
||||
fileName = Utils.GetTempPath(fileName);
|
||||
fileName = Utils.GetBackupPath(fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -210,7 +210,7 @@ namespace v2rayN.Handler
|
||||
//ConfigHandler.RemoveServerViaSubid(ref config, id);
|
||||
//_updateFunc(false, $"{hashCode}{UIRes.I18N("MsgClearSubscription")}");
|
||||
// RefreshServers();
|
||||
int ret = MainFormHandler.Instance.AddBatchServers(config, result, id, groupId);
|
||||
int ret = ConfigHandler.AddBatchServers(ref config, result, id, groupId);
|
||||
if (ret > 0)
|
||||
{
|
||||
// RefreshServers();
|
||||
|
||||
@@ -400,7 +400,7 @@ namespace v2rayN.Handler
|
||||
serversItem.address = node.address;
|
||||
serversItem.port = node.port;
|
||||
serversItem.password = node.id;
|
||||
if (config.GetShadowsocksSecuritys().Contains(node.security))
|
||||
if (LazyConfig.Instance.GetShadowsocksSecuritys().Contains(node.security))
|
||||
{
|
||||
serversItem.method = node.security;
|
||||
}
|
||||
@@ -912,7 +912,7 @@ namespace v2rayN.Handler
|
||||
string addressFileName = node.address;
|
||||
if (!File.Exists(addressFileName))
|
||||
{
|
||||
addressFileName = Path.Combine(Utils.GetTempPath(), addressFileName);
|
||||
addressFileName = Path.Combine(Utils.GetConfigPath(), addressFileName);
|
||||
}
|
||||
if (!File.Exists(addressFileName))
|
||||
{
|
||||
|
||||
@@ -332,11 +332,7 @@ namespace v2rayN.Handler
|
||||
{
|
||||
return;
|
||||
}
|
||||
var coreType = config.GetCoreType(item.configType);
|
||||
if (item.coreType != null)
|
||||
{
|
||||
coreType = (ECoreType)item.coreType;
|
||||
}
|
||||
var coreType = LazyConfig.Instance.GetCoreType(item, item.configType);
|
||||
|
||||
if (coreType == ECoreType.v2fly)
|
||||
{
|
||||
|
||||
@@ -256,16 +256,6 @@ namespace v2rayN.Mode
|
||||
return vmess.FirstOrDefault(it => it.indexId == id);
|
||||
}
|
||||
|
||||
public List<string> GetShadowsocksSecuritys()
|
||||
{
|
||||
if (GetCoreType(EConfigType.Shadowsocks) == ECoreType.v2fly)
|
||||
{
|
||||
return Global.ssSecuritys;
|
||||
}
|
||||
|
||||
return Global.ssSecuritysInXray;
|
||||
}
|
||||
|
||||
public bool IsActiveNode(VmessItem item)
|
||||
{
|
||||
if (!Utils.IsNullOrEmpty(item.indexId) && item.indexId == indexId)
|
||||
@@ -285,19 +275,6 @@ namespace v2rayN.Mode
|
||||
return groupItem.Where(it => it.id == groupId).FirstOrDefault()?.remarks;
|
||||
}
|
||||
|
||||
public ECoreType GetCoreType(EConfigType eConfigType)
|
||||
{
|
||||
if (coreTypeItem == null)
|
||||
{
|
||||
return ECoreType.v2fly;
|
||||
}
|
||||
var item = coreTypeItem.FirstOrDefault(it => it.configType == eConfigType);
|
||||
if (item == null)
|
||||
{
|
||||
return ECoreType.v2fly;
|
||||
}
|
||||
return item.coreType;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -358,7 +335,7 @@ namespace v2rayN.Mode
|
||||
break;
|
||||
default:
|
||||
summary += string.Format("{0}", remarks);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
|
||||
@@ -32,4 +32,4 @@ using System.Runtime.InteropServices;
|
||||
// 方法是按如下所示使用“*”:
|
||||
//[assembly: AssemblyVersion("1.0.*")]
|
||||
//[assembly: AssemblyVersion("1.0.0")]
|
||||
[assembly: AssemblyFileVersion("5.4")]
|
||||
[assembly: AssemblyFileVersion("5.5")]
|
||||
|
||||
2
v2rayN/v2rayN/Resx/ResUI.Designer.cs
generated
2
v2rayN/v2rayN/Resx/ResUI.Designer.cs
generated
@@ -115,7 +115,7 @@ namespace v2rayN.Resx {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Note that custom configuration relies entirely on your own configuration and does not work with all settings. The system agent is available when the socks port is equal to the port in the settings in the custom configuration inbound. 的本地化字符串。
|
||||
/// 查找类似 Note that custom configuration relies entirely on your own configuration and does not work with all settings. If you want to use the system proxy, please modify the listening port manually. 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string CustomServerTips {
|
||||
get {
|
||||
|
||||
@@ -130,7 +130,7 @@
|
||||
<value> configuration format is incorrect</value>
|
||||
</data>
|
||||
<data name="CustomServerTips" xml:space="preserve">
|
||||
<value>Note that custom configuration relies entirely on your own configuration and does not work with all settings. The system agent is available when the socks port is equal to the port in the settings in the custom configuration inbound.</value>
|
||||
<value>Note that custom configuration relies entirely on your own configuration and does not work with all settings. If you want to use the system proxy, please modify the listening port manually.</value>
|
||||
</data>
|
||||
<data name="Downloading" xml:space="preserve">
|
||||
<value>Downloading...</value>
|
||||
|
||||
@@ -130,7 +130,7 @@
|
||||
<value>配置格式不正确</value>
|
||||
</data>
|
||||
<data name="CustomServerTips" xml:space="preserve">
|
||||
<value>注意,自定义配置完全依赖您自己的配置,不能使用所有设置功能。在自定义配置inbound中有socks port等于设置中的port时,系统代理才可用</value>
|
||||
<value>注意,自定义配置完全依赖您自己的配置,不能使用所有设置功能。如需使用系统代理请手工修改监听端口。</value>
|
||||
</data>
|
||||
<data name="Downloading" xml:space="preserve">
|
||||
<value>下载开始...</value>
|
||||
|
||||
@@ -943,19 +943,21 @@ namespace v2rayN
|
||||
#region TempPath
|
||||
|
||||
// return path to store temporary files
|
||||
public static string GetTempPath()
|
||||
public static string GetTempPath(string filename = "")
|
||||
{
|
||||
string _tempPath = Path.Combine(StartupPath(), "v2ray_win_temp");
|
||||
if (!Directory.Exists(_tempPath))
|
||||
{
|
||||
Directory.CreateDirectory(_tempPath);
|
||||
}
|
||||
return _tempPath;
|
||||
}
|
||||
|
||||
public static string GetTempPath(string filename)
|
||||
{
|
||||
return Path.Combine(GetTempPath(), filename);
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
{
|
||||
return _tempPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Path.Combine(_tempPath, filename);
|
||||
}
|
||||
}
|
||||
|
||||
public static string UnGzip(byte[] buf)
|
||||
@@ -970,6 +972,32 @@ namespace v2rayN
|
||||
return Encoding.UTF8.GetString(sb.ToArray());
|
||||
}
|
||||
|
||||
public static string GetBackupPath(string filename)
|
||||
{
|
||||
string _tempPath = Path.Combine(StartupPath(), "guiBackups");
|
||||
if (!Directory.Exists(_tempPath))
|
||||
{
|
||||
Directory.CreateDirectory(_tempPath);
|
||||
}
|
||||
return Path.Combine(_tempPath, filename);
|
||||
}
|
||||
public static string GetConfigPath(string filename = "")
|
||||
{
|
||||
string _tempPath = Path.Combine(StartupPath(), "guiConfigs");
|
||||
if (!Directory.Exists(_tempPath))
|
||||
{
|
||||
Directory.CreateDirectory(_tempPath);
|
||||
}
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
{
|
||||
return _tempPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Path.Combine(_tempPath, filename);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Log
|
||||
|
||||
Reference in New Issue
Block a user