Read latest version from website and add Run when system starts

This commit is contained in:
Louis Lam
2023-02-20 20:26:53 +08:00
parent 6a98ffe2f6
commit cf32b8bc64
9 changed files with 373 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
namespace UptimeKuma {
public partial class DownloadForm : Form {
@@ -23,9 +24,18 @@ namespace UptimeKuma {
webClient.DownloadProgressChanged += DownloadProgressChanged;
webClient.DownloadFileCompleted += DownloadFileCompleted;
label.Text = "Reading latest version...";
// Read json from https://uptime.kuma.pet/version
var versionObj = JsonConvert.DeserializeObject<Version>(new WebClient().DownloadString("https://uptime.kuma.pet/version"));
var nodeVersion = versionObj.nodejs;
var uptimeKumaVersion = versionObj.latest;
if (!Directory.Exists("node")) {
downloadQueue.Enqueue(new DownloadItem {
URL = "https://nodejs.org/dist/v16.17.1/node-v16.17.1-win-x64.zip",
URL = $"https://nodejs.org/dist/v{nodeVersion}/node-v{nodeVersion}-win-x64.zip",
Filename = "node.zip",
TargetFolder = "node"
});
@@ -33,7 +43,7 @@ namespace UptimeKuma {
if (!Directory.Exists("node")) {
downloadQueue.Enqueue(new DownloadItem {
URL = "https://github.com/louislam/uptime-kuma/archive/refs/tags/1.18.3.zip",
URL = $"https://github.com/louislam/uptime-kuma/archive/refs/tags/{uptimeKumaVersion}.zip",
Filename = "core.zip",
TargetFolder = "core"
});