https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e9ba3a8ebcad051e1f17d…
commit e9ba3a8ebcad051e1f17d0fcad16976817accf82
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Aug 26 20:40:34 2018 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun Aug 26 20:41:57 2018 +0200
[USETUP] Progress-bar: Add support for displaying a custom progress text.
---
base/setup/usetup/progress.c | 93 +++++++++++++++++++++++++++++++-------------
base/setup/usetup/progress.h | 17 +++++++-
2 files changed, 81 insertions(+), 29 deletions(-)
diff --git a/base/setup/usetup/progress.c b/base/setup/usetup/progress.c
index e7ea1e5fc5..ebbc715cb1 100644
--- a/base/setup/usetup/progress.c
+++ b/base/setup/usetup/progress.c
@@ -1,3 +1,10 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS text-mode setup
+ * FILE: base/setup/usetup/progress.c
+ * PURPOSE: Partition list functions
+ * PROGRAMMER:
+ */
/* INCLUDES *****************************************************************/
@@ -8,6 +15,37 @@
/* FUNCTIONS ****************************************************************/
+static
+BOOLEAN NTAPI
+UpdateProgressPercentage(
+ IN PPROGRESSBAR Bar,
+ IN BOOLEAN ComputeProgress,
+ 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);
+ }
+
+ /* Build the progress string if it has changed */
+ if ( Bar->ProgressFormatText &&
+ (!ComputeProgress || (Bar->Progress != OldProgress)) )
+ {
+ RtlStringCchPrintfA(Buffer, cchBufferSize,
+ Bar->ProgressFormatText, Bar->Progress);
+ return TRUE;
+ }
+ return FALSE;
+}
+
static
VOID
DrawBorder(
@@ -179,10 +217,10 @@ VOID
DrawProgressBar(
IN PPROGRESSBAR Bar)
{
- CHAR TextBuffer[8];
COORD coPos;
DWORD Written;
PROGRESSBAR BarBorder = *Bar;
+ CHAR TextBuffer[256];
/* Draw the progress bar "border" border */
if (Bar->DoubleEdge)
@@ -201,16 +239,18 @@ DrawProgressBar(
if (Bar->DescriptionText)
CONSOLE_SetTextXY(Bar->TextTop, Bar->TextRight, Bar->DescriptionText);
- /* Print percentage */
- sprintf(TextBuffer, "%-3lu%%", Bar->Percent);
-
- coPos.X = Bar->Left + (Bar->Width - 2) / 2;
- coPos.Y = Bar->Top;
- WriteConsoleOutputCharacterA(StdOutput,
- TextBuffer,
- 4,
- coPos,
- &Written);
+ /* Display the progress */
+ if (Bar->UpdateProgressProc &&
+ Bar->UpdateProgressProc(Bar, FALSE, TextBuffer, ARRAYSIZE(TextBuffer)))
+ {
+ coPos.X = Bar->Left + (Bar->Width - strlen(TextBuffer) + 1) / 2;
+ coPos.Y = Bar->Top;
+ WriteConsoleOutputCharacterA(StdOutput,
+ TextBuffer,
+ strlen(TextBuffer),
+ coPos,
+ &Written);
+ }
/* Draw the empty bar */
coPos.X = Bar->Left + 1;
@@ -241,7 +281,9 @@ CreateProgressBarEx(
IN SHORT TextRight,
IN BOOLEAN DoubleEdge,
IN SHORT ProgressColour,
- IN PCSTR DescriptionText OPTIONAL)
+ IN PCSTR DescriptionText OPTIONAL,
+ IN PCSTR ProgressFormatText OPTIONAL,
+ IN PUPDATE_PROGRESS UpdateProgressProc OPTIONAL)
{
PPROGRESSBAR Bar;
@@ -263,11 +305,13 @@ CreateProgressBarEx(
Bar->DoubleEdge = DoubleEdge;
Bar->ProgressColour = ProgressColour;
Bar->DescriptionText = DescriptionText;
+ Bar->ProgressFormatText = ProgressFormatText;
Bar->StepCount = 0;
Bar->CurrentStep = 0;
- Bar->Percent = 0;
+ Bar->UpdateProgressProc = UpdateProgressProc;
+ Bar->Progress = 0;
Bar->Pos = 0;
DrawProgressBar(Bar);
@@ -291,7 +335,9 @@ CreateProgressBar(
TextTop, TextRight,
DoubleEdge,
FOREGROUND_YELLOW | BACKGROUND_BLUE,
- DescriptionText);
+ DescriptionText,
+ "%-3lu%%",
+ UpdateProgressPercentage);
}
VOID
@@ -325,32 +371,25 @@ ProgressSetStep(
IN PPROGRESSBAR Bar,
IN ULONG Step)
{
- CHAR TextBuffer[8];
COORD coPos;
DWORD Written;
- ULONG NewPercent;
ULONG NewPos;
+ CHAR TextBuffer[256];
if (Step > Bar->StepCount)
return;
Bar->CurrentStep = Step;
- /* Calculate new percentage */
- NewPercent = ((100 * Bar->CurrentStep + (Bar->StepCount / 2)) /
Bar->StepCount);
-
- /* Redraw percentage if changed */
- if (Bar->Percent != NewPercent)
+ /* Update the progress and redraw it if it has changed */
+ if (Bar->UpdateProgressProc &&
+ Bar->UpdateProgressProc(Bar, TRUE, TextBuffer, ARRAYSIZE(TextBuffer)))
{
- Bar->Percent = NewPercent;
-
- sprintf(TextBuffer, "%-3lu%%", Bar->Percent);
-
- coPos.X = Bar->Left + (Bar->Width - 2) / 2;
+ coPos.X = Bar->Left + (Bar->Width - strlen(TextBuffer) + 1) / 2;
coPos.Y = Bar->Top;
WriteConsoleOutputCharacterA(StdOutput,
TextBuffer,
- 4,
+ strlen(TextBuffer),
coPos,
&Written);
}
diff --git a/base/setup/usetup/progress.h b/base/setup/usetup/progress.h
index d125f7b712..1cc5ed3ce7 100644
--- a/base/setup/usetup/progress.h
+++ b/base/setup/usetup/progress.h
@@ -26,6 +26,15 @@
#pragma once
+struct _PROGRESSBAR;
+
+typedef BOOLEAN
+(NTAPI *PUPDATE_PROGRESS)(
+ IN struct _PROGRESSBAR* Bar,
+ IN BOOLEAN ComputeProgress,
+ OUT PSTR Buffer,
+ IN SIZE_T cchBufferSize);
+
typedef struct _PROGRESSBAR
{
/* Border and text positions */
@@ -43,13 +52,15 @@ typedef struct _PROGRESSBAR
ULONG CurrentStep;
/* User-specific displayed bar progress/position */
- ULONG Percent;
+ PUPDATE_PROGRESS UpdateProgressProc;
+ ULONG Progress;
SHORT Pos;
/* Static progress bar cues */
BOOLEAN DoubleEdge;
SHORT ProgressColour;
PCSTR DescriptionText;
+ PCSTR ProgressFormatText;
} PROGRESSBAR, *PPROGRESSBAR;
@@ -65,7 +76,9 @@ CreateProgressBarEx(
IN SHORT TextRight,
IN BOOLEAN DoubleEdge,
IN SHORT ProgressColour,
- IN PCSTR DescriptionText OPTIONAL);
+ IN PCSTR DescriptionText OPTIONAL,
+ IN PCSTR ProgressFormatText OPTIONAL,
+ IN PUPDATE_PROGRESS UpdateProgressProc OPTIONAL);
PPROGRESSBAR
CreateProgressBar(