123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- {
- $Id$
- This file is part of the Free Component Library (FCL)
- Copyright (c) 1999-2000 by the Free Pascal development team
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- {
- Based on getver by Bernd Juergens - Munich, Germany
- email :[email protected]
- Usage : Drop component on form. Set desired file name using
- FileVersionInfo.filename := 'c:\winnt\system32\comctl32.dll'
- or something like that.
- Read StringLists VersionStrings and VersionCategories.
- or check a single entry:
- FileVersionInfo1.fileName := 'd:\winnt\system32\comctl32.dll';
- showMessage(FileVersionInfo1.getVersionSetting('ProductVersion'));
- }
- unit fileinfo;
- {$mode objfpc}
- interface
- uses
- Windows, SysUtils, Classes;
- { Record to receive charset }
- type TTranslation = record
- langID : WORD;
- charset : WORD;
- end;
- type
- TFileVersionInfo = class(TComponent)
- private
- FFileName : String;
- FmyVersionStrings : TStringList;
- FmyVersionCategories : TStringList;
- procedure SetFileName (inp : string);
- procedure readVersionFromFile;
- protected
- { Protected-Deklarationen}
- public
- constructor Create(AOwner: TComponent); override;
- function getVersionSetting(inp : string): String;
- published
- property fileName : string read FFileName write SetFileName;
- property VersionStrings : TStringList read FmyVersionStrings;
- property VersionCategories : TStringList read FmyVersionCategories;
- end;
- implementation
- { initialize everything }
- constructor TFileVersionInfo.Create(AOwner: TComponent);
- begin
- FmyVersionStrings := TStringList.Create;
- FmyVersionCategories := TStringList.Create;
- FFileName := '';
- inherited create(Aowner);
- end;
- { Get filename, check if file exists and read info from file }
- procedure TFileVersionInfo.SetFileName (inp : string);
- begin
- FmyVersionStrings.clear;
- FmyVersionCategories.clear;
- if fileexists(inp) then
- begin
- FFileName := inp;
- readVersionFromFile;
- end
- else
- begin
- FFileName := '';
- end;
- end;
- { read info from file }
- procedure TFileVersionInfo.readVersionFromFile;
- var struSize : Dword;
- dwBytes,someDummy : Dword;
- a,txt : array[0..256] of char;
- p : pchar;
- i : integer;
- pp : pointer;
- theFixedInfo : TVSFixedFileInfo;
- theTrans : TTranslation;
- s : string;
- ts : TStringList;
- begin
- ts := TStringList.Create;
- ts.add('CompanyName');
- ts.add('FileDescription');
- ts.add('FileVersion');
- ts.add('InternalName');
- ts.add('LegalCopyright');
- ts.add('OriginalFilename');
- ts.add('ProductName');
- ts.add('ProductVersion');
- strPCopy(a,FFileName);
- { get size of data }
- struSize := GetFileVersionInfoSize(a,@someDummy);
- if struSize=0 then exit;
- p := NIL;
- try
- { get memory }
- GetMem(p,struSize+10);
- { get data }
- if not GetFileVersionInfo(a,0,struSize,p) then exit;
- { get root info }
- if not VerQueryValue(p,'\',pp,@dwBytes) then exit;
- move(pp^,theFixedInfo,dwBytes);
- { get translation info }
- if not VerQueryValue(p,'\VarFileInfo\Translation',pp,@dwBytes) then
- exit;
- move(pp^,theTrans,dwBytes);
- { iterate over defined items }
- for i:=0 to ts.count-1 do
- 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 dwBytes>0 then
- begin
- move(pp^,txt,dwBytes);
- FmyVersionCategories.add(ts[i]);
- FmyVersionStrings.add(StrPas(txt));
- end
- end;
- finally
- { release memory }
- FreeMem(p);
- end;
- end;
- { get single version string }
- function TFileVersionInfo.getVersionSetting(inp : string): String;
- var i : integer;
- begin
- result := '';
- for i:= 0 to FmyVersionCategories.Count -1 do
- begin
- if lowercase(FmyVersionCategories[i])=lowercase(inp) then
- begin
- result := FmyVersionStrings[i];
- break;
- end;
- end;
- end;
- end.
- {
- $Log$
- Revision 1.3 2000-07-25 11:27:34 jonas
- * fixed missing comment openers for log section
- Revision 1.2 2000/07/13 11:33:07 michael
- + removed logs
-
- }
|