refactor update core url

pull/2415/head
2dust 2022-06-06 17:28:38 +08:00
parent db7e8dd6dc
commit d5eaa56b60
5 changed files with 26 additions and 37 deletions

View File

@ -1314,10 +1314,7 @@ namespace v2rayN.Forms
menuExit_Click(null, null); menuExit_Click(null, null);
} }
}; };
Task.Run(() => (new UpdateHandle()).CheckUpdateGuiN(config, _updateUI);
{
(new UpdateHandle()).CheckUpdateGuiN(config, _updateUI);
});
} }
private void tsbCheckUpdateCore_Click(object sender, EventArgs e) private void tsbCheckUpdateCore_Click(object sender, EventArgs e)
@ -1350,10 +1347,7 @@ namespace v2rayN.Forms
AppendText(false, ResUI.MsgUpdateV2rayCoreSuccessfully); AppendText(false, ResUI.MsgUpdateV2rayCoreSuccessfully);
} }
}; };
Task.Run(() => (new UpdateHandle()).CheckUpdateCore(type, config, _updateUI);
{
(new UpdateHandle()).CheckUpdateCore(type, config, _updateUI);
});
} }
private void tsbCheckUpdateGeo_Click(object sender, EventArgs e) private void tsbCheckUpdateGeo_Click(object sender, EventArgs e)

View File

@ -18,6 +18,7 @@ namespace v2rayN
public const string clashMetaCoreUrl = "https://github.com/MetaCubeX/Clash.Meta/releases"; public const string clashMetaCoreUrl = "https://github.com/MetaCubeX/Clash.Meta/releases";
public const string hysteriaCoreUrl = "https://github.com/HyNetwork/hysteria/releases"; public const string hysteriaCoreUrl = "https://github.com/HyNetwork/hysteria/releases";
public const string naiveproxyCoreUrl = "https://github.com/klzgrad/naiveproxy/releases"; public const string naiveproxyCoreUrl = "https://github.com/klzgrad/naiveproxy/releases";
public const string geoUrl = "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/{0}.dat";

View File

@ -66,12 +66,22 @@ namespace v2rayN.Handler
{ {
coreInfos = new List<CoreInfo>(); coreInfos = new List<CoreInfo>();
coreInfos.Add(new CoreInfo
{
coreType = ECoreType.v2rayN,
coreUrl = Global.NUrl,
coreLatestUrl = Global.NUrl + "/latest",
coreDownloadUrl = Global.NUrl + "/download/{0}/v2rayN.zip",
});
coreInfos.Add(new CoreInfo coreInfos.Add(new CoreInfo
{ {
coreType = ECoreType.v2fly, coreType = ECoreType.v2fly,
coreExes = new List<string> { "wv2ray", "v2ray" }, coreExes = new List<string> { "wv2ray", "v2ray" },
arguments = "", arguments = "",
coreUrl = Global.v2flyCoreUrl, coreUrl = Global.v2flyCoreUrl,
coreLatestUrl = Global.v2flyCoreUrl + "/latest",
coreDownloadUrl = Global.v2flyCoreUrl + "/download/{0}/v2ray-windows-{1}.zip",
match = "V2Ray" match = "V2Ray"
}); });
@ -81,6 +91,8 @@ namespace v2rayN.Handler
coreExes = new List<string> { "xray" }, coreExes = new List<string> { "xray" },
arguments = "", arguments = "",
coreUrl = Global.xrayCoreUrl, coreUrl = Global.xrayCoreUrl,
coreLatestUrl = Global.xrayCoreUrl + "/latest",
coreDownloadUrl = Global.xrayCoreUrl + "/download/{0}/Xray-windows-{1}.zip",
match = "Xray" match = "Xray"
}); });

View File

@ -31,14 +31,6 @@ namespace v2rayN.Handler
} }
} }
private readonly string nLatestUrl = Global.NUrl + "/latest";
private const string nUrl = Global.NUrl + "/download/{0}/v2rayN.zip";
private readonly string v2flyCoreLatestUrl = Global.v2flyCoreUrl + "/latest";
private const string v2flyCoreUrl = Global.v2flyCoreUrl + "/download/{0}/v2ray-windows-{1}.zip";
private readonly string xrayCoreLatestUrl = Global.xrayCoreUrl + "/latest";
private const string xrayCoreUrl = Global.xrayCoreUrl + "/download/{0}/Xray-windows-{1}.zip";
private const string geoUrl = "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/{0}.dat";
public void CheckUpdateGuiN(Config config, Action<bool, string> update) public void CheckUpdateGuiN(Config config, Action<bool, string> update)
{ {
_config = config; _config = config;
@ -244,7 +236,7 @@ namespace v2rayN.Handler
{ {
_config = config; _config = config;
_updateFunc = update; _updateFunc = update;
var url = string.Format(geoUrl, geoName); var url = string.Format(Global.geoUrl, geoName);
DownloadHandle downloadHandle = null; DownloadHandle downloadHandle = null;
if (downloadHandle == null) if (downloadHandle == null)
@ -306,23 +298,8 @@ namespace v2rayN.Handler
{ {
try try
{ {
string url; var coreInfo = LazyConfig.Instance.GetCoreInfo(type);
if (type == ECoreType.v2fly) string url = coreInfo.coreLatestUrl;
{
url = v2flyCoreLatestUrl;
}
else if (type == ECoreType.Xray)
{
url = xrayCoreLatestUrl;
}
else if (type == ECoreType.v2rayN)
{
url = nLatestUrl;
}
else
{
throw new ArgumentException("Type");
}
var result = await (new DownloadHandle()).UrlRedirectAsync(url, true); var result = await (new DownloadHandle()).UrlRedirectAsync(url, true);
if (!Utils.IsNullOrEmpty(result)) if (!Utils.IsNullOrEmpty(result))
@ -396,6 +373,7 @@ namespace v2rayN.Handler
try try
{ {
string version = redirectUrl.Substring(redirectUrl.LastIndexOf("/", StringComparison.Ordinal) + 1); string version = redirectUrl.Substring(redirectUrl.LastIndexOf("/", StringComparison.Ordinal) + 1);
var coreInfo = LazyConfig.Instance.GetCoreInfo(type);
string curVersion; string curVersion;
string message; string message;
@ -405,20 +383,20 @@ namespace v2rayN.Handler
curVersion = "v" + getCoreVersion(type); curVersion = "v" + getCoreVersion(type);
message = string.Format(ResUI.IsLatestCore, curVersion); message = string.Format(ResUI.IsLatestCore, curVersion);
string osBit = Environment.Is64BitProcess ? "64" : "32"; string osBit = Environment.Is64BitProcess ? "64" : "32";
url = string.Format(v2flyCoreUrl, version, osBit); url = string.Format(coreInfo.coreDownloadUrl, version, osBit);
} }
else if (type == ECoreType.Xray) else if (type == ECoreType.Xray)
{ {
curVersion = "v" + getCoreVersion(type); curVersion = "v" + getCoreVersion(type);
message = string.Format(ResUI.IsLatestCore, curVersion); message = string.Format(ResUI.IsLatestCore, curVersion);
string osBit = Environment.Is64BitProcess ? "64" : "32"; string osBit = Environment.Is64BitProcess ? "64" : "32";
url = string.Format(xrayCoreUrl, version, osBit); url = string.Format(coreInfo.coreDownloadUrl, version, osBit);
} }
else if (type == ECoreType.v2rayN) else if (type == ECoreType.v2rayN)
{ {
curVersion = FileVersionInfo.GetVersionInfo(Utils.GetExePath()).FileVersion.ToString(); curVersion = FileVersionInfo.GetVersionInfo(Utils.GetExePath()).FileVersion.ToString();
message = string.Format(ResUI.IsLatestN, curVersion); message = string.Format(ResUI.IsLatestN, curVersion);
url = string.Format(nUrl, version); url = string.Format(coreInfo.coreDownloadUrl, version);
} }
else else
{ {

View File

@ -14,6 +14,10 @@ namespace v2rayN.Mode
public string coreUrl { get; set; } public string coreUrl { get; set; }
public string coreLatestUrl { get; set; }
public string coreDownloadUrl { get; set; }
public string match { get; set; } public string match { get; set; }
} }
} }