Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436/* * 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 *****************************************************************/
#include "usetup.h"
#define NDEBUG#include <debug.h>
/* FUNCTIONS ****************************************************************/
staticBOOLEAN NTAPIUpdateProgressPercentage( IN PPROGRESSBAR Bar, IN BOOLEAN AlwaysUpdate, OUT PSTR Buffer, IN SIZE_T cchBufferSize){ // static PCSTR ProgressFormatText; ULONG OldProgress = Bar->Progress;
/* 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 && (AlwaysUpdate || (Bar->Progress != OldProgress)) ) { RtlStringCchPrintfA(Buffer, cchBufferSize, Bar->ProgressFormatText, Bar->Progress); return TRUE; } return FALSE;}
staticVOIDDrawBorder( IN PPROGRESSBAR Bar){ COORD coPos; DWORD Written; SHORT i;
/* draw upper left corner */ coPos.X = Bar->Left; coPos.Y = Bar->Top + 1; FillConsoleOutputCharacterA(StdOutput, CharUpperLeftCorner, // '+', 1, coPos, &Written);
/* draw upper edge */ coPos.X = Bar->Left + 1; coPos.Y = Bar->Top + 1; FillConsoleOutputCharacterA(StdOutput, CharHorizontalLine, // '-', Bar->Right - Bar->Left - 1, coPos, &Written);
/* draw upper right corner */ coPos.X = Bar->Right; coPos.Y = Bar->Top + 1; FillConsoleOutputCharacterA(StdOutput, CharUpperRightCorner, // '+', 1, coPos, &Written);
/* draw left and right edge */ for (i = Bar->Top + 2; i < Bar->Bottom; i++) { coPos.X = Bar->Left; coPos.Y = i; FillConsoleOutputCharacterA(StdOutput, CharVerticalLine, // '|', 1, coPos, &Written);
coPos.X = Bar->Right; FillConsoleOutputCharacterA(StdOutput, CharVerticalLine, //'|', 1, coPos, &Written); }
/* draw lower left corner */ coPos.X = Bar->Left; coPos.Y = Bar->Bottom; FillConsoleOutputCharacterA(StdOutput, CharLowerLeftCorner, // '+', 1, coPos, &Written);
/* draw lower edge */ coPos.X = Bar->Left + 1; coPos.Y = Bar->Bottom; FillConsoleOutputCharacterA(StdOutput, CharHorizontalLine, // '-', Bar->Right - Bar->Left - 1, coPos, &Written);
/* draw lower right corner */ coPos.X = Bar->Right; coPos.Y = Bar->Bottom; FillConsoleOutputCharacterA(StdOutput, CharLowerRightCorner, // '+', 1, coPos, &Written);}
staticVOIDDrawThickBorder( IN PPROGRESSBAR Bar){ COORD coPos; DWORD Written; SHORT i;
/* draw upper left corner */ coPos.X = Bar->Left; coPos.Y = Bar->Top + 1; FillConsoleOutputCharacterA(StdOutput, CharDoubleUpperLeftCorner, // '+', 1, coPos, &Written);
/* draw upper edge */ coPos.X = Bar->Left + 1; coPos.Y = Bar->Top + 1; FillConsoleOutputCharacterA(StdOutput, CharDoubleHorizontalLine, // '-', Bar->Right - Bar->Left - 1, coPos, &Written);
/* draw upper right corner */ coPos.X = Bar->Right; coPos.Y = Bar->Top + 1; FillConsoleOutputCharacterA(StdOutput, CharDoubleUpperRightCorner, // '+', 1, coPos, &Written);
/* draw left and right edge */ for (i = Bar->Top + 2; i < Bar->Bottom; i++) { coPos.X = Bar->Left; coPos.Y = i; FillConsoleOutputCharacterA(StdOutput, CharDoubleVerticalLine, // '|', 1, coPos, &Written);
coPos.X = Bar->Right; FillConsoleOutputCharacterA(StdOutput, CharDoubleVerticalLine, //'|', 1, coPos, &Written); }
/* draw lower left corner */ coPos.X = Bar->Left; coPos.Y = Bar->Bottom; FillConsoleOutputCharacterA(StdOutput, CharDoubleLowerLeftCorner, // '+', 1, coPos, &Written);
/* draw lower edge */ coPos.X = Bar->Left + 1; coPos.Y = Bar->Bottom; FillConsoleOutputCharacterA(StdOutput, CharDoubleHorizontalLine, // '-', Bar->Right - Bar->Left - 1, coPos, &Written);
/* draw lower right corner */ coPos.X = Bar->Right; coPos.Y = Bar->Bottom; FillConsoleOutputCharacterA(StdOutput, CharDoubleLowerRightCorner, // '+', 1, coPos, &Written);}
staticVOIDDrawProgressBar( IN PPROGRESSBAR Bar){ COORD coPos; DWORD Written; PROGRESSBAR BarBorder = *Bar; CHAR TextBuffer[256];
/* Draw the progress bar "border" border */ if (Bar->DoubleEdge) { BarBorder.Top -= 5; BarBorder.Bottom += 2; BarBorder.Right += 5; BarBorder.Left -= 5; DrawThickBorder(&BarBorder); }
/* Draw the progress bar border */ DrawBorder(Bar);
/* Display the description text */ if (Bar->DescriptionText) CONSOLE_SetTextXY(Bar->TextTop, Bar->TextRight, Bar->DescriptionText);
/* Always update and display the progress */ if (Bar->UpdateProgressProc && Bar->UpdateProgressProc(Bar, TRUE, TextBuffer, ARRAYSIZE(TextBuffer))) { coPos.X = Bar->Left + (Bar->Width - (USHORT)strlen(TextBuffer) + 1) / 2; coPos.Y = Bar->Top; WriteConsoleOutputCharacterA(StdOutput, TextBuffer, strlen(TextBuffer), coPos, &Written); }
/* Draw the empty bar */ coPos.X = Bar->Left + 1; for (coPos.Y = Bar->Top + 2; coPos.Y <= Bar->Bottom - 1; coPos.Y++) { FillConsoleOutputAttribute(StdOutput, Bar->ProgressColour, Bar->Width - 2, coPos, &Written);
FillConsoleOutputCharacterA(StdOutput, ' ', Bar->Width - 2, coPos, &Written); }}
PPROGRESSBARCreateProgressBarEx( IN SHORT Left, IN SHORT Top, IN SHORT Right, IN SHORT Bottom, IN SHORT TextTop, 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){ PPROGRESSBAR Bar;
Bar = (PPROGRESSBAR)RtlAllocateHeap(ProcessHeap, 0, sizeof(PROGRESSBAR)); if (Bar == NULL) return NULL;
Bar->Left = Left; Bar->Top = Top; Bar->Right = Right; Bar->Bottom = Bottom; Bar->TextTop = TextTop; Bar->TextRight = TextRight;
Bar->Width = Bar->Right - Bar->Left + 1;
Bar->DoubleEdge = DoubleEdge; Bar->ProgressColour = ProgressColour; Bar->DescriptionText = DescriptionText; Bar->ProgressFormatText = ProgressFormatText;
Bar->UpdateProgressProc = UpdateProgressProc;
/* Reset the progress bar counts and initially draw it */ ProgressSetStepCount(Bar, StepCount);
return Bar;}
PPROGRESSBARCreateProgressBar( IN SHORT Left, IN SHORT Top, IN SHORT Right, IN SHORT Bottom, IN SHORT TextTop, IN SHORT TextRight, IN BOOLEAN DoubleEdge, IN PCSTR DescriptionText OPTIONAL){ /* Call the Ex variant of the function */ return CreateProgressBarEx(Left, Top, Right, Bottom, TextTop, TextRight, DoubleEdge, FOREGROUND_YELLOW | BACKGROUND_BLUE, 0, DescriptionText, "%-3lu%%", UpdateProgressPercentage);}
VOIDDestroyProgressBar( IN OUT PPROGRESSBAR Bar){ RtlFreeHeap(ProcessHeap, 0, Bar);}
VOIDProgressSetStepCount( IN PPROGRESSBAR Bar, IN ULONG StepCount){ Bar->CurrentStep = 0; Bar->StepCount = StepCount;
Bar->Progress = 0; Bar->Pos = 0;
DrawProgressBar(Bar);}
VOIDProgressNextStep( IN PPROGRESSBAR Bar){ ProgressSetStep(Bar, Bar->CurrentStep + 1);}
VOIDProgressSetStep( IN PPROGRESSBAR Bar, IN ULONG Step){ COORD coPos; DWORD Written; ULONG NewPos; CHAR TextBuffer[256];
if (Step > Bar->StepCount) return;
Bar->CurrentStep = Step;
/* Update the progress and redraw it if it has changed */ if (Bar->UpdateProgressProc && Bar->UpdateProgressProc(Bar, FALSE, TextBuffer, ARRAYSIZE(TextBuffer))) { coPos.X = Bar->Left + (Bar->Width - (USHORT)strlen(TextBuffer) + 1) / 2; coPos.Y = Bar->Top; WriteConsoleOutputCharacterA(StdOutput, TextBuffer, strlen(TextBuffer), coPos, &Written); }
/* Calculate the bar position */ NewPos = (((Bar->Width - 2) * 2 * Bar->CurrentStep + (Bar->StepCount / 2)) / Bar->StepCount);
/* Redraw the bar if it has 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; FillConsoleOutputCharacterA(StdOutput, CharBlock, Bar->Pos / 2, coPos, &Written); coPos.X += Bar->Pos / 2;
if (NewPos & 1) { FillConsoleOutputCharacterA(StdOutput, CharHalfBlock, 1, coPos, &Written); coPos.X++; }
if (coPos.X <= Bar->Right - 1) { FillConsoleOutputCharacterA(StdOutput, ' ', Bar->Right - coPos.X, coPos, &Written); } } }}
/* EOF */