https://git.reactos.org/?p=reactos.git;a=commitdiff;h=cdb9f03236fe15a46e042…
commit cdb9f03236fe15a46e042900af50efc56b11684a
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Mon Aug 27 23:55:58 2018 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Mon Aug 27 23:55:58 2018 +0200
[USETUP] Progress-bar: minor improvements.
- Simplify the usage of the PUPDATE_PROGRESS callback.
- Add the possibility of specifying an initial non-zero StepCount when
creating the progress-bar (using the -Ex version), so that it can be
initially drawn with the expected initial count.
Of course ProgressSetStepCount() can continue to be used.
---
base/setup/usetup/progress.c | 36 +++++++++++++++++-------------------
base/setup/usetup/progress.h | 3 ++-
2 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/base/setup/usetup/progress.c b/base/setup/usetup/progress.c
index ebbc715cb1..1d095aeb6d 100644
--- a/base/setup/usetup/progress.c
+++ b/base/setup/usetup/progress.c
@@ -19,25 +19,22 @@ static
BOOLEAN NTAPI
UpdateProgressPercentage(
IN PPROGRESSBAR Bar,
- IN BOOLEAN ComputeProgress,
+ IN BOOLEAN AlwaysUpdate,
OUT PSTR Buffer,
IN SIZE_T cchBufferSize)
{
// static PCSTR ProgressFormatText;
ULONG OldProgress = Bar->Progress;
- if (ComputeProgress)
- {
- /* Calculate the new percentage */
- if (Bar->StepCount == 0)
- Bar->Progress = 0;
- else
- Bar->Progress = ((100 * Bar->CurrentStep + (Bar->StepCount / 2)) /
Bar->StepCount);
- }
+ /* Calculate the new percentage */
+ if (Bar->StepCount == 0)
+ Bar->Progress = 0;
+ else
+ Bar->Progress = ((100 * Bar->CurrentStep + (Bar->StepCount / 2)) /
Bar->StepCount);
/* Build the progress string if it has changed */
if ( Bar->ProgressFormatText &&
- (!ComputeProgress || (Bar->Progress != OldProgress)) )
+ (AlwaysUpdate || (Bar->Progress != OldProgress)) )
{
RtlStringCchPrintfA(Buffer, cchBufferSize,
Bar->ProgressFormatText, Bar->Progress);
@@ -239,9 +236,9 @@ DrawProgressBar(
if (Bar->DescriptionText)
CONSOLE_SetTextXY(Bar->TextTop, Bar->TextRight, Bar->DescriptionText);
- /* Display the progress */
+ /* Always update and display the progress */
if (Bar->UpdateProgressProc &&
- Bar->UpdateProgressProc(Bar, FALSE, TextBuffer, ARRAYSIZE(TextBuffer)))
+ Bar->UpdateProgressProc(Bar, TRUE, TextBuffer, ARRAYSIZE(TextBuffer)))
{
coPos.X = Bar->Left + (Bar->Width - strlen(TextBuffer) + 1) / 2;
coPos.Y = Bar->Top;
@@ -281,6 +278,7 @@ CreateProgressBarEx(
IN SHORT TextRight,
IN BOOLEAN DoubleEdge,
IN SHORT ProgressColour,
+ IN ULONG StepCount,
IN PCSTR DescriptionText OPTIONAL,
IN PCSTR ProgressFormatText OPTIONAL,
IN PUPDATE_PROGRESS UpdateProgressProc OPTIONAL)
@@ -307,14 +305,10 @@ CreateProgressBarEx(
Bar->DescriptionText = DescriptionText;
Bar->ProgressFormatText = ProgressFormatText;
- Bar->StepCount = 0;
- Bar->CurrentStep = 0;
-
Bar->UpdateProgressProc = UpdateProgressProc;
- Bar->Progress = 0;
- Bar->Pos = 0;
- DrawProgressBar(Bar);
+ /* Reset the progress bar counts and initially draw it */
+ ProgressSetStepCount(Bar, StepCount);
return Bar;
}
@@ -335,6 +329,7 @@ CreateProgressBar(
TextTop, TextRight,
DoubleEdge,
FOREGROUND_YELLOW | BACKGROUND_BLUE,
+ 0,
DescriptionText,
"%-3lu%%",
UpdateProgressPercentage);
@@ -356,6 +351,9 @@ ProgressSetStepCount(
Bar->CurrentStep = 0;
Bar->StepCount = StepCount;
+ Bar->Progress = 0;
+ Bar->Pos = 0;
+
DrawProgressBar(Bar);
}
@@ -383,7 +381,7 @@ ProgressSetStep(
/* Update the progress and redraw it if it has changed */
if (Bar->UpdateProgressProc &&
- Bar->UpdateProgressProc(Bar, TRUE, TextBuffer, ARRAYSIZE(TextBuffer)))
+ Bar->UpdateProgressProc(Bar, FALSE, TextBuffer, ARRAYSIZE(TextBuffer)))
{
coPos.X = Bar->Left + (Bar->Width - strlen(TextBuffer) + 1) / 2;
coPos.Y = Bar->Top;
diff --git a/base/setup/usetup/progress.h b/base/setup/usetup/progress.h
index 1cc5ed3ce7..e66040419b 100644
--- a/base/setup/usetup/progress.h
+++ b/base/setup/usetup/progress.h
@@ -31,7 +31,7 @@ struct _PROGRESSBAR;
typedef BOOLEAN
(NTAPI *PUPDATE_PROGRESS)(
IN struct _PROGRESSBAR* Bar,
- IN BOOLEAN ComputeProgress,
+ IN BOOLEAN AlwaysUpdate,
OUT PSTR Buffer,
IN SIZE_T cchBufferSize);
@@ -76,6 +76,7 @@ CreateProgressBarEx(
IN SHORT TextRight,
IN BOOLEAN DoubleEdge,
IN SHORT ProgressColour,
+ IN ULONG StepCount,
IN PCSTR DescriptionText OPTIONAL,
IN PCSTR ProgressFormatText OPTIONAL,
IN PUPDATE_PROGRESS UpdateProgressProc OPTIONAL);