mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Display ETA when downloading.
This commit is contained in:
parent
28827b720a
commit
2ad6d02d59
4 changed files with 14 additions and 8 deletions
|
|
@ -31,8 +31,10 @@ namespace MinecraftClient.Commands
|
|||
|
||||
private static string DownloadUpdate(bool force)
|
||||
{
|
||||
UpgradeHelper.DownloadLatestBuild(force);
|
||||
if (UpgradeHelper.DownloadLatestBuild(force))
|
||||
return Translations.mcc_update_start;
|
||||
else
|
||||
return Translations.mcc_update_already_running;
|
||||
}
|
||||
|
||||
private static string CancelDownloadUpdate()
|
||||
|
|
|
|||
|
|
@ -5603,7 +5603,7 @@ namespace MinecraftClient {
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
internal static string mcc_update_progress {
|
||||
get {
|
||||
|
|
|
|||
|
|
@ -1988,7 +1988,7 @@ Switching to autodetection mode.</value>
|
|||
<value>The latest release does not contain a build that matches your operating system and CPU architecture.</value>
|
||||
</data>
|
||||
<data name="mcc.update.progress" xml:space="preserve">
|
||||
<value>Self-updating: {0:00.00}%, Downloaded {1:00.0}MB of {2:00.0}MB, Avg {3:0.0}KB/s</value>
|
||||
<value>Self-updating: {0:00.00}%, ETA {4}, Downloaded {1:00.0}MB of {2:00.0}MB, Avg {3:0.0}KB/s</value>
|
||||
</data>
|
||||
<data name="mcc.update.progress_type2" xml:space="preserve">
|
||||
<value>Self-updating: Downloaded {0:00.0}MB, Avg {1:0.0}KB/s</value>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue