Форум: "WinAPI";
Текущий архив: 2007.03.04;
Скачать: [xml.tar.bz2];
ВнизGetFileVersionInfo Найти похожие ветки
← →
#0FFFF (2006-10-21 18:12) [0]Доброго времени суток.
Подскажите пожалуйста примером как получить описание файла"FileDescription"
с помощью функции GetFileVersionInfo
← →
guav © (2006-10-21 18:38) [1]
VerQueryValue
← →
Джо © (2006-10-21 18:46) [2]{***********************************************************
Класс-обертка для функций:
Wrapper for API functions:
GetFileVersionInfo,GetFileVersionInfoSize,VerQueryValue
E-mail: sergeybox@gmail.com
Последнее изменение/Last modified: 20:56 03.08.2004
ПРИМЕРЫ ИСПОЛЬЗОВАНИЯ:
-----------------------------------------------------------
Пример 1:
var
FileInfo: TFileVersionInfo
VerInfo: FFileVersion;
begin
// file name passed to constructor
FileInfo := TFileVersionInfo.Create ("c:\prog.exe");
try
if FileInfo.HasInfo then
begin
Label1.Caption := FileInfo.GetString (INFO_CompanyName);
Label2.Caption := FileInfo.GetString (INFO_FileDescription);
VerInfo := FileInfo.GetVersion;
Label3.Caption := Format ("%d.%d",[VerInfo.Minor,VerInfo.Major]);
end;
finally
FileInfo.Free;
end;
end;
-----------------------------------------------------------
Пример 2:
var
FileInfo: TFileVersionInfo
VerInfo: FFileVersion;
begin
// no file name passed to constructor
FileInfo := TFileVersionInfo.Create;
try
FileInfo.FileName := "c:\myprog1.Exe"; // specify file
if FileInfo.HasInfo then
begin
Label1.Caption := FileInfo.GetString (INFO_CompanyName);
Label2.Caption := FileInfo.GetString (INFO_FileDescription);
VerInfo := FileInfo.GetVersion;
Label3.Caption := Format ("%d.%d",[VerInfo.Minor,VerInfo.Major]);
end;
FileInfo.FileName := "c:\myprog2.Exe"; // specify file
if FileInfo.HasInfo then
begin
Label4.Caption := FileInfo.GetString (INFO_CompanyName);
Label5.Caption := FileInfo.GetString (INFO_FileDescription);
VerInfo := FileInfo.GetVersion;
Label6.Caption := Format ("%d.%d",[VerInfo.Minor,VerInfo.Major]);
end;
finally
FileInfo.Free;
end;
end;
************************************************************}
unit VerInfo;
interface
uses Windows;
const
MaxInfoStrings = 7;
INFO_CompanyName = "CompanyName";
INFO_FileDescription = "FileDescription";
INFO_FileVersion = "FileVersion";
INFO_InternalName = "InternalName";
INFO_LegalCopyright = "LegalCopyright";
INFO_OriginalFileName = "OriginalFileName";
INFO_ProductName = "ProductName";
INFO_ProductVersion = "ProductVersion";
VersionInfoStrings: array [0..MaxInfoStrings] of string =
(
INFO_CompanyName,
INFO_FileDescription,
INFO_FileVersion,
INFO_InternalName,
INFO_LegalCopyright,
INFO_OriginalFileName,
INFO_ProductName,
INFO_ProductVersion
);
type
TFileVersion = record
Minor,
Major,
Build,
Release: WORD;
end;
TFileVersionInfo = class
private
FFileName: string;
FBuffer: PChar;
FBuffLen: Cardinal;
FLocale: string;
procedure SetFileName(const Value: string);
procedure LoadFile (AFileName: string);
procedure UnloadFile;
function GetHasInfo: Boolean;
public
constructor Create (AFileName: string);
destructor Destroy; override;
property HasInfo: Boolean read GetHasInfo;
property FileName: string read FFileName write SetFileName;
property Locale: string read FLocale;
function GetString (AString: string): string;
function GetVersion: TFileVersion;
end;
implementation
uses SysUtils;
{ TFileVersionInfo }
type
TVer1 = record
Minor: Word;
Major: Word;
end;
TVer2 = record
Build: Word;
Release: Word;
end;
constructor TFileVersionInfo.Create(AFileName: string);
begin
FFileName := AFileName;
LoadFile(AFileName);
end;
destructor TFileVersionInfo.Destroy;
begin
UnloadFile;
inherited;
end;
function TFileVersionInfo.GetHasInfo: Boolean;
begin
Result := (FFileName <> "") and (FBuffLen <> 0);
end;
function TFileVersionInfo.GetString(AString: string): string;
var
InfoLen: Cardinal;
PInfo: PChar;
begin
if VerQueryValue(
FBuffer,
PChar("\StringFileInfo\" + FLocale + "\"+AString),
Pointer(PInfo),
InfoLen
) then
begin
Result := PInfo;
end
else
Result := ""
end;
function TFileVersionInfo.GetVersion: TFileVersion;
var
FI: PVSFixedFileInfo;
VerSize: Cardinal;
Ver1: TVer1;
Ver2: TVer2;
begin
if VerQueryValue(FBuffer,"\",Pointer(FI),VerSize) then
begin
Ver1 := TVer1(FI.dwFileVersionMS);
Ver2 := TVer2(FI.dwFileVersionLS);
Result.Minor := Ver1.Minor;
Result.Major := Ver1.Major;
Result.Build := Ver2.Build;
Result.Release := Ver2.Release;
end;
end;
procedure TFileVersionInfo.LoadFile(AFileName: string);
var
Dummy,LangLen: Cardinal;
LangBuff: PChar;
begin
UnloadFile;
FBuffLen := 0;
// Buffer size
FBuffLen := GetFileVersionInfoSize(
PChar(AFileName),
Dummy
);
if FBuffLen <> 0 then
begin
GetMem (FBuffer,FBuffLen);
// read resource data
GetFileVersionInfo(
PChar(FileName),
0,
FBuffLen,
FBuffer
);
// check string locale
VerQueryValue(FBuffer, "\VarFileInfo\Translation", pointer(LangBuff), LangLen);
if langLen >= 4 then // if specified
begin
StrLCopy(@Dummy, LangBuff, 2);
FLocale:= Format("%4.4x", [Dummy]);
StrLCopy(@Dummy, LangBuff+2, 2);
FLocale := FLocale + Format("%4.4x", [Dummy]);
end
else
// use Amer. Engl, ANSI
FLocale := "040904E4";
end;
end;
procedure TFileVersionInfo.SetFileName(const Value: string);
begin
FFileName := Value;
LoadFile(Value);
end;
procedure TFileVersionInfo.UnloadFile;
begin
FreeMem (FBuffer);
end;
end.
← →
Ketmar © (2006-10-21 18:53) [3]>[2] Джо(c) 21-Oct-2006, 18:46
опять на тебя напала доброта, и ты не можешь отбиться? %-)
← →
#0FFFF (2006-10-21 18:57) [4]
> Джо © (21.10.06 18:46) [2]
Спасибо
← →
Джо © (2006-10-21 19:30) [5]> [3] Ketmar © (21.10.06 18:53)
> >[2] Джо(c) 21-Oct-2006, 18:46
> опять на тебя напала доброта, и ты не можешь отбиться? %-
> )
Лечу комплекс вины... :( Кстати, Кеннеди (и Кенни) убил, все-таки, не я :)
← →
#0FFFF (2006-10-21 19:39) [6]
> Джо © (21.10.06 19:30) [5]
> Лечу комплекс вины...
Интересно какой и за что?
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2007.03.04;
Скачать: [xml.tar.bz2];
Память: 0.48 MB
Время: 0.043 c