home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vp21beta.zip / OEXMPSRC.RAR / SYSLEVEL / SYSLVL.PAS
Pascal/Delphi Source File  |  2000-08-15  |  5KB  |  210 lines

  1. {█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█}
  2. {█                                                       █}
  3. {█      Virtual Pascal Examples. Version 2.1             █}
  4. {█      SysLevel example                                 █}
  5. {█      ─────────────────────────────────────────────────█}
  6. {█      Copyright (C) 1996-2000 vpascal.com              █}
  7. {█                                                       █}
  8. {▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀}
  9.  
  10. program SysLvl;
  11.  
  12. { This program performs a function identical to IBM's SysLevel }
  13. { command, but much faster than the original.                  }
  14.  
  15. {$IFNDEF OS2}
  16.   !! This example is for OS/2 only
  17. {$ENDIF}
  18.  
  19. {$PMTYPE VIO}
  20.  
  21. {$Delphi+,H-,Use32+}
  22. {$M 60000}
  23.  
  24. uses
  25.   VpSysLow, SysUtils, Os2Def, Os2Base, Crt, Dos, VPUtils;
  26.  
  27. const
  28.   dirs: Longint = 0;
  29.   SysFiles: Longint = 0;
  30.   MaxStack = 500;
  31.  
  32. type
  33.   StringList = Array[1..MaxStack] of String;
  34.   pStringList = ^StringList;
  35.  
  36. var
  37.   SysF: pStringList;
  38.   y: Integer;
  39.  
  40. procedure ScanPath( Path : String );
  41. var
  42.   i, stop: Longint;
  43.   s: SearchRec;
  44.   DirStack: pStringList;
  45.  
  46. begin
  47.   inc( Dirs );
  48.   if Dirs mod 6 = 0 then
  49.     begin
  50.       gotoxy( 5, y );
  51.       Write(dirs:6,'  ');
  52.       if length(Path) <= 60 then
  53.         Write( Path )
  54.       else
  55.         Write( copy( Path, Length(Path)-60, 60 ), '...' );
  56.       clreol;
  57.     end;
  58.  
  59.   FindFirst( Path+'\syslevel.*', AnyFile,  S );
  60.   while DosError = 0 do
  61.     begin
  62.       Inc( SysFiles );
  63.       gotoxy( 5, y+1 );Write('Files: ', SysFiles:3);
  64.       SysF^[SysFiles] := path+'\'+s.Name;
  65.       FindNext( s );
  66.     end;
  67.   FindClose( s );
  68.  
  69.   Stop := 0;
  70.   DirStack := nil;
  71.   FindFirst( Path+'\*', Must_Have_Directory, S );
  72.   while ( DosError = 0 ) and ( Stop < MaxStack ) do
  73.     begin
  74.       if ( s.Name <> '.' ) and ( s.Name <> '..' ) then
  75.         begin
  76.           if DirStack = nil then
  77.             New( DirStack );
  78.  
  79.           Inc( Stop );
  80.           DirStack^[Stop] := s.Name;
  81.         end;
  82.       FindNext( s );
  83.     end;
  84.   FindClose( s );
  85.  
  86.   for i := 1 to Stop do
  87.     ScanPath( Path+'\'+DirStack^[i] );
  88.  
  89.   if DirStack <> nil then
  90.     Dispose( DirStack );
  91. end;
  92.  
  93. procedure ShowSysFiles;
  94. var
  95.   Cnt, i: integer;
  96.   f : File;
  97.   Buf: Array[0..$200] of byte;
  98.   bytes: Longint;
  99.   pCurCSD : pChar;
  100.   pOldCSD : pChar;
  101.   pName   : pChar;
  102.   pCompID : pChar;
  103.   RevByte : Byte;
  104.   pType   : pChar;
  105.   Major   : Byte;
  106.   Minor   : Byte;
  107.  
  108. begin
  109.   ClrScr;
  110.   Cnt := 0;
  111.   FileMode := $40;
  112.   for i := 1 to SysFiles do
  113.     begin
  114.       assign( f, SysF^[i] );
  115.       {$I-}
  116.       Reset( f, 1 );
  117.       {$I+}
  118.       If IOResult = 0 then
  119.         begin
  120.           Blockread( f, Buf, Sizeof(Buf), Bytes );
  121.           if Bytes >= $96 then
  122.             if ( Buf[0] = $FF ) and ( Buf[1] = $FF ) and
  123.                ( 'SYSLEVEL' = strpas(@Buf[2]) ) then
  124.               begin
  125.                 Inc( Cnt );
  126.                 Writeln( SysF^[i] );
  127.  
  128.                 Major   := Buf[$28] shr 4;
  129.                 Minor   := ( Buf[$28] and $f )*10 or (Buf[$29] and $F);
  130.                 RevByte := Buf[$95];
  131.                 pCurCSD := @Buf[$2c]; pChar(pCurCSD+7)^ := #0;
  132.                 pOldCSD := @Buf[$34]; pChar(pOldCSD+7)^ := #0;
  133.                 pName   := @Buf[$3c];
  134.                 pCompID := @Buf[$8c]; pChar(pCompID+9)^ := #0;
  135.                 pType   := @Buf[$96];
  136.                 gotoxy( 20, WhereY );
  137.                 Writeln( pName );
  138.                 Write( Format( 'Version %d.%2.2d', [Major, Minor] ) );
  139.                 if RevByte <> 0 then
  140.                   Write( '.',RevByte );
  141.                 Writeln( '     Component ID ',pCompID );
  142.                 if pType^ <> #0 then
  143.                   Writeln( 'Type ',pType );
  144.                 Writeln( 'Current CSD level: ',pCurCSD );
  145.                 Writeln( 'Prior   CSD level: ',pOldCSD );
  146.                 Writeln;
  147.               end;
  148.           close( f );
  149.         end;
  150.  
  151.       if wherey > 15 then
  152.         begin
  153.           while (wherey < 22) do
  154.             writeln;
  155.           Writeln( 'Press Enter (<─┘) to display next page.' );
  156.           Writeln;
  157.           writeln( '───────────────────────────────────────────────────────────────────────────' );
  158.           write( ' Enter ' );
  159.           readkey;
  160.           clrscr;
  161.         end;
  162.     end;
  163. end;
  164.  
  165. function GetLocalDrives: String;
  166.   // Get a list of all local hard disk drive letters
  167. var
  168.   Drive: Char;
  169.  
  170. begin
  171.   Result := '';
  172.   For Drive := 'C' to 'Z' do
  173.     If GetDriveType( Drive ) in [ dtHDFAT, dtHDHPFS ] then
  174.       Result := Result + Drive;
  175. end;
  176.  
  177. var
  178.   s: String;
  179.   i: integer;
  180.  
  181. begin
  182.   Writeln('SysLevel v2.1     (C) 1996-2000 vpascal.com' );
  183.  
  184.   s := GetLocalDrives;
  185.  
  186.   Writeln;
  187.   Writeln( 'Scanning drives "',s,'" for SYSLEVEL.*' );
  188.   Writeln;
  189.  
  190.   try
  191.     try
  192.       New( SysF );
  193.       y := WhereY;
  194.       for i := 1 to Length(s) do
  195.         ScanPath( s[i]+':' );
  196.  
  197.       ShowSysFiles;
  198.     finally
  199.       Dispose( SysF );
  200.     end;
  201.   except
  202.     on e:Exception do
  203.       begin
  204.         Writeln;
  205.         Writeln( 'Exception: ',E.Message );
  206.         Writeln( 'SysLvl terminated.' );
  207.       end;
  208.   end;
  209. end.
  210.