mirror of
https://gitlab.com/2009scape/Saradomin-Launcher.git
synced 2026-08-01 14:19:14 -06:00
Improve UX while extracting - extract off main thread, add user feedback while it happens
This commit is contained in:
parent
3449d88fb1
commit
b2cf0bfb01
2 changed files with 14 additions and 9 deletions
|
|
@ -29,16 +29,16 @@ namespace Saradomin.Infrastructure.Services
|
|||
using (HttpClient httpClient = new HttpClient())
|
||||
{
|
||||
var response = await httpClient.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead);
|
||||
var contentLength = response.Content.Headers.ContentLength ?? 1;
|
||||
var contentLength = response.Content.Headers.ContentLength ?? 40 * 1024 * 1024L;
|
||||
var totalRead = 0L;
|
||||
var buffer = new byte[8192];
|
||||
|
||||
// Create a FileStream to write the downloaded bytes to
|
||||
using (var fileStream = new FileStream(downloadPath, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
await using (var fileStream = new FileStream(downloadPath, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
{
|
||||
using (var stream = await response.Content.ReadAsStreamAsync())
|
||||
await using (var stream = await response.Content.ReadAsStreamAsync())
|
||||
{
|
||||
var bytesRead = 0;
|
||||
int bytesRead;
|
||||
do
|
||||
{
|
||||
bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);
|
||||
|
|
@ -53,16 +53,16 @@ namespace Saradomin.Infrastructure.Services
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
JavaDownloadProgressChanged?.Invoke(this, 1f);
|
||||
if (Path.GetExtension(downloadUrl) == ".zip")
|
||||
{
|
||||
ZipFile.ExtractToDirectory(downloadPath, extractedPath);
|
||||
await Task.Run(() => ZipFile.ExtractToDirectory(downloadPath, extractedPath));
|
||||
}
|
||||
else if (Path.GetExtension(downloadUrl) == ".gz" || Path.GetExtension(downloadUrl) == ".tar.gz")
|
||||
{
|
||||
if (!Directory.Exists(extractedPath)) Directory.CreateDirectory(extractedPath);
|
||||
string extractOutput = CrossPlatform.RunCommandAndGetOutput($"tar xf {downloadPath} -C {extractedPath} --strip-components 1");
|
||||
Console.WriteLine($"Extract output: {extractOutput}");
|
||||
await Task.Run(() => CrossPlatform.RunCommandAndGetOutput($"tar xf {downloadPath} -C {extractedPath} --strip-components 1"));
|
||||
}
|
||||
|
||||
File.Delete(downloadPath);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
|
|
@ -308,6 +307,12 @@ namespace Saradomin.ViewModel.Windows
|
|||
}
|
||||
private void OnJavaDownloadProgressUpdated(object sender, float e)
|
||||
{
|
||||
if (e >= 0.999f)
|
||||
{
|
||||
Console.WriteLine($"Writing about extracting Java");
|
||||
LaunchText = "Updating... (Extracting Java)";
|
||||
return;
|
||||
}
|
||||
LaunchText = $"Updating... (Downloading Java: {e * 100:F2}%)";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue