refactor update core url

This commit is contained in:
2dust
2022-06-07 20:26:35 +08:00
parent aff055c781
commit bd6ddc3cc9
5 changed files with 34 additions and 42 deletions

View File

@@ -1018,10 +1018,7 @@ namespace clashN.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)
@@ -1054,10 +1051,7 @@ namespace clashN.Forms
AppendText(false, ResUI.MsgUpdateCoreCoreSuccessfully); AppendText(false, ResUI.MsgUpdateCoreCoreSuccessfully);
} }
}; };
Task.Run(() =>
{
(new UpdateHandle()).CheckUpdateCore(type, config, _updateUI); (new UpdateHandle()).CheckUpdateCore(type, config, _updateUI);
});
} }

View File

@@ -12,6 +12,7 @@ namespace clashN
public const string NUrl = @"https://github.com/2dust/clashN/releases"; public const string NUrl = @"https://github.com/2dust/clashN/releases";
public const string clashCoreUrl = "https://github.com/Dreamacro/clash/releases"; public const string clashCoreUrl = "https://github.com/Dreamacro/clash/releases";
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 geoUrl = "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/{0}.dat";
/// <summary> /// <summary>
/// SpeedTestUrl /// SpeedTestUrl

View File

@@ -58,12 +58,24 @@ namespace clashN.Handler
{ {
coreInfos = new List<CoreInfo>(); coreInfos = new List<CoreInfo>();
coreInfos.Add(new CoreInfo
{
coreType = ECoreType.clashN,
coreUrl = Global.NUrl,
coreLatestUrl = Global.NUrl + "/latest",
coreDownloadUrl32 = Global.NUrl + "/download/{0}/clashN-32.zip",
coreDownloadUrl64 = Global.NUrl + "/download/{0}/clashN.zip",
});
coreInfos.Add(new CoreInfo coreInfos.Add(new CoreInfo
{ {
coreType = ECoreType.clash, coreType = ECoreType.clash,
coreExes = new List<string> { "clash-windows-amd64-v3", "clash-windows-amd64", "clash-windows-386", "clash" }, coreExes = new List<string> { "clash-windows-amd64-v3", "clash-windows-amd64", "clash-windows-386", "clash" },
arguments = "-f config.yaml", arguments = "-f config.yaml",
coreUrl = Global.clashCoreUrl, coreUrl = Global.clashCoreUrl,
coreLatestUrl = Global.clashCoreUrl + "/latest",
coreDownloadUrl32 = Global.clashCoreUrl + "/download/{0}/clash-windows-386-{0}.zip",
coreDownloadUrl64 = Global.clashCoreUrl + "/download/{0}/clash-windows-amd64-{0}.zip",
match = "Clash" match = "Clash"
}); });
@@ -73,6 +85,9 @@ namespace clashN.Handler
coreExes = new List<string> { "Clash.Meta-windows-amd64v1", "Clash.Meta-windows-amd64", "Clash.Meta-windows-386", "Clash.Meta", "clash" }, coreExes = new List<string> { "Clash.Meta-windows-amd64v1", "Clash.Meta-windows-amd64", "Clash.Meta-windows-386", "Clash.Meta", "clash" },
arguments = "-f config.yaml", arguments = "-f config.yaml",
coreUrl = Global.clashMetaCoreUrl, coreUrl = Global.clashMetaCoreUrl,
coreLatestUrl = Global.clashMetaCoreUrl + "/latest",
coreDownloadUrl32 = Global.clashMetaCoreUrl + "/download/{0}/Clash.Meta-windows-386-{0}.zip",
coreDownloadUrl64 = Global.clashMetaCoreUrl + "/download/{0}/Clash.Meta-windows-amd64V1-{0}.zip",
match = "Clash Meta" match = "Clash Meta"
}); });

View File

@@ -33,16 +33,6 @@ namespace clashN.Handler
} }
} }
private readonly string nLatestUrl = Global.NUrl + "/latest";
private const string nUrl = Global.NUrl + "/download/{0}/clashN.zip";
private readonly string clashCoreLatestUrl = Global.clashCoreUrl + "/latest";
private const string clashCoreUrl32 = Global.clashCoreUrl + "/download/{0}/clash-windows-386-{0}.zip";
private const string clashCoreUrl64 = Global.clashCoreUrl + "/download/{0}/clash-windows-amd64-{0}.zip";
private readonly string clashMetaCoreLatestUrl = Global.clashMetaCoreUrl + "/latest";
private const string clashMetaCoreUrl32 = Global.clashMetaCoreUrl + "/download/{0}/Clash.Meta-windows-386-{0}.zip";
private const string clashMetaCoreUrl64 = Global.clashMetaCoreUrl + "/download/{0}/Clash.Meta-windows-amd64V1-{0}.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;
@@ -242,7 +232,7 @@ namespace clashN.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)
@@ -294,23 +284,8 @@ namespace clashN.Handler
{ {
try try
{ {
string url; var coreInfo = LazyConfig.Instance.GetCoreInfo(type);
if (type == ECoreType.clash) string url = coreInfo.coreLatestUrl;
{
url = clashCoreLatestUrl;
}
else if (type == ECoreType.clash_meta)
{
url = clashMetaCoreLatestUrl;
}
else if (type == ECoreType.clashN)
{
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))
@@ -381,6 +356,7 @@ namespace clashN.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;
@@ -391,11 +367,11 @@ namespace clashN.Handler
message = string.Format(ResUI.IsLatestCore, curVersion); message = string.Format(ResUI.IsLatestCore, curVersion);
if (Environment.Is64BitProcess) if (Environment.Is64BitProcess)
{ {
url = string.Format(clashCoreUrl64, version); url = string.Format(coreInfo.coreDownloadUrl64, version);
} }
else else
{ {
url = string.Format(clashCoreUrl32, version); url = string.Format(coreInfo.coreDownloadUrl32, version);
} }
} }
else if (type == ECoreType.clash_meta) else if (type == ECoreType.clash_meta)
@@ -404,18 +380,18 @@ namespace clashN.Handler
message = string.Format(ResUI.IsLatestCore, curVersion); message = string.Format(ResUI.IsLatestCore, curVersion);
if (Environment.Is64BitProcess) if (Environment.Is64BitProcess)
{ {
url = string.Format(clashMetaCoreUrl64, version); url = string.Format(coreInfo.coreDownloadUrl64, version);
} }
else else
{ {
url = string.Format(clashMetaCoreUrl32, version); url = string.Format(coreInfo.coreDownloadUrl32, version);
} }
} }
else if (type == ECoreType.clashN) else if (type == ECoreType.clashN)
{ {
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.coreDownloadUrl64, version);
} }
else else
{ {

View File

@@ -14,6 +14,12 @@ namespace clashN.Mode
public string coreUrl { get; set; } public string coreUrl { get; set; }
public string coreLatestUrl { get; set; }
public string coreDownloadUrl32 { get; set; }
public string coreDownloadUrl64 { get; set; }
public string match { get; set; } public string match { get; set; }
} }
} }