(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)
unit AHMTSystemDetails;

interface

uses Windows,Classes,AHMSystemClass,AHMSystemConst;

type
  TAHMSystemDetails = class(TAHMSystemsComponent)
  private
    FProcessorType : String;
    FProcessorLevel : String;
    FPlatFormCSD : String;
    FOperatingSystem : String;
    FOnUpdate: TNotifyEvent;
    FBuildNumber : String;
    FVersionNumber : String;
    FComputerName : String;
    FUserName : String;
    FSystemDirectory : String;
    FWindowsDirectory : String;
    FTempDirectory : String;
    FCurrentDirectory : String;
    FNoOfProcessors:DWord;
    FRegisteredOwner : String;
    FRegisteredCompany : String;
    FLanguage : String;
    FPlus: Boolean;
    function GetProcessorType: String;
    procedure SetString(const Value: String);
    function GetProcessorLevel: String;
    function GetOperatingSystem: String;
    function GetPlatFormCSD: String;
    function GetBuildNumber: String;
    function GetVersionNumber: String;
    function Get_ComputerName: String;
    function Get_UserName: String;
    function Get_SystemDirectory: String;
    function Get_WindowsDirectory: String;
    function GetNoOfProcessors: DWord;
    procedure SetDWord(const Value: DWord);
    function GetRegisteredCompany: String;
    function GetRegisteredOwner: String;
    function Get_TempDirectory: String;
    function GetScreenHeight: Dword;
    function GetScreenWidth: DWord;
    function Get_CurrentDirectory: String;
    function GetPlus: Boolean;
    procedure SetPlus(const Value: Boolean);
    function GetLanguage: String;
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    Procedure UpdateDetails;
    Constructor Create(AOwner : TComponent); override;
    Procedure Loaded; override;
  published
    { Published declarations }
    Property OnUpdate : TNotifyEvent read FOnUpdate write FOnUpdate;
    Property Plus : Boolean read GetPlus write SetPlus stored false;
    Property ProcessorType : String read GetProcessorType write SetString stored False;
    Property ProcessorLevel : String read GetProcessorLevel write SetString stored False;
    Property OperatingSystem : String read GetOperatingSystem write SetString stored False;
    Property PlatformCSD : String read GetPlatFormCSD write SetString stored False;
    Property BuildNumber : String read GetBuildNumber write SetString stored False;
    Property VersionNumber : String read GetVersionNumber write SetString stored False;
    Property ComputerName : String read Get_ComputerName write SetString stored False;
    Property UserName : String read Get_UserName write SetString stored False;
    Property DirectoryCurrent : String read Get_CurrentDirectory write SetString stored False;
    Property DirectoryWindows : String read Get_WindowsDirectory write SetString stored False;
    Property DirectorySystem : String read Get_SystemDirectory write SetString stored False;
    Property DirectoryTemp : String read Get_TempDirectory write SetString stored False;
    Property NoOfProcessors : DWord read GetNoOfProcessors write SetDWord stored False;
    Property RegisteredOwner : String read GetRegisteredOwner write SetString stored False;
    property RegisteredCompany : String read GetRegisteredCompany write SetString stored False;
    Property Language : String read GetLanguage write SetString stored False;
    Property ScreenWidth : DWord read GetScreenWidth write SetDWord stored False;
    Property ScreenHeight : DWord read GetScreenHeight write SetDWord stored False;
  end;

implementation
uses Registry,SysUtils,Forms;

{ TAHMSystemDetails }

Constructor TAHMSystemDetails.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  UpdateDetails;
end;

procedure TAHMSystemDetails.Loaded;
begin
  inherited Loaded;
  UpdateDetails;
end;

procedure TAHMSystemDetails.UpdateDetails;
var SystemInfo : TSystemInfo;
    OSVersionInfo : TOSVersionInfo;
    BUserName,BComputerName : Array[0..255] of Char;
    BCurrentDirectory,BTempDirectory,BSystemDirectory,
    BLanguage,BWindowsDirectory : Array[0..255] of Char;
    BInfoSize : DWord;
    VersionKey : String;
begin
  FillChar(SystemInfo,SizeOf(SystemInfo),0);
  GetSystemInfo(SystemInfo);
  FProcessorLevel:=ahmscsysinfounknown;
  case SystemInfo.wProcessorArchitecture of
      0 : begin
            FProcessorType:=ahmscsysinfoIntel;
            case SystemInfo.wProcessorLevel of
              2	: FProcessorLevel:=ahmscsysinfo80286;
              3	: FProcessorLevel:=ahmscsysinfo80386;
              4	: FProcessorLevel:=ahmscsysinfo80486;
              5	: FProcessorLevel:=ahmscsysinfoPentium;
              6	: FProcessorLevel:=ahmscsysinfoPentium2;
              7	: FProcessorLevel:=ahmscsysinfoAbovePentium2;
            end;
          end;
      1 : FProcessorType:=ahmscsysinfoMips;
      2 : FProcessorType:=ahmscsysinfoAlpha;
      3 : FProcessorType:=ahmscsysinfoPPC;
      4 : FProcessorType:=ahmscsysinfoSHX;
      5 : FProcessorType:=ahmscsysinfoArm;
  else
    FProcessorType:= ahmscsysinfoUnknownProcessor;
  end;
  FNoOfProcessors:=SystemInfo.dwNumberOfProcessors;
  FillChar(OSVersionInfo,SizeOf(OSVersionInfo),0);
  OSVersionInfo.dwOSVersionInfoSize := sizeof(TOSVERSIONINFO);
  GetVersionEx(OSVersionInfo);
  case OSVersionInfo.dwPlatformID of
    VER_PLATFORM_WIN32s        : FOperatingSystem := ahmscsysinfoWin31;
    VER_PLATFORM_WIN32_WINDOWS :
    begin
      FPlus := SystemParametersInfo(SPI_GETWINDOWSEXTENSION, 1, nil, 0);
      if (OSVersionInfo.dwMinorVersion>=10) then FOperatingSystem := ahmscsysinfoWin98 else FOperatingSystem := ahmscsysinfoWin95;
      FBuildNumber:=IntToStr(LoWord(OSVersionInfo.dwBuildNumber));
      VersionKey:=ahmscreginfowin95;
    end;
    VER_PLATFORM_WIN32_NT	 :
    begin
      FPlus:=False;
      FOperatingSystem := ahmscsysinfoWinNT;
      FBuildNumber:=IntToStr(OSVersionInfo.dwBuildNumber);
      VersionKey:=ahmscreginfowinNT;
    end;
  end;
  FPlatFOrmCSD:=String(OSVersionInfo.szCSDVersion);
  FVersionNumber :=  format('%d.%d', [OSVersionInfo.dwMajorVersion,OSVersionInfo.dwMinorVersion]);
  with TRegistry.Create do
  try
    RootKey := HKEY_LOCAL_MACHINE;
    if OpenKey(VersionKey, False) then
    begin
      FRegisteredOwner := ReadString(ahmscreginfoOwner);
      FRegisteredCompany := ReadString(ahmscreginfoCompany);
    end;
    Closekey;
  finally
    Free;
  end;
  FillChar(BComputerName,SizeOf(BComputerName),0);
  BInfoSize:=SizeOf(BComputerName)+1;
  if GetComputerName(@BComputerName,BInfoSize) then
  FComputerName:=StrPas(BComputerName) else FComputerName:='';
  FillChar(BLanguage,SizeOf(BLanguage),0);
  if VerLanguageName(GetSystemDefaultLangID,BLanguage,SizeOf(BLanguage))<>0 then
  FLanguage:=StrPas(BLanguage) else FLanguage:='';
  FillChar(BUserName,SizeOf(BUserName),0);
  BInfoSize:=SizeOf(BUserName)+1;
  if GetUserName(@BUserName,BInfoSize) then
  FUserName:=StrPas(BUserName) else FUserName:='';
  FillChar(BWindowsDirectory,SizeOf(BWindowsDirectory),0);
  BInfoSize:=SizeOf(BWindowsDirectory)+1;
  if GetWindowsDirectory(@BWindowsDirectory,BInfoSize)<>0 then
  FWindowsDirectory:=StrPas(BWindowsDirectory) else FWindowsDirectory:='';
  FillChar(BSystemDirectory,SizeOf(BSystemDirectory),0);
  BInfoSize:=SizeOf(BSystemDirectory)+1;
  if GetSystemDirectory(@BSystemDirectory,BInfoSize)<>0 then
  FSystemDirectory:=StrPas(BSystemDirectory) else FSystemDirectory:='';
  FillChar(BTempDirectory,SizeOf(BTempDirectory),0);
  BInfoSize:=SizeOf(BTempDirectory)+1;
  if GetTempPath(BInfoSize,@BTempDirectory)<>0 then
  FTempDirectory:=StrPas(BTempDirectory) else FTempDirectory:='';
  FillChar(BCurrentDirectory,SizeOf(BCurrentDirectory),0);
  BInfoSize:=SizeOf(BCurrentDirectory)+1;
  if GetCurrentDirectory(BInfoSize,@BCurrentDirectory)<>0 then
  FCurrentDirectory:=StrPas(BCurrentDirectory) else FCurrentDirectory:='';
  if assigned(FOnUpdate) then FOnUpdate(Self);
end;

function TAHMSystemDetails.GetBuildNumber: String;
begin
  result:=FBuildNumber;
end;


function TAHMSystemDetails.GetNoOfProcessors: DWord;
begin
  result:=FNoOfProcessors;
end;

function TAHMSystemDetails.GetOperatingSystem: String;
begin
  result:=FOperatingSystem;
end;


function TAHMSystemDetails.GetPlatFormCSD: String;
begin
  result:=FPlatFormCSD;
end;

function TAHMSystemDetails.GetProcessorLevel: String;
begin
  result:=FProcessorLevel;
end;

function TAHMSystemDetails.GetProcessorType: String;
begin
  result:=FProcessorType;
end;

function TAHMSystemDetails.GetRegisteredCompany: String;
begin
  result:=FRegisteredCompany;
end;

function TAHMSystemDetails.GetRegisteredOwner: String;
begin
  result:=FRegisteredOwner;
end;

function TAHMSystemDetails.GetVersionNumber: String;
begin
  result:=FVersionNumber;
end;

function TAHMSystemDetails.Get_ComputerName: String;
begin
  result:=FComputerName;
end;

function TAHMSystemDetails.Get_SystemDirectory: String;
begin
  result:=FSystemDirectory;
end;

function TAHMSystemDetails.Get_UserName: String;
begin
  result:=FUserName;
end;

function TAHMSystemDetails.Get_WindowsDirectory: String;
begin
  result:=FWindowsDirectory;
end;

procedure TAHMSystemDetails.SetDWord(const Value: DWord);
begin
  {Designtime Viewing only}
end;

procedure TAHMSystemDetails.SetString(const Value: String);
begin
  {Designtime Viewing only}
end;


function TAHMSystemDetails.Get_TempDirectory: String;
begin
  result:=FTempDirectory;
end;

function TAHMSystemDetails.GetScreenHeight: DWord;
begin
  result:=Screen.Height;
end;

function TAHMSystemDetails.GetScreenWidth: DWord;
begin
  result:=Screen.Width;
end;

function TAHMSystemDetails.Get_CurrentDirectory: String;
begin
  UpdateDetails;
  result:=FCurrentDirectory;
end;

function TAHMSystemDetails.GetPlus: Boolean;
begin
  result:=FPlus;
end;

procedure TAHMSystemDetails.SetPlus(const Value: Boolean);
begin
  {Designtime viewing only}
end;

function TAHMSystemDetails.GetLanguage: String;
begin
  result:=FLanguage;
end;

end.
