Added progress bar to file copy page.

svn path=/trunk/; revision=3828
This commit is contained in:
Eric Kohl 2002-12-06 21:39:04 +00:00
parent 72136233fb
commit 1a57936f09
4 changed files with 334 additions and 7 deletions

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.5 2002/11/23 01:55:27 ekohl Exp $
# $Id: makefile,v 1.6 2002/12/06 21:39:03 ekohl Exp $
PATH_TO_TOP = ../../..
@ -12,7 +12,8 @@ TARGET_INSTALLDIR = system32
TARGET_CFLAGS = -D__NTAPP__
TARGET_OBJECTS = $(TARGET_NAME).o console.o drivesup.o filequeue.o filesup.o inicache.o partlist.o
TARGET_OBJECTS = $(TARGET_NAME).o console.o drivesup.o filequeue.o filesup.o \
inicache.o partlist.o progress.o
include $(PATH_TO_TOP)/rules.mak

View file

@ -0,0 +1,246 @@
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <ntdll/rtl.h>
#include "usetup.h"
#include "progress.h"
/* FUNCTIONS ****************************************************************/
static VOID
DrawBorder(PPROGRESS Bar)
{
COORD coPos;
ULONG Written;
SHORT i;
/* draw upper left corner */
coPos.X = Bar->Left;
coPos.Y = Bar->Top + 1;
FillConsoleOutputCharacter(0xDA, // '+',
1,
coPos,
&Written);
/* draw upper edge */
coPos.X = Bar->Left + 1;
coPos.Y = Bar->Top + 1;
FillConsoleOutputCharacter(0xC4, // '-',
Bar->Right - Bar->Left - 1,
coPos,
&Written);
/* draw upper right corner */
coPos.X = Bar->Right;
coPos.Y = Bar->Top + 1;
FillConsoleOutputCharacter(0xBF, // '+',
1,
coPos,
&Written);
/* draw left and right edge */
for (i = Bar->Top + 2; i < Bar->Bottom; i++)
{
coPos.X = Bar->Left;
coPos.Y = i;
FillConsoleOutputCharacter(0xB3, // '|',
1,
coPos,
&Written);
coPos.X = Bar->Right;
FillConsoleOutputCharacter(0xB3, //'|',
1,
coPos,
&Written);
}
/* draw lower left corner */
coPos.X = Bar->Left;
coPos.Y = Bar->Bottom;
FillConsoleOutputCharacter(0xC0, // '+',
1,
coPos,
&Written);
/* draw lower edge */
coPos.X = Bar->Left + 1;
coPos.Y = Bar->Bottom;
FillConsoleOutputCharacter(0xC4, // '-',
Bar->Right - Bar->Left - 1,
coPos,
&Written);
/* draw lower right corner */
coPos.X = Bar->Right;
coPos.Y = Bar->Bottom;
FillConsoleOutputCharacter(0xD9, // '+',
1,
coPos,
&Written);
}
static VOID
DrawProgressBar(PPROGRESS Bar)
{
CHAR TextBuffer[8];
COORD coPos;
ULONG Written;
SHORT i;
/* Print percentage */
sprintf(TextBuffer, "%-3lu%%", Bar->Percent);
coPos.X = Bar->Left + (Bar->Width - 2) / 2;
coPos.Y = Bar->Top;
WriteConsoleOutputCharacters(TextBuffer,
4,
coPos);
DrawBorder(Bar);
/* Draw the bar */
coPos.X = Bar->Left + 1;
for (coPos.Y = Bar->Top + 2; coPos.Y <= Bar->Bottom - 1; coPos.Y++)
{
FillConsoleOutputAttribute(0x1E, /* Yellow on blue */
Bar->Width - 2,
coPos,
&Written);
FillConsoleOutputCharacter(' ',
Bar->Width - 2,
coPos,
&Written);
}
}
PPROGRESS
CreateProgressBar(SHORT Left,
SHORT Top,
SHORT Right,
SHORT Bottom)
{
PPROGRESS Bar;
Bar = (PPROGRESS)RtlAllocateHeap(ProcessHeap,
0,
sizeof(PROGRESS));
if (Bar == NULL)
return(NULL);
Bar->Left = Left;
Bar->Top = Top;
Bar->Right = Right;
Bar->Bottom = Bottom;
Bar->Width = Bar->Right - Bar->Left + 1;
Bar->Percent = 0;
Bar->Pos = 0;
Bar->StepCount = 0;
Bar->CurrentStep = 0;
DrawProgressBar(Bar);
return(Bar);
}
VOID
DestroyProgressBar(PPROGRESS Bar)
{
RtlFreeHeap(ProcessHeap,
0,
Bar);
}
VOID
ProgressSetStepCount(PPROGRESS Bar,
ULONG StepCount)
{
Bar->CurrentStep = 0;
Bar->StepCount = StepCount;
DrawProgressBar(Bar);
}
VOID
ProgressNextStep(PPROGRESS Bar)
{
CHAR TextBuffer[8];
COORD coPos;
ULONG Written;
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)
{
Bar->Percent = NewPercent;
sprintf(TextBuffer, "%-3lu%%", Bar->Percent);
coPos.X = Bar->Left + (Bar->Width - 2) / 2;
coPos.Y = Bar->Top;
WriteConsoleOutputCharacters(TextBuffer,
4,
coPos);
}
/* 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;
FillConsoleOutputCharacter(0xDB,
Bar->Pos / 2,
coPos,
&Written);
coPos.X += Bar->Pos/2;
if (Pos & 1)
{
FillConsoleOutputCharacter(0xDD,
1,
coPos,
&Written);
coPos.X++;
}
if (coPos.X <= Bar->Right - 1)
{
FillConsoleOutputCharacter(' ',
Bar->Right - coPos.X,
coPos,
&Written);
}
}
}
}
/* EOF */

View file

@ -0,0 +1,67 @@
/*
* ReactOS kernel
* Copyright (C) 2002 ReactOS Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: progress.h,v 1.1 2002/12/06 21:39:04 ekohl Exp $
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS text-mode setup
* FILE: subsys/system/usetup/partlist.h
* PURPOSE: Partition list functions
* PROGRAMMER: Eric Kohl
*/
#ifndef __PROGRESS_H__
#define __PROGRESS_H__
typedef struct _PROGRESS
{
SHORT Left;
SHORT Top;
SHORT Right;
SHORT Bottom;
SHORT Width;
ULONG Percent;
ULONG Pos;
ULONG StepCount;
ULONG CurrentStep;
} PROGRESS, *PPROGRESS;
/* FUNCTIONS ****************************************************************/
PPROGRESS
CreateProgressBar(SHORT Left,
SHORT Top,
SHORT Right,
SHORT Bottom);
VOID
DestroyProgressBar(PPROGRESS Bar);
VOID
ProgressSetStepCount(PPROGRESS Bar,
ULONG StepCount);
VOID
ProgressNextStep(PPROGRESS Bar);
#endif /* __PROGRESS_H__ */
/* EOF */

View file

@ -35,6 +35,7 @@
#include "partlist.h"
#include "inicache.h"
#include "filequeue.h"
#include "progress.h"
#define START_PAGE 0
@ -60,7 +61,7 @@ typedef struct _COPYCONTEXT
{
ULONG TotalOperations;
ULONG CompletedOperations;
ULONG Progress;
PPROGRESS ProgressBar;
} COPYCONTEXT, *PCOPYCONTEXT;
@ -1186,6 +1187,8 @@ FileCopyCallback(PVOID Context,
{
case SPFILENOTIFY_STARTSUBQUEUE:
CopyContext->TotalOperations = (ULONG)Param2;
ProgressSetStepCount(CopyContext->ProgressBar,
CopyContext->TotalOperations);
break;
case SPFILENOTIFY_STARTCOPY:
@ -1200,6 +1203,7 @@ FileCopyCallback(PVOID Context,
case SPFILENOTIFY_ENDCOPY:
CopyContext->CompletedOperations++;
ProgressNextStep(CopyContext->ProgressBar);
break;
}
@ -1212,15 +1216,22 @@ FileCopyPage(PINPUT_RECORD Ir)
{
WCHAR TargetRootPath[MAX_PATH];
COPYCONTEXT CopyContext;
CopyContext.TotalOperations = 0;
CopyContext.CompletedOperations = 0;
CopyContext.Progress = 0;
SHORT xScreen;
SHORT yScreen;
SetStatusText(" Please wait...");
SetTextXY(6, 8, "Copying files");
GetScreenSize(&xScreen, &yScreen);
CopyContext.TotalOperations = 0;
CopyContext.CompletedOperations = 0;
CopyContext.ProgressBar = CreateProgressBar(6,
yScreen - 14,
xScreen - 7,
yScreen - 10);
swprintf(TargetRootPath,
L"\\Device\\Harddisk%lu\\Partition%lu",
PartData.DiskNumber,
@ -1234,6 +1245,8 @@ FileCopyPage(PINPUT_RECORD Ir)
SetupCloseFileQueue(SetupFileQueue);
DestroyProgressBar(CopyContext.ProgressBar);
SetStatusText(" ENTER = Continue F3 = Quit");
while(TRUE)