1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
unit UFileVersionOptions;
interface
uses Winapi.Windows, Vcl.Forms, System.SysUtils, System.Classes, System.Rtti;
type
TOptionName = (CompanyName, FileDescription, FileVersion, InternalName, LegalCopyright, LegalTradeMarks, OriginalFileName, ProgramID, ProductName,
ProductVersion, Comments);
TOptionNames = set of TOptionName;
function GetoptionValue(FileName: string; OptionName: TOptionName): string;
function GetProductVersion: string;
procedure GetAllOptions(FileName: string; Resultat: TStrings);
implementation
function GetoptionValue(FileName: string; OptionName: TOptionName): string;
var
Size: DWORD;
Handle: DWORD;
Len: UINT;
Buffer: PChar;
Value: PChar;
TransNo: PLongInt;
SFInfo: string;
Opt: string;
begin
Result := '';
Opt := TRttiEnumerationType.GetName<TOptionName>(OptionName);
Size := GetFileVersionInfoSize(PChar(FileName), Handle);
if Size > 0 then
begin
Buffer := AllocMem(Size);
try
GetFileVersionInfo(PChar(FileName), 0, Size, Buffer);
VerQueryValue(Buffer, PChar('VarFileInfo\Translation'), Pointer(TransNo), Len);
SFInfo := Format('%s%.4x%.4x%s%s%', ['StringFileInfo\', LoWord(TransNo^), HiWord(TransNo^), '\', Opt]);
if VerQueryValue(Buffer, PChar(SFInfo), Pointer(Value), Len) then
Result := Value;
finally
if Assigned(Buffer) then
FreeMem(Buffer, Size);
end;
end;
end;
procedure GetAllOptions(FileName: string; Resultat: TStrings);
var
Size: DWORD;
Handle: DWORD;
Len: UINT;
Buffer: PChar;
Value: PChar;
TransNo: PLongInt;
SFInfo: string;
Opt: TOptionName;
N: string;
begin
if FileName.IsEmpty then
FileName := Application.ExeName;
if not Assigned(Resultat) then
Resultat := TStringList.Create;
Size := GetFileVersionInfoSize(PChar(FileName), Handle);
if Size > 0 then
begin
Buffer := AllocMem(Size);
try
GetFileVersionInfo(PChar(FileName), 0, Size, Buffer);
VerQueryValue(Buffer, PChar('VarFileInfo\Translation'), Pointer(TransNo), Len);
for Opt := Low(TOptionName) to High(TOptionName) do
begin
N := TRttiEnumerationType.GetName<TOptionName>(Opt);
SFInfo := Format('%s%.4x%.4x%s%s%', ['StringFileInfo\', LoWord(TransNo^), HiWord(TransNo^), '\', N]);
if VerQueryValue(Buffer, PChar(SFInfo), Pointer(Value), Len) then
Resultat.Add(N + '=' + Value);
end;
finally
if Assigned(Buffer) then
FreeMem(Buffer, Size);
end;
end;
end;
function GetProductVersion: string;
var
T: TArray<string>;
begin
Result := GetoptionValue(Application.ExeName, TOptionName.ProductVersion);
T := Result.Split(['.']);
if Length(T) > 3 then
Result := Format('%s.%s.%s', [T[0], T[1], T[2]]);
end;
end. |
Partager