home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / memsz231.zip / ITEMS.CPP < prev    next >
Text File  |  1994-02-14  |  18KB  |  822 lines

  1. /****************************************************************** ITEMS.CPP
  2.  *                                                                          *
  3.  *                     Display Item Class Functions                         *
  4.  *                                                                          *
  5.  ****************************************************************************/
  6.  
  7. #define INCL_BASE
  8. #define INCL_PM
  9. #include <os2.h>
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #include "debug.h"
  16. #include "support.h"
  17. #include "restring.h"
  18.  
  19. #include "items.h"
  20.  
  21.  
  22. VOID Item::Paint
  23. (
  24.   HPS hPS,
  25.   RECTL &Rectangle,
  26.   COLOR TextColor,
  27.   COLOR BackColor,
  28.   PSZ Text,
  29.   ULONG NewValue
  30. )
  31. {
  32.   WinDrawText ( hPS, strlen(PCHAR(Text)), Text, &Rectangle,
  33.     TextColor, BackColor, DT_RIGHT | DT_BOTTOM | DT_ERASERECT ) ;
  34.  
  35.   WinDrawText ( hPS, strlen(PCHAR(Label)), Label, &Rectangle,
  36.     TextColor, BackColor, DT_LEFT | DT_BOTTOM ) ;
  37.  
  38.   Value = NewValue ;
  39. }
  40.  
  41.  
  42. VOID Item::Measure ( HPS hPS, RECTL &Rectangle ) {
  43.    BYTE Text [100] ;
  44.    sprintf ( PCHAR(Text), "%s 1,234,567K", QueryLabel() ) ;
  45.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  46.    WinDrawText ( hPS, strlen(PCHAR(Text)), Text, &Rectangle, 0L, 0L, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  47. }
  48.  
  49.  
  50. VOID Clock::Measure ( HPS hPS, RECTL &Rectangle ) {
  51.    BYTE Text [100] ;
  52.    sprintf ( PCHAR(Text), " MMM, MM-DD HH:MMx " ) ;
  53.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  54.    WinDrawText ( hPS, strlen(PCHAR(Text)), Text, &Rectangle, 0L, 0L, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  55. }
  56.  
  57.  
  58. ULONG Clock::NewValue ( void ) {
  59.  
  60.   DATETIME DateTime ;
  61.   DosGetDateTime ( &DateTime ) ;
  62.  
  63.   ULONG Time ;
  64.   Time  = DateTime.weekday ;
  65.   Time *= 100 ;
  66.   Time += DateTime.month ;
  67.   Time *= 100 ;
  68.   Time += DateTime.day ;
  69.   Time *= 100 ;
  70.   Time += DateTime.hours ;
  71.   Time *= 100 ;
  72.   Time += DateTime.minutes ;
  73.  
  74.   return ( Time ) ;
  75. }
  76.  
  77.  
  78. VOID Clock::Repaint
  79. (
  80.   HPS hPS,
  81.   RECTL &Rectangle,
  82.   COLOR TextColor,
  83.   COLOR BackColor,
  84.   BOOL Mandatory
  85. )
  86. {
  87.   ULONG Time = NewValue ( ) ;
  88.  
  89.   if ( Mandatory || ( Time != Value ) )
  90.   {
  91.     BYTE Text [100] ;
  92.     ULONG Dow    = ( Time % 1000000000L ) / 100000000L ;
  93.     ULONG Month  = ( Time % 100000000L )  / 1000000L ;
  94.     ULONG Day    = ( Time % 1000000L )    / 10000L ;
  95.     ULONG Hour   = ( Time % 10000L )      / 100L ;
  96.     ULONG Minute = ( Time % 100L ) ;
  97.  
  98.     sprintf ( PCHAR(Text), "%0.3s, ", PSZ(*DaysOfWeek) + Dow*3 ) ;
  99.  
  100.     switch ( CountryInfo.fsDateFmt )
  101.     {
  102.       case DATEFMT_DD_MM_YY:
  103.         sprintf ( PCHAR(Text)+strlen(PCHAR(Text)), "%02lu%s%02lu ",
  104.           Day, CountryInfo.szDateSeparator, Month ) ;
  105.         break ;
  106.  
  107.       case DATEFMT_YY_MM_DD:
  108.       case DATEFMT_MM_DD_YY:
  109.       default:
  110.         sprintf ( PCHAR(Text)+strlen(PCHAR(Text)), "%02lu%s%02lu ",
  111.           Month, CountryInfo.szDateSeparator, Day ) ;
  112.         break ;
  113.     }
  114.  
  115.     if ( CountryInfo.fsTimeFmt )
  116.     {
  117.       sprintf ( PCHAR(Text)+strlen(PCHAR(Text)), "%02lu%s%02lu",
  118.         Hour,
  119.         CountryInfo.szTimeSeparator,
  120.         Minute ) ;
  121.     }
  122.     else
  123.     {
  124.       PCHAR AmPm ;
  125.  
  126.       if ( Hour )
  127.       {
  128.         if ( Hour < 12 )
  129.         {
  130.           AmPm = "a" ;
  131.         }
  132.         else if ( Hour == 12 )
  133.         {
  134.           if ( Minute )
  135.             AmPm = "p" ;
  136.           else
  137.             AmPm = "a" ;
  138.         }
  139.         else if ( Hour > 12 )
  140.         {
  141.           Hour -= 12 ;
  142.           AmPm = "p" ;
  143.         }
  144.       }
  145.       else
  146.       {
  147.         Hour = 12 ;
  148.         if ( Minute )
  149.           AmPm = "a" ;
  150.         else
  151.           AmPm = "p" ;
  152.       }
  153.       sprintf ( PCHAR(Text)+strlen(PCHAR(Text)), "%02lu%s%02lu%s",
  154.         Hour, CountryInfo.szTimeSeparator, Minute, AmPm ) ;
  155.     }
  156.  
  157.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Time ) ;
  158.  
  159.     WinDrawText ( hPS, strlen(PCHAR(Text)), Text, &Rectangle,
  160.       TextColor, BackColor, DT_CENTER | DT_BOTTOM | DT_ERASERECT ) ;
  161.  
  162.     Value = Time ;
  163.   }
  164. }
  165.  
  166.  
  167. VOID ElapsedTime::Measure ( HPS hPS, RECTL &Rectangle ) {
  168.    BYTE Text [100] ;
  169.    sprintf ( PCHAR(Text), "%s XX %s, XX:XX", QueryLabel(), PSZ(*Days) ) ;
  170.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  171.    WinDrawText ( hPS, strlen(PCHAR(Text)), Text, &Rectangle, 0L, 0L, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  172. }
  173.  
  174.  
  175. ULONG ElapsedTime::NewValue ( void )
  176. {
  177.   ULONG Milliseconds ;
  178.   DosQuerySysInfo ( QSV_MS_COUNT, QSV_MS_COUNT, &Milliseconds, sizeof(Milliseconds) ) ;
  179.   return ( Milliseconds / 60000L ) ;
  180. }
  181.  
  182.  
  183. VOID ElapsedTime::Repaint
  184. (
  185.   HPS hPS,
  186.   RECTL &Rectangle,
  187.   COLOR TextColor,
  188.   COLOR BackColor,
  189.   BOOL Mandatory
  190. )
  191. {
  192.   ULONG Time = NewValue ( ) ;
  193.  
  194.   if ( Mandatory || ( Time != Value ) ) {
  195.     BYTE Text [100] ;
  196.     memset ( Text, 0, sizeof(Text) ) ;
  197.  
  198.     ULONG NumberOfDays = Time / ( 60L * 24L ) ;
  199.  
  200.     if ( NumberOfDays ) {
  201.       sprintf ( PCHAR(Text), "%lu %s, ",
  202.         NumberOfDays, NumberOfDays > 1 ? PSZ(*Days) : PSZ(*Day) ) ;
  203.     }
  204.  
  205.     ULONG Minutes = Time % ( 60L * 24L ) ;
  206.  
  207.     sprintf ( PCHAR(Text+strlen(PCHAR(Text))), "%lu%s%02lu",
  208.       Minutes/60, CountryInfo.szTimeSeparator, Minutes%60 ) ;
  209.  
  210.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Time ) ;
  211.   }
  212. }
  213.  
  214.  
  215. APIRET16 APIENTRY16 Dos16MemAvail ( PULONG pulAvailMem ) ;
  216.  
  217. ULONG MemoryFree::NewValue ( void ) {
  218.   ULONG Space ;
  219.   Dos16MemAvail ( &Space ) ;
  220.   return ( Space ) ;
  221. }
  222.  
  223.  
  224. VOID MemoryFree::Repaint
  225. (
  226.   HPS hPS,
  227.   RECTL &Rectangle,
  228.   COLOR TextColor,
  229.   COLOR BackColor,
  230.   BOOL Mandatory
  231. )
  232. {
  233.   ULONG Size = NewValue ( ) ;
  234.  
  235.   if ( Mandatory || ( Size != Value ) ) {
  236.     BYTE Text [100] ;
  237.  
  238.     if ( Size < 0x80000 )
  239.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  240.     else
  241.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  242.  
  243.     {
  244.       PBYTE p1, p2 ;
  245.       BYTE Work[100] ;
  246.  
  247.       p1 = Text ;
  248.       p2 = Work ;
  249.       while ( *p1 )
  250.       {
  251.         *p2 = *p1 ;
  252.         p1 ++ ;
  253.         p2 ++ ;
  254.         if ( *p1 )
  255.         {
  256.           if ( strlen((PCHAR)p1) % 3 == 0 )
  257.           {
  258.             *p2 = CountryInfo.szThousandsSeparator [0] ;
  259.             p2 ++ ;
  260.           }
  261.         }
  262.       }
  263.       *p2 = 0 ;
  264.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  265.     }
  266.  
  267.     Text[strlen(PCHAR(Text))+1] = 0 ;
  268.     if ( Size < 0x80000 )
  269.       Text[strlen((PCHAR)Text)] = ' ' ;
  270.     else
  271.       Text[strlen((PCHAR)Text)] = 'K' ;
  272.  
  273.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  274.   }
  275. }
  276.  
  277.  
  278. ULONG SwapSize::NewValue ( void )
  279. {
  280.   char Path [_MAX_PATH+1] ;
  281.  
  282.   strcpy ( Path, (PCHAR)SwapPath ) ;
  283.  
  284.   if ( Path[strlen(Path)-1] != '\\' )
  285.   {
  286.     strcat ( Path, "\\" ) ;
  287.   }
  288.  
  289.   strcat ( Path, "SWAPPER.DAT" ) ;
  290.  
  291.   ULONG SwapSize = 0 ;
  292.   FILESTATUS3 Status ;
  293.   if ( DosQueryPathInfo ( (PSZ)Path, FIL_STANDARD, &Status, sizeof(Status) ) == 0 )
  294.   {
  295.     SwapSize = Status.cbFileAlloc ;
  296.   }
  297.  
  298.   return ( SwapSize ) ;
  299. }
  300.  
  301.  
  302. VOID SwapSize::Repaint
  303. (
  304.   HPS hPS,
  305.   RECTL &Rectangle,
  306.   COLOR TextColor,
  307.   COLOR BackColor,
  308.   BOOL Mandatory
  309. )
  310. {
  311.   ULONG Size = NewValue ( ) ;
  312.  
  313.   if ( Mandatory || ( Size != Value ) )
  314.   {
  315.     BYTE Text [100] ;
  316.  
  317.     if ( Size < 0x80000 )
  318.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  319.     else
  320.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  321.  
  322.     {
  323.       PBYTE p1, p2 ;
  324.       BYTE Work[100] ;
  325.  
  326.       p1 = Text ;
  327.       p2 = Work ;
  328.       while ( *p1 )
  329.       {
  330.         *p2 = *p1 ;
  331.         p1 ++ ;
  332.         p2 ++ ;
  333.         if ( *p1 )
  334.         {
  335.           if ( strlen((PCHAR)p1) % 3 == 0 )
  336.           {
  337.             *p2 = CountryInfo.szThousandsSeparator [0] ;
  338.             p2 ++ ;
  339.           }
  340.         }
  341.       }
  342.       *p2 = 0 ;
  343.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  344.     }
  345.  
  346.     Text[strlen(PCHAR(Text))+1] = 0 ;
  347.     if ( Size < 0x80000 )
  348.       Text[strlen((PCHAR)Text)] = ' ' ;
  349.     else
  350.       Text[strlen((PCHAR)Text)] = 'K' ;
  351.  
  352.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  353.   }
  354. }
  355.  
  356.  
  357. ULONG SwapFree::NewValue ( void )
  358. {
  359.   char Path [_MAX_PATH+1] ;
  360.  
  361.   strcpy ( Path, (PCHAR)SwapPath ) ;
  362.   strcat ( Path, "\\SWAPPER.DAT" ) ;
  363.  
  364.   ULONG SwapFree = 0 ;
  365.   if ( Path[0] )
  366.   {
  367.     DosError ( FERR_DISABLEHARDERR ) ;
  368.     FSALLOCATE Allocation ;
  369.     DosQueryFSInfo ( Path[0]-'A'+1, FSIL_ALLOC,
  370.       (PBYTE)&Allocation, sizeof(Allocation) ) ;
  371.     DosError ( FERR_ENABLEHARDERR ) ;
  372.  
  373.     SwapFree = Allocation.cUnitAvail*Allocation.cSectorUnit*Allocation.cbSector ;
  374.   }
  375.  
  376.   if ( SwapFree < ULONG(MinFree*1024L) )
  377.     return ( 0L ) ;
  378.   else
  379.     return ( SwapFree - ULONG(MinFree*1024L) ) ;
  380. }
  381.  
  382.  
  383. VOID SwapFree::Repaint
  384. (
  385.   HPS hPS,
  386.   RECTL &Rectangle,
  387.   COLOR TextColor,
  388.   COLOR BackColor,
  389.   BOOL Mandatory
  390. )
  391. {
  392.   ULONG Size = NewValue ( ) ;
  393.  
  394.   if ( Mandatory || ( Size != Value ) )
  395.   {
  396.     BYTE Text [100] ;
  397.  
  398.     if ( Size < 0x80000 )
  399.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  400.     else
  401.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  402.  
  403.     {
  404.       PBYTE p1, p2 ;
  405.       BYTE Work[100] ;
  406.  
  407.       p1 = Text ;
  408.       p2 = Work ;
  409.       while ( *p1 )
  410.       {
  411.         *p2 = *p1 ;
  412.         p1 ++ ;
  413.         p2 ++ ;
  414.         if ( *p1 )
  415.         {
  416.           if ( strlen((PCHAR)p1) % 3 == 0 )
  417.           {
  418.             *p2 = CountryInfo.szThousandsSeparator [0] ;
  419.             p2 ++ ;
  420.           }
  421.         }
  422.       }
  423.       *p2 = 0 ;
  424.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  425.     }
  426.  
  427.     Text[strlen(PCHAR(Text))+1] = 0 ;
  428.     if ( Size < 0x80000 )
  429.       Text[strlen((PCHAR)Text)] = ' ' ;
  430.     else
  431.       Text[strlen((PCHAR)Text)] = 'K' ;
  432.  
  433.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  434.   }
  435. }
  436.  
  437.  
  438. ULONG SpoolSize::NewValue ( void )
  439. {
  440.   ULONG PathSize ;
  441.   DosQuerySysInfo ( QSV_MAX_PATH_LENGTH, QSV_MAX_PATH_LENGTH, &PathSize, sizeof(PathSize) ) ;
  442.  
  443.   PBYTE Path = PBYTE ( malloc ( PathSize ) ) ;
  444.   if ( Path == NULL )
  445.   {
  446. //  Log ( "ERROR: Unable to allocate memory for spool-file search path.\r\n" ) ;
  447.     return ( 0 ) ;
  448.   }
  449.  
  450.   PFILEFINDBUF3 Found = PFILEFINDBUF3 ( malloc ( PathSize + sizeof(FILEFINDBUF3) ) ) ;
  451.   if ( Found == NULL )
  452.   {
  453. //  Log ( "ERROR: Unable to allocate memory for spool-file search result structure.\r\n" ) ;
  454.     free ( Path ) ;
  455.     return ( 0 ) ;
  456.   }
  457.  
  458.   strcpy ( (PCHAR)Path, (PCHAR)SpoolPath ) ;
  459.   strcat ( (PCHAR)Path, "\\*.*" ) ;
  460.  
  461.   HDIR hDir = (HDIR) HDIR_CREATE ;
  462.   ULONG Count = 1 ;
  463.   ULONG TotalSize = 0 ;
  464.  
  465.   if ( !DosFindFirst2 ( Path, &hDir,
  466.     FILE_NORMAL | FILE_READONLY | FILE_DIRECTORY | FILE_ARCHIVED,
  467.     Found, PathSize+sizeof(FILEFINDBUF3), &Count, FIL_STANDARD ) )
  468.   {
  469.  
  470.     do
  471.     {
  472.  
  473.       if ( !strcmp ( (PCHAR)Found->achName, "." )
  474.         OR !strcmp ( (PCHAR)Found->achName, ".." ) )
  475.       {
  476.         continue ;
  477.       }
  478.  
  479.       if ( Found->attrFile & FILE_DIRECTORY )
  480.       {
  481.         HDIR hDir2 = (HDIR) HDIR_CREATE ;
  482.  
  483.         strcpy ( (PCHAR)Path, (PCHAR)SpoolPath ) ;
  484.         strcat ( (PCHAR)Path, "\\" ) ;
  485.         strcat ( (PCHAR)Path, (PCHAR)Found->achName ) ;
  486.         strcat ( (PCHAR)Path, "\\*.*" ) ;
  487.  
  488.         ULONG Count2 = 1 ;
  489.         if ( !DosFindFirst2 ( Path, &hDir2,
  490.           FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED,
  491.           Found, PathSize+sizeof(FILEFINDBUF3), &Count2, FIL_STANDARD ) )
  492.         {
  493.           do
  494.           {
  495.             TotalSize += Found->cbFileAlloc ;
  496.           }
  497.           while ( !DosFindNext ( hDir2, Found, PathSize+sizeof(FILEFINDBUF3), &Count2 ) ) ;
  498.           DosFindClose ( hDir2 ) ;
  499.         }
  500.       }
  501.  
  502.       else
  503.       {
  504.         TotalSize += Found->cbFileAlloc ;
  505.       }
  506.     }
  507.     while ( !DosFindNext ( hDir, Found, PathSize+sizeof(FILEFINDBUF3), &Count ) ) ;
  508.  
  509.     DosFindClose ( hDir ) ;
  510.   }
  511.  
  512.   free ( Path ) ;
  513.   free ( Found ) ;
  514.  
  515.   return ( TotalSize ) ;
  516. }
  517.  
  518.  
  519. VOID SpoolSize::Repaint
  520. (
  521.   HPS hPS,
  522.   RECTL &Rectangle,
  523.   COLOR TextColor,
  524.   COLOR BackColor,
  525.   BOOL Mandatory
  526. )
  527. {
  528.   ULONG Size = NewValue ( ) ;
  529.  
  530.   if ( Mandatory || ( Size != Value ) )
  531.   {
  532.     BYTE Text [100] ;
  533.  
  534.     if ( Size < 0x80000 )
  535.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  536.     else
  537.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  538.  
  539.     {
  540.       PBYTE p1, p2 ;
  541.       BYTE Work[100] ;
  542.  
  543.       p1 = Text ;
  544.       p2 = Work ;
  545.       while ( *p1 )
  546.       {
  547.         *p2 = *p1 ;
  548.         p1 ++ ;
  549.         p2 ++ ;
  550.         if ( *p1 )
  551.         {
  552.           if ( strlen((PCHAR)p1) % 3 == 0 )
  553.           {
  554.             *p2 = CountryInfo.szThousandsSeparator [0] ;
  555.             p2 ++ ;
  556.           }
  557.         }
  558.       }
  559.       *p2 = 0 ;
  560.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  561.     }
  562.  
  563.     Text[strlen(PCHAR(Text))+1] = 0 ;
  564.     if ( Size < 0x80000 )
  565.       Text[strlen((PCHAR)Text)] = ' ' ;
  566.     else
  567.       Text[strlen((PCHAR)Text)] = 'K' ;
  568.  
  569.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  570.   }
  571. }
  572.  
  573.  
  574. ULONG CpuLoad::NewValue ( void ) {
  575.   MaxCount = (ULONG) max ( MaxCount, *IdleCount ) ;
  576.   ULONG Load = ( ( MaxCount - *IdleCount ) * 100 ) / MaxCount ;
  577.   return ( Load ) ;
  578. }
  579.  
  580.  
  581. VOID CpuLoad::Repaint
  582. (
  583.   HPS hPS,
  584.   RECTL &Rectangle,
  585.   COLOR TextColor,
  586.   COLOR BackColor,
  587.   BOOL Mandatory
  588. )
  589. {
  590.   ULONG Load = NewValue ( ) ;
  591.  
  592.   if ( Mandatory || ( Load != Value ) )
  593.   {
  594.     BYTE Text [100] ;
  595.     sprintf ( (PCHAR)Text, "%lu%%", Load ) ;
  596.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Load ) ;
  597.   }
  598. }
  599.  
  600.  
  601. ULONG TaskCount::NewValue ( void )
  602. {
  603.   return ( WinQuerySwitchList ( Anchor, PSWBLOCK(NULL), 0 ) ) ;
  604. }
  605.  
  606.  
  607. VOID TaskCount::Repaint
  608. (
  609.   HPS hPS,
  610.   RECTL &Rectangle,
  611.   COLOR TextColor,
  612.   COLOR BackColor,
  613.   BOOL Mandatory
  614. )
  615. {
  616.   ULONG Count = NewValue ( ) ;
  617.  
  618.   if ( Mandatory || ( Count != Value ) )
  619.   {
  620.     BYTE Text [100] ;
  621.     sprintf ( (PCHAR)Text, "%lu ", Count ) ;
  622.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Count ) ;
  623.   }
  624. }
  625.  
  626.  
  627. VOID DriveFree::Measure ( HPS hPS, RECTL &Rectangle ) {
  628.    BYTE Text [100] ;
  629.    if ( ShowFileSystemName ) {
  630.       sprintf ( PCHAR(Text), "%s (%s) 1,234,567K", QueryLabel(), FileSystem ) ;
  631.    } else {
  632.       sprintf ( PCHAR(Text), "%s 1,234,567K", QueryLabel() ) ;
  633.    } /* endif */
  634.    WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  635.    WinDrawText ( hPS, strlen(PCHAR(Text)), Text, &Rectangle, 0L, 0L, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  636. }
  637.  
  638.  
  639. ULONG DriveFree::NewValue ( void )
  640. {
  641.   if ( Error )
  642.   {
  643.     return ( 0 ) ;
  644.   }
  645.  
  646.   DosError ( FERR_DISABLEHARDERR ) ;
  647.  
  648.   FSALLOCATE Allocation ;
  649.   USHORT Status = DosQueryFSInfo ( DriveNumber, FSIL_ALLOC, (PBYTE)&Allocation, sizeof(Allocation) ) ;
  650.  
  651.   DosError ( FERR_ENABLEHARDERR ) ;
  652.  
  653.   if ( Status )
  654.   {
  655.     Error = TRUE ;
  656.     return ( 0 ) ;
  657.   }
  658.  
  659.   return ( Allocation.cUnitAvail*Allocation.cSectorUnit*Allocation.cbSector ) ;
  660. }
  661.  
  662.  
  663. VOID DriveFree::Repaint
  664. (
  665.   HPS hPS,
  666.   RECTL &Rectangle,
  667.   COLOR TextColor,
  668.   COLOR BackColor,
  669.   BOOL Mandatory
  670. )
  671. {
  672.   ULONG Size = NewValue ( ) ;
  673.  
  674.   if ( Mandatory || ( Size != Value ) )
  675.   {
  676.     BYTE Text [100] ;
  677.  
  678.     if ( Error )
  679.     {
  680.       strcpy ( PCHAR(Text), PCHAR(*DriveError) ) ;
  681.     }
  682.     else
  683.     {
  684.       if ( Size < 0x80000 )
  685.         sprintf ( (PCHAR)Text, "%lu", Size ) ;
  686.       else
  687.         sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  688.  
  689.       {
  690.         PBYTE p1, p2 ;
  691.         BYTE Work[100] ;
  692.  
  693.         p1 = Text ;
  694.         p2 = Work ;
  695.         while ( *p1 )
  696.         {
  697.           *p2 = *p1 ;
  698.           p1 ++ ;
  699.           p2 ++ ;
  700.           if ( *p1 )
  701.           {
  702.             if ( strlen((PCHAR)p1) % 3 == 0 )
  703.             {
  704.               *p2 = CountryInfo.szThousandsSeparator [0] ;
  705.               p2 ++ ;
  706.             }
  707.           }
  708.         }
  709.         *p2 = 0 ;
  710.         strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  711.       }
  712.  
  713.       Text[strlen(PCHAR(Text))+1] = 0 ;
  714.       if ( Size < 0x80000 )
  715.         Text[strlen((PCHAR)Text)] = ' ' ;
  716.       else
  717.         Text[strlen((PCHAR)Text)] = 'K' ;
  718.     }
  719.  
  720.     WinDrawText ( hPS, strlen(PCHAR(Text)), Text, &Rectangle,
  721.       TextColor, BackColor, DT_RIGHT | DT_BOTTOM | DT_ERASERECT ) ;
  722.  
  723.     if ( ShowFileSystemName ) {
  724.        sprintf ( PCHAR(Text), "%s (%s)", QueryLabel(), FileSystem ) ;
  725.     } else {
  726.        sprintf ( PCHAR(Text), "%s", QueryLabel() ) ;
  727.     } /* endif */
  728.     
  729.     WinDrawText ( hPS, strlen(PCHAR(Text)), Text, &Rectangle,
  730.       TextColor, BackColor, DT_LEFT | DT_BOTTOM ) ;
  731.  
  732.     Value = Size ;
  733.   }
  734. }
  735.  
  736.  
  737. ULONG TotalFree::NewValue ( void )
  738. {
  739.   ULONG Free = 0 ;
  740.   ULONG Mask = Drives >> 2 ;
  741.  
  742.   for ( int Drive=3; Drive<=26; Drive++ )
  743.   {
  744.     if ( Mask & 1 )
  745.     {
  746.       DosError ( FERR_DISABLEHARDERR ) ;
  747.  
  748.       FSALLOCATE Allocation ;
  749.       USHORT Status = DosQueryFSInfo ( Drive, FSIL_ALLOC, (PBYTE)&Allocation, sizeof(Allocation) ) ;
  750.  
  751.       DosError ( FERR_ENABLEHARDERR ) ;
  752.  
  753.       if ( Status )
  754.       {
  755.         Drives &= ~ ( 1 << (Drive-1) ) ;
  756.       }
  757.       else
  758.       {
  759.         Free += Allocation.cUnitAvail*Allocation.cSectorUnit*Allocation.cbSector ;
  760.       }
  761.     }
  762.     Mask >>= 1 ;
  763.   }
  764.  
  765.   return ( Free ) ;
  766. }
  767.  
  768.  
  769. VOID TotalFree::Repaint
  770. (
  771.   HPS hPS,
  772.   RECTL &Rectangle,
  773.   COLOR TextColor,
  774.   COLOR BackColor,
  775.   BOOL Mandatory
  776. )
  777. {
  778.   ULONG Size = NewValue ( ) ;
  779.  
  780.   if ( Mandatory || ( Size != Value ) )
  781.   {
  782.     BYTE Text [100] ;
  783.  
  784.     if ( Size < 0x80000 )
  785.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  786.     else
  787.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  788.  
  789.     {
  790.       PBYTE p1, p2 ;
  791.       BYTE Work[100] ;
  792.  
  793.       p1 = Text ;
  794.       p2 = Work ;
  795.       while ( *p1 )
  796.       {
  797.         *p2 = *p1 ;
  798.         p1 ++ ;
  799.         p2 ++ ;
  800.         if ( *p1 )
  801.         {
  802.           if ( strlen((PCHAR)p1) % 3 == 0 )
  803.           {
  804.             *p2 = CountryInfo.szThousandsSeparator [0] ;
  805.             p2 ++ ;
  806.           }
  807.         }
  808.       }
  809.       *p2 = 0 ;
  810.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  811.     }
  812.  
  813.     Text[strlen(PCHAR(Text))+1] = 0 ;
  814.     if ( Size < 0x80000 )
  815.       Text[strlen((PCHAR)Text)] = ' ' ;
  816.     else
  817.       Text[strlen((PCHAR)Text)] = 'K' ;
  818.  
  819.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  820.   }
  821. }
  822.