Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cdc83bc9d7 | ||
|
|
70feacd276 | ||
|
|
ece4572058 | ||
|
|
4d16a5e801 | ||
|
|
1493a8b03f |
@@ -1,10 +1,13 @@
|
|||||||
using System.Drawing;
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace v2rayN.Base
|
namespace v2rayN.Base
|
||||||
{
|
{
|
||||||
class ListViewFlickerFree : ListView
|
class ListViewFlickerFree : ListView
|
||||||
{
|
{
|
||||||
|
Action<int, int> _updateFunc;
|
||||||
|
|
||||||
public ListViewFlickerFree()
|
public ListViewFlickerFree()
|
||||||
{
|
{
|
||||||
SetStyle(ControlStyles.OptimizedDoubleBuffer
|
SetStyle(ControlStyles.OptimizedDoubleBuffer
|
||||||
@@ -13,40 +16,82 @@ namespace v2rayN.Base
|
|||||||
UpdateStyles();
|
UpdateStyles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RegisterDragEvent(Action<int, int> _update)
|
||||||
public void AutoResizeColumns()
|
|
||||||
{
|
{
|
||||||
try
|
_updateFunc = _update;
|
||||||
{
|
this.AllowDrop = true;
|
||||||
this.SuspendLayout();
|
|
||||||
Graphics graphics = this.CreateGraphics();
|
|
||||||
|
|
||||||
// 原生 ColumnHeaderAutoResizeStyle.ColumnContent 将忽略列头宽度
|
this.ItemDrag += new ItemDragEventHandler(this.lv_ItemDrag);
|
||||||
this.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
|
this.DragDrop += new DragEventHandler(this.lv_DragDrop);
|
||||||
|
this.DragEnter += new DragEventHandler(this.lv_DragEnter);
|
||||||
for (int i = 0; i < this.Columns.Count; i++)
|
this.DragOver += new DragEventHandler(this.lv_DragOver);
|
||||||
{
|
this.DragLeave += new EventHandler(this.lv_DragLeave);
|
||||||
ColumnHeader c = this.Columns[i];
|
|
||||||
int cWidth = c.Width;
|
|
||||||
string MaxStr = "";
|
|
||||||
Font font = this.Items[0].SubItems[0].Font;
|
|
||||||
|
|
||||||
foreach (ListViewItem item in this.Items)
|
|
||||||
{
|
|
||||||
// 整行视作相同字形,不单独计算每个单元格
|
|
||||||
font = item.SubItems[i].Font;
|
|
||||||
string str = item.SubItems[i].Text;
|
|
||||||
if (str.Length > MaxStr.Length) // 未考虑非等宽问题
|
|
||||||
MaxStr = str;
|
|
||||||
}
|
}
|
||||||
int strWidth = (int)graphics.MeasureString(MaxStr, font).Width;
|
|
||||||
c.Width = System.Math.Max(cWidth, strWidth);
|
private void lv_DragDrop(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
int targetIndex = this.InsertionMark.Index;
|
||||||
|
if (targetIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this.ResumeLayout();
|
if (this.InsertionMark.AppearsAfterItem)
|
||||||
}
|
{
|
||||||
catch { }
|
targetIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (this.SelectedIndices.Count <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_updateFunc(this.SelectedIndices[0], targetIndex);
|
||||||
|
|
||||||
|
//ListViewItem draggedItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
|
||||||
|
//this.BeginUpdate();
|
||||||
|
//this.Items.Insert(targetIndex, (ListViewItem)draggedItem.Clone());
|
||||||
|
//this.Items.Remove(draggedItem);
|
||||||
|
//this.EndUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void lv_DragEnter(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
e.Effect = e.AllowedEffect;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lv_DragLeave(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
this.InsertionMark.Index = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lv_DragOver(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
Point targetPoint = this.PointToClient(new Point(e.X, e.Y));
|
||||||
|
int targetIndex = this.InsertionMark.NearestIndex(targetPoint);
|
||||||
|
|
||||||
|
if (targetIndex > -1)
|
||||||
|
{
|
||||||
|
Rectangle itemBounds = this.GetItemRect(targetIndex);
|
||||||
|
this.EnsureVisible(targetIndex);
|
||||||
|
|
||||||
|
if (targetPoint.Y > itemBounds.Top + (itemBounds.Height / 2))
|
||||||
|
{
|
||||||
|
this.InsertionMark.AppearsAfterItem = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.InsertionMark.AppearsAfterItem = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.InsertionMark.Index = targetIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lv_ItemDrag(object sender, ItemDragEventArgs e)
|
||||||
|
{
|
||||||
|
this.DoDragDrop(e.Item, DragDropEffects.Move);
|
||||||
|
this.InsertionMark.Index = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,7 @@ namespace v2rayN.Forms
|
|||||||
{
|
{
|
||||||
cmbCoreType.Items.AddRange(Global.coreTypes.ToArray());
|
cmbCoreType.Items.AddRange(Global.coreTypes.ToArray());
|
||||||
cmbCoreType.Items.Add("clash");
|
cmbCoreType.Items.Add("clash");
|
||||||
|
cmbCoreType.Items.Add("hysteria");
|
||||||
cmbCoreType.Items.Add(string.Empty);
|
cmbCoreType.Items.Add(string.Empty);
|
||||||
|
|
||||||
txtAddress.ReadOnly = true;
|
txtAddress.ReadOnly = true;
|
||||||
|
|||||||
@@ -225,6 +225,7 @@ namespace v2rayN.Forms
|
|||||||
lvServers.Scrollable = true;
|
lvServers.Scrollable = true;
|
||||||
lvServers.MultiSelect = true;
|
lvServers.MultiSelect = true;
|
||||||
lvServers.HeaderStyle = ColumnHeaderStyle.Clickable;
|
lvServers.HeaderStyle = ColumnHeaderStyle.Clickable;
|
||||||
|
lvServers.RegisterDragEvent(UpdateDragEventHandler);
|
||||||
|
|
||||||
lvServers.Columns.Add("", 30);
|
lvServers.Columns.Add("", 30);
|
||||||
lvServers.Columns.Add(UIRes.I18N("LvServiceType"), 80);
|
lvServers.Columns.Add(UIRes.I18N("LvServiceType"), 80);
|
||||||
@@ -247,6 +248,18 @@ namespace v2rayN.Forms
|
|||||||
lvServers.EndUpdate();
|
lvServers.EndUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateDragEventHandler(int index, int targetIndex)
|
||||||
|
{
|
||||||
|
if (index < 0 || targetIndex < 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ConfigHandler.MoveServer(ref config, ref lstVmess, index, EMove.Position, targetIndex) == 0)
|
||||||
|
{
|
||||||
|
RefreshServers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 刷新服务器列表
|
/// 刷新服务器列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1379,15 +1392,15 @@ namespace v2rayN.Forms
|
|||||||
|
|
||||||
private void tsbCheckUpdateCore_Click(object sender, EventArgs e)
|
private void tsbCheckUpdateCore_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
CheckUpdateCore("v2fly");
|
CheckUpdateCore(ECoreType.v2fly);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tsbCheckUpdateXrayCore_Click(object sender, EventArgs e)
|
private void tsbCheckUpdateXrayCore_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
CheckUpdateCore("xray");
|
CheckUpdateCore(ECoreType.Xray);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckUpdateCore(string type)
|
private void CheckUpdateCore(ECoreType type)
|
||||||
{
|
{
|
||||||
void _updateUI(bool success, string msg)
|
void _updateUI(bool success, string msg)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ namespace v2rayN.Forms
|
|||||||
lvRoutings.View = View.Details;
|
lvRoutings.View = View.Details;
|
||||||
lvRoutings.MultiSelect = true;
|
lvRoutings.MultiSelect = true;
|
||||||
lvRoutings.HeaderStyle = ColumnHeaderStyle.Clickable;
|
lvRoutings.HeaderStyle = ColumnHeaderStyle.Clickable;
|
||||||
|
lvRoutings.RegisterDragEvent(UpdateDragEventHandler);
|
||||||
|
|
||||||
lvRoutings.Columns.Add("", 30);
|
lvRoutings.Columns.Add("", 30);
|
||||||
lvRoutings.Columns.Add("outboundTag", 80);
|
lvRoutings.Columns.Add("outboundTag", 80);
|
||||||
@@ -66,6 +67,17 @@ namespace v2rayN.Forms
|
|||||||
|
|
||||||
lvRoutings.EndUpdate();
|
lvRoutings.EndUpdate();
|
||||||
}
|
}
|
||||||
|
private void UpdateDragEventHandler(int index, int targetIndex)
|
||||||
|
{
|
||||||
|
if (index < 0 || targetIndex < 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ConfigHandler.MoveRoutingRule(ref routingItem, index, EMove.Position, targetIndex) == 0)
|
||||||
|
{
|
||||||
|
RefreshRoutingsView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void RefreshRoutingsView()
|
private void RefreshRoutingsView()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace v2rayN
|
|||||||
public const string xrayCoreUrl = "https://github.com/XTLS/Xray-core/releases";
|
public const string xrayCoreUrl = "https://github.com/XTLS/Xray-core/releases";
|
||||||
public const string NUrl = @"https://github.com/2dust/v2rayN/releases";
|
public const string NUrl = @"https://github.com/2dust/v2rayN/releases";
|
||||||
public const string clashCoreUrl = "https://github.com/Dreamacro/clash/releases";
|
public const string clashCoreUrl = "https://github.com/Dreamacro/clash/releases";
|
||||||
|
public const string hysteriaCoreUrl = "https://github.com/HyNetwork/hysteria/releases";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace v2rayN.Handler
|
|||||||
class ConfigHandler
|
class ConfigHandler
|
||||||
{
|
{
|
||||||
private static string configRes = Global.ConfigFileName;
|
private static string configRes = Global.ConfigFileName;
|
||||||
|
private static object objLock = new object();
|
||||||
|
|
||||||
#region ConfigHandler
|
#region ConfigHandler
|
||||||
|
|
||||||
@@ -203,9 +204,12 @@ namespace v2rayN.Handler
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="config"></param>
|
/// <param name="config"></param>
|
||||||
private static void ToJsonFile(Config config)
|
private static void ToJsonFile(Config config)
|
||||||
|
{
|
||||||
|
lock (objLock)
|
||||||
{
|
{
|
||||||
Utils.ToJsonFile(config, Utils.GetPath(configRes));
|
Utils.ToJsonFile(config, Utils.GetPath(configRes));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -353,7 +357,7 @@ namespace v2rayN.Handler
|
|||||||
/// <param name="index"></param>
|
/// <param name="index"></param>
|
||||||
/// <param name="eMove"></param>
|
/// <param name="eMove"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int MoveServer(ref Config config, ref List<VmessItem> lstVmess, int index, EMove eMove)
|
public static int MoveServer(ref Config config, ref List<VmessItem> lstVmess, int index, EMove eMove, int pos = -1)
|
||||||
{
|
{
|
||||||
int count = lstVmess.Count;
|
int count = lstVmess.Count;
|
||||||
if (index < 0 || index > lstVmess.Count - 1)
|
if (index < 0 || index > lstVmess.Count - 1)
|
||||||
@@ -409,6 +413,9 @@ namespace v2rayN.Handler
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case EMove.Position:
|
||||||
|
lstVmess[index].sort = pos * 10 + 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ToJsonFile(config);
|
ToJsonFile(config);
|
||||||
@@ -934,6 +941,15 @@ namespace v2rayN.Handler
|
|||||||
vmessItem.address = fileName;
|
vmessItem.address = fileName;
|
||||||
vmessItem.remarks = "clash_custom";
|
vmessItem.remarks = "clash_custom";
|
||||||
}
|
}
|
||||||
|
//Is Other configuration
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var fileName = Utils.GetTempPath($"{Utils.GetGUID(false)}.txt");
|
||||||
|
File.WriteAllText(fileName, clipboardData);
|
||||||
|
|
||||||
|
vmessItem.address = fileName;
|
||||||
|
vmessItem.remarks = "other_custom";
|
||||||
|
}
|
||||||
|
|
||||||
if (!Utils.IsNullOrEmpty(subid))
|
if (!Utils.IsNullOrEmpty(subid))
|
||||||
{
|
{
|
||||||
@@ -1258,7 +1274,7 @@ namespace v2rayN.Handler
|
|||||||
/// <param name="index"></param>
|
/// <param name="index"></param>
|
||||||
/// <param name="eMove"></param>
|
/// <param name="eMove"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int MoveRoutingRule(ref RoutingItem routingItem, int index, EMove eMove)
|
public static int MoveRoutingRule(ref RoutingItem routingItem, int index, EMove eMove, int pos = -1)
|
||||||
{
|
{
|
||||||
int count = routingItem.rules.Count;
|
int count = routingItem.rules.Count;
|
||||||
if (index < 0 || index > routingItem.rules.Count - 1)
|
if (index < 0 || index > routingItem.rules.Count - 1)
|
||||||
@@ -1316,6 +1332,14 @@ namespace v2rayN.Handler
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case EMove.Position:
|
||||||
|
{
|
||||||
|
var removeItem = routingItem.rules[index];
|
||||||
|
var item = Utils.DeepCopy(routingItem.rules[index]);
|
||||||
|
routingItem.rules.Insert(pos, item);
|
||||||
|
routingItem.rules.Remove(removeItem);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace v2rayN.Handler
|
|||||||
{
|
{
|
||||||
private static readonly Lazy<LazyConfig> _instance = new Lazy<LazyConfig>(() => new LazyConfig());
|
private static readonly Lazy<LazyConfig> _instance = new Lazy<LazyConfig>(() => new LazyConfig());
|
||||||
private Config _config;
|
private Config _config;
|
||||||
|
private List<CoreInfo> coreInfos;
|
||||||
|
|
||||||
public static LazyConfig Instance
|
public static LazyConfig Instance
|
||||||
{
|
{
|
||||||
@@ -51,5 +52,53 @@ namespace v2rayN.Handler
|
|||||||
}
|
}
|
||||||
return item.coreType;
|
return item.coreType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CoreInfo GetCoreInfo(ECoreType coreType)
|
||||||
|
{
|
||||||
|
if (coreInfos == null)
|
||||||
|
{
|
||||||
|
InitCoreInfo();
|
||||||
|
}
|
||||||
|
return coreInfos.Where(t => t.coreType == coreType).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitCoreInfo()
|
||||||
|
{
|
||||||
|
coreInfos = new List<CoreInfo>();
|
||||||
|
|
||||||
|
coreInfos.Add(new CoreInfo
|
||||||
|
{
|
||||||
|
coreType = ECoreType.v2fly,
|
||||||
|
coreExes = new List<string> { "wv2ray", "v2ray" },
|
||||||
|
arguments = "",
|
||||||
|
coreUrl = Global.v2flyCoreUrl
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
coreInfos.Add(new CoreInfo
|
||||||
|
{
|
||||||
|
coreType = ECoreType.Xray,
|
||||||
|
coreExes = new List<string> { "xray" },
|
||||||
|
arguments = "",
|
||||||
|
coreUrl = Global.xrayCoreUrl
|
||||||
|
});
|
||||||
|
|
||||||
|
coreInfos.Add(new CoreInfo
|
||||||
|
{
|
||||||
|
coreType = ECoreType.clash,
|
||||||
|
coreExes = new List<string> { "clash-windows-amd64", "clash-windows-386", "clash" },
|
||||||
|
arguments = "-f config.json",
|
||||||
|
coreUrl = Global.clashCoreUrl
|
||||||
|
});
|
||||||
|
|
||||||
|
coreInfos.Add(new CoreInfo
|
||||||
|
{
|
||||||
|
coreType = ECoreType.hysteria,
|
||||||
|
coreExes = new List<string> { "hysteria-tun-windows-6.0-amd64", "hysteria-tun-windows-6.0-386", "hysteria" },
|
||||||
|
arguments = "",
|
||||||
|
coreUrl = Global.hysteriaCoreUrl
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,11 +104,11 @@ namespace v2rayN.Handler
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
_updateFunc(false, string.Format(UIRes.I18N("MsgStartUpdating"), "v2rayN"));
|
_updateFunc(false, string.Format(UIRes.I18N("MsgStartUpdating"), "v2rayN"));
|
||||||
CheckUpdateAsync("v2rayN");
|
CheckUpdateAsync(ECoreType.v2rayN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void CheckUpdateCore(string type, Config config, Action<bool, string> update)
|
public void CheckUpdateCore(ECoreType type, Config config, Action<bool, string> update)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_updateFunc = update;
|
_updateFunc = update;
|
||||||
@@ -292,7 +292,7 @@ namespace v2rayN.Handler
|
|||||||
|
|
||||||
#region private
|
#region private
|
||||||
|
|
||||||
private async void CheckUpdateAsync(string type)
|
private async void CheckUpdateAsync(ECoreType type)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -310,15 +310,15 @@ namespace v2rayN.Handler
|
|||||||
HttpClient httpClient = new HttpClient(webRequestHandler);
|
HttpClient httpClient = new HttpClient(webRequestHandler);
|
||||||
|
|
||||||
string url;
|
string url;
|
||||||
if (type == "v2fly")
|
if (type == ECoreType.v2fly)
|
||||||
{
|
{
|
||||||
url = v2flyCoreLatestUrl;
|
url = v2flyCoreLatestUrl;
|
||||||
}
|
}
|
||||||
else if (type == "xray")
|
else if (type == ECoreType.Xray)
|
||||||
{
|
{
|
||||||
url = xrayCoreLatestUrl;
|
url = xrayCoreLatestUrl;
|
||||||
}
|
}
|
||||||
else if (type == "v2rayN")
|
else if (type == ECoreType.v2rayN)
|
||||||
{
|
{
|
||||||
url = nLatestUrl;
|
url = nLatestUrl;
|
||||||
}
|
}
|
||||||
@@ -347,18 +347,18 @@ namespace v2rayN.Handler
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取V2RayCore版本
|
/// 获取V2RayCore版本
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private string getCoreVersion(string type)
|
private string getCoreVersion(ECoreType type)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var core = string.Empty;
|
var core = string.Empty;
|
||||||
var match = string.Empty;
|
var match = string.Empty;
|
||||||
if (type == "v2fly")
|
if (type == ECoreType.v2fly)
|
||||||
{
|
{
|
||||||
core = "v2ray.exe";
|
core = "v2ray.exe";
|
||||||
match = "V2Ray";
|
match = "V2Ray";
|
||||||
}
|
}
|
||||||
else if (type == "xray")
|
else if (type == ECoreType.Xray)
|
||||||
{
|
{
|
||||||
core = "xray.exe";
|
core = "xray.exe";
|
||||||
match = "Xray";
|
match = "Xray";
|
||||||
@@ -392,7 +392,7 @@ namespace v2rayN.Handler
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void responseHandler(string type, string redirectUrl)
|
private void responseHandler(ECoreType type, string redirectUrl)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -401,21 +401,21 @@ namespace v2rayN.Handler
|
|||||||
string curVersion;
|
string curVersion;
|
||||||
string message;
|
string message;
|
||||||
string url;
|
string url;
|
||||||
if (type == "v2fly")
|
if (type == ECoreType.v2fly)
|
||||||
{
|
{
|
||||||
curVersion = "v" + getCoreVersion(type);
|
curVersion = "v" + getCoreVersion(type);
|
||||||
message = string.Format(UIRes.I18N("IsLatestCore"), curVersion);
|
message = string.Format(UIRes.I18N("IsLatestCore"), curVersion);
|
||||||
string osBit = Environment.Is64BitProcess ? "64" : "32";
|
string osBit = Environment.Is64BitProcess ? "64" : "32";
|
||||||
url = string.Format(v2flyCoreUrl, version, osBit);
|
url = string.Format(v2flyCoreUrl, version, osBit);
|
||||||
}
|
}
|
||||||
else if (type == "xray")
|
else if (type == ECoreType.Xray)
|
||||||
{
|
{
|
||||||
curVersion = "v" + getCoreVersion(type);
|
curVersion = "v" + getCoreVersion(type);
|
||||||
message = string.Format(UIRes.I18N("IsLatestCore"), curVersion);
|
message = string.Format(UIRes.I18N("IsLatestCore"), curVersion);
|
||||||
string osBit = Environment.Is64BitProcess ? "64" : "32";
|
string osBit = Environment.Is64BitProcess ? "64" : "32";
|
||||||
url = string.Format(xrayCoreUrl, version, osBit);
|
url = string.Format(xrayCoreUrl, version, osBit);
|
||||||
}
|
}
|
||||||
else if (type == "v2rayN")
|
else if (type == ECoreType.v2rayN)
|
||||||
{
|
{
|
||||||
curVersion = FileVersionInfo.GetVersionInfo(Utils.GetExePath()).FileVersion.ToString();
|
curVersion = FileVersionInfo.GetVersionInfo(Utils.GetExePath()).FileVersion.ToString();
|
||||||
message = string.Format(UIRes.I18N("IsLatestN"), curVersion);
|
message = string.Format(UIRes.I18N("IsLatestN"), curVersion);
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ namespace v2rayN.Handler
|
|||||||
inbound2.protocol = Global.InboundHttp;
|
inbound2.protocol = Global.InboundHttp;
|
||||||
inbound2.listen = inbound.listen;
|
inbound2.listen = inbound.listen;
|
||||||
inbound2.settings.allowTransparent = false;
|
inbound2.settings.allowTransparent = false;
|
||||||
|
inbound2.sniffing.enabled = inbound.sniffing.enabled;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,9 +21,7 @@ namespace v2rayN.Handler
|
|||||||
class V2rayHandler
|
class V2rayHandler
|
||||||
{
|
{
|
||||||
private static string v2rayConfigRes = Global.v2rayConfigFileName;
|
private static string v2rayConfigRes = Global.v2rayConfigFileName;
|
||||||
private List<string> lstCore;
|
private CoreInfo coreInfo;
|
||||||
private string coreUrl;
|
|
||||||
private string coreArguments;
|
|
||||||
public event ProcessDelegate ProcessEvent;
|
public event ProcessDelegate ProcessEvent;
|
||||||
//private int processId = 0;
|
//private int processId = 0;
|
||||||
private Process _process;
|
private Process _process;
|
||||||
@@ -46,7 +44,11 @@ namespace v2rayN.Handler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetCore(config, item);
|
if (SetCore(config, item) != 0)
|
||||||
|
{
|
||||||
|
ShowMsg(false, UIRes.I18N("CheckServerSettings"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
string fileName = Utils.GetPath(v2rayConfigRes);
|
string fileName = Utils.GetPath(v2rayConfigRes);
|
||||||
if (V2rayConfigHandler.GenerateClientConfig(item, fileName, false, out string msg) != 0)
|
if (V2rayConfigHandler.GenerateClientConfig(item, fileName, false, out string msg) != 0)
|
||||||
{
|
{
|
||||||
@@ -106,7 +108,7 @@ namespace v2rayN.Handler
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (string vName in lstCore)
|
foreach (string vName in coreInfo.coreExes)
|
||||||
{
|
{
|
||||||
Process[] existing = Process.GetProcessesByName(vName);
|
Process[] existing = Process.GetProcessesByName(vName);
|
||||||
foreach (Process p in existing)
|
foreach (Process p in existing)
|
||||||
@@ -178,7 +180,7 @@ namespace v2rayN.Handler
|
|||||||
}
|
}
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (Utils.IsNullOrEmpty(fileName))
|
||||||
{
|
{
|
||||||
string msg = string.Format(UIRes.I18N("NotFoundCore"), coreUrl);
|
string msg = string.Format(UIRes.I18N("NotFoundCore"), coreInfo.coreUrl);
|
||||||
ShowMsg(false, msg);
|
ShowMsg(false, msg);
|
||||||
}
|
}
|
||||||
return fileName;
|
return fileName;
|
||||||
@@ -193,7 +195,7 @@ namespace v2rayN.Handler
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string fileName = V2rayFindexe(lstCore);
|
string fileName = V2rayFindexe(coreInfo.coreExes);
|
||||||
if (fileName == "") return;
|
if (fileName == "") return;
|
||||||
|
|
||||||
Process p = new Process
|
Process p = new Process
|
||||||
@@ -201,7 +203,7 @@ namespace v2rayN.Handler
|
|||||||
StartInfo = new ProcessStartInfo
|
StartInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = fileName,
|
FileName = fileName,
|
||||||
Arguments = coreArguments,
|
Arguments = coreInfo.arguments,
|
||||||
WorkingDirectory = Utils.StartupPath(),
|
WorkingDirectory = Utils.StartupPath(),
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
@@ -247,7 +249,6 @@ namespace v2rayN.Handler
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
coreUrl = Global.xrayCoreUrl;
|
|
||||||
string fileName = V2rayFindexe(new List<string> { "xray" });
|
string fileName = V2rayFindexe(new List<string> { "xray" });
|
||||||
if (fileName == "") return -1;
|
if (fileName == "") return -1;
|
||||||
|
|
||||||
@@ -325,44 +326,21 @@ namespace v2rayN.Handler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetCore(Config config, VmessItem item)
|
private int SetCore(Config config, VmessItem item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
{
|
{
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
var coreType = LazyConfig.Instance.GetCoreType(item, item.configType);
|
var coreType = LazyConfig.Instance.GetCoreType(item, item.configType);
|
||||||
|
|
||||||
if (coreType == ECoreType.v2fly)
|
coreInfo = LazyConfig.Instance.GetCoreInfo(coreType);
|
||||||
|
|
||||||
|
if (coreInfo == null)
|
||||||
{
|
{
|
||||||
lstCore = new List<string>
|
return -1;
|
||||||
{
|
|
||||||
"wv2ray",
|
|
||||||
"v2ray"
|
|
||||||
};
|
|
||||||
coreUrl = Global.v2flyCoreUrl;
|
|
||||||
coreArguments = string.Empty;
|
|
||||||
}
|
|
||||||
else if (coreType == ECoreType.Xray)
|
|
||||||
{
|
|
||||||
lstCore = new List<string>
|
|
||||||
{
|
|
||||||
"xray"
|
|
||||||
};
|
|
||||||
coreUrl = Global.xrayCoreUrl;
|
|
||||||
coreArguments = string.Empty;
|
|
||||||
}
|
|
||||||
else if (coreType == ECoreType.clash)
|
|
||||||
{
|
|
||||||
lstCore = new List<string>
|
|
||||||
{
|
|
||||||
"clash-windows-amd64",
|
|
||||||
"clash-windows-386",
|
|
||||||
"clash"
|
|
||||||
};
|
|
||||||
coreUrl = Global.clashCoreUrl;
|
|
||||||
coreArguments = "-f config.json";
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
v2rayN/v2rayN/Mode/CoreInfo.cs
Normal file
17
v2rayN/v2rayN/Mode/CoreInfo.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace v2rayN.Mode
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public class CoreInfo
|
||||||
|
{
|
||||||
|
public ECoreType coreType { get; set; }
|
||||||
|
|
||||||
|
public List<string> coreExes { get; set; }
|
||||||
|
|
||||||
|
public string arguments { get; set; }
|
||||||
|
|
||||||
|
public string coreUrl { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@ namespace v2rayN.Mode
|
|||||||
{
|
{
|
||||||
v2fly = 1,
|
v2fly = 1,
|
||||||
Xray = 2,
|
Xray = 2,
|
||||||
clash = 3
|
clash = 11,
|
||||||
|
hysteria = 21,
|
||||||
|
v2rayN = 99
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace v2rayN.Mode
|
|||||||
Top = 1,
|
Top = 1,
|
||||||
Up = 2,
|
Up = 2,
|
||||||
Down = 3,
|
Down = 3,
|
||||||
Bottom = 4
|
Bottom = 4,
|
||||||
|
Position = 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,4 +32,4 @@ using System.Runtime.InteropServices;
|
|||||||
// 方法是按如下所示使用“*”:
|
// 方法是按如下所示使用“*”:
|
||||||
//[assembly: AssemblyVersion("1.0.*")]
|
//[assembly: AssemblyVersion("1.0.*")]
|
||||||
//[assembly: AssemblyVersion("1.0.0")]
|
//[assembly: AssemblyVersion("1.0.0")]
|
||||||
[assembly: AssemblyFileVersion("5.6")]
|
[assembly: AssemblyFileVersion("5.8")]
|
||||||
|
|||||||
@@ -208,6 +208,7 @@
|
|||||||
<Compile Include="Mode\RoutingItem.cs" />
|
<Compile Include="Mode\RoutingItem.cs" />
|
||||||
<Compile Include="Mode\RulesItem.cs" />
|
<Compile Include="Mode\RulesItem.cs" />
|
||||||
<Compile Include="Mode\ServerStatistics.cs" />
|
<Compile Include="Mode\ServerStatistics.cs" />
|
||||||
|
<Compile Include="Mode\CoreInfo.cs" />
|
||||||
<Compile Include="Mode\SysproxyConfig.cs" />
|
<Compile Include="Mode\SysproxyConfig.cs" />
|
||||||
<Compile Include="Mode\EConfigType.cs" />
|
<Compile Include="Mode\EConfigType.cs" />
|
||||||
<Compile Include="Mode\ServerTestItem.cs" />
|
<Compile Include="Mode\ServerTestItem.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user