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
| //aQuery:
// Comments, InternalName, ProductName, CompanyName, LegalCopyright, ProductVersion
// FileDescription, LegalTrademarks, PrivateBuild, FileVersion, OriginalFilename, SpecialBuild
//aLanguage:
// français (France): $040C, anglais (Etats-Unis): $0409, etc.
function GetFileInfo(aFileName :TFileName; aQuery :string; aLanguage :word; aCodePage :word = 0) :string; overload;
type
TTranslation = record
Language :word;
CodePage :word;
end;
PTranslations = ^TTranslations;
TTranslations = array[0..0] of TTranslation;
var
Block :pointer;
Buffer :pointer;
Size :cardinal;
Dummy :cardinal;
Translations :PTranslations;
Count :integer;
i :integer;
Index :integer;
begin
Result := '';
Size := GetFileVersionInfoSize(PChar(aFileName), Dummy);
if Size > 0 then
begin
GetMem(Block, Size);
try
if GetFileVersionInfo(PChar(aFileName), 0, Size, Block) and
VerQueryValue(Block, '\VarFileInfo\Translation', pointer(Translations), Size) then
begin
//Nombre de traductions
Count := Size div SizeOf(TTranslation);
//Si la langue n'est pas disponible, renverra la première info de la liste
Index := 0;
if Count > 1 then
for i := 0 to Count -1 do
//Langue recherchée ?
if Translations[i].Language = aLanguage then
begin
//Au minimum, renverra l'info dans la bonne langue
Index := i;
//Si bon CodePage ou si CodePage pas requis => trouvé !
if (Translations[i].CodePage = aCodePage) or (aCodePage = 0) then
Break;
end;
if VerQueryValue(Block, PChar(Format('\StringFileInfo\%.4x%.4x\%s', [Translations[Index].Language, Translations[Index].CodePage, aQuery])), Buffer, Size) then
SetString(Result, PChar(Buffer), Size);
end;
finally
FreeMem(Block);
end;
end;
end; |
Partager