Metropoli BBS
VIEWER: syslvl.pas MODE: TEXT (CP437)
{█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█}
{█                                                       █}
{█      Virtual Pascal Examples. Version 1.10            █}
{█      SysLevel example                                 █}
{█      ─────────────────────────────────────────────────█}
{█      Copyright (C) 1996 fPrint UK Ltd                 █}
{█                                                       █}
{▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀}

program SysLvl;

{ This program performs a function similar to IBM's SysLevel }
{ command, but much faster than the original.                }

{$PMTYPE VIO}

{$Delphi+}
{$M 60000}

uses
  SysUtils, Crt, Os2Base, Dos, VPUtils;

{$IFDEF VPDEMO}
  {&Dynamic VP11Demo.Lib}
{$ENDIF}

const
  dirs: Longint = 0;
  SysFiles: Longint = 0;
  MaxStack = 500;

type
  StringList = Array[1..MaxStack] of String;
  pStringList = ^StringList;

var
  SysF: pStringList;
  y: Integer;

procedure ScanPath( Path : String );
  // Scan a path and subdirectories for Syslevel.*
var
  i, stop: Longint;
  s: SearchRec;
  DirStack: pStringList;

begin
  inc( Dirs );
  if Dirs mod 6 = 0 then
    begin
      gotoxy( 5, y );
      Write(dirs:6,'  ');
      if length(Path) <= 60 then
        Write( Path )
      else
        Write( copy( Path, Length(Path)-60, 60 ), '...' );
      clreol;
    end;

  FindFirst( Path+'\syslevel.*', AnyFile,  S );
  while DosError = 0 do
    begin
      Inc( SysFiles );
      gotoxy( 5, y+1 );Write('Files: ', SysFiles:3);
      SysF^[SysFiles] := path+'\'+s.Name;
      FindNext( s );
    end;
  FindClose( s );

  Stop := 0;
  DirStack := nil;
  FindFirst( Path+'\*', Must_Have_Directory, S );
  while ( DosError = 0 ) and ( Stop < MaxStack ) do
    begin
      if ( s.Name <> '.' ) and ( s.Name <> '..' ) then
        begin
          if DirStack = nil then
            New( DirStack );

          Inc( Stop );
          DirStack^[Stop] := s.Name;
        end;
      FindNext( s );
    end;
  FindClose( s );

  for i := 1 to Stop do
    ScanPath( Path+'\'+DirStack^[i] );

  if DirStack <> nil then
    Dispose( DirStack );
end;

procedure ShowSysFiles;
  // Show all of the SysLevel informaiton found
var
  Cnt, i: integer;
  f : File;
  Buf: Array[0..$200] of byte;
  bytes: Longint;
  pCurCSD : pChar;
  pOldCSD : pChar;
  pName   : pChar;
  pCompID : pChar;
  RevByte : Byte;
  pType   : pChar;
  Major   : Byte;
  Minor   : Byte;

begin
  ClrScr;
  Cnt := 0;
  FileMode := $40;
  for i := 1 to SysFiles do
    begin
      assign( f, SysF^[i] );
      {$I-}
      Reset( f, 1 );
      {$I+}
      If IOResult = 0 then
        begin
          Blockread( f, Buf, Sizeof(Buf), Bytes );
          if Bytes >= $96 then
            if ( Buf[0] = $FF ) and ( Buf[1] = $FF ) and
               ( 'SYSLEVEL' = strpas(@Buf[2]) ) then
              begin
                Inc( Cnt );
                Writeln( SysF^[i] );

                Major   := Buf[$28] shr 4;
                Minor   := ( Buf[$28] and $f )*10 or (Buf[$29] and $F);
                RevByte := Buf[$95];
                pCurCSD := @Buf[$2c]; pChar(pCurCSD+7)^ := #0;
                pOldCSD := @Buf[$34]; pChar(pOldCSD+7)^ := #0;
                pName   := @Buf[$3c];
                pCompID := @Buf[$8c]; pChar(pCompID+9)^ := #0;
                pType   := @Buf[$96];
                gotoxy( 20, WhereY );
                Writeln( pName );
                Write( Format( 'Version %d.%2.2d', [Major, Minor] ) );
                if RevByte <> 0 then
                  Write( '.',RevByte );
                Writeln( '     Component ID ',pCompID );
                if pType^ <> #0 then
                  Writeln( 'Type ',pType );
                Writeln( 'Current CSD level: ',pCurCSD );
                Writeln( 'Prior   CSD level: ',pOldCSD );
                Writeln;
              end;
          close( f );
        end;

      if wherey > 15 then
        begin
          while (wherey < 22) do
            writeln;
          Writeln( 'Press Enter (<─┘) to display next page.' );
          Writeln;
          writeln( '───────────────────────────────────────────────────────────────────────────' );
          write( ' Enter ' );
          readkey;
          clrscr;
        end;
    end;
end;

function GetLocalDrives: String;
  // Get a list of all local hard disk drive letters
var
  Drive: Char;

begin
  Result := '';
  For Drive := 'C' to 'Z' do
    If GetDriveType( Drive ) in [ dtHDFAT, dtHDHPFS ] then
      Result := Result + Drive;
end;

var
  s: String;
  i: integer;

begin
  Writeln('SysLevel v1.10    (C) 1996 fPrint UK Ltd' );
  Popuperrors := false;

  Os2Base.DosError( ferr_DisableHardErr );
  s := GetLocalDrives;
  Os2Base.DosError( ferr_EnableHardErr );

  Writeln;
  Writeln( 'Scanning drives "',s,'" for SYSLEVEL.*' );
  Writeln;

  try
    try
      New( SysF );
      y := WhereY;
      for i := 1 to Length(s) do
        ScanPath( s[i]+':' );

      ShowSysFiles;
    finally
      Dispose( SysF );
    end;
  except
    on e:Exception do
      begin
        Writeln;
        Writeln( 'Exception: ',E.Message );
        Writeln( 'SysLvl terminated.' );
      end;
  end;
end.
[ RETURN TO DIRECTORY ]