mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-19 21:52:25 +00:00
commit
300f5ef949
29 changed files with 291 additions and 261 deletions
|
@ -63,7 +63,7 @@ namespace v2rayN.Forms
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UI.Show(UIRes.I18N("OperationFailed"));
|
UI.ShowWarning(UIRes.I18N("OperationFailed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ namespace v2rayN.Forms
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UI.Show(UIRes.I18N("OperationFailed"));
|
UI.ShowWarning(UIRes.I18N("OperationFailed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void btnClose_Click(object sender, EventArgs e)
|
private void btnClose_Click(object sender, EventArgs e)
|
||||||
|
@ -124,7 +124,7 @@ namespace v2rayN.Forms
|
||||||
VmessItem vmessItem = V2rayConfigHandler.ImportFromClipboardConfig(Utils.GetClipboardData(), out string msg);
|
VmessItem vmessItem = V2rayConfigHandler.ImportFromClipboardConfig(Utils.GetClipboardData(), out string msg);
|
||||||
if (vmessItem == null)
|
if (vmessItem == null)
|
||||||
{
|
{
|
||||||
UI.Show(msg);
|
UI.ShowWarning(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ namespace v2rayN.Forms
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UI.Show(UIRes.I18N("OperationFailed"));
|
UI.ShowWarning(UIRes.I18N("OperationFailed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void btnClose_Click(object sender, EventArgs e)
|
private void btnClose_Click(object sender, EventArgs e)
|
||||||
|
@ -113,7 +113,7 @@ namespace v2rayN.Forms
|
||||||
VmessItem vmessItem = V2rayConfigHandler.ImportFromClipboardConfig(Utils.GetClipboardData(), out string msg);
|
VmessItem vmessItem = V2rayConfigHandler.ImportFromClipboardConfig(Utils.GetClipboardData(), out string msg);
|
||||||
if (vmessItem == null)
|
if (vmessItem == null)
|
||||||
{
|
{
|
||||||
UI.Show(msg);
|
UI.ShowWarning(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ namespace v2rayN.Forms
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UI.Show(UIRes.I18N("OperationFailed"));
|
UI.ShowWarning(UIRes.I18N("OperationFailed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ namespace v2rayN.Forms
|
||||||
}
|
}
|
||||||
if (vmessItem == null)
|
if (vmessItem == null)
|
||||||
{
|
{
|
||||||
UI.Show(msg);
|
UI.ShowWarning(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ namespace v2rayN.Forms
|
||||||
VmessItem vmessItem = V2rayConfigHandler.ImportFromClipboardConfig(Utils.GetClipboardData(), out string msg);
|
VmessItem vmessItem = V2rayConfigHandler.ImportFromClipboardConfig(Utils.GetClipboardData(), out string msg);
|
||||||
if (vmessItem == null)
|
if (vmessItem == null)
|
||||||
{
|
{
|
||||||
UI.Show(msg);
|
UI.ShowWarning(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -804,7 +804,7 @@ namespace v2rayN.Forms
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UI.Show(UIRes.I18N("FailedImportedCustomServer"));
|
UI.ShowWarning(UIRes.I18N("FailedImportedCustomServer"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1197,7 +1197,7 @@ namespace v2rayN.Forms
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
downloadHandle.DownloadFileAsync(config, url, null, -1);
|
downloadHandle.DownloadFileAsync(url, null, -1);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -1237,7 +1237,7 @@ namespace v2rayN.Forms
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore"));
|
AppendText(false, string.Format(UIRes.I18N("MsgStartUpdating"), "v2rayN"));
|
||||||
downloadHandle.CheckUpdateAsync("v2rayN");
|
downloadHandle.CheckUpdateAsync("v2rayN");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1263,7 +1263,7 @@ namespace v2rayN.Forms
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
downloadHandle.DownloadFileAsync(config, url, null, -1);
|
downloadHandle.DownloadFileAsync(url, null, -1);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -1310,7 +1310,7 @@ namespace v2rayN.Forms
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore"));
|
AppendText(false, string.Format(UIRes.I18N("MsgStartUpdating"), "v2rayCore"));
|
||||||
downloadHandle.CheckUpdateAsync("Core");
|
downloadHandle.CheckUpdateAsync("Core");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1391,7 +1391,7 @@ namespace v2rayN.Forms
|
||||||
string result = Convert.ToString(e.UserState);
|
string result = Convert.ToString(e.UserState);
|
||||||
if (Utils.IsNullOrEmpty(result))
|
if (Utils.IsNullOrEmpty(result))
|
||||||
{
|
{
|
||||||
UI.Show(UIRes.I18N("NoValidQRcodeFound"));
|
UI.ShowWarning(UIRes.I18N("NoValidQRcodeFound"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -181,7 +181,7 @@ namespace v2rayN.Forms
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UI.Show(UIRes.I18N("OperationFailed"));
|
UI.ShowWarning(UIRes.I18N("OperationFailed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,15 +389,19 @@ namespace v2rayN.Forms
|
||||||
txtUserblock.Text = Utils.GetEmbedText(Global.CustomRoutingFileName + Global.blockTag);
|
txtUserblock.Text = Utils.GetEmbedText(Global.CustomRoutingFileName + Global.blockTag);
|
||||||
cmbroutingMode.SelectedIndex = 3;
|
cmbroutingMode.SelectedIndex = 3;
|
||||||
|
|
||||||
List<string> lstUrl = new List<string>();
|
List<string> lstUrl = new List<string>
|
||||||
lstUrl.Add(Global.CustomRoutingListUrl + Global.agentTag);
|
{
|
||||||
lstUrl.Add(Global.CustomRoutingListUrl + Global.directTag);
|
Global.CustomRoutingListUrl + Global.agentTag,
|
||||||
lstUrl.Add(Global.CustomRoutingListUrl + Global.blockTag);
|
Global.CustomRoutingListUrl + Global.directTag,
|
||||||
|
Global.CustomRoutingListUrl + Global.blockTag
|
||||||
|
};
|
||||||
|
|
||||||
List<TextBox> lstTxt = new List<TextBox>();
|
List<TextBox> lstTxt = new List<TextBox>
|
||||||
lstTxt.Add(txtUseragent);
|
{
|
||||||
lstTxt.Add(txtUserdirect);
|
txtUseragent,
|
||||||
lstTxt.Add(txtUserblock);
|
txtUserdirect,
|
||||||
|
txtUserblock
|
||||||
|
};
|
||||||
|
|
||||||
for (int k = 0; k < lstUrl.Count; k++)
|
for (int k = 0; k < lstUrl.Count; k++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -226,7 +226,7 @@
|
||||||
<value>23</value>
|
<value>23</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="chkAutoRun.Text" xml:space="preserve">
|
<data name="chkAutoRun.Text" xml:space="preserve">
|
||||||
<value>Boot automatically</value>
|
<value>Automatically start at system startup</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="chkEnableStatistics.AutoSize" type="System.Boolean, mscorlib">
|
<data name="chkEnableStatistics.AutoSize" type="System.Boolean, mscorlib">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
|
@ -244,7 +244,7 @@
|
||||||
<value>29</value>
|
<value>29</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="chkEnableStatistics.Text" xml:space="preserve">
|
<data name="chkEnableStatistics.Text" xml:space="preserve">
|
||||||
<value>Enable Statistics(Realtime net speed and traffic data amount. Need restart v2rayN client)</value>
|
<value>Enable Statistics (Realtime netspeed and traffic records. Require restart the v2rayN client)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="chkKcpcongestion.AutoSize" type="System.Boolean, mscorlib">
|
<data name="chkKcpcongestion.AutoSize" type="System.Boolean, mscorlib">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
|
|
|
@ -79,7 +79,7 @@ namespace v2rayN.Forms
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UI.Show(UIRes.I18N("OperationFailed"));
|
UI.ShowWarning(UIRes.I18N("OperationFailed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -221,6 +221,10 @@ namespace v2rayN
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
public static System.Threading.Mutex mutexObj
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
@ -540,8 +540,7 @@ namespace v2rayN.Handler
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int AddCustomServer(ref Config config, string fileName)
|
public static int AddCustomServer(ref Config config, string fileName)
|
||||||
{
|
{
|
||||||
string newFileName = string.Empty;
|
string newFileName = string.Format("{0}.json", Utils.GetGUID());
|
||||||
newFileName = string.Format("{0}.json", Utils.GetGUID());
|
|
||||||
//newFileName = Path.Combine(Utils.GetTempPath(), newFileName);
|
//newFileName = Path.Combine(Utils.GetTempPath(), newFileName);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
@ -172,12 +172,12 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
#region Download
|
#region Download
|
||||||
|
|
||||||
public void DownloadFileAsync(Config config, string url, WebProxy webProxy, int downloadTimeout)
|
public void DownloadFileAsync(string url, WebProxy webProxy, int downloadTimeout)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Utils.SetSecurityProtocol();
|
Utils.SetSecurityProtocol();
|
||||||
UpdateCompleted?.Invoke(this, new ResultEventArgs(false, "Downloading..."));
|
UpdateCompleted?.Invoke(this, new ResultEventArgs(false, UIRes.I18N("Downloading")));
|
||||||
|
|
||||||
progressPercentage = -1;
|
progressPercentage = -1;
|
||||||
totalBytesToReceive = 0;
|
totalBytesToReceive = 0;
|
||||||
|
|
|
@ -101,7 +101,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UI.Show(string.Format(UIRes.I18N("SaveClientConfigurationIn"), fileName));
|
UI.ShowWarning(string.Format(UIRes.I18N("SaveClientConfigurationIn"), fileName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UI.Show(string.Format(UIRes.I18N("SaveServerConfigurationIn"), fileName));
|
UI.ShowWarning(string.Format(UIRes.I18N("SaveServerConfigurationIn"), fileName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,14 +100,14 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
private void RunRealPing()
|
private void RunRealPing()
|
||||||
{
|
{
|
||||||
|
int pid = -1;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string msg = string.Empty;
|
string msg = string.Empty;
|
||||||
|
|
||||||
Global.reloadV2ray = true;
|
pid = _v2rayHandler.LoadV2rayConfigString(_config, _selecteds);
|
||||||
_v2rayHandler.LoadV2ray(_config, _selecteds);
|
|
||||||
|
|
||||||
Thread.Sleep(5000);
|
//Thread.Sleep(5000);
|
||||||
int httpPort = _config.GetLocalPort("speedtest");
|
int httpPort = _config.GetLocalPort("speedtest");
|
||||||
Task[] tasks = new Task[_selecteds.Count];
|
Task[] tasks = new Task[_selecteds.Count];
|
||||||
int i = -1;
|
int i = -1;
|
||||||
|
@ -119,7 +119,8 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
tasks[i] = Task.Run(() => {
|
tasks[i] = Task.Run(() =>
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort + itemIndex);
|
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort + itemIndex);
|
||||||
|
@ -137,28 +138,28 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
Task.WaitAll(tasks);
|
Task.WaitAll(tasks);
|
||||||
|
|
||||||
Global.reloadV2ray = true;
|
|
||||||
_v2rayHandler.LoadV2ray(_config);
|
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Utils.SaveLog(ex.Message, ex);
|
Utils.SaveLog(ex.Message, ex);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (pid > 0) _v2rayHandler.V2rayStopPid(pid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void RunSpeedTest()
|
private void RunSpeedTest()
|
||||||
{
|
{
|
||||||
|
int pid = -1;
|
||||||
|
|
||||||
if (_config.vmess.Count <= 0)
|
if (_config.vmess.Count <= 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Global.reloadV2ray = true;
|
pid = _v2rayHandler.LoadV2rayConfigString(_config, _selecteds);
|
||||||
_v2rayHandler.LoadV2ray(_config, _selecteds);
|
|
||||||
|
|
||||||
Thread.Sleep(5000);
|
|
||||||
|
|
||||||
string url = _config.speedTestUrl;
|
string url = _config.speedTestUrl;
|
||||||
testCounter = 0;
|
testCounter = 0;
|
||||||
|
@ -166,54 +167,36 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
downloadHandle2 = new DownloadHandle();
|
downloadHandle2 = new DownloadHandle();
|
||||||
downloadHandle2.UpdateCompleted += (sender2, args) =>
|
downloadHandle2.UpdateCompleted += (sender2, args) =>
|
||||||
{
|
|
||||||
if (args.Success)
|
|
||||||
{
|
{
|
||||||
_updateFunc(ItemIndex, args.Msg);
|
_updateFunc(ItemIndex, args.Msg);
|
||||||
if (ServerSpeedTestSub(testCounter, url) != 0)
|
if (args.Success) StartNext();
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_updateFunc(ItemIndex, args.Msg);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
downloadHandle2.Error += (sender2, args) =>
|
downloadHandle2.Error += (sender2, args) =>
|
||||||
{
|
{
|
||||||
_updateFunc(ItemIndex, args.GetException().Message);
|
_updateFunc(ItemIndex, args.GetException().Message);
|
||||||
if (ServerSpeedTestSub(testCounter, url) != 0)
|
StartNext();
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ServerSpeedTestSub(testCounter, url) != 0)
|
StartNext();
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int ServerSpeedTestSub(int index, string url)
|
void StartNext()
|
||||||
{
|
{
|
||||||
if (index >= _selecteds.Count)
|
if (testCounter >= _selecteds.Count)
|
||||||
{
|
{
|
||||||
Global.reloadV2ray = true;
|
if (pid > 0) _v2rayHandler.V2rayStopPid(pid);
|
||||||
_v2rayHandler.LoadV2ray(_config);
|
return;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int httpPort = _config.GetLocalPort("speedtest");
|
int httpPort = _config.GetLocalPort("speedtest");
|
||||||
index = _selecteds[index];
|
int index = _selecteds[testCounter];
|
||||||
|
|
||||||
testCounter++;
|
testCounter++;
|
||||||
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort + index);
|
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort + index);
|
||||||
downloadHandle2.DownloadFileAsync(_config, url, webProxy, 20);
|
downloadHandle2.DownloadFileAsync(url, webProxy, 20);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private int GetTcpingTime(string url, int port)
|
private int GetTcpingTime(string url, int port)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,8 +27,6 @@ namespace v2rayN.Handler
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int GenerateClientConfig(Config config, string fileName, bool blExport, out string msg)
|
public static int GenerateClientConfig(Config config, string fileName, bool blExport, out string msg)
|
||||||
{
|
{
|
||||||
msg = string.Empty;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//检查GUI设置
|
//检查GUI设置
|
||||||
|
@ -713,8 +711,6 @@ namespace v2rayN.Handler
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int GenerateClientCustomConfig(Config config, string fileName, out string msg)
|
public static int GenerateClientCustomConfig(Config config, string fileName, out string msg)
|
||||||
{
|
{
|
||||||
msg = string.Empty;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//检查GUI设置
|
//检查GUI设置
|
||||||
|
@ -768,8 +764,6 @@ namespace v2rayN.Handler
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int GenerateServerConfig(Config config, string fileName, out string msg)
|
public static int GenerateServerConfig(Config config, string fileName, out string msg)
|
||||||
{
|
{
|
||||||
msg = string.Empty;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//检查GUI设置
|
//检查GUI设置
|
||||||
|
@ -1358,7 +1352,6 @@ namespace v2rayN.Handler
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int Export2ClientConfig(Config config, string fileName, out string msg)
|
public static int Export2ClientConfig(Config config, string fileName, out string msg)
|
||||||
{
|
{
|
||||||
msg = string.Empty;
|
|
||||||
return GenerateClientConfig(config, fileName, true, out msg);
|
return GenerateClientConfig(config, fileName, true, out msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1371,7 +1364,6 @@ namespace v2rayN.Handler
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int Export2ServerConfig(Config config, string fileName, out string msg)
|
public static int Export2ServerConfig(Config config, string fileName, out string msg)
|
||||||
{
|
{
|
||||||
msg = string.Empty;
|
|
||||||
return GenerateServerConfig(config, fileName, out msg);
|
return GenerateServerConfig(config, fileName, out msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1419,10 +1411,8 @@ namespace v2rayN.Handler
|
||||||
#region Gen speedtest config
|
#region Gen speedtest config
|
||||||
|
|
||||||
|
|
||||||
public static int GenerateClientSpeedtestConfig(Config config, List<int> selecteds, string fileName, out string msg)
|
public static string GenerateClientSpeedtestConfigString(Config config, List<int> selecteds, out string msg)
|
||||||
{
|
{
|
||||||
msg = string.Empty;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (config == null
|
if (config == null
|
||||||
|
@ -1432,7 +1422,7 @@ namespace v2rayN.Handler
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
msg = UIRes.I18N("CheckServerSettings");
|
msg = UIRes.I18N("CheckServerSettings");
|
||||||
return -1;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = UIRes.I18N("InitialConfiguration");
|
msg = UIRes.I18N("InitialConfiguration");
|
||||||
|
@ -1443,20 +1433,21 @@ namespace v2rayN.Handler
|
||||||
if (Utils.IsNullOrEmpty(result))
|
if (Utils.IsNullOrEmpty(result))
|
||||||
{
|
{
|
||||||
msg = UIRes.I18N("FailedGetDefaultConfiguration");
|
msg = UIRes.I18N("FailedGetDefaultConfiguration");
|
||||||
return -1;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
V2rayConfig v2rayConfig = Utils.FromJson<V2rayConfig>(result);
|
V2rayConfig v2rayConfig = Utils.FromJson<V2rayConfig>(result);
|
||||||
if (v2rayConfig == null)
|
if (v2rayConfig == null)
|
||||||
{
|
{
|
||||||
msg = UIRes.I18N("FailedGenDefaultConfiguration");
|
msg = UIRes.I18N("FailedGenDefaultConfiguration");
|
||||||
return -1;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
log(configCopy, ref v2rayConfig, false);
|
log(configCopy, ref v2rayConfig, false);
|
||||||
//routing(config, ref v2rayConfig);
|
//routing(config, ref v2rayConfig);
|
||||||
dns(configCopy, ref v2rayConfig);
|
dns(configCopy, ref v2rayConfig);
|
||||||
|
|
||||||
|
v2rayConfig.inbounds.RemoveAt(0); // Remove "proxy" service for speedtest, avoiding port conflicts.
|
||||||
|
|
||||||
int httpPort = configCopy.GetLocalPort("speedtest");
|
int httpPort = configCopy.GetLocalPort("speedtest");
|
||||||
foreach (int index in selecteds)
|
foreach (int index in selecteds)
|
||||||
|
@ -1492,16 +1483,14 @@ namespace v2rayN.Handler
|
||||||
v2rayConfig.routing.rules.Add(rule);
|
v2rayConfig.routing.rules.Add(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils.ToJsonFile(v2rayConfig, fileName);
|
|
||||||
|
|
||||||
msg = string.Format(UIRes.I18N("SuccessfulConfiguration"), configCopy.getSummary());
|
msg = string.Format(UIRes.I18N("SuccessfulConfiguration"), configCopy.getSummary());
|
||||||
|
return Utils.ToJson(v2rayConfig);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
msg = UIRes.I18N("FailedGenDefaultConfiguration");
|
msg = UIRes.I18N("FailedGenDefaultConfiguration");
|
||||||
return -1;
|
return "";
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -28,9 +28,11 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
public V2rayHandler()
|
public V2rayHandler()
|
||||||
{
|
{
|
||||||
lstV2ray = new List<string>();
|
lstV2ray = new List<string>
|
||||||
lstV2ray.Add("wv2ray");
|
{
|
||||||
lstV2ray.Add("v2ray");
|
"wv2ray",
|
||||||
|
"v2ray"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -40,9 +42,8 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
if (Global.reloadV2ray)
|
if (Global.reloadV2ray)
|
||||||
{
|
{
|
||||||
string msg = string.Empty;
|
|
||||||
string fileName = Utils.GetPath(v2rayConfigRes);
|
string fileName = Utils.GetPath(v2rayConfigRes);
|
||||||
if (V2rayConfigHandler.GenerateClientConfig(config, fileName, false, out msg) != 0)
|
if (V2rayConfigHandler.GenerateClientConfig(config, fileName, false, out string msg) != 0)
|
||||||
{
|
{
|
||||||
ShowMsg(false, msg);
|
ShowMsg(false, msg);
|
||||||
}
|
}
|
||||||
|
@ -55,24 +56,25 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 载入V2ray
|
/// 新建进程,载入V2ray配置文件字符串
|
||||||
|
/// 返回新进程pid。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void LoadV2ray(Config config, List<int> _selecteds)
|
public int LoadV2rayConfigString(Config config, List<int> _selecteds)
|
||||||
{
|
{
|
||||||
if (Global.reloadV2ray)
|
int pid = -1;
|
||||||
{
|
string configStr = V2rayConfigHandler.GenerateClientSpeedtestConfigString(config, _selecteds, out string msg);
|
||||||
string msg = string.Empty;
|
if (configStr == "")
|
||||||
string fileName = Utils.GetPath(v2rayConfigRes);
|
|
||||||
if (V2rayConfigHandler.GenerateClientSpeedtestConfig(config, _selecteds, fileName, out msg) != 0)
|
|
||||||
{
|
{
|
||||||
ShowMsg(false, msg);
|
ShowMsg(false, msg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ShowMsg(true, msg);
|
ShowMsg(true, msg);
|
||||||
V2rayRestart();
|
pid = V2rayStartNew(configStr);
|
||||||
}
|
//V2rayRestart();
|
||||||
|
// start with -config
|
||||||
}
|
}
|
||||||
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -140,18 +142,26 @@ namespace v2rayN.Handler
|
||||||
Utils.SaveLog(ex.Message, ex);
|
Utils.SaveLog(ex.Message, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// V2ray启动
|
/// V2ray停止
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void V2rayStart()
|
public void V2rayStopPid(int pid)
|
||||||
{
|
{
|
||||||
ShowMsg(false, string.Format(UIRes.I18N("StartService"), DateTime.Now.ToString()));
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Process _p = Process.GetProcessById(pid);
|
||||||
|
KillProcess(_p);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Utils.SaveLog(ex.Message, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string V2rayFindexe() {
|
||||||
//查找v2ray文件是否存在
|
//查找v2ray文件是否存在
|
||||||
string fileName = string.Empty;
|
string fileName = string.Empty;
|
||||||
|
lstV2ray.Reverse();
|
||||||
foreach (string name in lstV2ray)
|
foreach (string name in lstV2ray)
|
||||||
{
|
{
|
||||||
string vName = string.Format("{0}.exe", name);
|
string vName = string.Format("{0}.exe", name);
|
||||||
|
@ -166,16 +176,34 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
string msg = string.Format(UIRes.I18N("NotFoundCore"), @"https://github.com/v2ray/v2ray-core/releases");
|
string msg = string.Format(UIRes.I18N("NotFoundCore"), @"https://github.com/v2ray/v2ray-core/releases");
|
||||||
ShowMsg(true, msg);
|
ShowMsg(true, msg);
|
||||||
return;
|
}
|
||||||
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
Process p = new Process();
|
/// <summary>
|
||||||
p.StartInfo.FileName = fileName;
|
/// V2ray启动
|
||||||
p.StartInfo.WorkingDirectory = Utils.StartupPath();
|
/// </summary>
|
||||||
p.StartInfo.UseShellExecute = false;
|
private void V2rayStart()
|
||||||
p.StartInfo.RedirectStandardOutput = true;
|
{
|
||||||
p.StartInfo.CreateNoWindow = true;
|
ShowMsg(false, string.Format(UIRes.I18N("StartService"), DateTime.Now.ToString()));
|
||||||
p.StartInfo.StandardOutputEncoding = Encoding.UTF8;
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string fileName = V2rayFindexe();
|
||||||
|
if (fileName == "") return;
|
||||||
|
|
||||||
|
Process p = new Process
|
||||||
|
{
|
||||||
|
StartInfo = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = fileName,
|
||||||
|
WorkingDirectory = Utils.StartupPath(),
|
||||||
|
UseShellExecute = false,
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
CreateNoWindow = true,
|
||||||
|
StandardOutputEncoding = Encoding.UTF8
|
||||||
|
}
|
||||||
|
};
|
||||||
p.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
|
p.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(e.Data))
|
if (!String.IsNullOrEmpty(e.Data))
|
||||||
|
@ -198,6 +226,57 @@ namespace v2rayN.Handler
|
||||||
ShowMsg(true, msg);
|
ShowMsg(true, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// V2ray启动,新建进程,传入配置字符串
|
||||||
|
/// </summary>
|
||||||
|
private int V2rayStartNew(string configStr)
|
||||||
|
{
|
||||||
|
ShowMsg(false, string.Format(UIRes.I18N("StartService"), DateTime.Now.ToString()));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string fileName = V2rayFindexe();
|
||||||
|
if (fileName == "") return -1;
|
||||||
|
|
||||||
|
Process p = new Process
|
||||||
|
{
|
||||||
|
StartInfo = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = fileName,
|
||||||
|
Arguments = "-config stdin:",
|
||||||
|
WorkingDirectory = Utils.StartupPath(),
|
||||||
|
UseShellExecute = false,
|
||||||
|
RedirectStandardInput = true,
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
CreateNoWindow = true,
|
||||||
|
StandardOutputEncoding = Encoding.UTF8
|
||||||
|
}
|
||||||
|
};
|
||||||
|
p.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
|
||||||
|
{
|
||||||
|
if (!String.IsNullOrEmpty(e.Data))
|
||||||
|
{
|
||||||
|
string msg = e.Data + Environment.NewLine;
|
||||||
|
ShowMsg(false, msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
p.Start();
|
||||||
|
p.BeginOutputReadLine();
|
||||||
|
|
||||||
|
p.StandardInput.Write(configStr);
|
||||||
|
p.StandardInput.Close();
|
||||||
|
|
||||||
|
Global.processJob.AddProcess(p.Handle);
|
||||||
|
return p.Id;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Utils.SaveLog(ex.Message, ex);
|
||||||
|
string msg = ex.Message;
|
||||||
|
ShowMsg(true, msg);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 消息委托
|
/// 消息委托
|
||||||
|
|
|
@ -172,8 +172,10 @@ namespace v2rayN.HttpProxyHandler
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<string> lstProxy = new List<string>();
|
List<string> lstProxy = new List<string>
|
||||||
lstProxy.Add(string.Format("PROXY {0}:{1};", address, port));
|
{
|
||||||
|
string.Format("PROXY {0}:{1};", address, port)
|
||||||
|
};
|
||||||
string proxy = string.Join("", lstProxy.ToArray());
|
string proxy = string.Join("", lstProxy.ToArray());
|
||||||
|
|
||||||
string strPacfile = Utils.GetPath(Global.pacFILE);
|
string strPacfile = Utils.GetPath(Global.pacFILE);
|
||||||
|
|
|
@ -384,10 +384,9 @@ namespace v2rayN.Mode
|
||||||
|
|
||||||
public string getSummary()
|
public string getSummary()
|
||||||
{
|
{
|
||||||
string summary = string.Empty;
|
string summary = string.Format("{0}-", ((EConfigType)configType).ToString());
|
||||||
summary = string.Format("{0}-", ((EConfigType)configType).ToString());
|
|
||||||
string[] arrAddr = address.Split('.');
|
string[] arrAddr = address.Split('.');
|
||||||
string addr = string.Empty;
|
string addr;
|
||||||
if (arrAddr.Length > 2)
|
if (arrAddr.Length > 2)
|
||||||
{
|
{
|
||||||
addr = $"{arrAddr[0]}***{arrAddr[arrAddr.Length - 1]}";
|
addr = $"{arrAddr[0]}***{arrAddr[arrAddr.Length - 1]}";
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using v2rayN.Forms;
|
using v2rayN.Forms;
|
||||||
|
@ -32,13 +31,11 @@ namespace v2rayN
|
||||||
|
|
||||||
//AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
|
//AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
|
||||||
|
|
||||||
Thread.Sleep(300); // 尽量避免切换语言后提示“已经运行”
|
if (!IsDuplicateInstance())
|
||||||
Process instance = RunningInstance();
|
|
||||||
if (instance == null)
|
|
||||||
{
|
{
|
||||||
if (!UnzipLibs())
|
if (!UnzipLibs())
|
||||||
{
|
{
|
||||||
UI.Show($"Error preparing the environment(准备运行环境出错)");
|
UI.ShowError($"Error preparing the environment(准备运行环境出错)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +51,7 @@ namespace v2rayN
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UI.Show($"v2rayN is already running(v2rayN已经运行)");
|
UI.ShowWarning($"v2rayN is already running(v2rayN已经运行)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,23 +78,17 @@ namespace v2rayN
|
||||||
//}
|
//}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取正在运行的实例,没有运行的实例返回null;
|
/// 检查是否已在运行
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Process RunningInstance()
|
public static bool IsDuplicateInstance()
|
||||||
{
|
{
|
||||||
Process current = Process.GetCurrentProcess();
|
//string name = "v2rayN";
|
||||||
Process[] processes = Process.GetProcessesByName(current.ProcessName);
|
|
||||||
foreach (Process process in processes)
|
string name = Utils.GetExePath(); // Allow different locations to run
|
||||||
{
|
name = name.Replace("\\", "/"); // https://stackoverflow.com/questions/20714120/could-not-find-a-part-of-the-path-error-while-creating-mutex
|
||||||
if (process.Id != current.Id)
|
|
||||||
{
|
Global.mutexObj = new Mutex(false, name, out bool bCreatedNew);
|
||||||
if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == process.MainModule.FileName)
|
return !bCreatedNew;
|
||||||
{
|
|
||||||
return process;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
|
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
|
||||||
|
|
|
@ -7,9 +7,9 @@ using System.Runtime.InteropServices;
|
||||||
[assembly: AssemblyTitle("v2rayN")]
|
[assembly: AssemblyTitle("v2rayN")]
|
||||||
[assembly: AssemblyDescription("")]
|
[assembly: AssemblyDescription("")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("Microsoft")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("v2rayN")]
|
[assembly: AssemblyProduct("v2rayN")]
|
||||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2020")]
|
[assembly: AssemblyCopyright("Copyright © 2019-2020 (GPLv3)")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
|
27
v2rayN/v2rayN/Resx/ResUI.Designer.cs
generated
27
v2rayN/v2rayN/Resx/ResUI.Designer.cs
generated
|
@ -105,6 +105,15 @@ namespace v2rayN.Resx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Downloading... 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
internal static string Downloading {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Downloading", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 DOWN 的本地化字符串。
|
/// 查找类似 DOWN 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -492,6 +501,15 @@ namespace v2rayN.Resx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Start updating {0}... 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
internal static string MsgStartUpdating {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("MsgStartUpdating", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Start updating PAC... 的本地化字符串。
|
/// 查找类似 Start updating PAC... 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -501,15 +519,6 @@ namespace v2rayN.Resx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查找类似 Start updating V2ray... 的本地化字符串。
|
|
||||||
/// </summary>
|
|
||||||
internal static string MsgStartUpdatingV2rayCore {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("MsgStartUpdatingV2rayCore", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Subscription content decoding failed (non-BASE64 code) 的本地化字符串。
|
/// 查找类似 Subscription content decoding failed (non-BASE64 code) 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -132,6 +132,9 @@
|
||||||
<data name="CustomServerTips" xml:space="preserve">
|
<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. The system agent is available when the socks port is equal to the port in the settings in the custom configuration inbound.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Downloading" xml:space="preserve">
|
||||||
|
<value>Downloading...</value>
|
||||||
|
</data>
|
||||||
<data name="downloadSpeed" xml:space="preserve">
|
<data name="downloadSpeed" xml:space="preserve">
|
||||||
<value>DOWN</value>
|
<value>DOWN</value>
|
||||||
</data>
|
</data>
|
||||||
|
@ -264,8 +267,8 @@
|
||||||
<data name="MsgStartUpdatingPAC" xml:space="preserve">
|
<data name="MsgStartUpdatingPAC" xml:space="preserve">
|
||||||
<value>Start updating PAC...</value>
|
<value>Start updating PAC...</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MsgStartUpdatingV2rayCore" xml:space="preserve">
|
<data name="MsgStartUpdating" xml:space="preserve">
|
||||||
<value>Start updating V2ray...</value>
|
<value>Start updating {0}...</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MsgSubscriptionDecodingFailed" xml:space="preserve">
|
<data name="MsgSubscriptionDecodingFailed" xml:space="preserve">
|
||||||
<value>Subscription content decoding failed (non-BASE64 code)</value>
|
<value>Subscription content decoding failed (non-BASE64 code)</value>
|
||||||
|
|
|
@ -132,6 +132,9 @@
|
||||||
<data name="CustomServerTips" xml:space="preserve">
|
<data name="CustomServerTips" xml:space="preserve">
|
||||||
<value>注意,自定义配置完全依赖您自己的配置,不能使用所有设置功能。在自定义配置inbound中有socks port等于设置中的port时,系统代理才可用</value>
|
<value>注意,自定义配置完全依赖您自己的配置,不能使用所有设置功能。在自定义配置inbound中有socks port等于设置中的port时,系统代理才可用</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Downloading" xml:space="preserve">
|
||||||
|
<value>下载开始...</value>
|
||||||
|
</data>
|
||||||
<data name="downloadSpeed" xml:space="preserve">
|
<data name="downloadSpeed" xml:space="preserve">
|
||||||
<value>下载</value>
|
<value>下载</value>
|
||||||
</data>
|
</data>
|
||||||
|
@ -262,10 +265,10 @@
|
||||||
<value>开始获取订阅内容</value>
|
<value>开始获取订阅内容</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MsgStartUpdatingPAC" xml:space="preserve">
|
<data name="MsgStartUpdatingPAC" xml:space="preserve">
|
||||||
<value>开始更新PAC...</value>
|
<value>开始更新 PAC...</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MsgStartUpdatingV2rayCore" xml:space="preserve">
|
<data name="MsgStartUpdating" xml:space="preserve">
|
||||||
<value>开始更新V2ray...</value>
|
<value>开始更新 {0}...</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MsgSubscriptionDecodingFailed" xml:space="preserve">
|
<data name="MsgSubscriptionDecodingFailed" xml:space="preserve">
|
||||||
<value>订阅内容解码失败(非BASE64码)</value>
|
<value>订阅内容解码失败(非BASE64码)</value>
|
||||||
|
|
|
@ -43,7 +43,6 @@ namespace v2rayN
|
||||||
if (extendedInfoPtr != IntPtr.Zero)
|
if (extendedInfoPtr != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
Marshal.FreeHGlobal(extendedInfoPtr);
|
Marshal.FreeHGlobal(extendedInfoPtr);
|
||||||
extendedInfoPtr = IntPtr.Zero;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,18 @@ namespace v2rayN
|
||||||
{
|
{
|
||||||
MessageBox.Show(msg, "v2rayN", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show(msg, "v2rayN", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
|
public static void ShowWarning(string msg)
|
||||||
|
{
|
||||||
|
MessageBox.Show(msg, "v2rayN", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||||
|
}
|
||||||
|
public static void ShowError(string msg)
|
||||||
|
{
|
||||||
|
MessageBox.Show(msg, "v2rayN", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
|
||||||
public static DialogResult ShowYesNo(string msg)
|
public static DialogResult ShowYesNo(string msg)
|
||||||
{
|
{
|
||||||
return MessageBox.Show(msg, "YesNo", MessageBoxButtons.YesNo);
|
return MessageBox.Show(msg, "v2rayN", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||||
}
|
}
|
||||||
|
|
||||||
//public static string GetResourseString(string key)
|
//public static string GetResourseString(string key)
|
||||||
|
|
|
@ -121,7 +121,7 @@ namespace v2rayN
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int ToJsonFile(Object obj, string filePath)
|
public static int ToJsonFile(Object obj, string filePath)
|
||||||
{
|
{
|
||||||
int result = -1;
|
int result;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (StreamWriter file = File.CreateText(filePath))
|
using (StreamWriter file = File.CreateText(filePath))
|
||||||
|
@ -485,24 +485,16 @@ namespace v2rayN
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="run"></param>
|
/// <param name="run"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int SetAutoRun(bool run)
|
public static void SetAutoRun(bool run)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
|
||||||
if (run)
|
|
||||||
{
|
{
|
||||||
string exePath = GetExePath();
|
string exePath = GetExePath();
|
||||||
RegWriteValue(autoRunRegPath, autoRunName, exePath);
|
RegWriteValue(autoRunRegPath, autoRunName, run ? exePath : "");
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RegWriteValue(autoRunRegPath, autoRunName, "");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -550,17 +542,9 @@ namespace v2rayN
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string StartupPath()
|
public static string StartupPath()
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string exePath = GetExePath();
|
|
||||||
return exePath.Substring(0, exePath.LastIndexOf("\\", StringComparison.Ordinal));
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
{
|
||||||
return Application.StartupPath;
|
return Application.StartupPath;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static string RegReadValue(string path, string name, string def)
|
public static string RegReadValue(string path, string name, string def)
|
||||||
{
|
{
|
||||||
|
@ -625,7 +609,7 @@ namespace v2rayN
|
||||||
long roundtripTime = -1;
|
long roundtripTime = -1;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int timeout = 120;
|
int timeout = 30;
|
||||||
int echoNum = 2;
|
int echoNum = 2;
|
||||||
Ping pingSender = new Ping();
|
Ping pingSender = new Ping();
|
||||||
for (int i = 0; i < echoNum; i++)
|
for (int i = 0; i < echoNum; i++)
|
||||||
|
@ -883,7 +867,6 @@ namespace v2rayN
|
||||||
|
|
||||||
public static string ScanScreen()
|
public static string ScanScreen()
|
||||||
{
|
{
|
||||||
string ret = string.Empty;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (Screen screen in Screen.AllScreens)
|
foreach (Screen screen in Screen.AllScreens)
|
||||||
|
@ -921,7 +904,7 @@ namespace v2rayN
|
||||||
Result result = reader.decode(bitmap);
|
Result result = reader.decode(bitmap);
|
||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
ret = result.Text;
|
string ret = result.Text;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
5
v2rayN/v2rayUpgrade/MainForm.Designer.cs
generated
5
v2rayN/v2rayUpgrade/MainForm.Designer.cs
generated
|
@ -41,7 +41,7 @@
|
||||||
this.btnClose.Location = new System.Drawing.Point(367, 118);
|
this.btnClose.Location = new System.Drawing.Point(367, 118);
|
||||||
this.btnClose.Name = "btnClose";
|
this.btnClose.Name = "btnClose";
|
||||||
this.btnClose.Size = new System.Drawing.Size(184, 89);
|
this.btnClose.Size = new System.Drawing.Size(184, 89);
|
||||||
this.btnClose.TabIndex = 6;
|
this.btnClose.TabIndex = 1;
|
||||||
this.btnClose.Text = "&Exit(退出)";
|
this.btnClose.Text = "&Exit(退出)";
|
||||||
this.btnClose.UseVisualStyleBackColor = true;
|
this.btnClose.UseVisualStyleBackColor = true;
|
||||||
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
|
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
this.btnOK.Location = new System.Drawing.Point(81, 118);
|
this.btnOK.Location = new System.Drawing.Point(81, 118);
|
||||||
this.btnOK.Name = "btnOK";
|
this.btnOK.Name = "btnOK";
|
||||||
this.btnOK.Size = new System.Drawing.Size(184, 89);
|
this.btnOK.Size = new System.Drawing.Size(184, 89);
|
||||||
this.btnOK.TabIndex = 7;
|
this.btnOK.TabIndex = 0;
|
||||||
this.btnOK.Text = "&Upgrade(升级)";
|
this.btnOK.Text = "&Upgrade(升级)";
|
||||||
this.btnOK.UseVisualStyleBackColor = true;
|
this.btnOK.UseVisualStyleBackColor = true;
|
||||||
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
|
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
|
||||||
|
@ -89,7 +89,6 @@
|
||||||
this.Name = "MainForm";
|
this.Name = "MainForm";
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
this.Text = "v2rayUpgrade";
|
this.Text = "v2rayUpgrade";
|
||||||
this.Load += new System.EventHandler(this.MainForm_Load);
|
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
|
|
|
@ -8,28 +8,24 @@ namespace v2rayUpgrade
|
||||||
{
|
{
|
||||||
public partial class MainForm : Form
|
public partial class MainForm : Form
|
||||||
{
|
{
|
||||||
private string[] _args;
|
private readonly string defaultFilename = "v2ray-windows.zip";
|
||||||
private string _tempFileName = "v2rayUpgradeTemp.zip";
|
private string fileName;
|
||||||
|
|
||||||
|
|
||||||
public MainForm(string[] args)
|
public MainForm(string[] args)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_args = args;
|
if (args.Length > 0)
|
||||||
}
|
|
||||||
|
|
||||||
private void MainForm_Load(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
|
fileName = args[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void showWarn(string message)
|
||||||
|
{
|
||||||
|
MessageBox.Show(message, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnOK_Click(object sender, EventArgs e)
|
private void btnOK_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_args.Length <= 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Process[] existing = Process.GetProcessesByName("v2rayN");
|
Process[] existing = Process.GetProcessesByName("v2rayN");
|
||||||
|
@ -45,20 +41,25 @@ namespace v2rayUpgrade
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Failed to close v2rayN(关闭v2rayN失败)." + ex.StackTrace);
|
showWarn("Failed to close v2rayN(关闭v2rayN失败)." + ex.StackTrace);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string fileName = GetPath(_tempFileName);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.Delete(fileName);
|
|
||||||
File.Copy(_args[0], fileName);
|
|
||||||
if (!File.Exists(fileName))
|
if (!File.Exists(fileName))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Upgrade Failed, File Not Exist(升级失败,文件不存在).");
|
if (File.Exists(defaultFilename))
|
||||||
|
{
|
||||||
|
fileName = defaultFilename;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
showWarn("Upgrade Failed, File Not Exist(升级失败,文件不存在).");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string startKey = "v2rayN/";
|
string startKey = "v2rayN/";
|
||||||
|
|
||||||
|
@ -86,23 +87,13 @@ namespace v2rayUpgrade
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Upgrade Failed(升级失败)." + ex.StackTrace);
|
showWarn("Upgrade Failed(升级失败)." + ex.StackTrace);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
File.Delete(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageBox.Show("Upgrade successed(升级成功)");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Process.Start("v2rayN.exe");
|
Process.Start("v2rayN.exe");
|
||||||
}
|
MessageBox.Show("Upgrade successed(升级成功)", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,17 +108,9 @@ namespace v2rayUpgrade
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string StartupPath()
|
public static string StartupPath()
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string exePath = GetExePath();
|
|
||||||
return exePath.Substring(0, exePath.LastIndexOf("\\", StringComparison.Ordinal));
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
{
|
||||||
return Application.StartupPath;
|
return Application.StartupPath;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
public static string GetPath(string fileName)
|
public static string GetPath(string fileName)
|
||||||
{
|
{
|
||||||
string startupPath = StartupPath();
|
string startupPath = StartupPath();
|
||||||
|
|
|
@ -11,12 +11,6 @@ namespace v2rayUpgrade
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
if (args.Length <= 0)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Please use v2rayN to upgrade(请用v2rayN升级)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
Application.Run(new MainForm(args));
|
Application.Run(new MainForm(args));
|
||||||
|
|
|
@ -9,7 +9,7 @@ using System.Runtime.InteropServices;
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("v2rayUpgrade")]
|
[assembly: AssemblyProduct("v2rayUpgrade")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
[assembly: AssemblyCopyright("Copyright © 2019-2020 (GPLv3)")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
@ -31,5 +31,4 @@ using System.Runtime.InteropServices;
|
||||||
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
||||||
// 方法是按如下所示使用“*”: :
|
// 方法是按如下所示使用“*”: :
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
||||||
|
|
Loading…
Reference in a new issue