mirror of
https://github.com/netchx/netch.git
synced 2026-05-07 22:44:03 +08:00
Feat: Update Download Progress
This commit is contained in:
@@ -19,7 +19,7 @@ namespace Netch.Controllers
|
||||
public const string Name = @"Netch";
|
||||
public const string Copyright = @"Copyright © 2019 - 2020";
|
||||
|
||||
public const string AssemblyVersion = @"1.7.0";
|
||||
public const string AssemblyVersion = @"1.7.1";
|
||||
private const string Suffix = @"";
|
||||
|
||||
public static readonly string Version = $"{AssemblyVersion}{(string.IsNullOrEmpty(Suffix) ? "" : $"-{Suffix}")}";
|
||||
@@ -68,10 +68,12 @@ namespace Netch.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task UpdateNetch()
|
||||
public static async Task UpdateNetch(DownloadProgressChangedEventHandler onDownloadProgressChanged)
|
||||
{
|
||||
using WebClient client = new();
|
||||
|
||||
var latestVersionDownloadUrl = LatestRelease.assets[0].browser_download_url;
|
||||
var tagPage = await WebUtil.DownloadStringAsync(WebUtil.CreateRequest(LatestVersionUrl));
|
||||
var tagPage = await client.DownloadStringTaskAsync(LatestVersionUrl);
|
||||
var match = Regex.Match(tagPage, @"<td .*>(?<sha256>.*)</td>", RegexOptions.Singleline);
|
||||
|
||||
// TODO Replace with regex get basename and sha256
|
||||
@@ -92,11 +94,11 @@ namespace Netch.Controllers
|
||||
File.Delete(fileFullPath);
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
// TODO Replace "New Version Found" to Progress bar
|
||||
await WebUtil.DownloadFileAsync(WebUtil.CreateRequest(latestVersionDownloadUrl), fileFullPath);
|
||||
client.DownloadProgressChanged += onDownloadProgressChanged;
|
||||
await client.DownloadFileTaskAsync(new Uri(latestVersionDownloadUrl), fileFullPath);
|
||||
client.DownloadProgressChanged -= onDownloadProgressChanged;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Windows.Forms;
|
||||
using Netch.Controllers;
|
||||
using Netch.Utils;
|
||||
@@ -30,12 +31,20 @@ namespace Netch.Forms
|
||||
return;
|
||||
NotifyTip(i18N.Translate("Start downloading new version"));
|
||||
|
||||
NewVersionLabel.Enabled = false;
|
||||
NewVersionLabel.Text = "...";
|
||||
try
|
||||
{
|
||||
await UpdateChecker.UpdateNetch();
|
||||
DownloadProgressChangedEventHandler OnDownloadProgressChanged()
|
||||
{
|
||||
return (_, args) => { BeginInvoke(new Action(() => { NewVersionLabel.Text = $"{args.ProgressPercentage}%"; })); };
|
||||
}
|
||||
|
||||
await UpdateChecker.UpdateNetch(OnDownloadProgressChanged());
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Logging.Error(exception.Message);
|
||||
NotifyTip(exception.Message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user