2002-12-06 21:39:04 +00:00
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2006-08-31 09:13:03 +00:00
|
|
|
#include "usetup.h"
|
2005-06-20 22:49:45 +00:00
|
|
|
|
2010-06-07 21:38:49 +00:00
|
|
|
#define NDEBUG
|
2005-06-20 22:49:45 +00:00
|
|
|
#include <debug.h>
|
2002-12-06 21:39:04 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
static VOID
|
2004-02-23 11:58:27 +00:00
|
|
|
DrawBorder(PPROGRESSBAR Bar)
|
2002-12-06 21:39:04 +00:00
|
|
|
{
|
|
|
|
COORD coPos;
|
2007-07-28 18:24:09 +00:00
|
|
|
DWORD Written;
|
2002-12-06 21:39:04 +00:00
|
|
|
SHORT i;
|
|
|
|
|
|
|
|
/* draw upper left corner */
|
|
|
|
coPos.X = Bar->Left;
|
|
|
|
coPos.Y = Bar->Top + 1;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xDA, // '+',
|
2002-12-06 21:39:04 +00:00
|
|
|
1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
|
|
|
|
/* draw upper edge */
|
|
|
|
coPos.X = Bar->Left + 1;
|
|
|
|
coPos.Y = Bar->Top + 1;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xC4, // '-',
|
2002-12-06 21:39:04 +00:00
|
|
|
Bar->Right - Bar->Left - 1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
|
|
|
|
/* draw upper right corner */
|
|
|
|
coPos.X = Bar->Right;
|
|
|
|
coPos.Y = Bar->Top + 1;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xBF, // '+',
|
2002-12-06 21:39:04 +00:00
|
|
|
1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
|
|
|
|
/* draw left and right edge */
|
|
|
|
for (i = Bar->Top + 2; i < Bar->Bottom; i++)
|
|
|
|
{
|
|
|
|
coPos.X = Bar->Left;
|
|
|
|
coPos.Y = i;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xB3, // '|',
|
2002-12-06 21:39:04 +00:00
|
|
|
1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
|
|
|
|
coPos.X = Bar->Right;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xB3, //'|',
|
2002-12-06 21:39:04 +00:00
|
|
|
1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw lower left corner */
|
|
|
|
coPos.X = Bar->Left;
|
|
|
|
coPos.Y = Bar->Bottom;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xC0, // '+',
|
2002-12-06 21:39:04 +00:00
|
|
|
1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
|
|
|
|
/* draw lower edge */
|
|
|
|
coPos.X = Bar->Left + 1;
|
|
|
|
coPos.Y = Bar->Bottom;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xC4, // '-',
|
2002-12-06 21:39:04 +00:00
|
|
|
Bar->Right - Bar->Left - 1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
|
|
|
|
/* draw lower right corner */
|
|
|
|
coPos.X = Bar->Right;
|
|
|
|
coPos.Y = Bar->Bottom;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xD9, // '+',
|
2002-12-06 21:39:04 +00:00
|
|
|
1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
}
|
|
|
|
|
2005-05-18 19:08:00 +00:00
|
|
|
static VOID
|
|
|
|
DrawThickBorder(PPROGRESSBAR Bar)
|
|
|
|
{
|
|
|
|
COORD coPos;
|
2007-07-28 18:24:09 +00:00
|
|
|
DWORD Written;
|
2005-05-18 19:08:00 +00:00
|
|
|
SHORT i;
|
|
|
|
|
|
|
|
/* draw upper left corner */
|
|
|
|
coPos.X = Bar->Left;
|
|
|
|
coPos.Y = Bar->Top + 1;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xC9, // '+',
|
2005-05-18 19:08:00 +00:00
|
|
|
1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
|
|
|
|
/* draw upper edge */
|
|
|
|
coPos.X = Bar->Left + 1;
|
|
|
|
coPos.Y = Bar->Top + 1;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xCD, // '-',
|
2005-05-18 19:08:00 +00:00
|
|
|
Bar->Right - Bar->Left - 1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
|
|
|
|
/* draw upper right corner */
|
|
|
|
coPos.X = Bar->Right;
|
|
|
|
coPos.Y = Bar->Top + 1;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xBB, // '+',
|
2005-05-18 19:08:00 +00:00
|
|
|
1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
|
|
|
|
/* draw left and right edge */
|
|
|
|
for (i = Bar->Top + 2; i < Bar->Bottom; i++)
|
|
|
|
{
|
|
|
|
coPos.X = Bar->Left;
|
|
|
|
coPos.Y = i;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xBA, // '|',
|
2005-05-18 19:08:00 +00:00
|
|
|
1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
|
|
|
|
coPos.X = Bar->Right;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xBA, //'|',
|
2005-05-18 19:08:00 +00:00
|
|
|
1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw lower left corner */
|
|
|
|
coPos.X = Bar->Left;
|
|
|
|
coPos.Y = Bar->Bottom;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xC8, // '+',
|
2005-05-18 19:08:00 +00:00
|
|
|
1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
|
|
|
|
/* draw lower edge */
|
|
|
|
coPos.X = Bar->Left + 1;
|
|
|
|
coPos.Y = Bar->Bottom;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xCD, // '-',
|
2005-05-18 19:08:00 +00:00
|
|
|
Bar->Right - Bar->Left - 1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
|
|
|
|
/* draw lower right corner */
|
|
|
|
coPos.X = Bar->Right;
|
|
|
|
coPos.Y = Bar->Bottom;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xBC, // '+',
|
2005-05-18 19:08:00 +00:00
|
|
|
1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
}
|
2002-12-06 21:39:04 +00:00
|
|
|
|
|
|
|
static VOID
|
2004-02-23 11:58:27 +00:00
|
|
|
DrawProgressBar(PPROGRESSBAR Bar)
|
2002-12-06 21:39:04 +00:00
|
|
|
{
|
|
|
|
CHAR TextBuffer[8];
|
|
|
|
COORD coPos;
|
2007-07-28 18:24:09 +00:00
|
|
|
DWORD Written;
|
2005-05-18 19:08:00 +00:00
|
|
|
PROGRESSBAR BarBorder = *Bar;
|
2002-12-06 21:39:04 +00:00
|
|
|
|
|
|
|
/* Print percentage */
|
2007-07-28 20:32:16 +00:00
|
|
|
sprintf(TextBuffer, "%-3lu%%", Bar->Percent);
|
2002-12-06 21:39:04 +00:00
|
|
|
|
|
|
|
coPos.X = Bar->Left + (Bar->Width - 2) / 2;
|
|
|
|
coPos.Y = Bar->Top;
|
2006-08-31 06:14:25 +00:00
|
|
|
WriteConsoleOutputCharacterA(StdOutput,
|
|
|
|
TextBuffer,
|
2002-12-06 21:39:04 +00:00
|
|
|
4,
|
2006-08-31 06:14:25 +00:00
|
|
|
coPos,
|
|
|
|
&Written);
|
2002-12-06 21:39:04 +00:00
|
|
|
|
2005-05-18 19:08:00 +00:00
|
|
|
/* Draw the progress bar border */
|
2002-12-06 21:39:04 +00:00
|
|
|
DrawBorder(Bar);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-05-18 19:08:00 +00:00
|
|
|
/* Write Text Associated with Bar */
|
2007-02-28 20:43:13 +00:00
|
|
|
CONSOLE_SetTextXY(Bar->TextTop, Bar->TextRight, Bar->Text);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-05-18 19:08:00 +00:00
|
|
|
/* Draw the progress bar "border" border */
|
2007-02-28 20:43:13 +00:00
|
|
|
if (Bar->Double)
|
|
|
|
{
|
|
|
|
BarBorder.Top -= 5;
|
|
|
|
BarBorder.Bottom += 2;
|
|
|
|
BarBorder.Right += 5;
|
|
|
|
BarBorder.Left -= 5;
|
|
|
|
DrawThickBorder(&BarBorder);
|
|
|
|
}
|
2002-12-06 21:39:04 +00:00
|
|
|
|
|
|
|
/* Draw the bar */
|
|
|
|
coPos.X = Bar->Left + 1;
|
|
|
|
for (coPos.Y = Bar->Top + 2; coPos.Y <= Bar->Bottom - 1; coPos.Y++)
|
|
|
|
{
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputAttribute(StdOutput,
|
|
|
|
FOREGROUND_YELLOW | BACKGROUND_BLUE,
|
2002-12-06 21:39:04 +00:00
|
|
|
Bar->Width - 2,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
' ',
|
2002-12-06 21:39:04 +00:00
|
|
|
Bar->Width - 2,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-02-23 11:58:27 +00:00
|
|
|
PPROGRESSBAR
|
2002-12-06 21:39:04 +00:00
|
|
|
CreateProgressBar(SHORT Left,
|
|
|
|
SHORT Top,
|
|
|
|
SHORT Right,
|
2005-05-18 19:08:00 +00:00
|
|
|
SHORT Bottom,
|
2007-02-28 20:43:13 +00:00
|
|
|
SHORT TextTop,
|
|
|
|
SHORT TextRight,
|
|
|
|
IN BOOLEAN DoubleEdge,
|
2005-05-18 19:08:00 +00:00
|
|
|
char* Text)
|
2002-12-06 21:39:04 +00:00
|
|
|
{
|
2004-02-23 11:58:27 +00:00
|
|
|
PPROGRESSBAR Bar;
|
2002-12-06 21:39:04 +00:00
|
|
|
|
2004-02-23 11:58:27 +00:00
|
|
|
Bar = (PPROGRESSBAR)RtlAllocateHeap(ProcessHeap,
|
|
|
|
0,
|
|
|
|
sizeof(PROGRESSBAR));
|
2002-12-06 21:39:04 +00:00
|
|
|
if (Bar == NULL)
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
Bar->Left = Left;
|
|
|
|
Bar->Top = Top;
|
|
|
|
Bar->Right = Right;
|
|
|
|
Bar->Bottom = Bottom;
|
2007-02-28 20:43:13 +00:00
|
|
|
Bar->TextTop = TextTop;
|
|
|
|
Bar->TextRight = TextRight;
|
|
|
|
Bar->Double = DoubleEdge;
|
2005-05-18 19:08:00 +00:00
|
|
|
Bar->Text = Text;
|
2002-12-06 21:39:04 +00:00
|
|
|
|
|
|
|
Bar->Width = Bar->Right - Bar->Left + 1;
|
|
|
|
|
|
|
|
Bar->Percent = 0;
|
|
|
|
Bar->Pos = 0;
|
|
|
|
|
|
|
|
Bar->StepCount = 0;
|
|
|
|
Bar->CurrentStep = 0;
|
|
|
|
|
|
|
|
DrawProgressBar(Bar);
|
|
|
|
|
|
|
|
return(Bar);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID
|
2004-02-23 11:58:27 +00:00
|
|
|
DestroyProgressBar(PPROGRESSBAR Bar)
|
2002-12-06 21:39:04 +00:00
|
|
|
{
|
|
|
|
RtlFreeHeap(ProcessHeap,
|
|
|
|
0,
|
|
|
|
Bar);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
2004-02-23 11:58:27 +00:00
|
|
|
ProgressSetStepCount(PPROGRESSBAR Bar,
|
2002-12-06 21:39:04 +00:00
|
|
|
ULONG StepCount)
|
|
|
|
{
|
|
|
|
Bar->CurrentStep = 0;
|
|
|
|
Bar->StepCount = StepCount;
|
|
|
|
|
|
|
|
DrawProgressBar(Bar);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID
|
2004-02-23 11:58:27 +00:00
|
|
|
ProgressNextStep(PPROGRESSBAR Bar)
|
2002-12-06 21:39:04 +00:00
|
|
|
{
|
|
|
|
CHAR TextBuffer[8];
|
|
|
|
COORD coPos;
|
2007-07-28 18:24:09 +00:00
|
|
|
DWORD Written;
|
2002-12-06 21:39:04 +00:00
|
|
|
ULONG NewPercent;
|
|
|
|
ULONG NewPos;
|
|
|
|
|
|
|
|
if ((Bar->StepCount == 0) ||
|
|
|
|
(Bar->CurrentStep == Bar->StepCount))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Bar->CurrentStep++;
|
|
|
|
|
|
|
|
/* Calculate new percentage */
|
|
|
|
NewPercent = (ULONG)(((100.0 * (float)Bar->CurrentStep) / (float)Bar->StepCount) + 0.5);
|
|
|
|
|
|
|
|
/* Redraw precentage if changed */
|
|
|
|
if (Bar->Percent != NewPercent)
|
2004-02-23 11:58:27 +00:00
|
|
|
{
|
|
|
|
Bar->Percent = NewPercent;
|
|
|
|
|
2007-07-28 20:32:16 +00:00
|
|
|
sprintf(TextBuffer, "%-3lu%%", Bar->Percent);
|
2004-02-23 11:58:27 +00:00
|
|
|
|
|
|
|
coPos.X = Bar->Left + (Bar->Width - 2) / 2;
|
|
|
|
coPos.Y = Bar->Top;
|
2006-08-31 06:14:25 +00:00
|
|
|
WriteConsoleOutputCharacterA(StdOutput,
|
|
|
|
TextBuffer,
|
2004-02-23 11:58:27 +00:00
|
|
|
4,
|
2006-08-31 06:14:25 +00:00
|
|
|
coPos,
|
|
|
|
&Written);
|
2004-02-23 11:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate bar position */
|
|
|
|
NewPos = (ULONG)((((float)(Bar->Width - 2) * 2.0 * (float)Bar->CurrentStep) / (float)Bar->StepCount) + 0.5);
|
|
|
|
|
|
|
|
/* Redraw bar if changed */
|
|
|
|
if (Bar->Pos != NewPos)
|
|
|
|
{
|
|
|
|
Bar->Pos = NewPos;
|
|
|
|
|
|
|
|
for (coPos.Y = Bar->Top + 2; coPos.Y <= Bar->Bottom - 1; coPos.Y++)
|
|
|
|
{
|
|
|
|
coPos.X = Bar->Left + 1;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xDB,
|
2004-02-23 11:58:27 +00:00
|
|
|
Bar->Pos / 2,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
coPos.X += Bar->Pos/2;
|
|
|
|
|
|
|
|
if (NewPos & 1)
|
|
|
|
{
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xDD,
|
2004-02-23 11:58:27 +00:00
|
|
|
1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
coPos.X++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coPos.X <= Bar->Right - 1)
|
|
|
|
{
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
' ',
|
2004-02-23 11:58:27 +00:00
|
|
|
Bar->Right - coPos.X,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
ProgressSetStep (PPROGRESSBAR Bar,
|
|
|
|
ULONG Step)
|
|
|
|
{
|
|
|
|
CHAR TextBuffer[8];
|
|
|
|
COORD coPos;
|
2007-07-28 18:24:09 +00:00
|
|
|
DWORD Written;
|
2004-02-23 11:58:27 +00:00
|
|
|
ULONG NewPercent;
|
|
|
|
ULONG NewPos;
|
|
|
|
|
|
|
|
if (Step > Bar->StepCount)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Bar->CurrentStep = Step;
|
|
|
|
|
|
|
|
/* Calculate new percentage */
|
|
|
|
NewPercent = (ULONG)(((100.0 * (float)Bar->CurrentStep) / (float)Bar->StepCount) + 0.5);
|
|
|
|
|
|
|
|
/* Redraw precentage if changed */
|
|
|
|
if (Bar->Percent != NewPercent)
|
2002-12-06 21:39:04 +00:00
|
|
|
{
|
|
|
|
Bar->Percent = NewPercent;
|
|
|
|
|
2007-07-28 20:32:16 +00:00
|
|
|
sprintf(TextBuffer, "%-3lu%%", Bar->Percent);
|
2002-12-06 21:39:04 +00:00
|
|
|
|
|
|
|
coPos.X = Bar->Left + (Bar->Width - 2) / 2;
|
|
|
|
coPos.Y = Bar->Top;
|
2006-08-31 06:14:25 +00:00
|
|
|
WriteConsoleOutputCharacterA(StdOutput,
|
|
|
|
TextBuffer,
|
2002-12-06 21:39:04 +00:00
|
|
|
4,
|
2006-08-31 06:14:25 +00:00
|
|
|
coPos,
|
|
|
|
&Written);
|
2002-12-06 21:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate bar position */
|
|
|
|
NewPos = (ULONG)((((float)(Bar->Width - 2) * 2.0 * (float)Bar->CurrentStep) / (float)Bar->StepCount) + 0.5);
|
|
|
|
|
|
|
|
/* Redraw bar if changed */
|
|
|
|
if (Bar->Pos != NewPos)
|
|
|
|
{
|
|
|
|
Bar->Pos = NewPos;
|
|
|
|
|
|
|
|
for (coPos.Y = Bar->Top + 2; coPos.Y <= Bar->Bottom - 1; coPos.Y++)
|
|
|
|
{
|
|
|
|
coPos.X = Bar->Left + 1;
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xDB,
|
2002-12-06 21:39:04 +00:00
|
|
|
Bar->Pos / 2,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
coPos.X += Bar->Pos/2;
|
|
|
|
|
2003-05-28 18:35:35 +00:00
|
|
|
if (NewPos & 1)
|
2002-12-06 21:39:04 +00:00
|
|
|
{
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
0xDD,
|
2002-12-06 21:39:04 +00:00
|
|
|
1,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
coPos.X++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coPos.X <= Bar->Right - 1)
|
|
|
|
{
|
2006-08-31 06:14:25 +00:00
|
|
|
FillConsoleOutputCharacterA(StdOutput,
|
|
|
|
' ',
|
2002-12-06 21:39:04 +00:00
|
|
|
Bar->Right - coPos.X,
|
|
|
|
coPos,
|
|
|
|
&Written);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|