/[projects]/dao/DelphiScanner/Utils.pas
ViewVC logotype

Diff of /dao/DelphiScanner/Utils.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2682 by torben, Wed Aug 26 19:52:38 2015 UTC revision 2693 by torben, Thu Sep 3 14:27:21 2015 UTC
# Line 20  type Line 20  type
20      class function TColorToHex(Color : TColor) : string;      class function TColorToHex(Color : TColor) : string;
21      class function HexToTColor(sColor : string) : TColor;      class function HexToTColor(sColor : string) : TColor;
22    
23        class function AdobeReaderExists(): Boolean;
24    
25        class function Sto_GetFmtFileVersion(const FileName: String = ''): String;
26    
27    
28    
29    
# Line 31  uses StrUtils, Line 35  uses StrUtils,
35    Types, //TRect ,    Types, //TRect ,
36    Windows,    Windows,
37    Messages,    Messages,
38    SysUtils //IntToStr etc    SysUtils, //IntToStr etc
39      Registry
40    
41    ;    ;
42    
43  {  {
# Line 161  begin Line 167  begin
167  end;  end;
168    
169    
170    class function TUtils.AdobeReaderExists(): Boolean;
171    var
172      AReg: TRegistry;
173    begin
174      result:= false;
175      AReg := TRegistry.Create;
176      AReg.RootKey := HKEY_LOCAL_MACHINE;
177      if AReg.KeyExists('\SOFTWARE\Adobe\Acrobat Reader') then
178        result:= True;
179      AReg.Free;
180    end;
181    
182    
183    /// <summary>
184    ///   This function reads the file resource of "FileName" and returns
185    ///   the version number as formatted text.</summary>
186    /// <example>
187    ///   Sto_GetFmtFileVersion() = '4.13.128.0'
188    ///   Sto_GetFmtFileVersion('', '%.2d-%.2d-%.2d') = '04-13-128'
189    /// </example>
190    /// <remarks>If "Fmt" is invalid, the function may raise an
191    ///   EConvertError exception.</remarks>
192    /// <param name="FileName">Full path to exe or dll. If an empty
193    ///   string is passed, the function uses the filename of the
194    ///   running exe or dll.</param>
195    /// <param name="Fmt">Format string, you can use at most four integer
196    ///   values.</param>
197    /// <returns>Formatted version number of file, '' if no version
198    ///   resource found.</returns>
199    class function TUtils.Sto_GetFmtFileVersion(const FileName: String = ''): String;
200    var
201      sFileName: String;
202      iBufferSize: DWORD;
203      iDummy: DWORD;
204      pBuffer: Pointer;
205      pFileInfo: Pointer;
206      iVer: array[1..4] of Integer;
207    begin
208      // set default value
209      Result := '';
210      // get filename of exe/dll if no filename is specified
211      sFileName := Trim(FileName);
212      if (sFileName = '') then
213        sFileName := GetModuleName(HInstance);
214      // get size of version info (0 if no version info exists)
215      iBufferSize := GetFileVersionInfoSize(PChar(sFileName), iDummy);
216      if (iBufferSize > 0) then
217      begin
218        GetMem(pBuffer, iBufferSize);
219        try
220        // get fixed file info (language independent)
221        GetFileVersionInfo(PChar(sFileName), 0, iBufferSize, pBuffer);
222        VerQueryValue(pBuffer, '\', pFileInfo, iDummy);
223        // read version blocks
224        iVer[1] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS);
225        iVer[2] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS);
226        iVer[3] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS);
227        iVer[4] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS);
228        finally
229          FreeMem(pBuffer);
230        end;
231    
232        // format result string
233        Result := Format('%d.%d.%d.%d', [iVer[1], iVer[2], iVer[3], iVer[4]]);
234    
235      end;
236    end;
237    
238    
239  end.  end.

Legend:
Removed from v.2682  
changed lines
  Added in v.2693

  ViewVC Help
Powered by ViewVC 1.1.20