diff --git a/MinecraftClient/Commands/Upgrade.cs b/MinecraftClient/Commands/Upgrade.cs index ffa37d3f..265a027b 100644 --- a/MinecraftClient/Commands/Upgrade.cs +++ b/MinecraftClient/Commands/Upgrade.cs @@ -31,8 +31,10 @@ namespace MinecraftClient.Commands private static string DownloadUpdate(bool force) { - UpgradeHelper.DownloadLatestBuild(force); - return Translations.mcc_update_start; + if (UpgradeHelper.DownloadLatestBuild(force)) + return Translations.mcc_update_start; + else + return Translations.mcc_update_already_running; } private static string CancelDownloadUpdate() diff --git a/MinecraftClient/Resources/Translations/Translations.Designer.cs b/MinecraftClient/Resources/Translations/Translations.Designer.cs index 9c93d166..4f39f391 100644 --- a/MinecraftClient/Resources/Translations/Translations.Designer.cs +++ b/MinecraftClient/Resources/Translations/Translations.Designer.cs @@ -5603,7 +5603,7 @@ namespace MinecraftClient { } /// - /// Looks up a localized string similar to Self-updating: {0:00.00}%, Downloaded {1:00.0}MB of {2:00.0}MB, Avg {3:0.0}KB/s. + /// Looks up a localized string similar to Self-updating: {0:00.00}%, ETA {4}, Downloaded {1:00.0}MB of {2:00.0}MB, Avg {3:0.0}KB/s. /// internal static string mcc_update_progress { get { diff --git a/MinecraftClient/Resources/Translations/Translations.resx b/MinecraftClient/Resources/Translations/Translations.resx index bc637797..c6715caa 100644 --- a/MinecraftClient/Resources/Translations/Translations.resx +++ b/MinecraftClient/Resources/Translations/Translations.resx @@ -1988,7 +1988,7 @@ Switching to autodetection mode. The latest release does not contain a build that matches your operating system and CPU architecture. - Self-updating: {0:00.00}%, Downloaded {1:00.0}MB of {2:00.0}MB, Avg {3:0.0}KB/s + Self-updating: {0:00.00}%, ETA {4}, Downloaded {1:00.0}MB of {2:00.0}MB, Avg {3:0.0}KB/s Self-updating: Downloaded {0:00.0}MB, Avg {1:0.0}KB/s diff --git a/MinecraftClient/UpgradeHelper.cs b/MinecraftClient/UpgradeHelper.cs index d47d4fff..77c694d4 100644 --- a/MinecraftClient/UpgradeHelper.cs +++ b/MinecraftClient/UpgradeHelper.cs @@ -48,11 +48,11 @@ namespace MinecraftClient }); } - public static void DownloadLatestBuild(bool forceUpdate, bool isCommandLine = false) + public static bool DownloadLatestBuild(bool forceUpdate, bool isCommandLine = false) { if (Interlocked.Exchange(ref running, 1) == 1) { - ConsoleIO.WriteLine(Translations.mcc_update_already_running); + return false; } else { @@ -105,7 +105,10 @@ namespace MinecraftClient (double)info.BytesTransferred / info.TotalBytes * 100.0, (double)info.BytesTransferred / 1024 / 1024, (double)info.TotalBytes / 1024 / 1024, - (double)info.BytesTransferred / 1024 / (now - downloadStartTime).TotalSeconds) + (double)info.BytesTransferred / 1024 / (now - downloadStartTime).TotalSeconds, + TimeSpan.FromMilliseconds( + (double)(info.TotalBytes - info.BytesTransferred) / (info.BytesTransferred / (now - downloadStartTime).TotalMilliseconds) + ).ToString("hh\\:mm\\:ss")) ); } else @@ -123,10 +126,10 @@ namespace MinecraftClient try { string downloadUrl = $"{GithubReleaseUrl}/download/{latestVersion}/MinecraftClient-{OSInfo}.zip"; - using HttpResponseMessage response = await httpClient.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken); downloadStartTime = DateTime.Now; lastNotifyTime = DateTime.MinValue; lastBytesTransferred = 0; + using HttpResponseMessage response = await httpClient.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken); using Stream zipFileStream = await response.Content.ReadAsStreamAsync(cancellationToken); if (!cancellationToken.IsCancellationRequested) @@ -162,6 +165,7 @@ namespace MinecraftClient } Interlocked.Exchange(ref running, 0); }, cancellationToken); + return true; } }