corrected by Michalis:

* VerQueryValue parameters (last parameter should be dwBytes instead of
    @dwBytes; you can call
      VerQueryValue(...,pp,dwBytes) or
      VerQueryValue(...,@pp,@dwBytes) but NOT
      VerQueryValue(...,pp,@dwBytes) (and that was the case) )
  * corrected
      if not VerQueryValue(p,a,pp,dwBytes) then Exit;
    to
      if not VerQueryValue(p,a,pp,dwBytes) then Continue;
    (when some info is missing the code should skip to the next info,
    not exit)
  + added destructor to Free FmyVersionStrings and FmyVersionCategories objects
    to avoid memory leaks
  + added ts.Free (and embedded some code in try..finally..end clause)
    to avoid memory leaks
  * inherited Create should be called at the beginning of constructor
    (it's just a good coding practice)
  * getVersionSetting re-written, optimised a little (LowerCase(inp) only once;
    this function is not supposed to be really "optimised" but this little
    improvement was so simple...) (note: when TStringList.CaseSensitive will
    be implemented in FPC, this function can be implemented even simpler,
    just by calling FmyVersionCategories.IndexOf)
This commit is contained in:
michael 2003-07-26 16:23:05 +00:00
parent 28ef3fa9d1
commit e89c99f6a7

View File

@ -50,9 +50,9 @@ type
procedure SetFileName (inp : string);
procedure readVersionFromFile;
protected
{ Protected-Deklarationen}
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function getVersionSetting(inp : string): String;
published
property fileName : string read FFileName write SetFileName;
@ -66,10 +66,17 @@ implementation
{ initialize everything }
constructor TFileVersionInfo.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FmyVersionStrings := TStringList.Create;
FmyVersionCategories := TStringList.Create;
FFileName := '';
inherited create(Aowner);
end;
destructor TFileVersionInfo.Destroy;
begin
FmyVersionCategories.Free;
FmyVersionStrings.Free;
inherited;
end;
{ Get filename, check if file exists and read info from file }
@ -103,6 +110,7 @@ var struSize : Dword;
ts : TStringList;
begin
ts := TStringList.Create;
try
ts.add('CompanyName');
ts.add('FileDescription');
ts.add('FileVersion');
@ -123,11 +131,11 @@ begin
{ get data }
if not GetFileVersionInfo(a,0,struSize,p) then exit;
{ get root info }
if not VerQueryValue(p,'\',pp,@dwBytes) then exit;
if not VerQueryValue(p,'\',pp,dwBytes) then exit;
move(pp^,theFixedInfo,dwBytes);
{ get translation info }
if not VerQueryValue(p,'\VarFileInfo\Translation',pp,@dwBytes) then
if not VerQueryValue(p,'\VarFileInfo\Translation',pp,dwBytes) then
exit;
move(pp^,theTrans,dwBytes);
@ -136,7 +144,7 @@ begin
begin
s := '\StringFileInfo\'+inttohex(theTrans.langID,4)+inttohex(theTrans.charset,4)+'\'+ts[i];
StrPCopy(a,s);
if not VerQueryValue(p,a,pp,@dwBytes) then exit;
if not VerQueryValue(p,a,pp,dwBytes) then Continue;
if dwBytes>0 then
begin
move(pp^,txt,dwBytes);
@ -148,27 +156,52 @@ begin
{ release memory }
FreeMem(p);
end;
finally ts.Free end;
end;
{ get single version string }
function TFileVersionInfo.getVersionSetting(inp : string): String;
var i : integer;
begin
result := '';
inp:=LowerCase(inp);
for i:= 0 to FmyVersionCategories.Count -1 do
begin
if lowercase(FmyVersionCategories[i])=lowercase(inp) then
if LowerCase(FmyVersionCategories[i])=inp then
begin
result := FmyVersionStrings[i];
break;
end;
Exit;
end;
result := '';
end;
end.
{
$Log$
Revision 1.4 2002-09-07 15:15:29 peter
Revision 1.5 2003-07-26 16:23:05 michael
corrected by Michalis:
* VerQueryValue parameters (last parameter should be dwBytes instead of
@dwBytes; you can call
VerQueryValue(...,pp,dwBytes) or
VerQueryValue(...,@pp,@dwBytes) but NOT
VerQueryValue(...,pp,@dwBytes) (and that was the case) )
* corrected
if not VerQueryValue(p,a,pp,dwBytes) then Exit;
to
if not VerQueryValue(p,a,pp,dwBytes) then Continue;
(when some info is missing the code should skip to the next info,
not exit)
+ added destructor to Free FmyVersionStrings and FmyVersionCategories objects
to avoid memory leaks
+ added ts.Free (and embedded some code in try..finally..end clause)
to avoid memory leaks
* inherited Create should be called at the beginning of constructor
(it's just a good coding practice)
* getVersionSetting re-written, optimised a little (LowerCase(inp) only once;
this function is not supposed to be really "optimised" but this little
improvement was so simple...) (note: when TStringList.CaseSensitive will
be implemented in FPC, this function can be implemented even simpler,
just by calling FmyVersionCategories.IndexOf)
Revision 1.4 2002/09/07 15:15:29 peter
* old logs removed and tabs fixed
}