Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. dngauge.c
  5. Abstract:
  6. Code implementing a gas gauge for file copies for DOS-hosted NT Setup.
  7. Author:
  8. Ted Miller (tedm) 14-April-1992
  9. Revision History:
  10. --*/
  11. #include "winnt.h"
  12. #include <string.h>
  13. unsigned FileCount;
  14. unsigned FilesCopied;
  15. unsigned CurrentPercent;
  16. int GaugeChar;
  17. VOID
  18. DnInitGauge(
  19. IN unsigned NumberOfFiles,
  20. IN PSCREEN AdditionalScreen OPTIONAL
  21. )
  22. /*++
  23. Routine Description:
  24. Initialize the gas gauge. This includes drawing the gas gauge at 0%
  25. and setting some global variables.
  26. Arguments:
  27. NumberOfFiles - supplies total number of files that 100% represents.
  28. Screen - If specified, supplies a screen to display along with the
  29. gas gauge.
  30. Return Value:
  31. None.
  32. --*/
  33. {
  34. FileCount = NumberOfFiles;
  35. FilesCopied = 0;
  36. CurrentPercent = 0;
  37. GaugeChar = DnGetGaugeChar();
  38. DnDrawGauge(AdditionalScreen);
  39. }
  40. VOID
  41. DnpRepaintGauge(
  42. IN BOOLEAN ForceRepaint
  43. )
  44. /*++
  45. Routine Description:
  46. Draw the entire gauge inits current state.
  47. Arguments:
  48. ForceRepaint - if TRUE, the gauge is redrawn even if the percentage
  49. hasn't changed since the last time the gauge was redrawn.
  50. Return Value:
  51. None.
  52. --*/
  53. {
  54. unsigned PercentComplete;
  55. unsigned temp;
  56. char Therm[GAUGE_WIDTH+1];
  57. unsigned SpacesOnScreen;
  58. #ifdef CODEPAGE_437
  59. BOOLEAN HalfSpace;
  60. #endif
  61. if(!FileCount) {
  62. return;
  63. }
  64. //
  65. // Figure out the percent complete.
  66. //
  67. PercentComplete = (unsigned)(100L * FilesCopied / FileCount);
  68. if(ForceRepaint || (PercentComplete != CurrentPercent)) {
  69. CurrentPercent = PercentComplete;
  70. //
  71. // Figure out how many spaces this represents on-screen.
  72. //
  73. temp = CurrentPercent * GAUGE_WIDTH;
  74. SpacesOnScreen = temp / 100;
  75. memset(Therm,GaugeChar,SpacesOnScreen);
  76. Therm[SpacesOnScreen] = '\0';
  77. DnPositionCursor(GAUGE_THERM_X,GAUGE_THERM_Y);
  78. DnSetGaugeAttribute(TRUE);
  79. DnWriteString(Therm);
  80. DnSetGaugeAttribute(FALSE);
  81. sprintf(Therm,"%u%%",CurrentPercent);
  82. DnPositionCursor(GAUGE_PERCENT_X,GAUGE_PERCENT_Y);
  83. DnWriteString(Therm);
  84. }
  85. }
  86. VOID
  87. DnTickGauge(
  88. VOID
  89. )
  90. /*++
  91. Routine Description:
  92. 'Tick' the gas gauge, ie, indicate that another file has been copied.
  93. Adjust the thermometer and percent-complete readouts.
  94. Arguments:
  95. None.
  96. Return Value:
  97. None.
  98. --*/
  99. {
  100. if(FilesCopied < FileCount) {
  101. FilesCopied++;
  102. }
  103. DnpRepaintGauge(FALSE);
  104. }
  105. VOID
  106. DnDrawGauge(
  107. IN PSCREEN AdditionalScreen OPTIONAL
  108. )
  109. /*++
  110. Routine Description:
  111. Clear the client area and redraw the gas gauge in its current state.
  112. Arguments:
  113. Screen - If specified, supplies a screen to display along with the
  114. gas gauge.
  115. Return Value:
  116. None.
  117. --*/
  118. {
  119. DnClearClientArea();
  120. if(AdditionalScreen) {
  121. DnDisplayScreen(AdditionalScreen);
  122. }
  123. DnDisplayScreen(&DnsGauge);
  124. DnpRepaintGauge(TRUE);
  125. }