diff --git a/Saradomin/Infrastructure/Services/JavaUpdateService.cs b/Saradomin/Infrastructure/Services/JavaUpdateService.cs index 8223554..c2039f9 100644 --- a/Saradomin/Infrastructure/Services/JavaUpdateService.cs +++ b/Saradomin/Infrastructure/Services/JavaUpdateService.cs @@ -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); diff --git a/Saradomin/ViewModel/Windows/MainWindowViewModel.cs b/Saradomin/ViewModel/Windows/MainWindowViewModel.cs index 350b631..de55669 100644 --- a/Saradomin/ViewModel/Windows/MainWindowViewModel.cs +++ b/Saradomin/ViewModel/Windows/MainWindowViewModel.cs @@ -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}%)"; } }