mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 06:16:38 +00:00
[USETUP] Progress-bar: Add support for displaying a custom progress text.
This commit is contained in:
parent
3a33de0fb1
commit
e9ba3a8ebc
2 changed files with 81 additions and 29 deletions
|
@ -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 *****************************************************************/
|
/* INCLUDES *****************************************************************/
|
||||||
|
|
||||||
|
@ -8,6 +15,37 @@
|
||||||
|
|
||||||
/* FUNCTIONS ****************************************************************/
|
/* 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
|
static
|
||||||
VOID
|
VOID
|
||||||
DrawBorder(
|
DrawBorder(
|
||||||
|
@ -179,10 +217,10 @@ VOID
|
||||||
DrawProgressBar(
|
DrawProgressBar(
|
||||||
IN PPROGRESSBAR Bar)
|
IN PPROGRESSBAR Bar)
|
||||||
{
|
{
|
||||||
CHAR TextBuffer[8];
|
|
||||||
COORD coPos;
|
COORD coPos;
|
||||||
DWORD Written;
|
DWORD Written;
|
||||||
PROGRESSBAR BarBorder = *Bar;
|
PROGRESSBAR BarBorder = *Bar;
|
||||||
|
CHAR TextBuffer[256];
|
||||||
|
|
||||||
/* Draw the progress bar "border" border */
|
/* Draw the progress bar "border" border */
|
||||||
if (Bar->DoubleEdge)
|
if (Bar->DoubleEdge)
|
||||||
|
@ -201,16 +239,18 @@ DrawProgressBar(
|
||||||
if (Bar->DescriptionText)
|
if (Bar->DescriptionText)
|
||||||
CONSOLE_SetTextXY(Bar->TextTop, Bar->TextRight, Bar->DescriptionText);
|
CONSOLE_SetTextXY(Bar->TextTop, Bar->TextRight, Bar->DescriptionText);
|
||||||
|
|
||||||
/* Print percentage */
|
/* Display the progress */
|
||||||
sprintf(TextBuffer, "%-3lu%%", Bar->Percent);
|
if (Bar->UpdateProgressProc &&
|
||||||
|
Bar->UpdateProgressProc(Bar, FALSE, TextBuffer, ARRAYSIZE(TextBuffer)))
|
||||||
coPos.X = Bar->Left + (Bar->Width - 2) / 2;
|
{
|
||||||
coPos.Y = Bar->Top;
|
coPos.X = Bar->Left + (Bar->Width - strlen(TextBuffer) + 1) / 2;
|
||||||
WriteConsoleOutputCharacterA(StdOutput,
|
coPos.Y = Bar->Top;
|
||||||
TextBuffer,
|
WriteConsoleOutputCharacterA(StdOutput,
|
||||||
4,
|
TextBuffer,
|
||||||
coPos,
|
strlen(TextBuffer),
|
||||||
&Written);
|
coPos,
|
||||||
|
&Written);
|
||||||
|
}
|
||||||
|
|
||||||
/* Draw the empty bar */
|
/* Draw the empty bar */
|
||||||
coPos.X = Bar->Left + 1;
|
coPos.X = Bar->Left + 1;
|
||||||
|
@ -241,7 +281,9 @@ CreateProgressBarEx(
|
||||||
IN SHORT TextRight,
|
IN SHORT TextRight,
|
||||||
IN BOOLEAN DoubleEdge,
|
IN BOOLEAN DoubleEdge,
|
||||||
IN SHORT ProgressColour,
|
IN SHORT ProgressColour,
|
||||||
IN PCSTR DescriptionText OPTIONAL)
|
IN PCSTR DescriptionText OPTIONAL,
|
||||||
|
IN PCSTR ProgressFormatText OPTIONAL,
|
||||||
|
IN PUPDATE_PROGRESS UpdateProgressProc OPTIONAL)
|
||||||
{
|
{
|
||||||
PPROGRESSBAR Bar;
|
PPROGRESSBAR Bar;
|
||||||
|
|
||||||
|
@ -263,11 +305,13 @@ CreateProgressBarEx(
|
||||||
Bar->DoubleEdge = DoubleEdge;
|
Bar->DoubleEdge = DoubleEdge;
|
||||||
Bar->ProgressColour = ProgressColour;
|
Bar->ProgressColour = ProgressColour;
|
||||||
Bar->DescriptionText = DescriptionText;
|
Bar->DescriptionText = DescriptionText;
|
||||||
|
Bar->ProgressFormatText = ProgressFormatText;
|
||||||
|
|
||||||
Bar->StepCount = 0;
|
Bar->StepCount = 0;
|
||||||
Bar->CurrentStep = 0;
|
Bar->CurrentStep = 0;
|
||||||
|
|
||||||
Bar->Percent = 0;
|
Bar->UpdateProgressProc = UpdateProgressProc;
|
||||||
|
Bar->Progress = 0;
|
||||||
Bar->Pos = 0;
|
Bar->Pos = 0;
|
||||||
|
|
||||||
DrawProgressBar(Bar);
|
DrawProgressBar(Bar);
|
||||||
|
@ -291,7 +335,9 @@ CreateProgressBar(
|
||||||
TextTop, TextRight,
|
TextTop, TextRight,
|
||||||
DoubleEdge,
|
DoubleEdge,
|
||||||
FOREGROUND_YELLOW | BACKGROUND_BLUE,
|
FOREGROUND_YELLOW | BACKGROUND_BLUE,
|
||||||
DescriptionText);
|
DescriptionText,
|
||||||
|
"%-3lu%%",
|
||||||
|
UpdateProgressPercentage);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
@ -325,32 +371,25 @@ ProgressSetStep(
|
||||||
IN PPROGRESSBAR Bar,
|
IN PPROGRESSBAR Bar,
|
||||||
IN ULONG Step)
|
IN ULONG Step)
|
||||||
{
|
{
|
||||||
CHAR TextBuffer[8];
|
|
||||||
COORD coPos;
|
COORD coPos;
|
||||||
DWORD Written;
|
DWORD Written;
|
||||||
ULONG NewPercent;
|
|
||||||
ULONG NewPos;
|
ULONG NewPos;
|
||||||
|
CHAR TextBuffer[256];
|
||||||
|
|
||||||
if (Step > Bar->StepCount)
|
if (Step > Bar->StepCount)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Bar->CurrentStep = Step;
|
Bar->CurrentStep = Step;
|
||||||
|
|
||||||
/* Calculate new percentage */
|
/* Update the progress and redraw it if it has changed */
|
||||||
NewPercent = ((100 * Bar->CurrentStep + (Bar->StepCount / 2)) / Bar->StepCount);
|
if (Bar->UpdateProgressProc &&
|
||||||
|
Bar->UpdateProgressProc(Bar, TRUE, TextBuffer, ARRAYSIZE(TextBuffer)))
|
||||||
/* Redraw percentage if changed */
|
|
||||||
if (Bar->Percent != NewPercent)
|
|
||||||
{
|
{
|
||||||
Bar->Percent = NewPercent;
|
coPos.X = Bar->Left + (Bar->Width - strlen(TextBuffer) + 1) / 2;
|
||||||
|
|
||||||
sprintf(TextBuffer, "%-3lu%%", Bar->Percent);
|
|
||||||
|
|
||||||
coPos.X = Bar->Left + (Bar->Width - 2) / 2;
|
|
||||||
coPos.Y = Bar->Top;
|
coPos.Y = Bar->Top;
|
||||||
WriteConsoleOutputCharacterA(StdOutput,
|
WriteConsoleOutputCharacterA(StdOutput,
|
||||||
TextBuffer,
|
TextBuffer,
|
||||||
4,
|
strlen(TextBuffer),
|
||||||
coPos,
|
coPos,
|
||||||
&Written);
|
&Written);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,15 @@
|
||||||
|
|
||||||
#pragma once
|
#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
|
typedef struct _PROGRESSBAR
|
||||||
{
|
{
|
||||||
/* Border and text positions */
|
/* Border and text positions */
|
||||||
|
@ -43,13 +52,15 @@ typedef struct _PROGRESSBAR
|
||||||
ULONG CurrentStep;
|
ULONG CurrentStep;
|
||||||
|
|
||||||
/* User-specific displayed bar progress/position */
|
/* User-specific displayed bar progress/position */
|
||||||
ULONG Percent;
|
PUPDATE_PROGRESS UpdateProgressProc;
|
||||||
|
ULONG Progress;
|
||||||
SHORT Pos;
|
SHORT Pos;
|
||||||
|
|
||||||
/* Static progress bar cues */
|
/* Static progress bar cues */
|
||||||
BOOLEAN DoubleEdge;
|
BOOLEAN DoubleEdge;
|
||||||
SHORT ProgressColour;
|
SHORT ProgressColour;
|
||||||
PCSTR DescriptionText;
|
PCSTR DescriptionText;
|
||||||
|
PCSTR ProgressFormatText;
|
||||||
} PROGRESSBAR, *PPROGRESSBAR;
|
} PROGRESSBAR, *PPROGRESSBAR;
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,7 +76,9 @@ CreateProgressBarEx(
|
||||||
IN SHORT TextRight,
|
IN SHORT TextRight,
|
||||||
IN BOOLEAN DoubleEdge,
|
IN BOOLEAN DoubleEdge,
|
||||||
IN SHORT ProgressColour,
|
IN SHORT ProgressColour,
|
||||||
IN PCSTR DescriptionText OPTIONAL);
|
IN PCSTR DescriptionText OPTIONAL,
|
||||||
|
IN PCSTR ProgressFormatText OPTIONAL,
|
||||||
|
IN PUPDATE_PROGRESS UpdateProgressProc OPTIONAL);
|
||||||
|
|
||||||
PPROGRESSBAR
|
PPROGRESSBAR
|
||||||
CreateProgressBar(
|
CreateProgressBar(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue