fix downloader
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO.Compression;
|
||||
using System.Net.Http.Json;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using Windows.Media.Protection.PlayReady;
|
||||
|
||||
namespace BlueberryUpdater
|
||||
{
|
||||
@@ -74,14 +70,12 @@ namespace BlueberryUpdater
|
||||
string releaseUrl = "https://git.technopunk.space/api/v1/repos/tomi/Blueberry/releases/latest";
|
||||
|
||||
// 1. Fetch JSON
|
||||
var root = client.GetFromJsonAsync<JsonElement>(releaseUrl).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
var json = client.GetStringAsync(releaseUrl).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
json = json.Split("\"name\":\"payload.zip\",")[1];
|
||||
|
||||
|
||||
// 2. Find URL for "payload.zip"
|
||||
string downloadUrl = root.GetProperty("assets")
|
||||
.EnumerateArray()
|
||||
.First(x => x.GetProperty("name").GetString() == "payload.zip")
|
||||
.GetProperty("browser_download_url")
|
||||
.GetString() ?? throw new NullReferenceException();
|
||||
string downloadUrl = json.Split("\"browser_download_url\":\"")[1].Split("\"")[0];
|
||||
|
||||
Console.WriteLine("Downloading Blueberry...");
|
||||
var stream = DownloadFileWithProgressAsync(client, downloadUrl).GetAwaiter().GetResult();
|
||||
@@ -146,6 +140,8 @@ namespace BlueberryUpdater
|
||||
|
||||
static void DrawProgressBar(int percent, string filename)
|
||||
{
|
||||
percent = Math.Clamp(percent, 0, 100);
|
||||
|
||||
// Move cursor to start of line
|
||||
Console.CursorLeft = 0;
|
||||
|
||||
@@ -153,7 +149,7 @@ namespace BlueberryUpdater
|
||||
string shortName = filename.Length > 20 ? filename.Substring(0, 17) + "..." : filename.PadRight(20);
|
||||
|
||||
Console.Write("[");
|
||||
int width = Console.WindowWidth - 21; // Width of the bar
|
||||
int width = Console.WindowWidth - 31; // Width of the bar
|
||||
int progress = (int)((percent / 100.0) * width);
|
||||
|
||||
// Draw filled part
|
||||
@@ -174,7 +170,7 @@ namespace BlueberryUpdater
|
||||
var canReportProgress = totalBytes != -1;
|
||||
|
||||
using var contentStream = await response.Content.ReadAsStreamAsync();
|
||||
using var memoryStream = new MemoryStream();
|
||||
var memoryStream = new MemoryStream();
|
||||
|
||||
var buffer = new byte[8192];
|
||||
long totalRead = 0;
|
||||
@@ -189,11 +185,13 @@ namespace BlueberryUpdater
|
||||
DrawProgressBar((int)((double)totalRead / totalBytes * 100), "Downloading...");
|
||||
}
|
||||
DrawProgressBar(100, "Done");
|
||||
Console.WriteLine();
|
||||
return memoryStream;
|
||||
}
|
||||
static void ExtractWithProgress(MemoryStream stream)
|
||||
{
|
||||
using (ZipArchive archive = new(stream))
|
||||
stream.Position = 0;
|
||||
using (ZipArchive archive = new(stream, ZipArchiveMode.Read))
|
||||
{
|
||||
int totalEntries = archive.Entries.Count;
|
||||
int currentEntry = 0;
|
||||
@@ -229,6 +227,20 @@ namespace BlueberryUpdater
|
||||
}
|
||||
}
|
||||
DrawProgressBar(100, "Done");
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
public class Dto
|
||||
{
|
||||
public class Item
|
||||
{
|
||||
public Assets[] assets { get; set; }
|
||||
}
|
||||
public class Assets
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string browser_download_url { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user