Версия, как?
2 отговора
123 прегледа
GetFileVersionInfoSize, GetFileVersionInfo
unit FileVersionInfoU;
interface
uses Windows, SysUtils;
const
MaxVersionKeys = 9;
type
TVersionInfo = class
private
FInfoAvailable: Boolean;
FStandardKeys: Array[0..MaxVersionKeys] of String;
FVersionInfo: Pointer;
FLangCharset: String;
function GetVersionInfo(Index: Integer): String;
function GetBuildNumber: String;
function GetKey(KeyName: String): String;
public
constructor Create(FileName: String);
destructor Destroy; override;
property InfoAvailable: Boolean read FInfoAvailable;
property Key[KeyName: String]: String read GetKey;
// Standard key information
property CompanyName: String index 0 read GetVersionInfo;
property FileDescription: String index 1 read GetVersionInfo;
property FileVersion: String index 2 read GetVersionInfo;
property InternalName: String index 3 read GetVersionInfo;
property Copyright: String index 4 read GetVersionInfo;
property TradeMarks: String index 5 read GetVersionInfo;
property OriginalFileName: String index 6 read GetVersionInfo;
property ProductName: String index 7 read GetVersionInfo;
property ProductVersion: String index 8 read GetVersionInfo;
property Comments: String index 9 read GetVersionInfo;
property BuildNumber: String read GetBuildNumber;
end;
implementation
constructor TVersionInfo.Create(FileName: String);
const
VersionKeyNames: array [0..MaxVersionKeys] of String =
('CompanyName', 'FileDescription',
'FileVersion', 'InternalName',
'LegalCopyright', 'LegalTrademarks',
'OriginalFilename', 'ProductName',
'ProductVersion', 'Comments');
var
i: Integer;
InfoLength: UINT;
Len: DWORD;
Handle: DWORD;
PCharset: PLongInt;
begin
inherited Create;
FInfoAvailable := False;
Len := GetFileVersionInfoSize(PChar(FileName), Handle);
GetMem(FVersionInfo, Len);
if GetFileVersionInfo(PChar(FileName), Handle, Len, FVersionInfo) then
begin
// Get translation info for Language / CharSet IDs
if VerQueryValue(FVersionInfo, '\VarFileInfo\Translation', Pointer(PCharset), InfoLength) then
begin
FLangCharset := Format('%.4x%.4x', [LoWord(PCharset^), HiWord(PCharset^)]);
FInfoAvailable := True;
for i := 0 to MaxVersionKeys do
FStandardKeys[ i ] := GetKey(VersionKeyNames[ i ]);
end;
end;
end;
function TVersionInfo.GetKey(KeyName: String): String;
var Len: UINT;
begin
Result := 'N/A';
if InfoAvailable then
begin
SetLength(Result, 255);
if VerQueryValue(FVersionInfo, PChar(Format('\StringFileInfo\%s\%s',
[FLangCharset, KeyName])), Pointer(Result), Len) then
SetString(Result, PChar(Result), Len - 1)
else
Result := '';
end;
end;
function TVersionInfo.GetVersionInfo(Index: Integer): String;
begin
Result := FStandardKeys[Index];
end;
function TVersionInfo.GetBuildNumber: string;
begin
// Strip the last element from the file version
Result := FileVersion;
while Pos ('.', Result) > 0 do
Result := Copy(Result, Pos('.', Result) + 1, Length(Result));
end;
destructor TVersionInfo.Destroy;
begin
FreeMem(FVersionInfo);
inherited Destroy;
end;
end.
Редактирано от andrew_nikoloff на