Fixed: incorrect unit naming for X2UtApp
Added: X2UtOS - Operating System information
This commit is contained in:
parent
78a034e789
commit
c5c46e76b5
@ -1,6 +1,6 @@
|
||||
{
|
||||
:: X2App provides a singleton App object to access properties associated
|
||||
:: to the application, such as the version number or executable path.
|
||||
:: X2UtApp provides a singleton App object to access properties associated
|
||||
:: with the application, such as the version number or executable path.
|
||||
:: It is part of the X2Utils suite.
|
||||
::
|
||||
:: Subversion repository available at:
|
||||
@ -36,7 +36,7 @@
|
||||
:$ /n/n
|
||||
:$ 3. This notice may not be removed or altered from any source distribution.
|
||||
}
|
||||
unit X2App;
|
||||
unit X2UtApp;
|
||||
|
||||
interface
|
||||
uses
|
||||
|
213
X2UtOS.pas
Normal file
213
X2UtOS.pas
Normal file
@ -0,0 +1,213 @@
|
||||
{
|
||||
:: X2UtOS provides a singleton OS object to access properties associated
|
||||
:: with the Operating System, such as the version number.
|
||||
:: It is part of the X2Utils suite.
|
||||
::
|
||||
:: Subversion repository available at:
|
||||
:: $URL$
|
||||
::
|
||||
:: Last changed: $Date$
|
||||
:: Revision: $Rev$
|
||||
:: Author: $LastChangedBy$
|
||||
|
||||
:$
|
||||
:$
|
||||
:$ X2Utils is released under the zlib/libpng OSI-approved license.
|
||||
:$ For more information: http://www.opensource.org/
|
||||
:$ /n/n
|
||||
:$ /n/n
|
||||
:$ Copyright (c) 2003 X2Software
|
||||
:$ /n/n
|
||||
:$ This software is provided 'as-is', without any express or implied warranty.
|
||||
:$ In no event will the authors be held liable for any damages arising from
|
||||
:$ the use of this software.
|
||||
:$ /n/n
|
||||
:$ Permission is granted to anyone to use this software for any purpose,
|
||||
:$ including commercial applications, and to alter it and redistribute it
|
||||
:$ freely, subject to the following restrictions:
|
||||
:$ /n/n
|
||||
:$ 1. The origin of this software must not be misrepresented; you must not
|
||||
:$ claim that you wrote the original software. If you use this software in a
|
||||
:$ product, an acknowledgment in the product documentation would be
|
||||
:$ appreciated but is not required.
|
||||
:$ /n/n
|
||||
:$ 2. Altered source versions must be plainly marked as such, and must not be
|
||||
:$ misrepresented as being the original software.
|
||||
:$ /n/n
|
||||
:$ 3. This notice may not be removed or altered from any source distribution.
|
||||
}
|
||||
unit X2UtOS;
|
||||
|
||||
interface
|
||||
uses
|
||||
Windows;
|
||||
|
||||
type
|
||||
{
|
||||
:$ Enumerates the recognized Operating System versions
|
||||
}
|
||||
TX2OSVersion =(osUnknown, osWin95, osWin98, osWinME, osWinNT3, osWinNT4,
|
||||
osWin2K, osWinXP, osWin2003);
|
||||
|
||||
{
|
||||
:$ Contains extended version information for the Operating System
|
||||
}
|
||||
TX2OSVersionEx = class(TObject)
|
||||
private
|
||||
FName: String;
|
||||
FVersionString: String;
|
||||
FBuild: Cardinal;
|
||||
FRawInfo: TOSVersionInfo;
|
||||
public
|
||||
//:$ Contains the name of the OS
|
||||
property Name: String read FName write FName;
|
||||
|
||||
//:$ Contains a string representation of the OS' version
|
||||
property VersionString: String read FVersionString write FVersionString;
|
||||
|
||||
//:$ Contains the build number of the OS
|
||||
property Build: Cardinal read FBuild write FBuild;
|
||||
|
||||
//:$ Contains the raw version information as provided by the OS
|
||||
property RawInfo: TOSVersionInfo read FRawInfo write FRawInfo;
|
||||
end;
|
||||
|
||||
{
|
||||
:$ Container for the Operating System's information
|
||||
}
|
||||
TX2OS = class(TObject)
|
||||
private
|
||||
FVersion: TX2OSVersion;
|
||||
FVersionEx: TX2OSVersionEx;
|
||||
protected
|
||||
procedure GetVersion(); virtual;
|
||||
public
|
||||
constructor Create();
|
||||
destructor Destroy(); override;
|
||||
|
||||
//:$ Contains the detected OS version
|
||||
property Version: TX2OSVersion read FVersion;
|
||||
|
||||
//:$ Contains extended OS version information
|
||||
property VersionEx: TX2OSVersionEx read FVersionEx;
|
||||
end;
|
||||
|
||||
function OS(): TX2OS;
|
||||
|
||||
implementation
|
||||
uses
|
||||
SysUtils;
|
||||
|
||||
var
|
||||
GOS: TX2OS;
|
||||
|
||||
|
||||
{========================================
|
||||
Singleton
|
||||
========================================}
|
||||
function OS;
|
||||
begin
|
||||
if not Assigned(GOS) then
|
||||
GOS := TX2OS.Create();
|
||||
|
||||
Result := GOS;
|
||||
end;
|
||||
|
||||
|
||||
{================================== TX2OS
|
||||
Initialization
|
||||
========================================}
|
||||
constructor TX2OS.Create;
|
||||
begin
|
||||
inherited;
|
||||
|
||||
FVersionEx := TX2OSVersionEx.Create();
|
||||
GetVersion();
|
||||
end;
|
||||
|
||||
destructor TX2OS.Destroy;
|
||||
begin
|
||||
FreeAndNil(FVersionEx);
|
||||
|
||||
inherited;
|
||||
end;
|
||||
|
||||
|
||||
{================================== TX2OS
|
||||
Version
|
||||
========================================}
|
||||
procedure TX2OS.GetVersion;
|
||||
var
|
||||
pVersion: TOSVersionInfo;
|
||||
|
||||
begin
|
||||
FVersion := osUnknown;
|
||||
|
||||
// Get version information
|
||||
pVersion.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
|
||||
GetVersionEx(pVersion);
|
||||
|
||||
with FVersionEx do begin
|
||||
// No Kylix support yet, sorry!
|
||||
RawInfo := pVersion;
|
||||
Name := 'Windows';
|
||||
|
||||
// Analyze version
|
||||
case pVersion.dwMajorVersion of
|
||||
3: // Windows NT 3.51
|
||||
FVersion := osWinNT3;
|
||||
4: // Windows 95/98/ME/NT 4
|
||||
case pVersion.dwMinorVersion of
|
||||
0: // Windows 95/NT 4
|
||||
case pVersion.dwPlatformId of
|
||||
VER_PLATFORM_WIN32_NT: // Windows NT 4
|
||||
FVersion := osWinNT4;
|
||||
VER_PLATFORM_WIN32_WINDOWS: // Windows 95
|
||||
FVersion := osWin95;
|
||||
end;
|
||||
10: // Windows 98
|
||||
FVersion := osWin98;
|
||||
90: // Windows ME
|
||||
FVersion := osWinME;
|
||||
end;
|
||||
5: // Windows 2000/XP/2003
|
||||
case pVersion.dwMinorVersion of
|
||||
0: // Windows 2000
|
||||
FVersion := osWin2K;
|
||||
1: // Windows XP
|
||||
FVersion := osWinXP;
|
||||
2: // Windows Server 2003
|
||||
FVersion := osWin2003;
|
||||
end;
|
||||
end;
|
||||
|
||||
case Version of
|
||||
osWin95: VersionString := '95';
|
||||
osWin98: VersionString := '98';
|
||||
osWinME: VersionString := 'ME';
|
||||
osWinNT3: VersionString := 'NT 3.51';
|
||||
osWinNT4: VersionString := 'NT 4';
|
||||
osWin2K: VersionString := '2000';
|
||||
osWinXP: VersionString := 'XP';
|
||||
osUnknown: VersionString := Format('%d.%d', [pVersion.dwMajorVersion,
|
||||
pVersion.dwMinorVersion]);
|
||||
end;
|
||||
|
||||
if StrLen(pVersion.szCSDVersion) > 0 then
|
||||
VersionString := VersionString + ' ' + pVersion.szCSDVersion;
|
||||
|
||||
case pVersion.dwPlatformId of
|
||||
VER_PLATFORM_WIN32_NT:
|
||||
Build := pVersion.dwBuildNumber;
|
||||
VER_PLATFORM_WIN32_WINDOWS:
|
||||
Build := LoWord(pVersion.dwBuildNumber);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
finalization
|
||||
FreeAndNil(GOS);
|
||||
|
||||
end.
|
Loading…
Reference in New Issue
Block a user