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
| //QueryValue peut prendre ces valeurs:
//Comments, InternalName, ProductName, CompanyName, LegalCopyright, ProductVersion
//FileDescription, LegalTrademarks, PrivateBuild, FileVersion, OriginalFilename, SpecialBuild
function GetFileInfo(FileName :string; QueryValue :string = 'FileVersion') :string;
const
TranslationFormat :ShortString = '\StringFileInfo\%s\%s';
var
FileVersionInfo :dword;
VersionInfoSize :dword;
Block :PChar;
SubBlock :String[8];
Translation :Pointer;
QueryResult :Pointer;
//
function VersionQueryValue(SubBlock :ShortString; var Buffer :Pointer) :boolean;
var
Len :dword;
SubBlockC :array[0..30] of Char;
begin
StrPCopy(SubBlockC, SubBlock);
Result := VerQueryValue(Block, SubBlockC, Buffer, Len)
end;
//
begin
Result := '';
{ Taille de la structure }
VersionInfoSize := GetFileVersionInfoSize(PChar(FileName), FileVersionInfo);
GetMem(Block, VersionInfoSize +1);
{ Informations fichier }
GetFileVersionInfo(PChar(FileName), 0, VersionInfoSize, Block);
{ Translation table }
if VersionQueryValue('\VarFileInfo\Translation', Translation) then
begin
SubBlock := IntToHex(LoWord(LongInt(Translation^)),4)
+IntToHex(HiWord(LongInt(Translation^)),4);
if VersionQueryValue(format(TranslationFormat , [SubBlock, QueryValue]), QueryResult) then
Result := StrPas(QueryResult);
end;
FreeMem(Block, VersionInfoSize +1);
end; |
Partager