Skip to content

Commit

Permalink
Use new speed calculation for Cache Update and Game Repair
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-nyan committed Aug 31, 2024
1 parent f20a6cf commit e210969
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions CollapseLauncher/Classes/Interfaces/Class/ProgressBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,11 @@ protected virtual void _httpClient_FetchAssetProgress(object sender, DownloadEve
protected virtual async void _httpClient_RepairAssetProgress(int size, DownloadProgress downloadProgress)
{
Interlocked.Add(ref _progressAllSizeCurrent, size);
Interlocked.Add(ref _progressAllIOReadCurrent, size);

if (await CheckIfNeedRefreshStopwatch())
{
double speed = (_progressAllSizeCurrent / _stopwatch.Elapsed.TotalSeconds).ClampLimitedSpeedNumber();
double speed = (_progressAllIOReadCurrent / _downloadSpeedRefreshStopwatch.Elapsed.TotalSeconds).ClampLimitedSpeedNumber();
TimeSpan timeLeftSpan = ((_progressAllSizeCurrent - _progressAllSizeTotal) / speed).ToTimeSpanNormalized();
double percentagePerFile = ConverterTool.GetPercentageNumber(downloadProgress.BytesDownloaded, downloadProgress.BytesTotal, 2);

Expand Down Expand Up @@ -184,6 +186,12 @@ protected virtual async void _httpClient_RepairAssetProgress(int size, DownloadP
// Trigger update
UpdateAll();
}

if (_downloadSpeedRefreshInterval < _downloadSpeedRefreshStopwatch!.ElapsedMilliseconds)
{
_progressAllIOReadCurrent = 0;
_downloadSpeedRefreshStopwatch.Restart();
}
}
}

Expand Down Expand Up @@ -255,11 +263,12 @@ protected virtual void UpdateRepairStatus(string activityStatus, string Activity
protected virtual async void _httpClient_UpdateAssetProgress(int size, DownloadProgress downloadProgress)
{
Interlocked.Add(ref _progressAllSizeCurrent, size);
Interlocked.Add(ref _progressAllIOReadCurrent, size);

if (await CheckIfNeedRefreshStopwatch())
{
double speed = _progressAllSizeCurrent / _stopwatch.Elapsed.TotalSeconds;
TimeSpan timeLeftSpan = ((_progressAllSizeTotal - _progressAllSizeCurrent) / speed.ClampLimitedSpeedNumber()).ToTimeSpanNormalized();
double speed = (_progressAllIOReadCurrent / _downloadSpeedRefreshStopwatch.Elapsed.TotalSeconds).ClampLimitedSpeedNumber();
TimeSpan timeLeftSpan = ((_progressAllSizeTotal - _progressAllSizeCurrent) / speed).ToTimeSpanNormalized();
double percentage = ConverterTool.GetPercentageNumber(_progressAllSizeCurrent, _progressAllSizeTotal, 2);

// Update current progress percentages and speed
Expand All @@ -272,6 +281,12 @@ protected virtual async void _httpClient_UpdateAssetProgress(int size, DownloadP
+ string.Format($"({Lang._Misc.SpeedPerSec})", ConverterTool.SummarizeSizeSimple(speed))
+ $" | {timeLeftString}";

if (_downloadSpeedRefreshInterval < _downloadSpeedRefreshStopwatch!.ElapsedMilliseconds)
{
_progressAllIOReadCurrent = 0;
_downloadSpeedRefreshStopwatch.Restart();
}

// Trigger update
UpdateAll();
}
Expand Down Expand Up @@ -708,12 +723,14 @@ protected void ResetStatusAndProgressProperty()
_progress.ProgressPerFileEntryCountTotal = 0;

// Reset all inner counter
_progressAllCountCurrent = 0;
_progressAllCountTotal = 0;
_progressAllSizeCurrent = 0;
_progressAllSizeTotal = 0;
_progressPerFileSizeCurrent = 0;
_progressPerFileSizeTotal = 0;
_progressAllCountCurrent = 0;
_progressAllCountTotal = 0;
_progressAllSizeCurrent = 0;
_progressAllSizeTotal = 0;
_progressAllIOReadCurrent = 0;
_progressPerFileSizeCurrent = 0;
_progressPerFileSizeTotal = 0;
_progressPerFileIOReadCurrent = 0;
}
}

Expand Down

0 comments on commit e210969

Please sign in to comment.