增强检查更新

pull/453/head
YFdyh000 5 years ago
parent a62f375f5b
commit 643a8094a6

@ -5,6 +5,7 @@ using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using v2rayN.Base;
using v2rayN.Mode;
using v2rayN.Properties;
@ -75,7 +76,8 @@ namespace v2rayN.Handler
{
if (AbsoluteCompleted != null)
{
AbsoluteCompleted(this, new ResultEventArgs(false, "Already the latest version"));
string message = string.Format(UIRes.I18N("IsLatestN"), curVersion);
AbsoluteCompleted(this, new ResultEventArgs(false, message));
}
return;
}
@ -108,7 +110,42 @@ namespace v2rayN.Handler
WebRequest request = WebRequest.Create(coreLatestUrl);
request.BeginGetResponse(new AsyncCallback(OnResponseV2rayCore), request);
}
/// <summary>
/// 获取V2RayCore版本
/// </summary>
public string getV2rayVersion()
{
try
{
string filePath = Utils.GetPath("V2ray.exe");
if (!File.Exists(filePath))
{
string msg = string.Format(UIRes.I18N("NotFoundCore"), @"https://github.com/v2ray/v2ray-core/releases");
//ShowMsg(true, msg);
return "";
}
Process p = new Process();
p.StartInfo.FileName = filePath;
p.StartInfo.Arguments = "-version";
p.StartInfo.WorkingDirectory = Utils.StartupPath();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.StandardOutputEncoding = Encoding.UTF8;
p.Start();
p.WaitForExit(5000);
string echo = p.StandardOutput.ReadToEnd();
string version = Regex.Match(echo, "V2Ray ([0-9.]+) \\(").Groups[1].Value;
return version;
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
return "";
}
}
private void OnResponseV2rayCore(IAsyncResult ar)
{
try
@ -118,15 +155,18 @@ namespace v2rayN.Handler
string redirectUrl = response.ResponseUri.AbsoluteUri;
string version = redirectUrl.Substring(redirectUrl.LastIndexOf("/", StringComparison.Ordinal) + 1);
string osBit = string.Empty;
if (Environment.Is64BitProcess)
{
osBit = "64";
}
else
string curVersion = "v" + getV2rayVersion();
if (curVersion == version)
{
osBit = "32";
if (AbsoluteCompleted != null)
{
string message = string.Format(UIRes.I18N("IsLatestCore"), curVersion);
AbsoluteCompleted(this, new ResultEventArgs(false, message));
}
return;
}
string osBit = Environment.Is64BitProcess ? "64" : "32";
string url = string.Format(coreUrl, version, osBit);
if (AbsoluteCompleted != null)
{

@ -267,6 +267,24 @@ namespace v2rayN.Resx {
}
}
/// <summary>
/// 查找类似 {0} already up to date. 的本地化字符串。
/// </summary>
internal static string IsLatestCore {
get {
return ResourceManager.GetString("IsLatestCore", resourceCulture);
}
}
/// <summary>
/// 查找类似 {0} already up to date. 的本地化字符串。
/// </summary>
internal static string IsLatestN {
get {
return ResourceManager.GetString("IsLatestN", resourceCulture);
}
}
/// <summary>
/// 查找类似 Address 的本地化字符串。
/// </summary>
@ -574,7 +592,7 @@ namespace v2rayN.Resx {
}
/// <summary>
/// 查找类似 V2ray-core not found, download address: {0} 的本地化字符串。
/// 查找类似 V2ray-core not found, please download: {0} 的本地化字符串。
/// </summary>
internal static string NotFoundCore {
get {
@ -709,7 +727,7 @@ namespace v2rayN.Resx {
}
/// <summary>
/// 查找类似 Start service ({0})...... 的本地化字符串。
/// 查找类似 Start service ({0})... 的本地化字符串。
/// </summary>
internal static string StartService {
get {

@ -236,10 +236,16 @@
{0}</value>
</data>
<data name="NotFoundCore" xml:space="preserve">
<value>V2ray-core not found, download address: {0}</value>
<value>V2ray-core not found, please download: {0}</value>
</data>
<data name="IsLatestN" xml:space="preserve">
<value>{0} already up to date.</value>
</data>
<data name="IsLatestCore" xml:space="preserve">
<value>{0} already up to date.</value>
</data>
<data name="StartService" xml:space="preserve">
<value>Start service ({0})......</value>
<value>Start service ({0})...</value>
</data>
<data name="LvAddress" xml:space="preserve">
<value>Address</value>

@ -236,10 +236,16 @@
{0}</value>
</data>
<data name="NotFoundCore" xml:space="preserve">
<value>未找到v2ray-core,下载地址:{0}</value>
<value>找不到 v2ray-core下载地址: {0}</value>
</data>
<data name="IsLatestN" xml:space="preserve">
<value>{0} 已是最新版本。</value>
</data>
<data name="IsLatestCore" xml:space="preserve">
<value>{0} 已是最新版本。</value>
</data>
<data name="StartService" xml:space="preserve">
<value>启动服务({0})......</value>
<value>启动服务({0})...</value>
</data>
<data name="LvAddress" xml:space="preserve">
<value>地址</value>

Loading…
Cancel
Save