refactor update core url
This commit is contained in:
@@ -1018,10 +1018,7 @@ namespace clashN.Forms
|
||||
menuExit_Click(null, null);
|
||||
}
|
||||
};
|
||||
Task.Run(() =>
|
||||
{
|
||||
(new UpdateHandle()).CheckUpdateGuiN(config, _updateUI);
|
||||
});
|
||||
(new UpdateHandle()).CheckUpdateGuiN(config, _updateUI);
|
||||
}
|
||||
|
||||
private void tsbCheckUpdateCore_Click(object sender, EventArgs e)
|
||||
@@ -1054,10 +1051,7 @@ namespace clashN.Forms
|
||||
AppendText(false, ResUI.MsgUpdateCoreCoreSuccessfully);
|
||||
}
|
||||
};
|
||||
Task.Run(() =>
|
||||
{
|
||||
(new UpdateHandle()).CheckUpdateCore(type, config, _updateUI);
|
||||
});
|
||||
(new UpdateHandle()).CheckUpdateCore(type, config, _updateUI);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace clashN
|
||||
public const string NUrl = @"https://github.com/2dust/clashN/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 geoUrl = "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/{0}.dat";
|
||||
|
||||
/// <summary>
|
||||
/// SpeedTestUrl
|
||||
|
||||
@@ -58,12 +58,24 @@ namespace clashN.Handler
|
||||
{
|
||||
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
|
||||
{
|
||||
coreType = ECoreType.clash,
|
||||
coreExes = new List<string> { "clash-windows-amd64-v3", "clash-windows-amd64", "clash-windows-386", "clash" },
|
||||
arguments = "-f config.yaml",
|
||||
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"
|
||||
});
|
||||
|
||||
@@ -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" },
|
||||
arguments = "-f config.yaml",
|
||||
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"
|
||||
});
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
_config = config;
|
||||
@@ -242,7 +232,7 @@ namespace clashN.Handler
|
||||
{
|
||||
_config = config;
|
||||
_updateFunc = update;
|
||||
var url = string.Format(geoUrl, geoName);
|
||||
var url = string.Format(Global.geoUrl, geoName);
|
||||
|
||||
DownloadHandle downloadHandle = null;
|
||||
if (downloadHandle == null)
|
||||
@@ -294,23 +284,8 @@ namespace clashN.Handler
|
||||
{
|
||||
try
|
||||
{
|
||||
string url;
|
||||
if (type == ECoreType.clash)
|
||||
{
|
||||
url = clashCoreLatestUrl;
|
||||
}
|
||||
else if (type == ECoreType.clash_meta)
|
||||
{
|
||||
url = clashMetaCoreLatestUrl;
|
||||
}
|
||||
else if (type == ECoreType.clashN)
|
||||
{
|
||||
url = nLatestUrl;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Type");
|
||||
}
|
||||
var coreInfo = LazyConfig.Instance.GetCoreInfo(type);
|
||||
string url = coreInfo.coreLatestUrl;
|
||||
|
||||
var result = await (new DownloadHandle()).UrlRedirectAsync(url, true);
|
||||
if (!Utils.IsNullOrEmpty(result))
|
||||
@@ -381,6 +356,7 @@ namespace clashN.Handler
|
||||
try
|
||||
{
|
||||
string version = redirectUrl.Substring(redirectUrl.LastIndexOf("/", StringComparison.Ordinal) + 1);
|
||||
var coreInfo = LazyConfig.Instance.GetCoreInfo(type);
|
||||
|
||||
string curVersion;
|
||||
string message;
|
||||
@@ -391,11 +367,11 @@ namespace clashN.Handler
|
||||
message = string.Format(ResUI.IsLatestCore, curVersion);
|
||||
if (Environment.Is64BitProcess)
|
||||
{
|
||||
url = string.Format(clashCoreUrl64, version);
|
||||
url = string.Format(coreInfo.coreDownloadUrl64, version);
|
||||
}
|
||||
else
|
||||
{
|
||||
url = string.Format(clashCoreUrl32, version);
|
||||
url = string.Format(coreInfo.coreDownloadUrl32, version);
|
||||
}
|
||||
}
|
||||
else if (type == ECoreType.clash_meta)
|
||||
@@ -404,18 +380,18 @@ namespace clashN.Handler
|
||||
message = string.Format(ResUI.IsLatestCore, curVersion);
|
||||
if (Environment.Is64BitProcess)
|
||||
{
|
||||
url = string.Format(clashMetaCoreUrl64, version);
|
||||
url = string.Format(coreInfo.coreDownloadUrl64, version);
|
||||
}
|
||||
else
|
||||
{
|
||||
url = string.Format(clashMetaCoreUrl32, version);
|
||||
url = string.Format(coreInfo.coreDownloadUrl32, version);
|
||||
}
|
||||
}
|
||||
else if (type == ECoreType.clashN)
|
||||
{
|
||||
curVersion = FileVersionInfo.GetVersionInfo(Utils.GetExePath()).FileVersion.ToString();
|
||||
message = string.Format(ResUI.IsLatestN, curVersion);
|
||||
url = string.Format(nUrl, version);
|
||||
url = string.Format(coreInfo.coreDownloadUrl64, version);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -14,6 +14,12 @@ namespace clashN.Mode
|
||||
|
||||
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; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user