madTools: GetFileVersion

delphi package - madRes, madTools, madStrings, ...
Post Reply
Nicka
Posts: 6
Joined: Mon Jan 18, 2010 11:26 am

madTools: GetFileVersion

Post by Nicka »

Hi
GetFileVersion returns the result only if there are only numbers fileversion
But some program\library does not contain VersionInfo, but contain String VersionInfo (oracleclient.dll)
Maybe add function GetFileVersionInfoStr

Code: Select all

function GetFileVersionStr(const AFileName: String) : String;
var
  P: Pointer;
  Value: Pointer;
  Len: DWORD;
  FHandle: DWORD;
  FBuffer: String;
  VerInt64: Int64;
begin
  VerInt64 := GetFileVersion(AFileName);
  if VerInt64 > 0 then
    Result := FileVersionToStr(VerInt64)
  else begin
    P := nil;
    Len := GetFileVersionInfoSize(PAnsiChar(AFileName), FHandle);
    if Len > 0 then
      SetLength(FBuffer, Len);
      if GetFileVersionInfo(PAnsiChar(AFileName), FHandle, Len, Pointer(FBuffer)) and
        VerQueryValue(Pointer(FBuffer), '\VarFileInfo\Translation', P, Len) and (P <> nil) then begin
        VerInt64 := MakeLong(HiWord(Longint(P^)), LoWord(Longint(P^)));
        if VerQueryValue(Pointer(FBuffer), PAnsiChar('\StringFileInfo\' +
          CopyR(IntToHexEx(VerInt64, 8), 8) + '\FileVersion'), Value, Len) then
          Result := PAnsiChar(Value);
      end;
  end;
end;
and Call this function in madExcept.pas and madListModules.pas

code

Code: Select all

        i64 := GetFileVersion(filePath);
        if i64 <> 0 then
          version := string(FileVersionToStr(i64));
replaced by

Code: Select all

  version := GetFileVersionStr(filePath);
madshi
Site Admin
Posts: 10749
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Thanks, I'll add that to my to do list.
Nicka
Posts: 6
Joined: Mon Jan 18, 2010 11:26 am

Post by Nicka »

Hi
What about implementation function GetFileVersionInfoStr ?
In the next release?
When? :)
madshi
Site Admin
Posts: 10749
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Could you please upload a sample dll which has no version number but only a string? That would help!
Nicka
Posts: 6
Joined: Mon Jan 18, 2010 11:26 am

Post by Nicka »

I sent a sample file to you by email.
madshi
Site Admin
Posts: 10749
Joined: Sun Mar 21, 2004 5:25 pm

Re: madTools: GetFileVersion

Post by madshi »

The latest beta build should contain this now:

http://madshi.net/madCollectionBeta.exe
Post Reply