Skip to content

Commit

Permalink
Remote: Add time display to download
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Jun 9, 2024
1 parent 0cfbd15 commit 3170ff8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion RemoteDownloaderPlugin/Game/GameDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class GameDownload : ProgressStatus
public GameType Type { get; private set; }
public string BaseFileName { get; private set; }
public ContentTypes InstalledEntries { get; private set; }

private DateTimeOffset _downloadStart = DateTimeOffset.Now;

public GameDownload(IEntry entry)
{
Expand All @@ -29,9 +31,27 @@ private void OnProgressUpdate(object? obj, float progress)
return;

_lastSecond = DateTime.Now.Second;

var timeBetweenNowAndStart = DateTimeOffset.Now - _downloadStart;
var totalTime = timeBetweenNowAndStart * (1 / progress);
var estimatedTime = totalTime - timeBetweenNowAndStart;
var estimatedDisplay = "";

if (estimatedTime.TotalMinutes < 60)
{
estimatedDisplay = $"{estimatedTime.Minutes}m";
}
else if (estimatedTime.TotalMinutes < 1440)
{
estimatedDisplay = $"{estimatedTime.Hours}h{estimatedTime.Minutes}m";
}
else
{
estimatedDisplay = $"{estimatedTime.Days}d{estimatedTime.Hours}h{estimatedTime.Minutes}m";
}

progress *= 100;
Line1 = $"Downloading: {progress:0}%";
Line1 = $"Downloading: {progress:0}% {estimatedDisplay}";
Percentage = progress;
InvokeOnUpdate();
}
Expand Down

0 comments on commit 3170ff8

Please sign in to comment.