Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress bar resetting fix. #1106

Merged
merged 2 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions UndertaleModTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2303,29 +2303,40 @@ public void DisableAllSyncBindings() //disable all sync. bindings

private void ProgressUpdater()
{
DateTime prevTime = default;
Stopwatch sw = new();
Stopwatch swTimeout = null;
int prevValue = 0;

while (true)
{
sw.Restart();

if (cToken.IsCancellationRequested)
{
if (prevValue >= progressValue) //if reached maximum
if (prevValue >= progressValue) // if reached maximum
{
sw.Stop();
swTimeout?.Stop();
return;
}
else
{
if (prevTime == default)
prevTime = DateTime.UtcNow; //begin measuring
else if (DateTime.UtcNow.Subtract(prevTime).TotalMilliseconds >= 500) //timeout - 0.5 seconds
if (swTimeout is null)
swTimeout = Stopwatch.StartNew(); // begin measuring
else if (swTimeout.ElapsedMilliseconds >= 500) // timeout - 0.5 seconds
{
sw.Stop();
swTimeout.Stop();
return;
}
}
}

UpdateProgressValue(progressValue);

prevValue = progressValue;

Thread.Sleep(100); //10 times per second
Thread.Sleep((int)Math.Max(0, 33 - sw.ElapsedMilliseconds)); // ~30 times per second
}
}
public void StartProgressBarUpdater()
Expand Down
11 changes: 1 addition & 10 deletions UndertaleModTool/Windows/LoaderDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,7 @@ public void ReportProgress(double value) //update without status text changing
}
public void UpdateValue(double value)
{
if (value - ProgressBar.Value <= 1) //if value not changed or changed by 1
{
ProgressBar.Value = value;
}
else
{
DoubleAnimation animation = new(value, TimeSpan.FromMilliseconds(100)); //time is the same as in "ProgressUpdater()"
ProgressBar.BeginAnimation(ProgressBar.ValueProperty, animation); //smooth progress change
}

ProgressBar.Value = value;
TaskbarItemInfo.ProgressValue = value / ProgressBar.Maximum;
}

Expand Down