v2rayN/v2rayN/ServiceLib/Handler/UpdateHandler.cs

506 lines
20 KiB
C#
Raw Normal View History

2024-08-19 10:15:54 +00:00
using System.Diagnostics;
2023-04-07 10:13:37 +00:00
using System.Runtime.InteropServices;
2021-05-13 12:51:20 +00:00
using System.Text;
using System.Text.RegularExpressions;
2024-08-19 10:15:54 +00:00
namespace ServiceLib.Handler
2021-05-13 12:51:20 +00:00
{
2024-08-19 10:15:54 +00:00
public class UpdateHandler
2021-05-13 12:51:20 +00:00
{
2023-04-14 12:49:36 +00:00
private Action<bool, string> _updateFunc;
2021-05-13 12:51:20 +00:00
private Config _config;
2024-09-04 07:47:17 +00:00
private int _timeout = 30;
2021-05-13 12:51:20 +00:00
2024-09-04 07:47:17 +00:00
private class ResultEventArgs
2021-05-13 12:51:20 +00:00
{
public bool Success;
public string Msg;
2023-12-03 09:02:34 +00:00
public string Url;
2021-05-13 12:51:20 +00:00
2023-12-03 09:02:34 +00:00
public ResultEventArgs(bool success, string msg, string url = "")
2021-05-13 12:51:20 +00:00
{
2022-06-22 01:48:00 +00:00
Success = success;
Msg = msg;
2023-12-03 09:02:34 +00:00
Url = url;
2021-05-13 12:51:20 +00:00
}
}
2024-09-04 07:47:17 +00:00
public async Task CheckUpdateGuiN(Config config, Action<bool, string> update, bool preRelease)
2021-05-13 12:51:20 +00:00
{
_config = config;
_updateFunc = update;
2021-10-10 12:16:30 +00:00
var url = string.Empty;
2024-09-04 07:47:17 +00:00
var fileName = string.Empty;
2021-05-13 12:51:20 +00:00
2024-08-15 12:13:59 +00:00
DownloadHandler downloadHandle = new();
2023-02-19 04:18:08 +00:00
downloadHandle.UpdateCompleted += (sender2, args) =>
2021-05-13 12:51:20 +00:00
{
2023-02-19 04:18:08 +00:00
if (args.Success)
2021-05-13 12:51:20 +00:00
{
2023-02-19 04:18:08 +00:00
_updateFunc(false, ResUI.MsgDownloadV2rayCoreSuccessfully);
2024-09-04 07:47:17 +00:00
_updateFunc(true, Utils.UrlEncode(fileName));
2023-02-19 04:18:08 +00:00
}
else
2021-05-13 12:51:20 +00:00
{
2023-02-19 04:18:08 +00:00
_updateFunc(false, args.Msg);
}
};
downloadHandle.Error += (sender2, args) =>
{
_updateFunc(false, args.GetException().Message);
};
2021-05-13 12:51:20 +00:00
2024-08-19 10:15:54 +00:00
_updateFunc(false, string.Format(ResUI.MsgStartUpdating, ECoreType.v2rayN));
2024-09-04 07:47:17 +00:00
var args = await CheckUpdateAsync(downloadHandle, ECoreType.v2rayN, preRelease);
if (args.Success)
{
_updateFunc(false, string.Format(ResUI.MsgParsingSuccessfully, ECoreType.v2rayN));
_updateFunc(false, args.Msg);
url = args.Url;
fileName = Utils.GetTempPath(Utils.GetGUID());
await downloadHandle.DownloadFileAsync(url, fileName, true, _timeout);
}
else
{
_updateFunc(false, args.Msg);
}
2021-05-13 12:51:20 +00:00
}
2024-09-04 07:47:17 +00:00
public async Task CheckUpdateCore(ECoreType type, Config config, Action<bool, string> update, bool preRelease)
2021-05-13 12:51:20 +00:00
{
_config = config;
_updateFunc = update;
2021-10-10 12:16:30 +00:00
var url = string.Empty;
2024-09-04 07:47:17 +00:00
var fileName = string.Empty;
2021-05-13 12:51:20 +00:00
2024-08-15 12:13:59 +00:00
DownloadHandler downloadHandle = new();
2023-02-19 04:18:08 +00:00
downloadHandle.UpdateCompleted += (sender2, args) =>
2021-05-13 12:51:20 +00:00
{
2023-02-19 04:18:08 +00:00
if (args.Success)
2021-05-13 12:51:20 +00:00
{
2023-02-19 04:18:08 +00:00
_updateFunc(false, ResUI.MsgDownloadV2rayCoreSuccessfully);
_updateFunc(false, ResUI.MsgUnpacking);
2021-05-13 12:51:20 +00:00
2023-02-19 04:18:08 +00:00
try
{
2024-09-04 07:47:17 +00:00
_updateFunc(true, fileName);
2021-05-13 12:51:20 +00:00
}
2023-02-19 04:18:08 +00:00
catch (Exception ex)
2021-05-13 12:51:20 +00:00
{
2023-02-19 04:18:08 +00:00
_updateFunc(false, ex.Message);
2021-05-13 12:51:20 +00:00
}
2023-02-19 04:18:08 +00:00
}
else
2021-05-13 12:51:20 +00:00
{
2023-02-19 04:18:08 +00:00
_updateFunc(false, args.Msg);
}
};
downloadHandle.Error += (sender2, args) =>
{
2024-09-04 07:47:17 +00:00
_updateFunc(false, args.GetException().Message);
2023-02-19 04:18:08 +00:00
};
2021-05-13 12:51:20 +00:00
2024-09-04 07:47:17 +00:00
_updateFunc(false, string.Format(ResUI.MsgStartUpdating, type));
var args = await CheckUpdateAsync(downloadHandle, type, preRelease);
if (args.Success)
2021-05-13 12:51:20 +00:00
{
2024-09-04 07:47:17 +00:00
_updateFunc(false, string.Format(ResUI.MsgParsingSuccessfully, type));
_updateFunc(false, args.Msg);
2023-12-03 09:02:34 +00:00
2024-09-04 07:47:17 +00:00
url = args.Url;
2024-10-04 09:10:30 +00:00
var ext = Path.GetExtension(url);
fileName = Utils.GetTempPath(Utils.GetGUID()+ ext);
2024-09-04 07:47:17 +00:00
await downloadHandle.DownloadFileAsync(url, fileName, true, _timeout);
}
else
{
if (!args.Msg.IsNullOrEmpty())
2021-05-13 12:51:20 +00:00
{
_updateFunc(false, args.Msg);
}
2024-09-04 07:47:17 +00:00
}
2021-05-13 12:51:20 +00:00
}
2023-01-01 11:42:01 +00:00
public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy, Action<bool, string> update)
2021-05-13 12:51:20 +00:00
{
_config = config;
_updateFunc = update;
2022-03-31 11:53:58 +00:00
_updateFunc(false, ResUI.MsgUpdateSubscriptionStart);
2023-06-04 07:50:25 +00:00
var subItem = LazyConfig.Instance.SubItems().OrderBy(t => t.sort).ToList();
2021-05-13 12:51:20 +00:00
2023-01-01 11:42:01 +00:00
if (subItem == null || subItem.Count <= 0)
2021-05-13 12:51:20 +00:00
{
2022-03-31 11:53:58 +00:00
_updateFunc(false, ResUI.MsgNoValidSubscription);
2021-05-13 12:51:20 +00:00
return;
}
2022-04-11 07:26:32 +00:00
Task.Run(async () =>
2021-05-13 12:51:20 +00:00
{
2023-01-01 11:42:01 +00:00
foreach (var item in subItem)
2021-05-13 12:51:20 +00:00
{
2022-04-11 07:26:32 +00:00
string id = item.id.TrimEx();
string url = item.url.TrimEx();
string userAgent = item.userAgent.TrimEx();
string hashCode = $"{item.remarks}->";
2024-09-17 08:52:41 +00:00
if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url) || (Utils.IsNotEmpty(subId) && item.id != subId))
2022-04-11 07:26:32 +00:00
{
//_updateFunc(false, $"{hashCode}{ResUI.MsgNoValidSubscription}");
continue;
}
2023-12-19 10:09:11 +00:00
if (!url.StartsWith(Global.HttpsProtocol) && !url.StartsWith(Global.HttpProtocol))
2023-06-04 07:50:25 +00:00
{
continue;
}
2023-03-31 12:07:39 +00:00
if (item.enabled == false)
{
_updateFunc(false, $"{hashCode}{ResUI.MsgSkipSubscriptionUpdate}");
continue;
}
2021-05-13 12:51:20 +00:00
2024-08-15 12:13:59 +00:00
var downloadHandle = new DownloadHandler();
2022-07-02 12:02:20 +00:00
downloadHandle.Error += (sender2, args) =>
{
_updateFunc(false, $"{hashCode}{args.GetException().Message}");
};
2022-04-11 07:26:32 +00:00
_updateFunc(false, $"{hashCode}{ResUI.MsgStartGettingSubscriptions}");
//one url
2024-03-26 06:26:03 +00:00
url = Utils.GetPunycode(url);
//convert
2024-09-17 08:52:41 +00:00
if (Utils.IsNotEmpty(item.convertTarget))
{
2024-03-26 06:26:03 +00:00
var subConvertUrl = Utils.IsNullOrEmpty(config.constItem.subConvertUrl) ? Global.SubConvertUrls.FirstOrDefault() : config.constItem.subConvertUrl;
url = string.Format(subConvertUrl!, Utils.UrlEncode(url));
if (!url.Contains("target="))
{
url += string.Format("&target={0}", item.convertTarget);
}
if (!url.Contains("config="))
{
url += string.Format("&config={0}", Global.SubConvertConfig.FirstOrDefault());
}
}
var result = await downloadHandle.TryDownloadString(url, blProxy, userAgent);
2024-03-26 06:26:03 +00:00
if (blProxy && Utils.IsNullOrEmpty(result))
2022-06-26 12:18:43 +00:00
{
result = await downloadHandle.TryDownloadString(url, false, userAgent);
2022-06-26 12:18:43 +00:00
}
2022-04-11 07:26:32 +00:00
//more url
2024-09-17 08:52:41 +00:00
if (Utils.IsNullOrEmpty(item.convertTarget) && Utils.IsNotEmpty(item.moreUrl.TrimEx()))
{
2024-09-18 11:54:38 +00:00
if (Utils.IsNotEmpty(result) && Utils.IsBase64String(result))
{
2024-03-26 06:26:03 +00:00
result = Utils.Base64Decode(result);
}
2024-08-19 10:15:54 +00:00
var lstUrl = item.moreUrl.TrimEx().Split(",") ?? [];
foreach (var it in lstUrl)
{
2024-03-26 06:26:03 +00:00
var url2 = Utils.GetPunycode(it);
if (Utils.IsNullOrEmpty(url2))
{
continue;
}
var result2 = await downloadHandle.TryDownloadString(url2, blProxy, userAgent);
2024-03-26 06:26:03 +00:00
if (blProxy && Utils.IsNullOrEmpty(result2))
{
result2 = await downloadHandle.TryDownloadString(url2, false, userAgent);
}
2024-09-17 08:52:41 +00:00
if (Utils.IsNotEmpty(result2))
{
2024-09-18 11:54:38 +00:00
if (Utils.IsBase64String(result2))
{
2024-03-26 06:26:03 +00:00
result += Utils.Base64Decode(result2);
}
else
{
result += result2;
}
}
}
}
2024-03-26 06:26:03 +00:00
if (Utils.IsNullOrEmpty(result))
2022-04-11 07:26:32 +00:00
{
_updateFunc(false, $"{hashCode}{ResUI.MsgSubscriptionDecodingFailed}");
}
else
{
2022-07-02 12:02:20 +00:00
_updateFunc(false, $"{hashCode}{ResUI.MsgGetSubscriptionSuccessfully}");
2024-03-13 08:38:37 +00:00
if (result?.Length < 99)
2022-07-02 12:02:20 +00:00
{
_updateFunc(false, $"{hashCode}{result}");
}
2023-12-22 08:03:25 +00:00
int ret = ConfigHandler.AddBatchServers(config, result, id, true);
2023-01-07 12:15:20 +00:00
if (ret <= 0)
{
2024-01-10 02:43:48 +00:00
Logging.SaveLog("FailedImportSubscription");
Logging.SaveLog(result);
2023-01-07 12:15:20 +00:00
}
2022-06-22 01:48:00 +00:00
_updateFunc(false,
ret > 0
? $"{hashCode}{ResUI.MsgUpdateSubscriptionEnd}"
: $"{hashCode}{ResUI.MsgFailedImportSubscription}");
2021-05-13 12:51:20 +00:00
}
2022-06-22 01:48:00 +00:00
_updateFunc(false, "-------------------------------------------------------");
2022-04-11 07:26:32 +00:00
}
2022-04-11 07:26:32 +00:00
_updateFunc(true, $"{ResUI.MsgUpdateSubscriptionEnd}");
});
2021-05-13 12:51:20 +00:00
}
2024-09-04 07:47:17 +00:00
public async Task UpdateGeoFileAll(Config config, Action<bool, string> update)
2021-05-13 12:51:20 +00:00
{
2024-09-04 07:47:17 +00:00
await UpdateGeoFile("geosite", _config, update);
await UpdateGeoFile("geoip", _config, update);
_updateFunc(true, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, "geo"));
2021-05-13 12:51:20 +00:00
}
2024-09-16 03:09:44 +00:00
public async Task RunAvailabilityCheck(Action<bool, string> update)
2022-04-12 12:24:48 +00:00
{
2024-09-16 03:09:44 +00:00
var time = await (new DownloadHandler()).RunAvailabilityCheck(null);
update(false, string.Format(ResUI.TestMeOutput, time));
2022-04-12 12:24:48 +00:00
}
2021-05-13 12:51:20 +00:00
#region private
2024-09-04 07:47:17 +00:00
private async Task<ResultEventArgs> CheckUpdateAsync(DownloadHandler downloadHandle, ECoreType type, bool preRelease)
2021-05-13 12:51:20 +00:00
{
try
{
2024-08-15 12:13:59 +00:00
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(type);
2024-09-04 07:47:17 +00:00
var url = coreInfo?.coreReleaseApiUrl;
2022-04-11 07:26:32 +00:00
2024-09-23 09:05:03 +00:00
var result = await downloadHandle.TryDownloadString(url, true, Global.AppName);
2024-09-17 08:52:41 +00:00
if (Utils.IsNotEmpty(result))
2021-05-13 12:51:20 +00:00
{
2024-09-04 07:47:17 +00:00
return await ParseDownloadUrl(type, result, preRelease);
2021-05-13 12:51:20 +00:00
}
else
{
2024-09-04 07:47:17 +00:00
return new ResultEventArgs(false, "");
2021-05-13 12:51:20 +00:00
}
}
catch (Exception ex)
{
2024-01-10 02:43:48 +00:00
Logging.SaveLog(ex.Message, ex);
2021-05-13 12:51:20 +00:00
_updateFunc(false, ex.Message);
2024-09-04 07:47:17 +00:00
return new ResultEventArgs(false, ex.Message);
2021-05-13 12:51:20 +00:00
}
}
/// <summary>
2024-08-27 05:06:39 +00:00
/// 获取Core版本
2021-05-13 12:51:20 +00:00
/// </summary>
2024-06-03 09:50:18 +00:00
private SemanticVersion GetCoreVersion(ECoreType type)
2021-05-13 12:51:20 +00:00
{
try
{
2024-08-15 12:13:59 +00:00
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(type);
2022-04-11 07:26:32 +00:00
string filePath = string.Empty;
foreach (string name in coreInfo.coreExes)
2021-05-13 12:51:20 +00:00
{
2024-08-27 05:06:39 +00:00
string vName = Utils.GetExeName(name);
2024-03-26 06:26:03 +00:00
vName = Utils.GetBinPath(vName, coreInfo.coreType.ToString());
2022-04-11 07:26:32 +00:00
if (File.Exists(vName))
{
filePath = vName;
break;
}
2021-05-13 12:51:20 +00:00
}
2022-04-11 07:26:32 +00:00
2021-05-13 12:51:20 +00:00
if (!File.Exists(filePath))
{
2023-01-01 11:42:01 +00:00
string msg = string.Format(ResUI.NotFoundCore, @"", "", "");
2021-05-13 12:51:20 +00:00
//ShowMsg(true, msg);
return new SemanticVersion("");
2021-05-13 12:51:20 +00:00
}
2023-02-19 05:34:22 +00:00
using Process p = new();
2024-10-04 09:10:30 +00:00
p.StartInfo.FileName = filePath;
2022-07-30 12:12:14 +00:00
p.StartInfo.Arguments = coreInfo.versionArg;
2024-10-04 09:10:30 +00:00
p.StartInfo.WorkingDirectory = Utils.GetConfigPath();
2021-05-13 12:51:20 +00:00
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();
2022-07-30 12:12:14 +00:00
string version = string.Empty;
switch (type)
{
case ECoreType.v2fly:
case ECoreType.Xray:
2022-09-08 12:52:44 +00:00
case ECoreType.v2fly_v5:
2022-07-30 12:12:14 +00:00
version = Regex.Match(echo, $"{coreInfo.match} ([0-9.]+) \\(").Groups[1].Value;
break;
2023-04-14 12:49:36 +00:00
2024-02-18 03:02:50 +00:00
case ECoreType.mihomo:
2023-04-14 12:49:36 +00:00
version = Regex.Match(echo, $"v[0-9.]+").Groups[0].Value;
2023-04-13 07:50:28 +00:00
break;
2023-04-14 12:49:36 +00:00
2023-04-13 07:50:28 +00:00
case ECoreType.sing_box:
version = Regex.Match(echo, $"([0-9.]+)").Groups[1].Value;
2022-07-30 12:12:14 +00:00
break;
}
return new SemanticVersion(version);
2021-05-13 12:51:20 +00:00
}
catch (Exception ex)
{
2024-01-10 02:43:48 +00:00
Logging.SaveLog(ex.Message, ex);
2021-05-13 12:51:20 +00:00
_updateFunc(false, ex.Message);
return new SemanticVersion("");
2021-05-13 12:51:20 +00:00
}
}
2023-04-14 12:49:36 +00:00
2024-09-04 07:47:17 +00:00
private async Task<ResultEventArgs> ParseDownloadUrl(ECoreType type, string gitHubReleaseApi, bool preRelease)
2021-05-13 12:51:20 +00:00
{
try
{
2024-03-26 06:26:03 +00:00
var gitHubReleases = JsonUtils.Deserialize<List<GitHubRelease>>(gitHubReleaseApi);
2024-03-13 08:38:37 +00:00
var gitHubRelease = preRelease ? gitHubReleases?.First() : gitHubReleases?.First(r => r.Prerelease == false);
2024-09-18 11:54:38 +00:00
var version = new SemanticVersion(gitHubRelease?.TagName);
2024-03-13 08:38:37 +00:00
var body = gitHubRelease?.Body;
2023-12-03 09:02:34 +00:00
2024-08-15 12:13:59 +00:00
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(type);
SemanticVersion curVersion;
2021-05-13 12:51:20 +00:00
string message;
2024-08-27 05:06:39 +00:00
string? url;
2022-06-24 01:32:55 +00:00
switch (type)
2021-05-13 12:51:20 +00:00
{
2022-06-24 01:32:55 +00:00
case ECoreType.v2fly:
case ECoreType.Xray:
2022-09-08 12:52:44 +00:00
case ECoreType.v2fly_v5:
2022-06-24 01:32:55 +00:00
{
2024-06-03 09:50:18 +00:00
curVersion = GetCoreVersion(type);
2023-11-22 03:48:48 +00:00
message = string.Format(ResUI.IsLatestCore, type, curVersion.ToVersionString("v"));
2024-08-27 05:06:39 +00:00
url = string.Format(GetUrlFromCore(coreInfo), version.ToVersionString("v"));
2022-06-24 01:32:55 +00:00
break;
}
2024-02-18 03:02:50 +00:00
case ECoreType.mihomo:
2022-06-24 01:32:55 +00:00
{
2024-06-03 09:50:18 +00:00
curVersion = GetCoreVersion(type);
2023-11-22 03:48:48 +00:00
message = string.Format(ResUI.IsLatestCore, type, curVersion);
2024-08-27 05:06:39 +00:00
url = string.Format(GetUrlFromCore(coreInfo), version.ToVersionString("v"));
2023-04-13 07:50:28 +00:00
break;
}
case ECoreType.sing_box:
{
2024-06-03 09:50:18 +00:00
curVersion = GetCoreVersion(type);
2023-11-22 03:48:48 +00:00
message = string.Format(ResUI.IsLatestCore, type, curVersion.ToVersionString("v"));
2024-08-27 05:06:39 +00:00
url = string.Format(GetUrlFromCore(coreInfo), version.ToVersionString("v"), version);
2022-06-24 01:32:55 +00:00
break;
}
case ECoreType.v2rayN:
{
2024-08-29 07:19:03 +00:00
curVersion = new SemanticVersion(Utils.GetVersionInfo());
2023-11-22 03:48:48 +00:00
message = string.Format(ResUI.IsLatestN, type, curVersion);
2024-08-27 05:06:39 +00:00
url = string.Format(GetUrlFromCore(coreInfo), version);
2022-06-24 01:32:55 +00:00
break;
}
default:
throw new ArgumentException("Type");
2021-05-13 12:51:20 +00:00
}
2023-06-18 08:18:50 +00:00
if (curVersion >= version && version != new SemanticVersion(0, 0, 0))
2021-05-13 12:51:20 +00:00
{
2024-09-04 07:47:17 +00:00
return new ResultEventArgs(false, message);
2021-05-13 12:51:20 +00:00
}
2024-09-04 07:47:17 +00:00
return new ResultEventArgs(true, body, url);
2021-05-13 12:51:20 +00:00
}
catch (Exception ex)
{
2024-01-10 02:43:48 +00:00
Logging.SaveLog(ex.Message, ex);
2021-05-13 12:51:20 +00:00
_updateFunc(false, ex.Message);
2024-09-04 07:47:17 +00:00
return new ResultEventArgs(false, ex.Message);
2021-05-13 12:51:20 +00:00
}
}
2024-08-27 05:06:39 +00:00
private string? GetUrlFromCore(CoreInfo? coreInfo)
{
2024-08-27 11:44:50 +00:00
if (Utils.IsWindows())
2024-08-27 05:06:39 +00:00
{
2024-09-06 06:07:26 +00:00
//Check for standalone windows .Net version
if (coreInfo?.coreType == ECoreType.v2rayN
&& File.Exists(Path.Combine(Utils.StartupPath(), "wpfgfx_cor3.dll"))
&& File.Exists(Path.Combine(Utils.StartupPath(), "D3DCompiler_47_cor3.dll"))
)
{
return coreInfo?.coreDownloadUrl64.Replace("v2rayN.zip", "zz_v2rayN-SelfContained.zip");
}
2024-08-27 05:06:39 +00:00
return RuntimeInformation.ProcessArchitecture switch
{
Architecture.Arm64 => coreInfo?.coreDownloadUrlArm64,
Architecture.X86 => coreInfo?.coreDownloadUrl32,
Architecture.X64 => coreInfo?.coreDownloadUrl64,
_ => null,
};
}
2024-08-27 11:44:50 +00:00
else if (Utils.IsLinux())
2024-08-27 05:06:39 +00:00
{
return RuntimeInformation.ProcessArchitecture switch
{
Architecture.Arm64 => coreInfo?.coreDownloadUrlLinuxArm64,
Architecture.X86 => coreInfo?.coreDownloadUrlLinux32,
Architecture.X64 => coreInfo?.coreDownloadUrlLinux64,
_ => null,
};
}
return null;
}
2023-04-28 07:54:51 +00:00
private async Task UpdateGeoFile(string geoName, Config config, Action<bool, string> update)
{
_config = config;
_updateFunc = update;
2023-12-19 08:49:45 +00:00
var url = string.Format(Global.GeoUrl, geoName);
2024-09-04 07:47:17 +00:00
var fileName = Utils.GetTempPath(Utils.GetGUID());
2023-04-28 07:54:51 +00:00
2024-08-15 12:13:59 +00:00
DownloadHandler downloadHandle = new();
2023-04-28 07:54:51 +00:00
downloadHandle.UpdateCompleted += (sender2, args) =>
{
if (args.Success)
{
_updateFunc(false, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, geoName));
try
{
if (File.Exists(fileName))
{
2024-03-26 06:26:03 +00:00
string targetPath = Utils.GetBinPath($"{geoName}.dat");
2023-04-28 07:54:51 +00:00
File.Copy(fileName, targetPath, true);
File.Delete(fileName);
//_updateFunc(true, "");
}
}
catch (Exception ex)
{
_updateFunc(false, ex.Message);
}
}
else
{
_updateFunc(false, args.Msg);
}
};
downloadHandle.Error += (sender2, args) =>
{
_updateFunc(false, args.GetException().Message);
};
2024-09-04 07:47:17 +00:00
await downloadHandle.DownloadFileAsync(url, fileName, true, _timeout);
2023-04-28 07:54:51 +00:00
}
2023-04-14 12:49:36 +00:00
#endregion private
2021-05-13 12:51:20 +00:00
}
2023-04-14 12:49:36 +00:00
}